NSIS插件与坏串(NSIS Plugin with bad string)

2019-11-04 14:25发布

我试图建立一个NSIS PluginC++

这里是我的方法从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将被正确地显示它:

你能告诉我,什么是错? 我试图打造导致.dllpluginapi-x86-ansi.libpluginapi-x86-unicode.lib但结果是一样的...

Answer 1:

解释为Unicode(UTF-16LE)ANSI字符往往看中国 。

当你创建一个Unicode插件,您需要:

  • 确保 UNICODE_UNICODE在你的工程/ .C文件中定义。
  • 链接与pluginapi 86 unicode.lib
  • 添加Unicode True到你.NSI
  • 放置插件在\ NSIS \ x86的统一

在你的情况,你最有可能忘记了Unicode True 。 返回值的作品,因为你从来没有真正改变的存储server ,它仍然是相同的输入字符串。



文章来源: NSIS Plugin with bad string