ComVisible在C ++ / CLI [英] ComVisible in C++/CLI
问题描述
我正在将C ++转换为C ++ / CLI,并希望将一些托管类公开为COM对象。在C#中很容易和设置[ComVisible]&继承自interface(也是ComVisible)做的工作。
但是C ++项目构建为C ++ / CLI不导出DllRegisterServer。
i'm converting C++ to C++/CLI and would like to expose some managed classes as COM objects. In C# it was easy and setting [ComVisible] & inheriting from interface (also ComVisible) did the job. However C++ project build as C++/CLI does not export DllRegisterServer.
以下是示例项目(从VS 2008中的CLR控制台应用程序项目开始)。
Here is sample project (started from CLR Console Application project in VS 2008).
#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;
}
当我在输出.exe上运行regsvr32时出现错误说没有找到DllRegisterServer 。
When I run regsvr32 on output .exe I got error saying DllRegisterServer was not found. I've tried google for some help but with no success.
推荐答案
您需要使用 TlbExp ,TlbExp是工具用于将托管类导出到COM,它将读取程序集,找到ComVisible类型并注册它们。
You need to use TlbExp instead, TlbExp is the tool use to export managed classes to COM, it will read the assembly find the ComVisible type and register them.
这篇关于ComVisible在C ++ / CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!