You just need to use interop to describe your function GetFactory, something like this
[DllImport("myfakecom.dll")]
[return: MarshalAs(UnmanagedType.IUnknown)]
static extern object GetFactory();
Then, if you have an object in managed code. Cast is the equivalent of QueryInterface
void Foo(Object unk)
{
IMyType mytype = (IMyType)unk;
}
You will need to duplicate C ++ interface definitions as C # interface definitions, possibly with [marshalas] attributes. But since you have already done this, the rest should be easy.
I would suggest that you change the factory prototype from
IUnknown * GetFactory();
to
HRESULT GetFactory([out] IUnknown ** ppunk);
It seems that the COM iterop code has a strong assumption that all COM methods return HRESULT, and it will be easier to get marshalling to work if you go there with a stream.
source
share