帮助从 c++/Cli 加载 .Net DLL
我有一个 .Net DLL,我需要从第三方应用程序调用它。 3rd 方应用程序不支持加载托管 DLL,因此我使用 c++/CLI DLL,它公开了要由应用程序调用的本机 c++ 函数,如下所示。
第 3 方应用程序 -> c++/cli DLL -> .Net DLL
我的问题是,当我的 c++/Cli dll 尝试从 .Net dll 调用函数时,它会崩溃并出现“访问冲突”错误。如果我直接从 VC++ 控制台应用程序调用 .Net DLL,则不会出现此问题。
当我在 Visual Studio 中创建 clr 选项设置为 true 的 c++/cli dll 时,您认为我缺少一些依赖项吗?
我按照 Hans Passant 的建议进行了调试。结果我得到的异常是“文件未找到异常”。我的场景是
第 3 方应用程序 -> c++/cli dll -> .Net 托管 DLL
将 .Net 托管 DLL 放置在与第 3 方 exe 相同的文件夹中解决了该问题。现在我的问题是
“我可以让 C++/CLI dll 在指定路径中查找 .Net dll,而不必将 .Net dll 放在与第 3 方应用程序相同的文件夹中吗?”
谢谢
I have a .Net DLL which I need to call from a 3rd party application. The 3rd party application does not support loading managed DLLs and so I am using a c++/CLI DLL which exposes a native c++ function to be called by the application as shown below.
3rd party application -> c++/cli DLL -> .Net DLL
My problem is that my c++/Cli dll crashes with an "Access violation" error when it tries to call functions from the .Net dll. This problem does not occur if I call the .Net DLL directly from a VC++ console application.
Do you think I am missing some dependencies when I create a c++/cli dll with the clr option set true in visual studio?
I followed Hans Passant's suggestion and debugged it. Turns out the exception I was getting was a "file not found exception". My scenario is
3rd party app -> c++/cli dll -> .Net managed DLL
Placing the .Net managed DLL in the same folder as the 3rd party exe solved the problem. Now my question is
"Can I get the C++/CLI dll to look for the .Net dll in a specified path instead of having to place the .Net dll in the same folder as the 3rd party app?."
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要对其进行调试。在“解决方案资源管理器”窗口中右键单击该项目,依次选择“属性”、“调试”。将 Command 属性设置为要加载 DLL 的 EXE 的路径。根据需要设置命令参数和工作目录。在导出的函数上设置断点。按 F5。
You'll need to debug it. Right-click the project in the Solution Explorer window, Properties, Debugging. Set the Command property to the path of the EXE that is going to load your DLL. Set Command Arguments and Working Directory as necessary. Set a breakpoint on the exported function. Press F5.