我有一个非托管的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;
};
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试运行代码时,我得到以下C++异常:
First-chance exception at 0x000007fefd5a9e5d in DependencyTest2.exe: Microsoft C++ exception: EEFileLoadException * __ptr64 at memory location 0x0094ca58..
Run Code Online (Sandbox Code Playgroud)
我试图在Main的第一行设置断点,但在执行到达该点之前抛出异常.如果我点击"继续"(我正在使用MVS 2010),我会得到:
First-chance exception at 0x76d8c5e2 in DependencyTest2.exe: 0xC0000005: Access violation reading location 0x0000000000000020.
Run Code Online (Sandbox Code Playgroud)
有人有建议吗?这是在Windows 7 x64上,并且已经为x64编译了所有内容,包括C++ DLL.
EEFileLoadException指示可执行文件无法找到或加载其中一个依赖项.这当然可以有不同的原因(路径问题,混合配置,混合平台).
一个好的开始是在你的DLL /可执行文件上使用Dependency Walker(确保使用x64版本).
| 归档时间: |
|
| 查看次数: |
12727 次 |
| 最近记录: |