我正在尝试为现有的.net Lib创建一个COM Wrapper。
从COM角度看,似乎没有任何作用。我开始了#34; walk"回到我的代码仍然没有
我尝试了一个基本的C ++ COM客户端,指向一个示例.net服务器,以确定COM互操作是否正常工作。
我可以__uuidof()并获取propper UUID,但_com_ptr_t中的createIntance返回Class Not Registered,并指向IPtr为null。
c ++客户端:
#include <iostream>
#define _WIN32_DCOM
#import "..\\bin\\Debug\\TestServer.tlb"
using namespace TestServer;
int main()
{
std::cout << "Hello, World!";
TestServer::_Numbers *com_ptr;
CoInitialize(NULL);
TestServer::_NumbersPtr p(__uuidof(TestServer::Numbers));
com_ptr = p;
int m_iDay = com_ptr->GetDay();
std::cout << m_iDay;
return 0;
}
<。> .Net服务器:
using System;
using System.Runtime.InteropServices;
namespace TestServer
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Numbers
{
[DispId(1)]
int GetDay();
}
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tester.Numbers")]
public class Numbers : _Numbers
{
public Numbers(){}
public int GetDay()
{
return(DateTime.Today.Day);
}
}
}
我已经检查过,oleView可以获得TypeLib,如下所示:
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: TestServer.tlb
[
uuid(AB9E360D-4B96-32C2-AB45-66E4A99A5FF0),
version(1.0),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, "TestServer, Version=1.0.6670.3022, Culture=neutral, PublicKeyToken=null")
]
library TestServer
{
// TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
dispinterface _Numbers;
[
uuid(D6F88E95-8A27-4AE6-B6DE-0542A0FC7039),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "TestServer._Numbers")
]
dispinterface _Numbers {
properties:
methods:
[id(0x00000001)]
long GetDay();
};
[
uuid(13FE32AD-4BF8-495F-AB4D-6C61BD463EA4),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "TestServer.Numbers")
]
coclass Numbers {
interface _Object;
[default] dispinterface _Numbers;
};
};
我缺少什么?
这可能是与OS相关的东西(Win 7 Ultimate x64)吗?
GACL上的垃圾?
我该如何清理?
提前致谢。任何评论都是有帮助的,因为我无法解决这个问题。重点应放在我的项目上,而不是COM基础知识
谢谢致谢:Nick Parker(https://www.codeproject.com/Articles/3511/Exposing-NET-Components-to-COM#mfc)重复使用的示例代码