How to pass structure between .NET and C ++ using COM?

I have a .NET library in my C ++ program using the following methods, but not an exhaustive list:

CorBindToRuntimeEx()
GetDefaultDomain()
CreateInstance()
GetIDsOfNames()

And finally, a challenge Invoke().

This works great for base types, enumerations, strings, and arrays. However, I cannot figure out how to convey the structure. Here is the skeleton of what I have now:

//library.cs  
public class AStruct
{
    public int i1;
    public string s1;
    public double d1;
}  

//...
public AStruct getAStruct();

//interop.cpp  
HRESULT hr = assembly->Invoke (id_getAStruct, ...);

The return value OUT PARAMfor this function is VARIANTwith a type VT_DISPATCH.

When I look retVal.pdispValin my debugger, I see that the contents of my structure are not close to this address. I would like to use varIDis.pdispVal->QueryInterface()to access my structure, but I have no idea what it IIDis and how to find it.

, .NET, Reflector. , .NET, , .

, .NET ++ COM?

.

+3
1

, . , #, ++, COM. getAStruct ( ?) IDispatch AStruct.

, - , ... ( ...)

. IDispatch *. AStruct , , , , : DISPID - 0x6002000. - 0x6002001 .. , , . , DISPIDs 0x60020000, . , , - , DISPIDs , .

, IDispatch:: Invoke IDispatch *, , DISPID wFlags = DISPATCH_PROPERTYGET/PUT.

, . , .

+1

All Articles