我将C++转换为C++/CLI,并将一些托管类公开为COM对象。在C#中,设置[ComVisible]非常简单;从接口继承(也是ComVisible)完成了该工作。
但是C++ C++项目构建并没有导出DLRealStServer。
下面是示例项目(从VS2008中的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<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}