Why would QueryInterface() fail when the interface is surely implemented and has built-in marshaller in Windows?

让人想犯罪 __ 提交于 2019-12-02 03:35:24

One of the possible scenarios that matches the behavior is the following:

  • you don't have any marhshaling between caller and callee
  • the interface pointer is valid
  • however the object which implements IStream, does not have a corresponding COM_INTERFACE_ENTRY map entry and does not make the interface available, the caller might have obtained the pointer via non-COM way, e.g. direct C++ cast

This is easy to check by QueryInterface'ing the stream on the caller side before the call.

The callee in this scenario can just reinterpret_cast to IStream and have it nicely working.

You can either have your IDL import objidl.idl, or define IStream (and ancestors) manually in your own IDL (just be sure to use the standard IID value for it). Then you can use IStream instead of IUnknown as your parameter type and not worry about QueryInterface() anymore.

you may replace IUnknown by IDispatch as parameter type of your method. In my mind, the server actually has a stub instead of the stream itself since it is in another process.

this is just a guess

I hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!