在本机 COM 接口中托管 CLR,未解析的外部符号 _CStdStubBuffer_Release@4

发布于 2024-12-18 01:41:27 字数 2080 浏览 0 评论 0 原文

我正在尝试托管 CLR(目前不尝试使用 mono,尽管我可能会尝试)。基本上,我遵循以下内容:

http://www.lenholgate.com/blog/2010/07/clr-hosting---a-flexible-management-plugin-system-part-1.html

但是,我有一些COM 本身的麻烦,因为在那篇文章中没有那么彻底地解释它,而且我正在学习(以前没有使用过 COM)。

我定义了一个接口:

import "unknwn.idl";
[
    object,
    uuid(55d96f88-9633-4ad7-b9de-1a546ea73307),
    helpstring("INative interface"),
    pointer_default(unique)
]
interface INative : IUnknown
{
    HRESULT Write(BSTR s);
}
[
   object,
   uuid(74eeeaaa-d73c-436e-b52d-5c8a972ce60a),
   helpstring("ITestManager Interface"),
   pointer_default(unique)
]
interface IManagedHost : IUnknown
{
    HRESULT Init(INative* native);
}

并将生成的文件包含在我的本机项目中。但是,我无法构建可执行文件,因为链接器无法解析:_CStdStubBuffer_Release@4。 RpcRT4.lib 已链接,但我已运行 dumpbin rpcrt4.lib /all | grep _CStdStubBuffer_Release 并且没有类似该库导出的内容,有 CStdStubBuffer_DebugServerRelease。那么,问题是,如果该方法不应该存在,那么到底是什么引用了该方法?

做了一些更多的调查,我发现这个方法是通过IDL工具生成的.c文件引用的:

const CInterfaceStubVtbl _INativeStubVtbl =
{
    &IID_INative,
    &INative_ServerInfo,
    4,
    0, /* pure interpreted */
    CStdStubBuffer_METHODS
};

CStdStubBuffer_METHODS是在windows SDK v7的RpcProxy.h中定义的.0A

#define CStdStubBuffer_METHODS \
    CStdStubBuffer_QueryInterface,\
    CStdStubBuffer_AddRef, \
    CStdStubBuffer_Release, \
    CStdStubBuffer_Connect, \
    CStdStubBuffer_Disconnect, \
    CStdStubBuffer_Invoke, \
    CStdStubBuffer_IsIIDSupported, \
    CStdStubBuffer_CountRefs, \
    CStdStubBuffer_DebugServerQueryInterface, \
    CStdStubBuffer_DebugServerRelease

确实需要 CStdStubBuffer_Release 方法,尽管它与: http://msdn.microsoft.com /en-us/library/windows/desktop/ms764247%28v=VS.85%29.aspx

那我应该链接哪个其他库?

I'm experimenting with hosting CLR (not trying to use mono for now, though I will probably try). Basically, I'm following this:

http://www.lenholgate.com/blog/2010/07/clr-hosting---a-flexible-managed-plugin-system-part-1.html

However, I've got some troubles with COM itself, as it's not so thoroughly explained in that article, and I'm learning as I go (haven't been playing with COM before).

I've defined an interface:

import "unknwn.idl";
[
    object,
    uuid(55d96f88-9633-4ad7-b9de-1a546ea73307),
    helpstring("INative interface"),
    pointer_default(unique)
]
interface INative : IUnknown
{
    HRESULT Write(BSTR s);
}
[
   object,
   uuid(74eeeaaa-d73c-436e-b52d-5c8a972ce60a),
   helpstring("ITestManager Interface"),
   pointer_default(unique)
]
interface IManagedHost : IUnknown
{
    HRESULT Init(INative* native);
}

And included generated files in my native project. However, I can't build the executable, because linker cannot resolve: _CStdStubBuffer_Release@4. The RpcRT4.lib is linked, but I've run dumpbin rpcrt4.lib /all | grep _CStdStubBuffer_Release and there is nothing like that exported by that library, there is CStdStubBuffer_DebugServerRelease. So, question is what exactly references that method, if it supposedly should not exist?

Did some more investigation, and I've found out that this method is referenced via the .c file that is generated by IDL tool:

const CInterfaceStubVtbl _INativeStubVtbl =
{
    &IID_INative,
    &INative_ServerInfo,
    4,
    0, /* pure interpreted */
    CStdStubBuffer_METHODS
};

and CStdStubBuffer_METHODS are defined in RpcProxy.h of windows SDK v7.0A:

#define CStdStubBuffer_METHODS \
    CStdStubBuffer_QueryInterface,\
    CStdStubBuffer_AddRef, \
    CStdStubBuffer_Release, \
    CStdStubBuffer_Connect, \
    CStdStubBuffer_Disconnect, \
    CStdStubBuffer_Invoke, \
    CStdStubBuffer_IsIIDSupported, \
    CStdStubBuffer_CountRefs, \
    CStdStubBuffer_DebugServerQueryInterface, \
    CStdStubBuffer_DebugServerRelease

which indeed wants that CStdStubBuffer_Release method, though it's a bit different than: http://msdn.microsoft.com/en-us/library/windows/desktop/ms764247%28v=VS.85%29.aspx.

What other library should I link then?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟稳重的好男人 2024-12-25 01:41:27

CStdStubBuffer_Release() 由 midl.exe 自动生成的另一个文件 dlldata.c 实现。 DLLDATA_ROUTINES 宏生成它。

这个问题指向项目配置错误,听起来像是您将代理 .c 文件添加到主项目中,而不是在代理/存根项目中使用它。它还消耗 dlldata.c。我非常确定自定义 CLR 主机中不需要代理/存根,因此只需删除 .c 文件即可。

CStdStubBuffer_Release() is implemented by another file that's auto-generated by midl.exe, dlldata.c. The DLLDATA_ROUTINES macro generates it.

This problem is pointing to a project configuration mistake, sounds like you added the proxy .c file to your main project instead of using it in the proxy/stub project. Which also consumes the dlldata.c. I'm pretty sure there is no need for the proxy/stub in a custom CLR host, so simply remove the .c file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文