none
Bug: CreateWindowExW assumes input is ASCII?

    Question

  • Appologies if this is on the wrong board, but I noticed a huge number of posts contiaining CreateWindowEx over here while checking to see if my question had already been answered elsewhere, and figured it was the right place.

    Anyway, I've got a program that was designed to use single-byte characters (it actually used to only accept character values in the [0, 127] range) that now has to accept unicode input. Unfortunately I can't just change my project settings to use Unicode since that breaks a ton of other code that I cannot patch at this point.

    Changing the (only active) window's CreateWindowEx call to CreateWindowExW (and patching up the associated RegisterClass) did the trick in that I now get propper Unicode character values in WM_CHAR's wParam, however the window title now cuts off after the first character.

    Yet if I change this:

    Code Block

    CreateWindowExW( WS_EX_APPWINDOW, L"WndClassName", L"MyCaption",

        WS_OVERLAPPED | WS_SYSMENU | WS_BORDER | WS_CAPTION, ...


    to this:

    Code Block

    CreateWindowExW( WS_EX_APPWINDOW, L"WndClassName", (LPCWSTR)"MyCaption",

        WS_OVERLAPPED | WS_SYSMENU | WS_BORDER | WS_CAPTION, ...


    the title text shows up fine.

    I've already tried throwing a W on the end of every windowing/message pump API call I can find and it changes nothing. Why is CreateWindowExW treating the caption parameter as though it's a single-byte character string? What else does the Unicode compiler option do that gets Windows to properly interpret the caption string? I'm at a bit of a loss here...

    Thus far I've managed to reproduce this behavior on Windows XP Pro, Windows XP Pro 64-bit, and Windows Vista Home Premium (32-bit).

    Thanks
    Thursday, December 20, 2007 4:30 AM

All replies

  • I've just had the same issue. Found the solution here:
    http://www.gamedev.net/community/forums/topic.asp?topic_id=458638

    To summarise, change:
    GetMessage -> GetMessageW or PeekMessage -> PeekMessageW
    DispatchMessage -> DispatchMessageW
    DefWindowProc -> DefWindowProcW

    By using DefWindowProcA, it was converting the set window name message from ANSII and treating the wide character's upper 8 bits as a null terminator.

    Thanks
    Paul
    Wednesday, October 21, 2009 9:23 AM