简体   繁体   English

在C ++ / CLI中是可见的

[英]ComVisible in C++/CLI

i'm converting C++ to C++/CLI and would like to expose some managed classes as COM objects. 我正在将C ++转换为C ++ / CLI,并希望将一些托管类公开为COM对象。 In C# it was easy and setting [ComVisible] & inheriting from interface (also ComVisible) did the job. 在C#中它很容易并且设置[ComVisible]并继承自界面(也是ComVisible)完成了这项工作。 However C++ project build as C++/CLI does not export DllRegisterServer. 但是,作为C ++ / CLI的C ++项目构建不会导出DllRegisterServer。

Here is sample project (started from CLR Console Application project in VS 2008). 这是示例项目(从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<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}

When I run regsvr32 on output .exe I got error saying DllRegisterServer was not found. 当我在输出.exe上运行regsvr32时,我收到错误,说没有找到DllRegisterServer。 I've tried google for some help but with no success. 我试过谷歌一些帮助,但没有成功。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM