passando una struttura a un metodo IDispatch
-
12-10-2019 - |
Domanda
In una terza parte COM Modulo devo passare una struttura a un metodo.
Le parti importanti del look definizione IDL in questo modo:
interface ITheirInterface : IDispatch {
[id(0x0000012d)]
HRESULT TheirMethod([in] TheirStruct Attributes);
};
struct TheirStruct {
BSTR TheirFieldA;
BSTR TheirFieldB;
} TheirStruct;
I Come chiamo il metodo da C ++ utilizzando 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);
Soluzione
il supporto di automazione COM per le strutture è molto debole, CComVariant non supporta direttamente. È necessario utilizzare IRecordInfo e creare una variante di tipo VT_RECORD. Ottenere il puntatore di interfaccia IRecordInfo da GetRecordInfoFromTypeInfo o GetRecordInfoFromGuids. Buona fortuna.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow