[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] Win64 cleanups (#329)

Nicolas Cellier notifications at github.com
Fri Dec 28 20:56:39 UTC 2018

Hi Tobias, about LoadLibraryA, I see nothing in MSDN suggesting that these ASCII versions will be deprecated.

The purpose of using W variants is to enable usage of internationalized strings, like in window titles, file names, etc... But when we have a simple explicit ASCII string like "advapi32.dll", using the W variant brings nothing.

About windowTitle, I can explain more: if you look at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/476f70605a0352dd7528d251f7403e9233716cdb/platforms/win32/vm/sqWin32Window.c

you'll see this: `if(*windowTitle) sprintf(titleString, "%s", windowTitle);` we first copy the `char *windowTitle` to the `char *titleString`. It obviously cannot be UTF16 at this stage, otherwise the copy would be shorten at first ASCII character.

Then `titleString` is interpreted as UTF8, converted to UTF16 before being displayed as title, line 773:

    MultiByteToWideChar(CP_UTF8, 0, titleString, -1, wideTitle, MAX_PATH+20);
    SetWindowTextW(stWindow, wideTitle);

This was before I change anything. Also we have this function:

    char *ioGetWindowLabel(void) {
      return windowTitle;

I think it is for the purpose of communicating the title back to the image. For communicating with the image, we wish using UTF8, so the minimal and simplest change was to just declare `windowTitle` as char * (which it is now because we can't use -DUNICODE yet), and align the squeak.ini preference to read in UTF16 and convert back to UTF8. You are right, I messed up this part (because I currently compile with `-DUNICODE` for the purpose of discovering the flaws, when I should rather compile with AND without this option). I will issue another commit and use `GetPrivateProfileStringW` unconditionnally, which is a lot simpler.

In fact, most of the time, we have to communicate the strings with the image, and for that, we will need to perform UTF8-UTF16 conversions, so compiling with `-DUNICODE` is not enough and not really a goal per se. Using the generic versions and generic TCHAR *string has only a value if we want to maintain both an ASCII version and a Wide version. But as you said, the ASCII version does not have much interest now, so we could as well directly use W version where we think we need them, or for making the code a bit more uniform (polishing). If it adds un-necessary complexity, I would say just stick to the A version.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20181228/7dd5729d/attachment-0001.html>

More information about the Vm-dev mailing list