我正在尝试托管 CLR(暂时不尝试使用单声道,尽管我可能会尝试)。基本上,我正在关注这个:
http://www.lenholgate.com/blog/2010/07/clr-hosting---a-flexible-managed-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 在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有点不同。
那我应该链接什么其他图书馆?