简体   繁体   中英

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. 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.)

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):

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.

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?

事实证明,在使用 regasm 注册 dll 时,我需要使用/codebase选项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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