我尝试用 C++
开发一个 NSIS 插件
。
这是我从 NSIS 设置信息的方法:
void __declspec(dllexport) SetCredentials(HWND hWndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
EXDLL_INIT();
server = getuservariable(INST_0);
port = myatou(getuservariable(INST_1));
database = getuservariable(INST_2);
username = getuservariable(INST_3);
password = getuservariable(INST_4);
MessageBox(hWndParent, server, L"Info", MB_OK); // Here is the problem
setuservariable(INST_0, server);
}
示例:
OutFile "Example.exe"
BrandingText " "
Section
MySQL::SetCredentials "localhost" 3306 "banananode" "root" ""
Pop $0
MessageBox MB_OK "Server: $0" ; Returns the server value...
SectionEnd
问题是,当我尝试打印出 server
变量时,将显示中文字符,而不是正确的文本:
当我使用 setuservariable(INST_0, server);
返回值时,NSIS 将正确显示它:
你能告诉我,有什么问题吗?
我尝试使用 pluginapi-x86-ansi.lib
和 pluginapi-x86-unicode.lib
构建结果 .dll
但结果是一样的……
最佳答案
ANSI 字符解释为 Unicode (UTF-16LE) tends to look Chinese .
创建 Unicode 插件时,您需要:
- Make sure
UNICODE
和_UNICODE
在您的项目/.C 文件中定义。 - 与 pluginapi-x86-unicode.lib 链接
- 将
Unicode True
添加到您的 .NSI - 将插件放在\NSIS\x86-unicode 中
在您的情况下,您很可能忘记了 Unicode True
。返回值是有效的,因为您实际上从未更改过 server
的内存,它仍然是相同的输入字符串。
关于c++ - 带有错误字符串的 NSIS 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48608015/