We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5435 - inconsistent/misleading use of windows ANSI/UNICODE api function calls
Summary: inconsistent/misleading use of windows ANSI/UNICODE api function calls
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Ozkan Sezer
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-02 16:58 UTC by Ozkan Sezer
Modified: 2021-01-07 19:10 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ozkan Sezer 2021-01-02 16:58:16 UTC
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. */
Comment 1 Sam Lantinga 2021-01-02 18:20:04 UTC
Let's go with LoadLibrary(TEXT("foo")), and the same for GetModuleHandleW(), etc. Your patch above also looks fine.

Thanks!
Comment 3 Ozkan Sezer 2021-01-04 07:01:40 UTC
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..
Comment 4 Ozkan Sezer 2021-01-05 12:50:47 UTC
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.
Comment 5 Ozkan Sezer 2021-01-07 19:10:02 UTC
Closing as fixed.