NSIS 系统 kernel32::LoadLibrary 不搜索 Outdir 或 Path
NSIS system kernel32::LoadLibrary does not search Outdir or Path
我正在尝试在我的 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
DetailPrint
DetailPrint [=11=]
System::Call 'kernel32::GetProcAddress(i r0,m "GetVersion")i.r1 ? e'
Pop
DetailPrint
DetailPrint
System::Call 'kernel32::FreeLibrary(ir0)'
SectionEnd
你可以看到我将outpath设置为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
如何让我的输出路径被搜索以查找依赖项?需要注意的是,"C:\Program Files (x86)\MyApp"也在Path环境变量中,为什么也没有被搜索到呢?
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} P<> 0
...
${EndIf}
System::Call 'KERNEL32::FreeLibrary(pr0)'
SectionEnd
我正在尝试在我的 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
DetailPrint
DetailPrint [=11=]
System::Call 'kernel32::GetProcAddress(i r0,m "GetVersion")i.r1 ? e'
Pop
DetailPrint
DetailPrint
System::Call 'kernel32::FreeLibrary(ir0)'
SectionEnd
你可以看到我将outpath设置为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
如何让我的输出路径被搜索以查找依赖项?需要注意的是,"C:\Program Files (x86)\MyApp"也在Path环境变量中,为什么也没有被搜索到呢?
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} P<> 0
...
${EndIf}
System::Call 'KERNEL32::FreeLibrary(pr0)'
SectionEnd