其他分享
首页 > 其他分享> > c-LoadLibrary失败,错误代码为193

c-LoadLibrary失败,错误代码为193

作者:互联网

我对为何无法使用LoadLibrary加载dll“ interfac”感到困惑.加载依赖项时似乎失败了,但我不确定为什么.

这是代码:

AfxMessageBox(L"before load library");
HMODULE interfacDll = LoadLibrary(TEXT("C:\\QA\\Pcdlrn\\Win32\\Release\\INTERFAC.DLL"));
if (!interfacDll)
  DWORD dw = GetLastError(); // returns 0xc1 (193)
AfxMessageBox(L"after load library");

这是gflags(x86)的加载程序快照的输出:

18a0:2a40 @ 06858973 - LdrGetDllHandleEx - ENTER: DLL name: ntdll.dll DLL path: NULL
18a0:2a40 @ 06858973 - LdrGetDllHandleEx - INFO: Locating DLL ntdll.dll in path C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows
18a0:2a40 @ 06858989 - LdrpFindLoadedDll - ENTER: DLL name: ntdll.dll DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows
18a0:2a40 @ 06858989 - LdrpFindLoadedDll - RETURN: Status: 0x00000000
18a0:2a40 @ 06858989 - LdrGetDllHandleEx - RETURN: Status: 0x00000000
18a0:2a40 @ 06858989 - LdrGetProcedureAddressEx - INFO: Locating procedure "KiUserExceptionDispatcher" by name
18a0:2a40 @ 06858989 - LdrLoadDll - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\syste
18a0:2a40 @ 06858989 - LdrpLoadDll - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\syst
18a0:2a40 @ 06858989 - LdrpLoadDll - INFO: Loading DLL C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL from path C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\sys
18a0:2a40 @ 06858989 - LdrpFindOrMapDll - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows
18a0:2a40 @ 06858989 - LdrpSearchPath - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\s
18a0:2a40 @ 06858989 - LdrpResolveFileName - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL
18a0:2a40 @ 06858989 - LdrpResolveFileName - RETURN: Status: 0x00000000
18a0:2a40 @ 06858989 - LdrpResolveDllName - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL
18a0:2a40 @ 06858989 - LdrpResolveDllName - RETURN: Status: 0x00000000
18a0:2a40 @ 06858989 - LdrpSearchPath - RETURN: Status: 0x00000000
18a0:2a40 @ 06859036 - LdrpMapViewOfSection - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL
'CNCServer.exe': Loaded 'C:\QA\Pcdlrn\Win32\Release\INTERFAC.dll', Symbols loaded.
18a0:2a40 @ 06859098 - LdrpMapViewOfSection - RETURN: Status: 0x40000003
18a0:2a40 @ 06859098 - LdrpRelocateImage - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL
18a0:2a40 @ 06859098 - LdrpProtectAndRelocateImage - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpRelocateImage - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpFindOrMapDll - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpHandleOneOldFormatImportDescriptor - INFO: DLL "C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL" imports "PCDLRN.exe"
18a0:2a40 @ 06859098 - LdrpLoadImportModule - ENTER: DLL name: PCDLRN.exe DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\W
18a0:2a40 @ 06859098 - LdrpFindOrMapDll - ENTER: DLL name: PCDLRN.exe DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windo
18a0:2a40 @ 06859098 - LdrpFindKnownDll - ENTER: DLL name: PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpFindKnownDll - RETURN: Status: 0xc0000135
18a0:2a40 @ 06859098 - LdrpSearchPath - ENTER: DLL name: PCDLRN.exe DLL path: C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows
18a0:2a40 @ 06859098 - LdrpResolveFileName - ENTER: DLL name: C:\QA\Pcdlrn\CNCSERVER\Win32\Release\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveFileName - RETURN: Status: 0xc0000135
18a0:2a40 @ 06859098 - LdrpResolveFileName - ENTER: DLL name: C:\Windows\system32\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveFileName - RETURN: Status: 0xc0000135
18a0:2a40 @ 06859098 - LdrpResolveFileName - ENTER: DLL name: C:\Windows\system\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveFileName - RETURN: Status: 0xc0000135
18a0:2a40 @ 06859098 - LdrpResolveFileName - ENTER: DLL name: C:\Windows\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveFileName - RETURN: Status: 0xc0000135
18a0:2a40 @ 06859098 - LdrpResolveFileName - ENTER: DLL name: .\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveFileName - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpResolveDllName - ENTER: DLL name: .\PCDLRN.exe
18a0:2a40 @ 06859098 - LdrpResolveDllName - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpSearchPath - RETURN: Status: 0x00000000
18a0:2a40 @ 06859098 - LdrpMapViewOfSection - ENTER: DLL name: C:\QA\Pcdlrn\Win32\Release\PCDLRN.exe
'CNCServer.exe': Loaded 'C:\QA\Pcdlrn\Win32\Release\PCDLRN.exe', Symbols loaded.
18a0:2a40 @ 06859597 - LdrpMapViewOfSection - RETURN: Status: 0x40000003
'CNCServer.exe': Unloaded 'C:\QA\Pcdlrn\Win32\Release\PCDLRN.exe'
18a0:2a40 @ 06859597 - LdrpFindOrMapDll - RETURN: Status: 0xc000007b
18a0:2a40 @ 06859597 - LdrpLoadImportModule - ERROR: Loading DLL PCDLRN.exe from path C:\QA\Pcdlrn\CNCSERVER\Win32\Release;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\NativeBinaries\x86;C:\windows\system32;C:\windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:
18a0:2a40 @ 06859597 - LdrpLoadImportModule - RETURN: Status: 0xc000007b
18a0:2a40 @ 06859597 - LdrpHandleOneOldFormatImportDescriptor - ERROR: Loading "?????" from the import table of DLL "C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL" failed with status 0xc000007b
18a0:2a40 @ 06859613 - LdrpUnloadDll - INFO: Unmapping DLL "C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL"
'CNCServer.exe': Unloaded 'C:\QA\Pcdlrn\Win32\Release\INTERFAC.dll'
18a0:2a40 @ 06859613 - LdrpLoadDll - RETURN: Status: 0xc000007b
18a0:2a40 @ 06859613 - LdrLoadDll - RETURN: Status: 0xc000007b

我应该提到我正在使用64位Windows,但是我所有的可执行代码都针对x86(c#)或win32(c).

我该如何解决这个问题?

任何建议将不胜感激.
非常感谢你.

附:这是依赖项walker的输出:

p.p.s.这是一个截图,显示我的DLL是x86:

p.p.p.s.这是interfac.dll的链接器输入:

编辑.这是dumpbin的输出:

Microsoft (R) COFF/PE Dumper Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file pcdlrn.exe

File Type: EXECUTABLE IMAGE

Section contains the following exports for PCDLRN.exe

00000000 characteristics
5796AD2A time date stamp Mon Jul 25 20:22:02 2016
    0.00 version
       1 ordinal base
    5784 number of functions
    5784 number of names

ordinal hint RVA      name

     1    0 0029CDF0 ??0?$CArray@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@V12@@@QAE@XZ = ??0?$CArray@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@V12@@@QAE@XZ (public: __thiscall CArray<class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >,class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > >::CArray<class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >,class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > >(void))
...
5783 1696 02593550 ?zoomOutFine@VisionTargetControls@UIEvents@@YAXXZ = ?zoomOutFine@VisionTargetControls@UIEvents@@YAXXZ (void __cdecl UIEvents::VisionTargetControls::zoomOutFine(void))
5784 1697 02593640 ?zoomOutMaximum@VisionTargetControls@UIEvents@@YAXXZ = ?zoomOutMaximum@VisionTargetControls@UIEvents@@YAXXZ (void __cdecl UIEvents::VisionTargetControls::zoomOutMaximum(void))

Summary

  2C0000 .data
    1000 .fnp_dir
    1000 .fnp_mar
  AFA000 .rdata
   1B000 .rsrc
 2E7A000 .text
   E5000 .textidx
    1000 .tls

解决方法:

LoadLibrary中的ERROR_BAD_EXE_FORMAT错误的一种可能解释是INTERFAC.DLL与声明PCDLRN导出的PCDLRN.LIB导入库链接在一起,但是在运行时找到的PCDLRN.EXE没有exports table.

> gflags(x86)的加载器快照显示,加载PCDLRN.EXE时(特别是在解析INTERFAC.DLL的导入表时)触发了错误:

18a0:2a40 @ 06859098 - LdrpHandleOneOldFormatImportDescriptor - INFO: DLL "C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL" imports "PCDLRN.exe"
[...]
18a0:2a40 @ 06859597 - LdrpHandleOneOldFormatImportDescriptor - ERROR: Loading "?????" from the import table of DLL "C:\QA\Pcdlrn\Win32\Release\INTERFAC.DLL" failed with status 0xc000007b

>状态0xc000007b为STATUS_INVALID_IMAGE_FORMAT

{Bad Image} %hs is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support.

>每个INFO: Mapping NT Status Error Codes to Win32 Error Codes,NTSTATUS STATUS_INVALID_IMAGE_FORMAT映射到Win32错误代码ERROR_BAD_EXE_FORMAT.

我可以使用给定方案的模型复制相同的ERROR_BAD_EXE_FORMAT:将INTERFAC.DLL链接到声明了导出的foo的PCDLRN.LIB,然后替换没有导出表的PCDLRN.EXE,最后尝试加载LoadLibrary INTERFAC.DLL .

附带说明,将DLL链接到另一个EXE的导入库并不常见,并且充满陷阱.在这种情况下,即使错误193被修复,EXE中的功能也无法从DLL直接使用.有关更多详细信息,请参见示例Load EXE as DLL: Mission Possible.

标签:loadlibrary,c,windows,winapi,dll
来源: https://codeday.me/bug/20191012/1898627.html