gpt4 book ai didi

c# - ATL 进程外回调接口(interface)上的“接口(interface)未注册”错误

转载 作者:行者123 更新时间:2023-11-28 03:12:55 24 4
gpt4 key购买 nike

我有一个 ATL 进程内服务器,它实现了这样一个回调接口(interface):

.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)”时出现“未注册接口(interface)”(80040105) 错误.

我花了几个小时搜索类似的问题,但找不到任何东西。任何帮助将不胜感激。

最佳答案

为了使其在进程外工作,您需要在进程之间编码接口(interface)。您很可能希望依赖自动化编码,它使用从您的 IDL 生成的类型库来查找编码内容和方式。问题是它只适用于在 IDL 中标记为 [oleautomation][dual] 或两者的接口(interface)。 See this answer for more details .

最好的办法是将要编码的接口(interface)标记为 [oleautomation] 并添加评论,例如“如果删除它,编码魔法就会消失”。

关于c# - ATL 进程外回调接口(interface)上的“接口(interface)未注册”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17875073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com