"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/script_com.h" (8 May 2021, 3830 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "script_com.h" see the Fossies "Dox" file reference documentation.

    1 #pragma once
    2 
    3 
    4 extern bool g_ComErrorNotify;
    5 
    6 
    7 class ComObject;
    8 class ComEvent : public ObjectBase
    9 {
   10     DWORD mCookie;
   11     ComObject *mObject;
   12     ITypeInfo *mTypeInfo;
   13     IID mIID;
   14     IObject *mAhkObject;
   15     TCHAR mPrefix[64];
   16 
   17 public:
   18     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
   19     STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId);
   20     STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
   21     
   22     // IObject::Invoke() and Type() are unlikely to be called, since that would mean
   23     // the script has a reference to the object, which means either that the script
   24     // itself has implemented IConnectionPoint (and why would it?), or has used the
   25     // IEnumConnections interface to retrieve its own object (unlikely).
   26     ResultType STDMETHODCALLTYPE Invoke(ExprTokenType &aResultToken, ExprTokenType &aThisToken, int aFlags, ExprTokenType *aParam[], int aParamCount)
   27     {
   28         return INVOKE_NOT_HANDLED;
   29     }
   30     IObject_Type_Impl("ComEvent") // Unlikely to be called; see above.
   31 
   32     HRESULT Connect(LPTSTR pfx = NULL, IObject *ahkObject = NULL);
   33 
   34     ComEvent(ComObject *obj, ITypeInfo *tinfo, IID iid)
   35         : mCookie(0), mObject(obj), mTypeInfo(tinfo), mIID(iid), mAhkObject(NULL)
   36     {
   37     }
   38     ~ComEvent()
   39     {
   40         mTypeInfo->Release();
   41         if (mAhkObject)
   42             mAhkObject->Release();
   43     }
   44 
   45     friend class ComObject;
   46 };
   47 
   48 
   49 class ComObject : public ObjectBase
   50 {
   51 public:
   52     union
   53     {
   54         IDispatch *mDispatch;
   55         IUnknown *mUnknown;
   56         SAFEARRAY *mArray;
   57         void *mValPtr;
   58         __int64 mVal64; // Allow 64-bit values when ComObject is used as a VARIANT in 32-bit builds.
   59     };
   60     ComEvent *mEventSink;
   61     VARTYPE mVarType;
   62     enum { F_OWNVALUE = 1 };
   63     USHORT mFlags;
   64 
   65     ResultType STDMETHODCALLTYPE Invoke(ExprTokenType &aResultToken, ExprTokenType &aThisToken, int aFlags, ExprTokenType *aParam[], int aParamCount);
   66     ResultType SafeArrayInvoke(ExprTokenType &aResultToken, int aFlags, ExprTokenType *aParam[], int aParamCount);
   67     LPTSTR Type();
   68 
   69     void ToVariant(VARIANT &aVar)
   70     {
   71         aVar.vt = mVarType;
   72         aVar.llVal = mVal64;
   73         // Caller handles this if needed:
   74         //if (VT_DISPATCH == mVarType && mDispatch)
   75         //  mDispatch->AddRef();
   76     }
   77 
   78     ComObject(IDispatch *pdisp)
   79         : mVal64((__int64)pdisp), mVarType(VT_DISPATCH), mEventSink(NULL), mFlags(0) { }
   80     ComObject(__int64 llVal, VARTYPE vt, USHORT flags = 0)
   81         : mVal64(llVal), mVarType(vt), mEventSink(NULL), mFlags(flags) { }
   82     ~ComObject()
   83     {
   84         if ((VT_DISPATCH == mVarType || VT_UNKNOWN == mVarType) && mUnknown)
   85         {
   86             if (mEventSink)
   87             {
   88                 mEventSink->Connect();
   89                 mEventSink->mObject = NULL;
   90                 mEventSink->Release();
   91             }
   92             mUnknown->Release();
   93         }
   94         else if ((mVarType & (VT_BYREF|VT_ARRAY)) == VT_ARRAY && (mFlags & F_OWNVALUE))
   95         {
   96             SafeArrayDestroy(mArray);
   97         }
   98     }
   99 
  100 #ifdef CONFIG_DEBUGGER
  101     void DebugWriteProperty(IDebugProperties *, int aPage, int aPageSize, int aDepth);
  102 #endif
  103 };
  104 
  105 
  106 class ComEnum : public EnumBase
  107 {
  108     IEnumVARIANT *penum;
  109 
  110 public:
  111     int Next(Var *aOutput, Var *aOutputType);
  112 
  113     ComEnum(IEnumVARIANT *enm)
  114         : penum(enm)
  115     {
  116     }
  117     ~ComEnum()
  118     {
  119         penum->Release();
  120     }
  121     IObject_Type_Impl("ComObject.Enumerator")
  122 };
  123 
  124 
  125 class ComArrayEnum : public EnumBase
  126 {
  127     ComObject *mArrayObject;
  128     char *mPointer, *mEnd;
  129     UINT mElemSize;
  130     VARTYPE mType;
  131 
  132     ComArrayEnum(ComObject *aObj, char *aData, char *aDataEnd, UINT aElemSize, VARTYPE aType)
  133         : mArrayObject(aObj), mPointer(aData - aElemSize), mEnd(aDataEnd), mElemSize(aElemSize), mType(aType)
  134     {
  135     }
  136 
  137 public:
  138     static HRESULT Begin(ComObject *aArrayObject, ComArrayEnum *&aOutput);
  139     int Next(Var *aOutput, Var *aOutputType);
  140     ~ComArrayEnum();
  141     IObject_Type_Impl("ComObjArray.Enumerator")
  142 };
  143 
  144 
  145 void ComError(HRESULT, LPTSTR = _T(""), EXCEPINFO* = NULL);
  146 
  147 bool SafeSetTokenObject(ExprTokenType &aToken, IObject *aObject);
  148