NSIS:使用带空格的绝对路径调用 System::Call 的 DLL 函数
NSIS: calling DLL function with System::Call using absolute path with blanks
我正在尝试从 myfile.dll 调用函数 int MyFunction()
并在消息框中显示它的 return 值。
目前有效的:
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 "[=11=]"
System::Call '$TEMP\myfile.dll::MyFunction()i.r0'
MessageBox MB_OK "[=11=]"
System::Free 0
一旦我将 $TEMP
替换为 $INSTDIR
,它就不再起作用了。实际上它确实如此,只要 $INSTDIR
不包含空格,不幸的是 C:\Program Files (x86)
会...
有一次我从 this NSIS forum post that this behavior is a bug, namely this one 中得出结论。我真的没有弄清楚它的状态。
我还尝试了在两个页面中都提供的 kernel32::LoadLibrary
和 kernel32::GetProcAddress
的解决方法,但我不知道在 System::Call "::(the usual parameters here)"
.[=21 行中使用什么=]
那么现在我该如何调用 MyFunction() 呢?
最终修复它的方法是按照建议将 $INSTDIR
添加到搜索路径 :
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")'
系统插件现在支持路径中的引号:
System::Call '"$InstDir\MyLibrary.dll"::MyFunction(i 42)'
如果 DLL 依赖于同一目录中的其他 DLL,则需要调用 KERNEL32::AddDllDirectory,但单个 DLL 应该可以在没有它的情况下工作。
使用kernel32::GetProcAddress时参数是一样的,只是路径和函数名改成了直接地址。
我正在尝试从 myfile.dll 调用函数 int MyFunction()
并在消息框中显示它的 return 值。
目前有效的:
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 "[=11=]"
System::Call '$TEMP\myfile.dll::MyFunction()i.r0'
MessageBox MB_OK "[=11=]"
System::Free 0
一旦我将 $TEMP
替换为 $INSTDIR
,它就不再起作用了。实际上它确实如此,只要 $INSTDIR
不包含空格,不幸的是 C:\Program Files (x86)
会...
有一次我从 this NSIS forum post that this behavior is a bug, namely this one 中得出结论。我真的没有弄清楚它的状态。
我还尝试了在两个页面中都提供的 kernel32::LoadLibrary
和 kernel32::GetProcAddress
的解决方法,但我不知道在 System::Call "::(the usual parameters here)"
.[=21 行中使用什么=]
那么现在我该如何调用 MyFunction() 呢?
最终修复它的方法是按照建议将 $INSTDIR
添加到搜索路径
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")'
系统插件现在支持路径中的引号:
System::Call '"$InstDir\MyLibrary.dll"::MyFunction(i 42)'
如果 DLL 依赖于同一目录中的其他 DLL,则需要调用 KERNEL32::AddDllDirectory,但单个 DLL 应该可以在没有它的情况下工作。
使用kernel32::GetProcAddress时参数是一样的,只是路径和函数名改成了直接地址。