CoCreateInstance returning E_NOINTERFACE even though interface is found

后端 未结 4 1267
温柔的废话
温柔的废话 2020-12-05 20:58

I have a COM class CMyCOMServer implementing IMyInterface in one application, both with correct GUIDs. CMyCOMServer::QueryInterface wi

4条回答
  •  一向
    一向 (楼主)
    2020-12-05 22:00

    If your COM server is running in a different process, or a different apartment in the same process, COM needs to know how to package and transmit parameters when you make calls to your interface. This process is called "marshaling".

    If you define a custom interface, you need to implement marshaling for it using one of the following approaches.

    • Standard marshaling: have the MIDL compiler to generate a proxy and stub which you must register on the system. This is probably the best option since you have already defined your interface.
    • OLE Automation marshaling: you define an automation compatible custom interface and use the marshaller which is already part of the COM framework
    • Custom marshaling: you implement the methods of IMarshal

    When you are debugging your COM server, although you see that you are returning your custom interface in the call to QueryInterface, it does not make it across the process boundary because COM cannot figure out how to marshal that interface, hence the client sees E_NOINTERFACE.

    UPDATE (based on your comment)

    If this is an existing COM server app then you probably already have a proxy/stub. You need to register this on both the client and server. Could it be that you were testing this on a new machine(s) and you simply forgot to register this? To register you simply do regsvr32 on the proxy/stub dll.

提交回复
热议问题