在托管DLL中加载c++ DLL时出现eefileloadeexception
EEFileLoadException When Loading C++ DLL in Managed DLL
我有一个非托管的c++ DLL,我想从c# exe中调用。我研究了可能的解决方案,在我看来,最好的办法是使用c++/CLI作为非托管c++类的包装器。所以我写了一个c++/CLI类,看起来像这样,并被编译成一个DLL(我知道它应该有一个析构函数和一个终结器,但到目前为止,代码不会进入Main函数,所以为了简单起见,我把它们排除了):
#include <cppheader.h>
using namespace System;
namespace DependencyInterface
{
public ref class DependencyTester
{
public:
DependencyTester()
{
_class = new CPPClass();
}
private:
CPPClass* _class;
};
}
然后我有一个c#可执行文件,看起来像这样:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DependencyInterface;
namespace DependencyTest2
{
class Program
{
static void Main(string[] args)
{
DependencyTester tester;
}
}
}
不幸的是,当我尝试运行代码时,我得到了以下c++异常:
First-chance exception at 0x000007fefd5a9e5d in DependencyTest2.exe: Microsoft C++ exception: EEFileLoadException * __ptr64 at memory location 0x0094ca58..
我试图在Main的第一行设置一个断点,但是在执行到达该点之前抛出了异常。如果我点击"继续"(我使用的是MVS 2010),我得到这个:
First-chance exception at 0x76d8c5e2 in DependencyTest2.exe: 0xC0000005: Access violation reading location 0x0000000000000020.
有人有什么建议吗?这是在Windows 7 x64上,所有内容都是为x64编译的,包括c++ DLL。
eefileloadeexception表示可执行文件无法找到或加载它的一个依赖项。当然,这可能有不同的原因(路径问题,混合配置,混合平台)。
一个好的开始是在你的DLL的/可执行文件上使用Dependency Walker(确保使用x64版本)
我有一个类似的问题,我在c#项目中引用了一个dll,并且引用的dll本身依赖于我没有包含在我的解决方案中的其他一些dll。在我的解决方案中添加了对缺失dll的引用后,问题得到了解决。或者,您可以将缺失的dll直接复制到应用程序目录。使用Dependency Walker没有帮助,因为他们没有显示丢失的dll的名称。
相关文章:
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
- Python ctypes:不会按预期加载 dll
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL