在C ++ / CLI中是可见的

我正在将C ++转换为C ++ / CLI,并希望将一些托管类公开为COM对象。 在C#中它很容易并且设置[ComVisible]并inheritance自接口(也是ComVisible)完成了这项工作。 但是,作为C ++ / CLI的C ++项目构建不会导出DllRegisterServer。

这是示例项目(从VS 2008中的CLR控制台应用程序项目开始)。

#include "stdafx.h" using namespace System; using namespace System::Runtime::InteropServices; [ComVisible(true)] [Guid("E3CF8A18-E4A0-4bc3-894E-E9C8648DC1F0")] [InterfaceType(ComInterfaceType::InterfaceIsDual)] public interface class ITestInterface { void TestMethod(); }; [ComVisible(true)] [Guid("1514adf6-7cb0-4561-9fbb-b75c0467149b")] public ref class CliComClass : ITestInterface { public: virtual void TestMethod() { } }; int main(array ^args) { Console::WriteLine(L"Hello World"); return 0; } 

当我在输出.exe上运行regsvr32时,我收到错误,说没有找到DllRegisterServer。 我试过谷歌一些帮助,但没有成功。

您需要使用TlbExp ,TlbExp是用于将托管类导出到COM的工具,它将读取程序集找到ComVisible类型并注册它们。