问题描述
我尝试用 C++
开发一个 NSIS 插件
.
I've tried to develop an NSIS Plugin
in C++
.
这是我从 NSIS 设置信息的方法:
Here is my method to set informations from 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
变量时,将显示中文字符,而不是正确的文本:
The Problem is, when i try to print out the server
variable, chinese characters will be shown, not the correct text:
当我用 setuservariable(INST_0, server);
返回值时,NSIS 将正确显示它:
When i return the value with setuservariable(INST_0, server);
, NSIS will be display it correctly:
你能告诉我,怎么了?我试图用 pluginapi-x86-ansi.lib
和 pluginapi-x86-unicode.lib
构建结果 .dll
但结果是一样的...
Can you tell me, whats wrong?I've tried to build the resulted .dll
with pluginapi-x86-ansi.lib
and pluginapi-x86-unicode.lib
but the result is the same...
推荐答案
ANSI 字符解释为 Unicode (UTF-16LE) 倾向于中国人.
ANSI characters interpreted as Unicode (UTF-16LE) tends to look Chinese.
创建 Unicode 插件时,您需要:
When you create a Unicode plug-in you need to:
- 确保
UNICODE
和_UNICODE
在您的项目/.C 文件中定义. - 与 pluginapi-x86-unicode.lib 链接
- 将
Unicode True
添加到您的 .NSI - 将插件放入\NSIS\x86-unicode
- Make sure
UNICODE
and_UNICODE
is defined in your project/.C files. - Link with pluginapi-x86-unicode.lib
- Add
Unicode True
to your .NSI - Place the plug-in in \NSIS\x86-unicode
就您而言,您很可能忘记了 Unicode True
.返回值是有效的,因为您实际上从未更改过 server
的内存,它仍然是相同的输入字符串.
In your case you most likely forgot about Unicode True
. Returning the value works because you never actually changed the memory of server
, it is still the same input string.
这篇关于带有错误字符串的 NSIS 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!