Fonction CreateDispTypeInfo (oleauto.h)
Crée des informations de type simplifiées à utiliser dans une implémentation d’IDispatch.
Syntaxe
HRESULT CreateDispTypeInfo(
INTERFACEDATA *pidata,
LCID lcid,
ITypeInfo **pptinfo
);
Paramètres
pidata
Description de l’interface décrite par ces informations de type.
lcid
Identificateur de paramètres régionaux pour les noms utilisés dans les informations de type.
pptinfo
Au retour, pointez vers une implémentation d’informations de type à utiliser dans DispGetIDsOfNames et DispInvoke.
Valeur retournée
Cette fonction peut retourner l’une de ces valeurs.
Code de retour | Description |
---|---|
|
L’interface est prise en charge. |
|
La description de l’interface ou le LCID n’est pas valide. |
|
Mémoire insuffisante pour terminer l’opération. |
Remarques
Vous pouvez construire des informations de type au moment de l’exécution à l’aide de CreateDispTypeInfo et d’une structure INTERFACEDATA qui décrit l’objet exposé.
Les informations de type retournées par cette fonction sont principalement conçues pour automatiser l’implémentation d’IDispatch. CreateDispTypeInfo ne retourne pas toutes les informations de type décrites dans Interfaces de description de type. L’argument pidata n’est pas une description complète d’une interface. Il n’inclut pas d’informations d’aide, de commentaires, de paramètres facultatifs et d’autres informations de type utiles dans différents contextes.
Par conséquent, la méthode recommandée pour fournir des informations de type sur un objet consiste à décrire l’objet à l’aide du langage ODL (Object Description Language) et à compiler la description de l’objet dans une bibliothèque de types à l’aide du compilateur MIDL (Microsoft Interface Definition Language).
Pour utiliser les informations de type d’une bibliothèque de types, utilisez les fonctions LoadTypeLib et GetTypeInfoOfGuid au lieu de CreateDispTypeInfo. Pour plus d’informations , type Description Interfaces.
Exemples
Le code suivant crée des informations de type à partir d’INTERFACEDATA pour exposer l’objet CCalc.
static METHODDATA NEARDATA rgmdataCCalc[] =
{
PROPERTY(VALUE, IMETH_ACCUM, IDMEMBER_ACCUM, VT_I4),
PROPERTY(ACCUM, IMETH_ACCUM, IDMEMBER_ACCUM, VT_I4),
PROPERTY(OPND, IMETH_OPERAND, IDMEMBER_OPERAND, VT_I4),
PROPERTY(OP, IMETH_OPERATOR, IDMEMBER_OPERATOR, VT_I2),
METHOD0(EVAL, IMETH_EVAL, IDMEMBER_EVAL, VT_BOOL),
METHOD0(CLEAR, IMETH_CLEAR, IDMEMBER_CLEAR, VT_EMPTY),
METHOD0(DISPLAY, IMETH_DISPLAY, IDMEMBER_DISPLAY, VT_EMPTY),
METHOD0(QUIT, IMETH_QUIT, IDMEMBER_QUIT, VT_EMPTY),
METHOD1(BUTTON, IMETH_BUTTON, IDMEMBER_BUTTON, VT_BOOL),
};
INTERFACEDATA NEARDATA g_idataCCalc =
{
rgmdataCCalc, DIM(rgmdataCCalc)
};
// Use Dispatch interface API functions to implement IDispatch.
CCalc *
CCalc::Create()
{
HRESULT hresult;
CCalc * pcalc;
CArith * parith;
ITypeInfo * ptinfo;
IUnknown * punkStdDisp;
extern INTERFACEDATA NEARDATA g_idataCCalc;
if((pcalc = new 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 |