CreateStdDispatch, fonction (oleauto.h)

Crée une implémentation standard de l’interface IDispatch par le biais d’un appel de fonction unique. Cela simplifie l’exposition d’objets via Automation.

Syntaxe

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

Paramètres

punkOuter

Implémentation IUnknown de l’objet.

pvThis

Objet à exposer.

ptinfo

Informations de type qui décrivent l’objet exposé.

ppunkStdDisp

Privé inconnu pour l’objet qui implémente l’appel QueryInterface de l’interface IDispatch . Ce pointeur est null si la fonction échoue.

Valeur retournée

Cette fonction peut retourner l’une de ces valeurs.

Code de retour Description
S_OK
Réussite.
E_INVALIDARG
L’un des trois premiers arguments n’est pas valide.
E_OUTOFMEMORY
La mémoire était insuffisante pour terminer l’opération.

Remarques

Vous pouvez utiliser CreateStdDispatch lors de la création d’un objet au lieu d’implémenter les fonctions membres IDispatch pour l’objet . Toutefois, l’implémentation créée par CreateStdDispatch présente les limitations suivantes :

  • Prend en charge une seule langue nationale.
  • Prend en charge uniquement les codes d’exception définis par la distribution retournés par Invoke.

LoadTypeLib, GetTypeInfoOfGuid et CreateStdDispatch constituent l’ensemble minimal de fonctions que vous devez appeler pour exposer un objet à l’aide d’une bibliothèque de types. Pour plus d’informations sur LoadTypeLib et GetTypeInfoOfGuid, consultez Interfaces de description de type.

CreateDispTypeInfo et CreateStdDispatch constituent l’ensemble minimal de composants de dispatch que vous devez appeler pour exposer un objet à l’aide des informations de type fournies par la structure INTERFACEDATA.

Exemples

Le code suivant implémente l’interface IDispatch pour la classe CCalc à l’aide de CreateStdDispatch.

CCalc FAR*
CCalc::Create()
{
   HRESULT hresult;
   CCalc * pcalc;
   CArith * parith;
   ITypeInfo* ptinfo;
   IUnknown * 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;
}

Configuration requise

Condition requise Valeur
Plateforme cible Windows
En-tête oleauto.h
Bibliothèque OleAut32.lib
DLL OleAut32.dll

Voir aussi

Création de fonctions d’API Dispatch

IDispatch