按照a similar SO question中提出的解決方案,我想在C++ CLI應用程序(或C#)中加載相當複雜的dll文件。目標體系結構始終設置爲64位。在C++ CLI中加載託管DLL,具體取決於本地dll
在這個應用程序中使用的.dll是在另一個項目中生成的,它使用本地C++庫(例如Ogre,Boost等)在C++ CLI中編寫,並且依賴於它自己的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適用(即它不是因爲位之間的位差衝突e應用程序和dll),那麼問題的根源是什麼?我懷疑該DLL不能加載其他(本機)dll,因此崩潰,但如何檢查哪些dll導致問題,如果這可能是這種情況?
抱歉長的問題,爲,也許愚蠢的問題..
聽起來,你的OgreWrapper.dll是本地的DLL,應該用pinvoke來處理。 – Totonga 2012-07-23 13:15:00
http://blogs.msdn.com/b/junfeng/archive/2006/11/20/debugging-loadlibrary-failures.aspx – 2012-07-23 13:40:17
我用'Common Language Runtime Support(/ clr)'標記編譯它。難道這個DLL仍然是本地的,而不是混合的?我聽說有人說它應該是混合的,因爲它是他們包裝其他C++庫的方式,並且在C#應用程序中利用它們的功能。 – teodron 2012-07-23 13:45:17