servers: drop CRT and curlx calls from main_window_loop() (Windows)

To simplify and to avoid the chance of potential interference or
thread-safety issues. If one these 3 Win32 API calls fail, there is
likely a serious problem, out of the code's control. Knowing
`GetLastError()` is unlikely to help.

Refs:
https://learn.microsoft.com/windows/win32/api/winuser/nc-winuser-wndproc
https://learn.microsoft.com/previous-versions/windows/desktop/legacy/ms686736(v=vs.85)
https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-getmessage
https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-createwindowexa
https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-registerclassa

Ref: 9ea48811fe #22487
Ref: 1c49f2f26d #18451
Follow-up to ac1e206278

Closes #22045
This commit is contained in:
Viktor Szakats 2026-06-16 13:50:51 +02:00
parent de9919f38a
commit 7db9947fcf
No known key found for this signature in database

View file

@ -471,7 +471,7 @@ static LRESULT CALLBACK main_window_proc(HWND hwnd, UINT uMsg,
static const char msg[] = "main_window_proc(): WM_CLOSE -> SIGTERM\n"; static const char msg[] = "main_window_proc(): WM_CLOSE -> SIGTERM\n";
DWORD dwWritten; DWORD dwWritten;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, CURL_CSTRLEN(msg), WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, CURL_CSTRLEN(msg),
&dwWritten, NULL); &dwWritten, NULL);
exit_msg = msg; exit_msg = msg;
initiate_exit(SIGTERM); initiate_exit(SIGTERM);
break; break;
@ -490,17 +490,16 @@ static DWORD WINAPI main_window_loop(void *lpParameter)
WNDCLASS wc; WNDCLASS wc;
BOOL ret; BOOL ret;
MSG msg; MSG msg;
DWORD err; DWORD dwWritten;
char buffer[WINAPI_ERROR_LEN];
ZeroMemory(&wc, sizeof(wc)); ZeroMemory(&wc, sizeof(wc));
wc.lpfnWndProc = (WNDPROC)main_window_proc; wc.lpfnWndProc = (WNDPROC)main_window_proc;
wc.hInstance = (HINSTANCE)lpParameter; wc.hInstance = (HINSTANCE)lpParameter;
wc.lpszClassName = TEXT("MainWClass"); wc.lpszClassName = TEXT("MainWClass");
if(!RegisterClass(&wc)) { if(!RegisterClass(&wc)) {
err = GetLastError(); static const char str[] = "RegisterClass() failed\n";
curlx_winapi_strerror(err, buffer, sizeof(buffer)); WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str),
fprintf(stderr, "RegisterClass failed: %s\n", buffer); &dwWritten, NULL);
return (DWORD)-1; return (DWORD)-1;
} }
@ -512,18 +511,18 @@ static DWORD WINAPI main_window_loop(void *lpParameter)
(HWND)NULL, (HMENU)NULL, (HWND)NULL, (HMENU)NULL,
wc.hInstance, NULL); wc.hInstance, NULL);
if(!hidden_main_window) { if(!hidden_main_window) {
err = GetLastError(); static const char str[] = "CreateWindowEx() failed\n";
curlx_winapi_strerror(err, buffer, sizeof(buffer)); WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str),
fprintf(stderr, "CreateWindowEx failed: (0x%08lx) - %s\n", err, buffer); &dwWritten, NULL);
return (DWORD)-1; return (DWORD)-1;
} }
do { do {
ret = GetMessage(&msg, NULL, 0, 0); ret = GetMessage(&msg, NULL, 0, 0);
if(ret == -1) { if(ret == -1) {
err = GetLastError(); static const char str[] = "GetMessage() failed\n";
curlx_winapi_strerror(err, buffer, sizeof(buffer)); WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str),
fprintf(stderr, "GetMessage failed: (0x%08lx) - %s\n", err, buffer); &dwWritten, NULL);
return (DWORD)-1; return (DWORD)-1;
} }
else if(ret) { else if(ret) {