2009-08-10 91 views
6

我正在將C++轉換爲C++/CLI,並且想將一些託管類作爲COM對象公開。在C#中很容易,並設置[ComVisible] &繼承自接口(也ComVisible)做了這項工作。 但是C++項目構建爲C++/CLI不會導出DllRegisterServer。ComVisible在C++/CLI

下面是示例項目(從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; 
} 

當我在輸出.exe上運行regsvr32時出現錯誤,說DllRegisterServer未找到。我試過谷歌一些幫助,但沒有成功。

回答

4

您需要使用TlbExp來替代,TlbExp是用於將託管類導出到COM的工具,它將讀取程序集查找ComVisible類型並註冊它們。

+0

謝謝你的幫助Shay – 2009-08-10 22:29:09

相關問題