How to use IDispatch in plain C to call a COM object

后端 未结 3 1405
时光取名叫无心
时光取名叫无心 2020-12-07 23:51

I need to compile some code of mine using the gcc compiler included in the R tools (R the statistical program for windows), the problem is that I need to use IDispatch in my

3条回答
  •  半阙折子戏
    2020-12-08 00:17

    In general, a C++ IDispatch interface is just a table of function pointers. In C, it would look something like:

    typedef struct {
      HRESULT(*pQueryInterface)(void* this, REFIID riid, void **ppvObject);
      ULONG(*pAddRef)(void* this);
      ULONG(*pRelease)(void* this);
      HRESULT(*pGetTypeInfoCount)(void* this, unsigned int* pctInfo);
      HRESULT(*pGetTypeInfo)(void* this, unsigned int iTInfo,LCID lcid, ITypeInfo** ppTInfo);
      HRESULT(*pGetIDsOfNames)(void* this, REFIID riid, OLECHAR** rgszNames, unsigned int cNames, LCID lcid, DISPID* rgDispId);
     HRESULT(*pInvoke)(void* this, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, unsigned int* puArgErr);
    } IDispatch_in_C;
    

    Note that every method has a THIS pointer as the first parameter, and that you will need to define more types, such as ITypeInfo, REFIID, DISPID, etc, etc.

    So, its a big task. But it is possible to create C++ interfaces in pure C.

提交回复
热议问题