I'm hosting a .NET library in my C++ program using the following methods, though not an exhaustive list:
CorBindToRuntimeEx()
GetDefaultDomain()
CreateInstance()
GetIDsOfNames()
And eventually a call to Invoke().
This works fine for basic types, enums, strings, and arrays. However, I cannot figure out how to pass a struct. Here's a 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 OUT PARAM return value of this function is a VARIANT with type VT_DISPATCH.
When I view retVal.pdispVal in my debugger, I can see that the contents of my struct are not near that address. I'd like to use varIDis.pdispVal->QueryInterface() to access my struct, but I have no idea what the IID is, nor how to discover it.
Also, I don't have the source code to the .NET library, though I can see much of it with Reflector. I'm using a test library I wrote in .NET to figure out how to proceed.
So, how can I pass and receive structs between .NET and C++ using COM?
Thanks greatly.