le passage d'une structure à une méthode IDispatch
-
12-10-2019 - |
Question
Dans un tiers COM Module Je dois passer un struct à une méthode.
Les parties importantes du regard de la définition IDL comme ceci:
interface ITheirInterface : IDispatch {
[id(0x0000012d)]
HRESULT TheirMethod([in] TheirStruct Attributes);
};
struct TheirStruct {
BSTR TheirFieldA;
BSTR TheirFieldB;
} TheirStruct;
Je comment puis-je appeler la méthode de C ++ en utilisant l'ATL?
CComPtr<IDispatch> comPtr;
comPtr.CoCreateInstance(L"theirModule.TheirCoClass");
CComVariant returnValue;
CComVariant attribute= I_DO_NOT_KNOW_WHAT_TO_PLACE_HERE;
comPtr.Invoke1(T2COLE(L"TheirMethod"),&attribute,&returnValue);
La solution
COM support d'automatisation des structures est très faible, CComVariant ne supporte pas directement. Vous devez utiliser IRecordInfo et créer une variante de type VT_RECORD. Obtenir le pointeur d'interface IRecordInfo de GetRecordInfoFromTypeInfo ou GetRecordInfoFromGuids. Bonne chance.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow