无法加载由 {dll} 导入的过程 [英] A procedure imported by {dll} could not be loaded

查看:226
本文介绍了无法加载由 {dll} 导入的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个非托管 C++ 编写的 lib 文件,我需要将它们链接到托管 C++ dll.
然后我需要从 C# 应用程序调用这个托管 C++ 的函数.

I have several Unmanaged C++ written lib files which I need to link to Managed C++ dll.
Then I need to invoke functions of this Managed C++ from C# application.

第一步没问题 - 创建了托管 C++ dll,我可以用 ildasm 看到它导出了我需要的函数.但是,当我尝试从我的 C# 编写的测试应用程序中调用此函数时,它说:

First step is OK - Managed C++ dll is created, I can see with ildasm that it exports functions I need. However when I try to call this function from my C#-written test app it says:

在未知模块中发生类型为System.IO.FileLoadException"的未处理异常.
无法加载由 {MyManagedCPP.dll} 导入的过程.

An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
A procedure imported by {MyManagedCPP.dll} could not be loaded.

此消息来自 VS2010.
我做了一个简单的实验 - 从 Managed C++ dll 中的所有 lib 文件中删除依赖项并重建它.
有了这个更改就可以了 - 应用程序启动,我可以从 C# 测试应用程序调用托管 C++ dll 的函数.

This message goes from VS2010.
I made simple experiment - removed dependencies from all lib files in Managed C++ dll and rebuild it.
With this change it is OK - app starts, I can call functions of Managed C++ dll from C# test app.

当 dll 与 lib 文件有静态链接时,是否无法按照设计调用托管 C++ 函数?技术限制?或者有一些解决方法?

Is it not possible by design to call managed c++ functions when dll has static linkage with lib files? Technical restriction? Or there is some workaround?

谢谢

推荐答案

毫无疑问,您对本机 DLL 具有隐式依赖关系.从问题中不清楚可能是什么 DLL.例如,它可以是 msvcrxx.dll,本机 C++ 代码的运行时支持库.这会很糟糕,你不想混合 CRT 版本.否则,此类缺失的 DLL 会阻止加载 C++/CLI 程序集,从而产生 FileLoadException.

You no doubt have an implicit dependency on a native DLL. It isn't clear from the question what DLL that might be. It could be msvcrxx.dll for example, a runtime support library for native C++ code. Which would be rather bad, you don't want to mix CRT versions. Such a missing DLL otherwise prevents the C++/CLI assembly from getting loaded, producing the FileLoadException.

如果您不知道该 DLL 可能是什么,那么您可以使用 SysInternals 的 ProcMon 实用程序.跟踪将向您显示正在搜索 DLL 且未找到它的程序.如果它是 msvcrxx.dll,那么一定要使用与用于构建 C++/CLI 程序集的编译器版本相同的编译器版本来重建 .lib 文件.如果是其他内容,请确保将该 DLL 复制到构建目录.

If you have no idea what that DLL might be then you could use SysInternals' ProcMon utility. The trace will show you the program searching for the DLL and not finding it. If it is msvcrxx.dll then be sure to rebuild the .lib files using the same compiler version you used to build the C++/CLI assembly. If it is something else then make sure you copy that DLL to the build directory.

这篇关于无法加载由 {dll} 导入的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆