COM Interop.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UmFodWwgUGF0ZWw=?=

    #1

    COM Interop.

    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).
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: COM Interop.

    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 GetObjectForIUn known
    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@spam.guard. caspershouse.co m

    "Rahul Patel" <RahulPatel@dis cussions.micros oft.comwrote in message
    news:D9498BC7-5F9B-4C15-BF5D-570BF6F86A25@mi crosoft.com...
    >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).

    Comment

    Working...