问题描述
我正在尝试从 myfile.dll 调用函数 int MyFunction()
并在消息框中显示它的返回值。
目前有效的方法:
SetoutPath "$TEMP"
File "myfile.dll"
;File "System.dll" for some time I thought one needs to copy the plugin,but that's not needed
MessageBox MB_OK "$0"
System::Call '$TEMP\myfile.dll::MyFunction()i.r0'
MessageBox MB_OK "$0"
System::Free 0
一旦我用 $TEMP
替换 $INSTDIR
,它就不再起作用了。实际上确实如此,只要 $INSTDIR
不包含空格,那么 C:\Program Files (x86)
不幸的是...
有一次我从 this NSIS forum post 中发现这种行为是一个错误,即 this one。我真的不知道它的状态是什么。
我还尝试了两个页面中都显示的 kernel32::LoadLibrary
和 kernel32::GetProcAddress
的解决方法,但我不知道在 System::Call "::$1(the usual parameters here)"
行中使用什么。
那么我现在如何调用 MyFunction()?
解决方法
系统插件现在支持路径中的引号:
System::Call '"$InstDir\MyLibrary.dll"::MyFunction(i 42)'
如果 DLL 依赖于同一目录中的其他 DLL,则需要调用 KERNEL32::AddDllDirectory,但单个 DLL 应该可以在没有它的情况下工作。
使用 kernel32::GetProcAddress 时,参数是一样的,只是路径和函数名变成了直接地址。
,最终修复它的是将 $INSTDIR
添加到搜索路径,如建议的 in this answer:
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")'