我正在使用COM互操作从C++应用程序调用C#DLL中的方法。创建COM接口指针在开发机器上工作,但导致应用程序崩溃在其他机器上
的C#代码:
namespace MyLibrary
{
[ComVisible(true)]
[Guid("f08942b1-db20-44aa-9713-7d28fff51e2b")]
public interface IMyLibraryInterface
{
string POSRequest(string request);
}
[ComVisible(true)]
[Guid("4d962dd5-05ed-431b-82e2-378aebe8d0dc")]
public class MyLibraryInterface : IMyLibraryInterface
{
public string myRequest(string request)
{
....
return response;
}
}
}
调用C++代码:
CoInitialize(NULL);
MyLibrary::IMyLibraryInterfacePtr MyLibraryInterface(__uuidof(MyLibrary::MyLibraryInterface));
myResult = (LPCTSTR) MyLibraryInterface->myRequest(myInput);
CoUninitialize();
在相关TLB文件已经导入:
#import "MyLibrary.tlb"
这适用调试时并从我的开发机器运行发行版本,但导致应用程序崩溃时,我来回跑在另一台机器上。具体地说,创建指针行似乎是这个问题:
MyLibrary::IMyLibraryInterfacePtr MyLibraryInterface(__uuidof(MyLibrary::MyLibraryInterface));
好像事情是在另一台机器上也许缺少的,但我无法弄清楚什么?
您是否在其他机器上注册了C#COM DLL?你必须使用'regasm.exe'来注册DLL。 – pstrjds
是项目工作目录中的dll,还是放置在您所制作的程序可以访问它的新机器上的某个位置? – holycatcrusher
我不知道我需要注册C#的DLL。每次安装时都需要这样做吗? –