| Summary: | inconsistent/misleading use of windows ANSI/UNICODE api function calls | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Ozkan Sezer <sezeroz> |
| Component: | *don't know* | Assignee: | Ozkan Sezer <sezeroz> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | Windows (All) | ||
Let's go with LoadLibrary(TEXT("foo")), and the same for GetModuleHandleW(), etc. Your patch above also looks fine.
Thanks!
Pushed the following: https://hg.libsdl.org/SDL/rev/ee405c036b91 https://hg.libsdl.org/SDL/rev/3c7f4fe6b587 https://hg.libsdl.org/SDL/rev/99c67f5783ee https://hg.libsdl.org/SDL/rev/beaa69311c40 https://hg.libsdl.org/SDL/rev/59f95219016b https://hg.libsdl.org/SDL/rev/24df29cff70e There are a few more things I'd like to look at before closing this. Made ANSI/UNICODE versions of WIN??UTF8 macros individually available: https://hg.libsdl.org/SDL/rev/a5af9b64b320 and pushed this: https://hg.libsdl.org/SDL/rev/55ff0bbedf23 There should be more of these.. Pushed https://hg.libsdl.org/SDL/rev/e8c96c9511cd and https://hg.libsdl.org/SDL/rev/57eaf41f8a15 The last one was tricky to work through but I think I got it right. If there are no issues, we can close this. Closing as fixed. |
We have inconsistencies in calling ANSI/UNICODE versions of win32 apis. Most noticeable one is LoadLibrary. E.g. we have: LoadLibrary(L"xx"), (core/windows/SDL_hid.c, core/windows/SDL_xinput.c, filesystem/windows/SDL_sysfilesystem.c) LoadLibrary(TEXT("xx")) (video/windows/SDL_windowsmessagebox.c) LoadLibraryW(L"xx") (audio/wasapi/SDL_wasapi_win32.c) LoadLibraryA("xx"), (hidapi/windows/hid.c, joystick/windows/SDL_windows_gaming_input.c, joystick/windows/SDL_rawinputjoystick.c) The 3rd and 4th versions are correct in that they are explicit, albeit inconsistent accross the source tree. The first one is wrong but works only because core/windows/SDL_windows.h does define UNICODE. The 2nd one is correct, and accommodates both ANSI and UNICODE options. What is the preferred style here? Should we always call ANSI or UNICODE? If the second, we should change all to the explicit LoadLibraryW(L"xx") version. Or we can change all to universal LoadLibrary(TEXT("xx")) version. If you tell me your decision, I can handle this janitorial task. (Speaking of TEXT("xx") usage: video/windows/SDL_windowswindow.c does do use that, but also suffers from the similar issues -- I suggest the following for it.) --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -47,8 +47,8 @@ /* Fake window to help with DirectInput events. */ HWND SDL_HelperWindow = NULL; -static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher"); -static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow"); +static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher"); +static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow"); static ATOM SDL_HelperWindowClass = 0; /* For borderless Windows, still want the following flags: @@ -826,7 +826,7 @@ SDL_HelperWindowCreate(void) /* Create the class. */ SDL_zero(wce); wce.lpfnWndProc = DefWindowProc; - wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName; + wce.lpszClassName = SDL_HelperWindowClassName; wce.hInstance = hInstance; /* Register the class. */