Re: COM Interop.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Rahul Patel" <RahulPatel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D9498BC7-5F9B-4C15-BF5D-570BF6F86A25@xxxxxxxxxxxxxxxx
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).


.



Relevant Pages

  • Re: Void pointer to managed object type
    ... Typically you can solve that problem with the IntPtr type. ... pointer out of it. ... That's if you need to store a void* in a managed type. ... There are restrictions regarding tracking references and pointers. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: confusion: casting function pointers
    ... pointer from the 'actual/other modules' that takes arguments of type ... list to types of void *). ... int main{ ... without a prototype, a number of special "promotion" rules take ...
    (comp.lang.c)
  • Re: [RFC] timers, pointers to functions and type safety
    ... * they have callback of type void ... callback is called by the code that even in theory has no ... cast to unsigned long and cast back in the callback. ... number - not a pointer cast to unsigned long, not an index in array, etc. ...
    (Linux-Kernel)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... You can't do pointer arithmetic on a void* value. ... qsort behaves in a manner consistent with its specification. ... actually works as advertised...but doesn't mean that the cast is ...
    (comp.lang.c)
  • Re: The void** pointer breaking symmetry?
    ... void** is a generic pointer type that can be implicitly converted ... because dereferencing the void ** variable once gives ...
    (comp.lang.c)