How do I pass an IUnknown** pointer from C++ COM to C# RRS feed

  • Question

  • Hi,

    I need to pass an IUnknown** pointer to a C# module through COM interop. I can add a method in an interface to on the C# side to handle this. The question is how do I handle it on the C# side

    For example, from the C++ COM side I have access to the C# module through some interface, say m_pMyInterface:

    Also, this IUnknown interface pointer is actually some other interface which derives from IUnknown, say IProgInterace.

    IUnknown** pUnknown = <some_value>;


    How do I handle this parameter in C#? Should it be an IntPtr, and if so how do I convert it back to the desired interface (IProgInterface) to call its methods?



    Thursday, July 19, 2018 12:28 PM

All replies

  • If you don't need to do anything with the pointer then use IntPtr. If you need to call functions on it then you need to import the COM definition into .NET (or write it yourself). Then use the generated C# interface (by ref) instead. You can then call methods on the interface object you get.

    Michael Taylor

    Thursday, July 19, 2018 1:47 PM