com - 在 native 中托管 CLR - COM 接口(interface),未解析的外部符号 _CStdStubBuffer_Release@4

标签 com linker idl unresolved-external clr-hosting

我正在尝试托管 CLR(暂时不尝试使用单声道,尽管我可能会尝试)。基本上,我正在关注这个:

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

但是,我在使用 COM 本身时遇到了一些问题,因为在那篇文章中没有对它进行彻底的解释,而且我边走边学(以前没有玩过 COM)。

我定义了一个接口(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);
}

并将生成的文件包含在我的 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 在 RpcProxy.h 中定义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

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

那我应该链接什么其他图书馆?

最佳答案

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

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

关于com - 在 native 中托管 CLR - COM 接口(interface),未解析的外部符号 _CStdStubBuffer_Release@4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8278722/

相关文章:

c# - 如何将 IDL 翻译成 C#?

c++ - 为什么修改IDL会导致C++项目崩溃,而VB项目不会?

silverlight - Com Interop 问题 Silverlight 4 和 MS Access 2010

ubuntu - 将 OpenCL.so 库添加到 makefile,我收到错误 "undefined reference to"

c++ - g++ 无法链接 curl lib 文件

c++ - COM:如何将特定类型的 COM 对象指定为 idl 中的参数

c# - 用 C# 编写的托管 OleDB 提供程序

php - COM 对象方法未定义

使用纯 C 创建 COM 对象

c++ - 如何调试 STL/C++ 的 GCC/LD 链接过程