pasando una struct a un método IDispatch
-
12-10-2019 - |
Pregunta
En un tercero COM Módulo tengo que pasar una estructura a un método.
Las partes importantes de la mirada definición IDL como esto:
interface ITheirInterface : IDispatch {
[id(0x0000012d)]
HRESULT TheirMethod([in] TheirStruct Attributes);
};
struct TheirStruct {
BSTR TheirFieldA;
BSTR TheirFieldB;
} TheirStruct;
Como llamar en el método de C ++ con la 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);
Solución
apoyo a la automatización COM para estructuras es muy débil, CComVariant no soporta directamente. Es necesario utilizar IRecordInfo y crear una variante del tipo VT_RECORD. Obtener el puntero de interfaz IRecordInfo de GetRecordInfoFromTypeInfo o GetRecordInfoFromGuids. Buena suerte.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow