COM Interop.

G

Guest

I have a COM dll that I am consuming from C#, one of the methods is returning
an object as void** which gets converted to IntPtr in C#.

So the question is how do I convert the IntPtr to myObject wehre myObject is
of type IMyIface myObject; (I know that hte void** is of type IMyIface).
 
N

Nicholas Paldino [.NET/C# MVP]

Rahul,

I'm assuming that the double pointer to void is a parameter, so you pass
a pointer to a pointer to void (the declaration of the variable you pass is
void* and then you pass &ptr to the function). If that is the case, then
that maps to an IntPtr.

With the IntPtr, you can pass that to the static GetObjectForIUnknown
method on the Marshal class and it will give you an object that you can cast
to your interface.

Assuming that the method always returns that interface type, you could
define the parameter as a ref parameter of that interface type (i.e. ref
IMyFace output) and then use that. The COM interop layer should be able to
handle that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top