Nic*_*sui 3 c++ dll loadlibrary
我有这个Loadlibraty()错误3765269347困扰我.我正在实现一个构建为x64的C++控制台应用程序来加载x64本机C++ DLL.以下是加载DLL的C++控制台应用程序中的代码:
bool InitDll()
{
HINSTANCE hInst = LoadLibrary(_T("C:\\TIS_Nick\\Hardware\\Devices\\ThorDetectorSwitch\\TDSTest\\TDSTest\\Debug\\Modules_Native\\ThorDetectorSwitch.dll"));
if( hInst != NULL )
{
FreeLibrary( hInst );
return true;
}
else
{
DWORD err = GetLastError();
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是3765269347,我认为这意味着C++无法处理此错误.我确定我加载dll的路径是正确的.
我还使用Monitor Process来跟踪调用dll和函数的内容.这是我认为相关的信息.
11:08:07.3196483 AM TDSTest.exe 1604 QueryNameInformationFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\x64\Debug\TDSTest.exe SUCCESS Name: \TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\x64\Debug\TDSTest.exe
11:08:08.5720585 AM TDSTest.exe 1604 CreateFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
11:08:08.5721041 AM TDSTest.exe 1604 QueryBasicInformationFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS CreationTime: 6/11/2013 6:30:08 PM, LastAccessTime: 6/11/2013 6:30:08 PM, LastWriteTime: 6/12/2013 11:00:28 AM, ChangeTime: 6/12/2013 11:05:51 AM, FileAttributes: A
11:08:08.5721293 AM TDSTest.exe 1604 CloseFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS
11:08:08.5722797 AM TDSTest.exe 1604 CreateFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS Desired Access: Read Data/List Directory, Execute/Traverse, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: n/a, ShareMode: Read, Delete, AllocationSize: n/a, OpenResult: Opened
11:08:08.5723228 AM TDSTest.exe 1604 CreateFileMapping C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll FILE LOCKED WITH ONLY READERS SyncType: SyncTypeCreateSection, PageProtection:
11:08:08.5724896 AM TDSTest.exe 1604 CreateFileMapping C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS SyncType: SyncTypeOther
11:08:08.5725861 AM TDSTest.exe 1604 Load Image C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS Image Base: 0x7fef7830000, Image Size: 0x6d000
11:08:08.5726385 AM TDSTest.exe 1604 QueryNameInformationFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS Name: \TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll
11:08:08.5728910 AM TDSTest.exe 1604 CreateFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
11:08:08.5912215 AM TDSTest.exe 1604 CloseFile C:\TIS_Nick\Hardware\Devices\ThorDetectorSwitch\TDSTest\TDSTest\Debug\Modules_Native\ThorDetectorSwitch.dll SUCCESS
Run Code Online (Sandbox Code Playgroud)
我认为这看起来有点乱,我试图在这里发布一张图片,但事实证明我没有足够的声誉这样做.任何建议表示赞赏.
更新
我已追溯到构造函数ThorDetectorSwitch.dll,如下所示:
ThorDetectorSwitch::ThorDetectorSwitch() : _mcSwitch(__uuidof(MCLControlClass))
{
_A = WstringToBSTR(L"A");
_B = WstringToBSTR(L"B");
_C = WstringToBSTR(L"C");
_D = WstringToBSTR(L"D");
_deviceDetected = FALSE;
}
Run Code Online (Sandbox Code Playgroud)
我在第一个括号处设置断点,但它永远不会进入函数.相反,它跳转到异常.我想错了MCLControlClass,或者_mcSwitch?
我得到的错误是3765269347
像这样具有大错误数值的通用策略是将它们转换为十六进制.3765269347 == 0xE06D7363.这是一个神奇的数字,谷歌也很好.Microsoft程序员使用的一种策略是使异常代码ASCII代码的最后3个字节.6D7363 =="msc".没有足够的空间来添加++ :)
诊断是DLL中的DllMain()函数由于未处理的C++异常而死亡.那当然发生了.
调试它的方法是强制调试器在抛出异常时停止,在Window加载器捕获它并将其转换为失败代码之前.在Visual Studio中,使用Debug + Exceptions,勾选C++异常的Thrown复选框.
理解你在调试器停止时看到的内容在很大程度上取决于你是否有一个好的PDB文件和你是否有源代码.当然,通常需要源来解决问题.如果您无法访问此类任何内容,那么您需要编写该DLL的程序员的帮助.向他发送一个重现崩溃的小型repro项目.