[英]Creating COM interface pointer in DLL method works when called from one application but does not when called from another application
I am using COM interop to call a method in a C# dll from a C++ dll.我正在使用 COM 互操作从 C++ dll 调用 C# dll 中的方法。 The C++ dll is called from another application that is essentially a black box to me (eg I can't see any of it's code.) C++ dll 是从另一个应用程序调用的,该应用程序对我来说本质上是一个黑匣子(例如,我看不到它的任何代码。)
When this application calls the method in the C++ dll, it executes as expected until trying to create the pointer/allocate memory to the C# COM interface, at which point the method fails (error is logged):当此应用程序调用 C++ dll 中的方法时,它会按预期执行,直到尝试创建指向 C# COM 接口的指针/分配内存,此时方法失败(记录错误):
TJIntegration::ITJInterfacePtr tJPtr = NULL;
HRESULT hRes = tJPtr.CreateInstance(__uuidof(TJIntegration::TJInterface));
if (!(SUCCEEDED(hRes)))
{
LOG_ERROR << "Could not create pointer for TJInterface. Has the COM DLL been registered?";
}
However, I have created a test application that also calls into this dll, and the method executes completely as expected, including creating this pointer.但是,我创建了一个测试应用程序,它也调用了这个 dll,并且该方法完全按预期执行,包括创建这个指针。
I am testing these applications on the same machine (where the dll is registered) so I can't understand why the method would function correctly when called from one application, but fail at this point when called from another?我正在同一台机器上测试这些应用程序(在那里注册了 dll),所以我不明白为什么从一个应用程序调用时该方法可以正常运行,但在从另一个应用程序调用时却失败了?
事实证明,在使用 regasm 注册 dll 时,我需要使用/codebase
选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.