2017-08-08 59 views
0

我想加載並調用我的NSIS安裝程序中的C庫DLL函數。當我嘗試加載DLL時,會發出錯誤126(ERROR_MOD_NOT_FOUND)。NSIS系統kernel32 :: LoadLibrary不搜索Outdir或路徑

這是我使用來測試這個最小的安裝腳本:

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 

你可以看到,我設置我的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     

我怎樣才能要搜索的依賴我outpath中?應該注意的是,「C:\ Program Files(x86)\ MyApp」也位於Path環境變量中,那爲什麼還沒有被搜索?

+0

這可能是針對近期NSIS版本,但我不能告訴,因爲你從來沒有告訴我們您正在使用哪個版本。另外,不要使用LoadLibraryA,使用LoadLibrary和't'類型! – Anders

回答

0

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