Restore ANSI win32 API functions (PR #25965)

38 views
Skip to first unread message

Maarten

unread,
Nov 9, 2025, 9:08:37 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed

wxWidgets is always build in UNICODE using the WIDE win32 API functions. But applications using it might be built without UNICODE, using the ANSI win32 functions.

Right now wxWidgets #undefs some of the win32 API functions and defines them as inline functions using the WIDE win32 API. Making these unavailable for applications that want to use the ANSI versions later.

Fix this by inlining the functions as WIDE only when UNICODE was already defined, not when wxWidgets defines it themselves in platform.h.

See #25803

cc @jamarr81 would this work?


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/25965

Commit Summary

  • 9df7257 Remove unneeded winundef.h includes
  • 3cbe762 Partially revert 53b3b979fe (Remove tests for _UNICODE too)
  • 3378f9f Restore ANSI win32 functions if UNICODE was not set
  • bafbaa6 White-space and style cleanup in winundef.h

File Changes

(10 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965@github.com>

Maarten

unread,
Nov 9, 2025, 9:46:07 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Push

@MaartenBent pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/before/bafbaa6c62d4e78b0df462eab50ae30a02c44762/after/ce274d3687909f5c14324b0a18aed07e5ea31fc5@github.com>

VZ

unread,
Nov 9, 2025, 10:13:52 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks, I think this should work and I can't think of anything else that this would break, but I'd prefer to condense all the wrapper definitions using a helper macro before merging this.


In include/wx/msw/winundef.h:

> +    #if wxUSE_UNICODE_WINDOWS_H
         return CreateDialogW(hInstance, pTemplate, hwndParent, pDlgProc);
+    #else
+        return CreateDialogA(hInstance, pTemplate, hwndParent, pDlgProc);
+    #endif

Could we just define our own wxFUNC_AW() macro once, depending on wxUSE_UNICODE_WINDOWS_H value, and then replace all these fragments with just

⬇️ Suggested change
-    #if wxUSE_UNICODE_WINDOWS_H
-        return CreateDialogW(hInstance, pTemplate, hwndParent, pDlgProc);
-    #else
-        return CreateDialogA(hInstance, pTemplate, hwndParent, pDlgProc);
-    #endif
+        return wxFUNC_AW(CreateDialog)(hInstance, pTemplate, hwndParent, pDlgProc);

?


In include/wx/msw/winundef.h:

> +    #define wxLPCTSTR LPCWSTR
+    #define wxLPSTR LPWSTR
+    #define wxLPWNDCLASS LPWNDCLASSW
+    #define wxDOCINFO DOCINFOW
+    #define wxLPFINDREPLACE LPFINDREPLACEW

Minor, but these could be typedefs (or even using) if we try to minimize the use of preprocessor (possibly not really helpful in this header...).


In include/wx/msw/winundef.h:

>  //
 // This looks quite ugly here but allows us to write clear (and correct!) code
 // elsewhere because the functions, unlike the macros, respect the scope

Maarten

unread,
Nov 9, 2025, 10:39:44 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Push

@MaartenBent pushed 2 commits.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/before/ce274d3687909f5c14324b0a18aed07e5ea31fc5/after/243773e307f12f331551f559f971d2d39f7f321d@github.com>

Maarten

unread,
Nov 9, 2025, 11:07:44 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In include/wx/msw/winundef.h:

> +    #define wxLPCTSTR LPCWSTR
+    #define wxLPSTR LPWSTR
+    #define wxLPWNDCLASS LPWNDCLASSW
+    #define wxDOCINFO DOCINFOW
+    #define wxLPFINDREPLACE LPFINDREPLACEW

typedef/using doesn't work when these types are not defined. Apparent in the non-PCH builds.

This can happen for example when winundef.h is included but windows.h is not, like in wrapcdlg.h or ioswrap.h or iosfwrap.h.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/review/3440113099@github.com>

Maarten

unread,
Nov 9, 2025, 11:33:52 AM (2 days ago) Nov 9
to wx-...@googlegroups.com, Push

@MaartenBent pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/before/243773e307f12f331551f559f971d2d39f7f321d/after/92900acbe3b7f86b92814d6741c211c25d5397be@github.com>

Maarten

unread,
Nov 9, 2025, 3:44:44 PM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed
MaartenBent left a comment (wxWidgets/wxWidgets#25965)

Not sure how to fix these last errors in CI. In this case UNICODE is not defined by the build system / user. So wxWidgets defines is. Then windows.h is included (with UNICODE defined), resulting in TEXT and other defines/macros becoming the WIDE variant.

But later in the application code, after winundef.h, the ANSI variants will be used. But TEXT is still the WIDE variant.

I think I'll just let it default to the WIDE variant, unless the application defines wxWIN32_UNDEF_AS_ANSI before including wx headers:

#if defined(WXBUILDING) || !defined(wxWIN32_UNDEF_AS_ANSI)
   // wide
#else
   // ansi
#endif


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/c3508818904@github.com>

VZ

unread,
Nov 9, 2025, 4:04:58 PM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25965)

We could define something (_UNICODE?) in the sample to work around this problem there but it seems indeed safer and better to require predefining some symbol if you really need A versions of the API. But arguably, wxNO_WIN32_WIDE_FUNCTIONS (or just wxNO_WIN32_W) would be more in line with our preprocessor symbol naming conventions.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/c3508834548@github.com>

Maarten

unread,
Nov 9, 2025, 5:19:36 PM (2 days ago) Nov 9
to wx-...@googlegroups.com, Push

@MaartenBent pushed 4 commits.

  • 8593de0 Remove unneeded winundef.h includes
  • 5228892 White-space and style cleanup in winundef.h
  • 2b2160c Restore ANSI win32 functions if UNICODE is not set
  • dff7453 Use WIDE variant of win32 API functions


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/before/92900acbe3b7f86b92814d6741c211c25d5397be/after/dff74533df9504a418802634651aa270f692ec35@github.com>

jamarr

unread,
Nov 9, 2025, 7:03:20 PM (2 days ago) Nov 9
to wx-...@googlegroups.com, Subscribed
jamarr81 left a comment (wxWidgets/wxWidgets#25965)

@MaartenBent @vadz tysm for following up on this! I haven't had a chance to revisit it; however, these changes look good to me on paper.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/c3508973616@github.com>

Maarten

unread,
Nov 10, 2025, 5:13:17 PM (19 hours ago) Nov 10
to wx-...@googlegroups.com, Push

@MaartenBent pushed 2 commits.

  • b7705f8 Add option to restore ANSI win32 functions
  • 940b850 Use WIDE variant of win32 API functions


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/before/dff74533df9504a418802634651aa270f692ec35/after/940b850b8e0bccc0950e84c8b32fd9bbc98a3750@github.com>

VZ

unread,
10:45 AM (1 hour ago) 10:45 AM
to wx-...@googlegroups.com, Subscribed

@vadz approved this pull request.

Looks good, thanks!

It would be great if this could be tested in some application which needed this, but if nobody does it soon, I'll just merge this and hope that it works for them.


In include/wx/msw/private.h:

> @@ -847,13 +847,13 @@ class ClassRegistrar
     bool IsRegistered() const { return m_registered == 1; }
 
     // try to register the class if not done yet, return true on success
-    bool Register(const WNDCLASS& wc)
+    bool Register(const WNDCLASSW& wc)

It would be good to add a test for compiling this file with wxNO_WIN32_W to at least one MSW CI job to catch any errors that could be introduced into it later by forgetting to explicitly use W symbol versions.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/25965/review/3448684920@github.com>

Reply all
Reply to author
Forward
0 new messages