0

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# client

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();
    }

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.

4

1 回答 1

2

为了使其在进程外工作,您需要在进程之间编组接口。您很可能希望依赖自动化编组,它使用从 IDL 生成的类型库来查找编组的内容和方式。问题在于,这仅适用于 IDL中标记为 的接口[oleautomation],或两者兼有。有关更多详细信息,请参阅此答案[dual]

你最好的办法是标记你想要编组的接口,[oleautomation]并添加一个评论,比如“如果你删除它,编组魔法就会消失”。

于 2013-07-26T07:49:49.577 回答