fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
792 stars 126 forks source link

Win32 build issue with Unicode #75

Open walbourn opened 1 year ago

walbourn commented 1 year ago

Per the UTF-8 Everywhere Manifesto, it's best to not rely on the legacy ANSI .vs UNICODE macros for Win32 functions that take strings. Since you explicitly use an ANSI string for the call to LoadLibrary you should explicitly use the LoadLibraryA method.

This causes problems when trying to build your library using vcpkg manager when the setup adds the recommended UNICODE _UNICODE defines.

In exception.cpp use FormatMessageA instead of FormatMessage.

fpagliughi commented 1 year ago

Ugh. The Win32 API just confuses the hell out of me! But thanks for the tip. Let me know if you spot anything else. I'll look to get a little fix release out in the next few weeks.

BTW... If you have a suggestion for a better way to do this, let me know.

walbourn commented 1 year ago

Blame on back-compat with 16-bit Windows and the transition from ANSI to Unicode :)

LoadLibrary and FormatMessage aren't actually functions. They are just macros based on MBCS vs. UNICODE settings. By explicitly calling LoadLibraryA you are ignoring those crazy macros. For more information on why this is a 'best practice' these days, see UTF-8 Everywhere.

fpagliughi commented 1 year ago

Ha. Yeah, I'm so old, the last time I programmed Windows professionally, I was dealing with segments and offsets, not Unicode! I didn't realize those agnostic "functions" were actually macros. Thanks.

walbourn commented 1 year ago

It's all part of the TCHAR and Uniscribe pain that was Windows 9x :)