【发布时间】:2013-08-29 22:41:21
【问题描述】:
我正在尝试使用以下代码在 C:\Windows\System32\ 文件夹中加载与打印机驱动程序一起安装的 DLL:
LoadLibraryW(L"C:\\Windows\\System32\\MagAPI.dll");
GetLastError() 报告“找不到指定的模块”。如果我将 DLL 移到 System32 文件夹之外(例如 C:\SomeFolder\MagAPI.dll),那么它会很好地加载,所以看起来这不是 DLL 本身的问题。是否有一些奇怪的 Windows 安全功能可能会阻止我的应用程序加载它?这是我唯一能想到的,但我找不到任何确定的答案。
这是 ShowSnaps 的调试输出,它显示了失败的地方:
1a8c:1fd4 @ 19006756 - LdrLoadDll - ENTER: DLL name: C:\Windows\system32\MagAPI.dll DLL path: C:\Windows\system32;C:\Windows\system;C:\Windows;.;<otherstuff>
1a8c:1fd4 @ 19006756 - LdrpLoadDll - ENTER: DLL name: C:\Windows\system32\MagAPI.dll DLL path: C:\Windows\system32;C:\Windows\system;C:\Windows;.;<otherstuff>
1a8c:1fd4 @ 19006756 - LdrpLoadDll - INFO: Loading DLL C:\Windows\system32\MagAPI.dll from path C:\Windows\system32;C:\Windows\system;C:\Windows;.;<otherstuff>
1a8c:1fd4 @ 19006756 - LdrpFindOrMapDll - ENTER: DLL name: C:\Windows\system32\MagAPI.dll DLL path: C:\Windows\system32;C:\Windows\system;C:\Windows;.;<otherstuff>
1a8c:1fd4 @ 19006756 - LdrpSearchPath - ENTER: DLL name: C:\Windows\system32\MagAPI.dll DLL path: C:\Windows\system32;C:\Windows\system;C:\Windows;.;<otherstuff>
1a8c:1fd4 @ 19006756 - LdrpResolveFileName - ENTER: DLL name: C:\Windows\system32\MagAPI.dll
1a8c:1fd4 @ 19006756 - LdrpResolveFileName - RETURN: Status: 0xc0000135
1a8c:1fd4 @ 19006756 - LdrpSearchPath - RETURN: Status: 0xc0000135
1a8c:1fd4 @ 19006756 - LdrpFindOrMapDll - RETURN: Status: 0xc0000135
1a8c:1fd4 @ 19006756 - LdrpLoadDll - RETURN: Status: 0xc0000135
1a8c:1fd4 @ 19006756 - LdrLoadDll - RETURN: Status: 0xc0000135
【问题讨论】:
-
您使用的是哪个版本的 Windows?您可能需要管理员权限才能查看 System32 的内容。您可以做的快速测试是右键单击并以管理员身份运行您的应用程序(我认为是 win vista 及以上),如果它有效,那就是问题所在。
-
-
不,我要求您确认这是否是权限问题。有时从代码访问 System32 需要对正在运行的应用程序的管理员权限,即使只是为了读取文件。
-
似乎不是问题。我刚刚尝试以管理员身份运行该应用程序,但它仍然以完全相同的方式失败。我在 Windows 7 64 位顺便说一句。不过它是一个 32 位应用程序。
-
当您将文件“移出”system32 时,您将它移到哪里到?库是否有可能在正确加载的文件夹中满足导入依赖项,而在驻留在 system32 中时不满足。您能否对其进行依赖遍历(例如,使用来自 MS 的
depends.exe)并查看可能缺少的内容。这是一种可能性,但从您的 ShowSnaps 输出来看,文件名本身根本无法解析。多么奇怪。
标签: c++ dll loadlibrary system32