简体   繁体   English

在 DLL 方法中创建 COM 接口指针在从一个应用程序调用时有效,但在从另一个应用程序调用时无效

[英]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.

相关问题 从Winforms调用时,SQL(或linq to sql)的工作速度比在Web应用程序上调用时的慢吗? - SQL (or linq to sql) works slower when called from winforms than when called on web application? 创建MenuFlyout时,“该应用程序调用了一个已编入不同线程的接口” - “The application called an interface that was marshalled for a different thread” when creating MenuFlyout 从其他应用程序调用时方法同步中的问题 - Issue in synchronization of method when called from different application 为什么在使用控制台应用程序测试时在 DLL 文件中启动的进程可以工作,但在被另一个 DLL 文件调用时却不能工作? - Why does a process started in a DLL file work when tested using console application, but not when called by another DLL file? 通过 MIM .dll 调用时,无法从任何应用程序调用 cmd.exe - Cannot call cmd.exe from any application when it is called via the MIM .dll 从exe应用程序调用时,不显示Wpf dll用户控制窗口 - Wpf dll user control window not showing when called from an exe application 从Visual Studio 2008中的C#应用​​程序调用时如何调试C DLL - How to debug C DLL when called from a C# application in Visual Studio 2008 NHibernate在从一个项目调用时工作,但不从另一个项目调用 - NHibernate works when called from one project, but not from the other 从其他应用程序运行应用程序时无法加载DLL - Dll cannot loaded when running application from another application INSERT存储过程可以工作,但从方法调用时未插入数据吗? - INSERT Stored Procedure works but data is not inserted when called from method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM