NSIS Plugin with bad string

天大地大妈咪最大 提交于 2019-12-13 03:58:30

问题


I've tried to develop an NSIS Plugin in C++.

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);
}

Sample:

OutFile "Example.exe"
BrandingText " "

Section
   MySQL::SetCredentials "localhost" 3306 "banananode" "root" ""
   Pop $0
   MessageBox MB_OK "Server: $0" ; Returns the server value...
SectionEnd

The Problem is, when i try to print out the server variable, chinese characters will be shown, not the correct text:

When i return the value with setuservariable(INST_0, server);, NSIS will be display it correctly:

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...


回答1:


ANSI characters interpreted as Unicode (UTF-16LE) tends to look Chinese.

When you create a Unicode plug-in you need to:

  • 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

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.



来源:https://stackoverflow.com/questions/48608015/nsis-plugin-with-bad-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!