IDispatch

IDispatch is the interface that exposes the OLE Automation protocol. It is extended and derived from IUnknown. It is one of the standard interfaces that can be exposed by COM objects.

IDispatch IDL definition

[
  object,
  uuid(00020400-0000-0000-C000-000000000046),
  pointer_default(unique)
]

interface IDispatch : IUnknown
{
  HRESULT GetTypeInfoCount(
              [out] UINT * pctinfo
            );

  HRESULT GetTypeInfo(
                [in] UINT iTInfo,
                [in] LCID lcid,
                [out] ITypeInfo ** ppTInfo
            );

  HRESULT GetIDsOfNames(
                [in] REFIID riid,
                [in, size_is(cNames)] LPOLESTR * rgszNames,
                [in] UINT cNames,
                [in] LCID lcid,
                [out, size_is(cNames)] DISPID * rgDispId
            );

  HRESULT Invoke(
                [in] DISPID dispIdMember,
                [in] REFIID riid,
                [in] LCID lcid,
                [in] WORD wFlags,
                [in, out] DISPPARAMS * pDispParams,
                [out] VARIANT * pVarResult,
                [out] EXCEPINFO * pExcepInfo,
                [out] UINT * puArgErr
            );
}

IDispatch C++ definition

IDispatch is derived from IUnknown. So QueryInterface, AddRef and Release virtual functions will be at the top of the vTable entries. Below four functions will be added after those three entries.

class IDispatch : public IUnknown
{
public:

  virtual __stdcall HRESULT GetTypeInfoCount(UINT * pctinfo
            ) = 0;

  virtual __stdcall HRESULT GetTypeInfo(
                UINT iTInfo,
                LCID lcid,
                ITypeInfo ** ppTInfo
            ) = 0;

  virtual __stdcall HRESULT GetIDsOfNames(
                REFIID riid,
                LPOLESTR * rgszNames,
                UINT cNames,
                LCID lcid,
                DISPID * rgDispId
            ) = 0;

  virtual __stdcall HRESULT Invoke(
                DISPID dispIdMember,
                REFIID riid,
                LCID lcid,
                WORD wFlags,
                DISPPARAMS * pDispParams,
                VARIANT * pVarResult,
                EXCEPINFO * pExcepInfo,
                UINT * puArgErr
            ) = 0;
};

IDispatch methods

GetTypeInfoCount

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

GetTypeInfo

Retrieves the type information for an object, which can then be used to get the type information for an interface.

GetIDsOfNames

Maps a single member and an optional set of argument names to a corresponding set of integer DISPIDs, which can be used on subsequent calls to Invoke.

Invoke

Provides access to properties and methods exposed by an object.

About our authors: Team EQA

You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

#