ATL进程外回调接口上的“未注册接口"错误 [英] 'Interface not Registered' error on ATL out-of-process callback interface

查看:171
本文介绍了ATL进程外回调接口上的“未注册接口"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ATL进程内服务器,该服务器实现了这样的回调接口:

I have an ATL in-process server that implements a callback interface like so:

.idl

interface IClientEvents : IUnknown{
    [] HRESULT TestEvent(void);
};

interface IATLSimpleObject : IDispatch{

    [id(1)] HRESULT Advise([in] IClientEvents* clientEvents);
    [id(2)] HRESULT Unadvise(void);
};

.h

private:
    IClientEvents* m_ClientEvents;
public:
    STDMETHOD(Advise)(IClientEvents* clientEvents);
    STDMETHOD(Unadvise)(void);

.cpp

STDMETHODIMP CATLSimpleObject::Advise(IClientEvents* clientEvents)
{
    m_ClientEvents = clientEvents;
    m_ClientEvents->AddRef();

    return S_OK;
}

STDMETHODIMP CATLSimpleObject::Unadvise(void)
{
    m_ClientEvents->Release();
    m_ClientEvents = NULL;

    return S_OK;
}

C#客户端

public partial class Form1 : Form, ATLProject1Lib.IClientEvents
{
    private ATLProject1Lib.ATLSimpleObject ATLSimple = new ATLProject1Lib.ATLSimpleObject();

    private void Form1_Shown(object sender, EventArgs e)
    {
        ATLSimple.Advise(this);
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        ATLSimple.Unadvise();
    }

它工作正常,但是我需要在进程外服务器中执行完全相同的操作,但是,在执行时,调用"ATLSimple.Advise(this)"时出现未注册接口"(80040105)错误.

It works fine, but I need to do exactly the same in an out-of-process server, however, on execution I get an 'Interface not Registered' (80040105) error when calling 'ATLSimple.Advise(this)'.

我已经花了数小时寻找类似的问题,但找不到任何东西.任何帮助将不胜感激.

I've spent hours searching for similar problems, but can't find anything. Any help would be greatly appreciated.

推荐答案

为使此过程无法正常进行,您需要在进程之间编排接口.您最有可能希望依靠自动化编组,该编组使用从IDL生成的typelib查找要编组的内容和方式.问题是,这仅适用于在IDL中标记为[oleautomation][dual]或两者都标记为接口的接口. 有关更多详细信息,请参见此答案.

In order for this to work out-of-proc you need the interfaces to be marshalled between processes. Most likely you will want to rely on Automation marshalling which uses a typelib generated from your IDL to find what and how to marshall. The problem is that will only work for interfaces that are marked [oleautomation], [dual] or both in the IDL. See this answer for more details.

最好的选择是将要编组的接口标记为[oleautomation],并添加诸如如果删除此编组魔术就会消失"之类的注释.

You best bet is marking the interfaces you want marshalled as [oleautomation] and adding a comment like "Marshalling magic goes away if you remove this".

这篇关于ATL进程外回调接口上的“未注册接口"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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