[英]NSIS: calling DLL function with System::Call using absolute path with blanks
I'm trying to call the function int MyFunction()
from myfile.dll and to display it's return value in a message box.我正在尝试从 myfile.dll 调用 function
int MyFunction()
并在消息框中显示它的返回值。
What works so far:到目前为止有效的方法:
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
As soon as I replace $TEMP
by $INSTDIR
it doesn't work anymore.一旦我用
$INSTDIR
替换$TEMP
,它就不再起作用了。 Actually it does, as long as $INSTDIR
doesn't contain blanks, what C:\Program Files (x86)
unfortunately does...实际上它确实如此,只要
$INSTDIR
不包含空格,不幸的是C:\Program Files (x86)
会...
At one point I figured out from this NSIS forum post that this behavior is a bug, namely this one .有一次,我从这个 NSIS 论坛帖子中发现这种行为是一个错误,即this . I didn't really figure out what's the status of it.
我并没有真正弄清楚它的状态。
I also tried the workaround with kernel32::LoadLibrary
and kernel32::GetProcAddress
that was presented in both pages, but I don't know what to use in the line System::Call "::$1(the usual parameters here)"
.我还尝试了两个页面中都显示的
kernel32::LoadLibrary
和kernel32::GetProcAddress
的解决方法,但我不知道在System::Call "::$1(the usual parameters here)"
行中使用什么。
So how do I call MyFunction() now?那么我现在如何调用 MyFunction() 呢?
The System plug-in supports quotes in the path now:系统插件现在支持路径中的引号:
System::Call '"$InstDir\MyLibrary.dll"::MyFunction(i 42)'
Calling KERNEL32::AddDllDirectory is required if the DLL depends on other DLLs in the same directory but a single DLL should work without it.如果 DLL 依赖于同一目录中的其他 DLL,但单个 DLL 应该在没有它的情况下工作,则需要调用 KERNEL32::AddDllDirectory。
When using kernel32::GetProcAddress the parameters are the same, it is only the path and function name that has changed to a direct address.使用 kernel32::GetProcAddress 时参数相同,只是路径和 function 名称改为直接地址。
What fixed it in the end, was adding $INSTDIR
to the search path, as suggested in this answer :最终修复它的是将
$INSTDIR
添加到搜索路径中,如this answer中所建议的那样:
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.