lv2 / pugl

A minimal portable API for embeddable GUIs
https://gitlab.com/lv2/pugl/
ISC License
174 stars 34 forks source link

Windows: puglGetProcAddress calls wrong function if UNICODE macro is defined #124

Closed theuser27 closed 2 months ago

theuser27 commented 2 months ago

Hello everyone, I'm new to this library and tried to configure a build from scratch (for opengl shader demo on Windows 10 with Visual Studio 2022) since I didn't have meson installed and by default empty projects are automatically configured with Unicode character set which sets the UNICODE and _UNICODE macros. So upon trying to run the demo I got tripped up by a call in win_gl.c (puglGetProcAddress) to GetModuleFileName which was defined as GetModuleFileNameW and the parameter passed in was a normal char which gets interpreted as wide char . Because of that the function failed and I couldn't get a handle to opengl32.dll to get glGetString function pointer. After doing a short search I found that there's a different instance in win.c (puglRegisterWindowClass) where the GetModuleHandleEx macro might be susceptible to the same error. I would suggest choosing a specific version (either -A or -W with appropriate strings) of these and other functions macros to avoid such errors.

Cheers

drobilla commented 2 months ago

Whenever I'm feeling down, I remember that at least I've never screwed anything up nearly as badly as MS did Unicode.

drobilla commented 2 months ago

I would suggest choosing a specific version (either -A or -W with appropriate strings) of these and other functions macros to avoid such errors.

It's not that easy, but it's not that terrible to deal with: 996196c.

drobilla commented 2 months ago

Note that the API is always UTF-8, so you're probably going to have a bad time doing this for other reasons.

It's generally expected that applications aren't dealing with the win32 API directly much if at all (being the point of pugl), so I recommend using the https://utf8everywhere.org/ philosophy in your own code.