Export (0) Print
Expand All

CreateStdDispatch Function

Creates a standard implementation of the IDispatch interface through a single function call. This simplifies exposing objects through Automation.

HRESULT CreateStdDispatch(  
  IUnknown FAR*  punkOuter,        
  void FAR*  pvThis,               
  ITypeInfo FAR*  ptinfo,          
  IUnknown FAR* FAR* ppunkStdDisp  
);

punkOuter

Pointer to the object's IUnknown implementation.

pvThis

Pointer to the object to expose.

ptinfo

Pointer to the type information that describes the exposed object.

ppunkStdDisp

This is the private unknown for the object that implements the IDispatch interface QueryInterface call. This pointer is Null if the function fails.

The return value obtained from the returned HRESULT is one of the following:

Return value

Meaning

S_OK

Success.

E_INVALIDARG

One of the first three arguments is invalid.

E_OUTOFMEMORY

There was insufficient memory to complete the operation.

You can use CreateStdDispatch when creating an object instead of implementing the IDispatch member functions for the object. However, the implementation that CreateStdDispatch creates has these limitations:

  • Supports only one national language.

  • Supports only dispatch-defined exception codes returned from Invoke.

LoadTypeLib, GetTypeInfoOfGuid, and CreateStdDispatch comprise the minimum set of functions that you need to call to expose an object using a type library. For more information on LoadTypeLib and GetTypeInfoOfGuid, see Type Description Interfaces.

CreateDispTypeInfo and CreateStdDispatch comprise the minimum set of dispatch components you need to call to expose an object using type information provided by the INTERFACEDATA structure.

The following code implements the IDispatch interface for the CCalc class using CreateStdDispatch.

CCalc FAR*
CCalc::Create()
{
   HRESULT hresult;
   CCalc FAR* pcalc;
   CArith FAR* parith;
   ITypeInfo FAR* ptinfo;
   IUnknown FAR* punkStdDisp;
extern INTERFACEDATA NEARDATA g_idataCCalc;

   if((pcalc = new FAR CCalc()) == NULL)
      return NULL;
   pcalc->AddRef();

   parith = &(pcalc->m_arith);

   // Build type information for the functionality on this object that
   // is being exposed for external programmability.
   hresult = CreateDispTypeInfo(
      &g_idataCCalc, LOCALE_SYSTEM_DEFAULT, &ptinfo);
   if(hresult != NOERROR)
      goto LError0;

   // Create an aggregate with an instance of the default
   // implementation of IDispatch that is initialized with
   // type information.
   hresult = CreateStdDispatch(
      pcalc,            // Controlling unknown.
      parith,            // Instance to dispatch on.
      ptinfo,            // Type information describing the instance.
   &punkStdDisp);

   ptinfo->Release();

   if(hresult != NOERROR)
      goto LError0;

   pcalc->m_punkStdDisp = punkStdDisp;

   return pcalc;

LError0:;
   pcalc->Release();
   return NULL;
}
Show:
© 2014 Microsoft