无法在另一个进程中获取COM接口。 [英] Can't get a COM interface in another process.

查看:94
本文介绍了无法在另一个进程中获取COM接口。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我遇到了COM问题。我没有找到COM的类别,所以我把它放在这里。

I encounter a COM issue. I didn't find a category of COM, so I put it here.

我的问题是:

在进程A中,我想在另一个进程中获取一个接口,但是当我得到接口时,指针是空值。就像这样:

In process A, I want to get an interface in another process, but when I got the interface, the pointer is null. Just like this:

在我的设计中,接口管理器可以由组件2获得,接口控制器可以由组件3获得。通过接口2,组件1可以获得接口控制器。

In my design, the interface manager could be got by component 2 and the interface controller could be got by component 3. And through interface 2, component 1 could got the interface controller.

组件2是现有组件,它具有加载组件3的实现,因此组件1可以轻松获得接口管理器:

The component 2 is an existing component and it has the implementation to load component 3, so component 1 could get the interface manager easily:

在组件1中,此代码可用于获取接口管理器:

In component 1, this code could be used to get interface manager:

CComPtr<IUnknown> pUnk;
BindService(pUnk);

CComPtr<IManager> pMgr;
pUnk->QueryInterface(IID_IManager, (void**)pMgr);

这是BindService()的实现:

And this is the implementation of BindService():

...
CoCreateInstance(CLSID_Manager, NULL, CLSCTX_SERVER, IID_IManager, (void**)pIf);
...
pIf->Bind(ppUnk); // ppUnk is a IUnknown pointer parameter
...




Bind的实现:


The implementation of Bind:

//It's just return an IUnknown pointer.
...
return AtlComPtrAssign(ppUnk, GetUnknown()) != NULL ? S_OK : E_NOINTERFACE;

在上面的过程中,接口管理器可以成功,但是当我使用这个接口来获取接口控制器时,会发生错误。

我在接口管理器中实现了一个很可能是BindService函数的方法:

In the process above, the interface manager could be got successfully, but when I use this interface to get the interface controller, something wrong happens.
I implement a method in interface manager which is very likely to the BindService function:

HRESULT Load(IUnknown** pUnk) { CoCreateInstance(CLSID_Controller, NULL, CLSCTX_SERVER, IID_IContrller, (void**)pIf); ... pIf->Bind(ppUnk); ... }

// Bind()的实现与上述相同。

// The implementation of Bind() is the same with above.

所以我可以在进程A中使用接口管理器并调用Load()方法来加载组件4并获取接口控制器。在方法Load()中,接口控制器和IUnknown可以成功获得,但是当此方法返回时,在Process
A中,调用者获得的接口为NULL。这意味着,尽管Load()方法成功,但接口控制器值未传递给进程A.

So I could use interface manager in Process A and call the Load() method to load the component 4 and get the interface controller. In method Load(), the interface controller and IUnknown could be got successfully, but when this method returns, in Process A, the caller got the interface is NULL. That means, though the Load() method succeeds, but the interface controller value is not passed to Process A.

我不知道为什么会发生这种情况,因为我使用相同的方式获取接口管理器成功。

从我的调试结果来看,似乎该值未传递给进程A而不是接口控制器已发布。

I don't know why this happens because I use the same way get the interface manager successfully.
From my debug result, it seems that the value is not passed to process A rather than the interface controller released.

感谢所有建议和帮助!

推荐答案

你好Claude Zhao,

Hi Claude Zhao,

我已经把这个案子移到了Visual C ++论坛。

I've moved this case to Visual C++ forum for you.


这篇关于无法在另一个进程中获取COM接口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆