带有错误字符串的 NSIS 插件

NSIS Plugin with bad string

我试图在 C++ 中开发一个 NSIS Plugin

这是我从 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 [=11=]
   MessageBox MB_OK "Server: [=11=]" ; Returns the server value...
SectionEnd

问题是,当我尝试打印 server 变量时,将显示中文字符,而不是正确的文本:

当我 return 带有 setuservariable(INST_0, server); 的值时,NSIS 将正确显示它:

你能告诉我,怎么了吗? 我尝试用 pluginapi-x86-ansi.libpluginapi-x86-unicode.lib 构建结果 .dll 但结果是一样的...

ANSI 字符解释为 Unicode (UTF-16LE) tends to look Chinese

创建 Unicode 插件时,您需要:

  • Make sure UNICODE_UNICODE 在您的项目/.C 文件中定义。
  • Link 与 pluginapi-x86-unicode.lib
  • Unicode True 添加到您的 .NSI
  • 将插件放在\NSIS\x86-unicode

在你的情况下,你很可能忘记了 Unicode True。返回该值是有效的,因为您实际上从未更改 server 的内存,它仍然是相同的输入字符串。