【问题标题】:NSIS system kernel32::LoadLibrary does not search Outdir or PathNSIS 系统 kernel32::LoadLibrary 不搜索 Outdir 或 Path
【发布时间】:2017-08-08 11:47:43
【问题描述】:

我正在尝试在我的 NSIS 安装程序中加载和调用 C 库 DLL 的函数。当我尝试加载 DLL 时,会发出错误 126 (ERROR_MOD_NOT_FOUND)。

这是我用来测试的最小安装脚本:

OutFile Main.exe

ShowInstDetails show

Section
  SetOutPath "C:\Program Files (x86)\MyApp"
  System::Call 'kernel32::LoadLibraryA(m "C:\Program Files (x86)\MyApp\API.dll")i.r0 ? e'
  Pop $9
  DetailPrint $9
  DetailPrint $0

  System::Call 'kernel32::GetProcAddress(i r0,m "GetVersion")i.r1 ? e'
  Pop $9
  DetailPrint $9
  DetailPrint $1
  System::Call 'kernel32::FreeLibrary(ir0)'
SectionEnd

您可以看到我正在将我的出路设置为 DLL 所在的位置;它的所有依赖项都在哪里。然而,在检查 procmon 中的进程时,我发现只有 Windows 系统目录正在搜索依赖项,而不是 outpath:

Load Image             C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CreateFile             C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
QueryBasicInformationFiC:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CloseFile              C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CloseFile              C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
Thread Create                                                SUCCESS                 
CreateFile             C:\Windows\syswow64\DEPENDENCY_1.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\msvcr100.dll      SUCCESS                 
QueryBasicInformationFiC:\Windows\syswow64\msvcr100.dll      SUCCESS                 
CloseFile              C:\Windows\syswow64\msvcr100.dll      SUCCESS                 
CreateFile             C:\Windows\syswow64\DEPENDENCY_2.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\DEPENDENCY_3.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\msvcr100.dll      SUCCESS                 

我怎样才能让我的 outpath 被搜索依赖项?需要注意的是,“C:\Program Files (x86)\MyApp”也在Path环境变量中,为什么也搜索不到呢?

【问题讨论】:

  • 这可能特定于最近的 NSIS 版本,但我无法确定,因为您从未告诉我们您使用的是哪个版本。另外,不要使用 LoadLibraryA,使用 LoadLibrary 和 't' 类型!

标签: nsis


【解决方案1】:

最近 NSIS 中的安全更改已锁定它允许您从中加载库的位置。您可以拨打AddDllDirectory添加其他目录:

Section
System::Call 'KERNEL32::AddDllDirectory(w "c:\path")' ; Note: Path must exist at this point
System::Call 'KERNEL32::LoadLibrary(t "c:\path\file.dll")p.r0'
System::Call 'KERNEL32::GetProcAddress(pr0, m "somefunction")p.r1'
${If} $1 P<> 0
  ...
${EndIf}
System::Call 'KERNEL32::FreeLibrary(pr0)'
SectionEnd

【讨论】:

    猜你喜欢
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2013-01-12
    相关资源
    最近更新 更多