【问题标题】:Call dll function in NSIS and return boolean在 NSIS 中调用 dll 函数并返回布尔值
【发布时间】:2019-02-22 06:19:23
【问题描述】:

我试图在我的 dll 中调用该函数,但它失败了。 这是我的 NSIS 脚本:

!include "LogicLib.nsh"
Section "MyTest"
Strcpy $0 "abc"
System::Call 'MyDll::FindSomething(t, b) i(r0, false) .r1'

${If} $1 == true
    MessageBox MB_OK "1"
${ElseIf} $1 == false
    MessageBox MB_OK "0"
${EndIf}
SectionEnd

FindSomething 函数应返回布尔值 true 或 false。我的脚本执行后结果什么都不显示。

【问题讨论】:

  • 请在询问 System::Call 问题时包含 C 定义。

标签: c dll syntax nsis


【解决方案1】:
  • 您没有提取 MyDll.dll?

  • false 不是受支持的关键字,请使用 0

如果没有 C/C++ 声明,很难给出完整的示例,但我可以尝试:

Section
InitPluginsDir
File "/oname=$PluginsDir\MyDll.dll" "c:\myfiles\MyDll.dll" ; Extract

System::Call 'KERNEL32::AddDllDirectory(w "$PluginsDir")' ; Make sure we are allowed to load from here

System::Call 'KERNEL32::LoadLibrary(t "$PluginsDir\MyDll.dll")p.r9'
MessageBox mb_OK "Loaded MyDll at address $9" ; This should not be 0!

; bool __cdecl FindSomething1(char* p1, bool p2):
StrCpy $0 "abc"
System::Call 'MyDll::FindSomething1(m r0, b 0)b.r1 ?c'
MessageBox mb_OK "Returned $1"

; int WINAPI FindSomething2(LPTSTR p1, BOOL p2):
StrCpy $0 "abc"
System::Call 'MyDll::FindSomething2(t r0, i 0)i.r1'
MessageBox mb_OK "Returned $1"
; ${If} $1 <> 0 ...

System::Call 'KERNEL32::FreeLibrary(p r9)'
SectionEnd

只有最新版本的 System 插件支持 b 类型,但无论如何您都可以在大多数地方使用 i

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2013-03-18
    • 2012-09-06
    • 2021-10-29
    • 2013-03-11
    • 1970-01-01
    相关资源
    最近更新 更多