Invoke COM object RRS feed

  • Question

  • How can I work from C# with interface instance received in IntPtr through Marshal.QueryInterface() ? I need to get/set instance properties, and, may be, call methods.

    I suspect I should use Marshal.GetTypeForITypeInfo(), but 1st I must to do thing similar to above - get ITypeInfo from IDispatch instance - it requires COM object invoking again.


    Monday, May 3, 2010 1:26 PM


All replies

  • Do you have a managed representation of the COM interface? If so, you can use Marshal.Get[Typed]ObjectForIUnkown.


    Mattias, C# MVP
    • Marked as answer by SamAgain Monday, May 24, 2010 10:08 AM
    Monday, May 3, 2010 2:02 PM
  • Actually, I'm working with VS2010 SDK, traversing opened solution and trying to use Reference interface (uuid(35D6FB50-35B6-4c81-B91C-3930B0D95386)) from

    Microsoft Visual Studio 2010 SDK\VisualStudioIntegration\Common\IDL\vslangproj.idl

    I already have System.__ComObject instance for solution tree node and I successfully queried Reference interface from it.



    My current idea is: can I import vslangproj.idl (partially, for "Reference" only) and use some generated .NET wrapper class ?

    Tuesday, May 4, 2010 7:16 AM
  • Hi AlexNG2,

        Hope the following reference could be helpful.

        COM Interop Part 1: C# Client Tutorial



    Please mark the right answer at right time.
    • Marked as answer by SamAgain Monday, May 17, 2010 10:01 AM
    Thursday, May 13, 2010 9:28 AM