none
Create COM object from Pointer RRS feed

  • Question

  • I'm not even sure this is possible, and I'm no expert on COM or Interop, so any help is appreciated.

    I have an application in C that uses COM objects. It exposes them to me via VBA. I've created a CCW for a simple library in C# which allows me to pass a COM reference between VBA and .NET in-process. I wanted to the advertise the object via Remoting so I don't have to close / open the host program during debugging for every iteration. All I need is a reference to a COM object the host C++ program creates.

    I haven't had any success with this yet getting a File Not Found HRESULT from fusion. I assume it's unable to find the COM RCW for the COM library.

    I was hoping I could dumb it down a bit instead. What if I passed an IntPtr via remoting to a .NET client, and then used the .NET client to create a reference to the COM object? Are COM objects safe to use out-of-process like this? How would I get the handle? How would I create the handle? Am I limited to late-binding all calls this way?
    Monday, July 13, 2009 8:43 PM

Answers

  • You can't pass a pointer from one process to another and expect it to be meaningful in the target process. Each process has its own virtual memory adress space.
    Mattias, C# MVP
    Tuesday, July 14, 2009 8:15 AM
    Moderator

All replies

  • You can't pass a pointer from one process to another and expect it to be meaningful in the target process. Each process has its own virtual memory adress space.
    Mattias, C# MVP
    Tuesday, July 14, 2009 8:15 AM
    Moderator
  • What about the Running Object's Table? How can I leverage that for inter-process communication? I know it's possible, but is there a better way? Should I just wrap it in a Remoting interface?
    Monday, July 20, 2009 6:50 PM
  • Making a COM object work out-of-process is a supported scenario.  However, your COM server is very likely an in-process server.  Turning it into an oop server takes a fair amount of work.  You have to generate the proxy/stub DLLs for the interfaces from the IDL.  Or use type library marshaling if the interfaces implement IDispatch and use OLE Automation compatible argument types.  If this sounds like Chinese, you probably don't want to pursue that.

    Hans Passant.
    Monday, July 20, 2009 7:25 PM
    Moderator
  • Right now I have the RCW I use for strong-typing the COM library in .NET. My .NET component has a CCW and I've loaded that into the application. Since my .NET object is loaded into the application (i.e. same virtual memory space) via COM I should be able to marshal the COM object by-ref using VBA to my .NET app. Once I have the object reference in .NET I'm free and clear. I currently use WCF to marshal remote calls to the object. In essense I've set up a remoting host to a COM object hosted in the C++ application by using a .NET component loaded into the VBA host.

    e.g.

    Dim SomeComObject As New SomeComObject   'ISomeComObject
    Dim MyDotNetCOMObject As New MyDotNetCOMObject
    MyDotNetCOMObject.Instance = SomeComObject


    The problem I'm having is that I'm getting a FileNotFound error from fusion when I try and and set the Instance property. I assume it's something silly with how it's trying to load a dependent DLL. Worst-case is that I'll find a pointer in VBA, send that to .NET instead, and I'll just custom-marshal it. I was hoping I was over-engineering it and maybe there was a simpler approach :(

    Monday, July 20, 2009 8:02 PM