【发布时间】:2012-07-23 13:00:45
【问题描述】:
按照a similar SO question 中提出的解决方案,我想在 C++ CLI 应用程序(或者实际上是 C#)中加载一个相当复杂的 dll 文件。目标架构始终设置为 64 位。
在这个应用程序中使用的 .dll 是在另一个项目中生成的,它是使用 C++ CLI 使用本地 C++ 库(例如 Ogre、Boost 等)编写的,并且依赖于它自己的 dll(所有这些都已编译对于 64 位平台)。这些依赖 dll 与使用它们的讨厌的 .dll 一起复制到我的应用程序的输出文件夹中。
但是,当到达这条线时:
Assembly^ SampleAssembly;
SampleAssembly = Assembly::LoadFrom( "E:\\x64\\Debug\\OgreWrapper.dll" );
输出控制台显示:
'DumbTestCLR.exe': Loaded 'E:\x64\Debug\OgreWrapper.dll', Symbols loaded.
'DumbTestCLR.exe': Unloaded 'E:\x64\Debug\OgreWrapper.dll'
并抛出一些致命的未捕获异常:
First-chance exception at 0x000007fefe32cacd (KernelBase.dll) in DumbTestCLR.exe: Microsoft C++ exception: EEFileLoadException * __ptr64 at memory location 0x0016d588..
First-chance exception at 0x77cace3b (ntdll.dll) in DumbTestCLR.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
First-chance exception at 0x77cace3b (ntdll.dll) in DumbTestCLR.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
First-chance exception at 0x77cace3b (ntdll.dll) in DumbTestCLR.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
由于没有任何建议 given here 适用(即不是因为应用程序和 dll 之间的位冲突),问题的根源可能是什么?我怀疑 dll 无法加载其他(本机)dll 并因此崩溃,但是如果可能是这种情况,如何检查哪些 dll 导致问题?
抱歉这个问题太长了,也许是个愚蠢的问题..
【问题讨论】:
-
在我看来,您的 OgreWrapper.dll 是本机 dll,应改为使用 pinvoke 处理。
-
我用
Common Language Runtime Support (/clr)标志编译了它。难道这个dll仍然是原生的,而不是混合的吗?我听说人们说它应该是一个混合的,因为这是他们包装其他 C++ 库并在 C# 应用程序中使用它们的功能的方式.. -
你确定它不是原生 dll 吗?您是否尝试过在 C# 项目中引用它? Check this answer out,可能会帮助您确定正在处理的 dll 类型。
-
谢谢,现在检查并确认(版本:v4.0.30319 CLR 标头:2.5 - PE:PE32+ - CorFlags:16 - ILONLY:0 - 32BIT:0 - 签名:0)跨度>