c++ - 带有错误字符串的 NSIS 插件

标签 c++ nsis nsis-plugin

我尝试用 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 变量时,将显示中文字符,而不是正确的文本:

enter image description here

当我使用 setuservariable(INST_0, server); 返回值时,NSIS 将正确显示它:

enter image description here

你能告诉我,有什么问题吗? 我尝试使用 pluginapi-x86-ansi.libpluginapi-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/

相关文章:

c++ - int 到固定长度的字符串表示

c++ - 使用指针将 uint16_t 值注入(inject) uint8_t 数组?

java - 如何在运行时使用java代码执行脚本

java - NSIS - 无法使用 64 位 Java 运行 Java 应用程序

installation - NSIS 脚本是用什么语言编写的?

c++ - 类局部变量的指针?

c++ - 使用堆栈的数独无限循环