libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.79k stars 1.82k forks source link

compilability of WGI code against MinGW headers #5589

Closed sezero closed 2 years ago

sezero commented 2 years ago

MinGW-w64 recently imported all missing headers in git so that our WGI code can be compiled against it. However it was reported to me that the following patch is needed for the time being - not sure why, yet. I am putting this info here so that it may possibly be discussed and solved by help from others.

Hint: @icculus, @slouken. CC: @Biswa96

diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c
index 8b552bb..c1608a7 100644
--- a/src/joystick/windows/SDL_windows_gaming_input.c
+++ b/src/joystick/windows/SDL_windows_gaming_input.c
@@ -34,6 +34,11 @@
 #include <cfgmgr32.h>
 #include <roapi.h>

+#ifdef __MINGW32__
+#define __FIReference_1_int __FIReference_1_INT32
+#define __FIReference_1_int_get_Value __FIReference_1_INT32_get_Value
+#define __FIReference_1_int_Release __FIReference_1_INT32_Release
+#endif

 struct joystick_hwdata
 {
Biswa96 commented 2 years ago

I considered it as a workaround and not an issue of SDL code. The issue is a bit confusing (as always with any Microsoft stuff). According to the Windows.Devices.Power.idl file, the get_FullChargeCapacityInMilliwattHours function has the parameter of type Windows.Foundation.IReference<INT32> **. It was translated to __FIReference_1_INT32 ** type in Windows.Devices.Power.h in wine & mingw-w64. But the Microsoft Windows SDK translated it to __FIReference_1_int **.

slouken commented 2 years ago

This seems like a reasonable patch, with appropriate documentation

sezero commented 2 years ago

If looking at windows sdk headers is not out of the question, here is someone's github repo of them: https://github.com/hughbe/windows-sdk-headers

Biswa96 commented 2 years ago

There is also another confusion with Windows.Foundation.IReference<BYTE>** type. It is translated to __FIReference_1_byte** (see the different uppercase/lowercase).

By the way, I have not tested the SDL project with those new mingw-w64 headers due to absence of any gaming hardware. If anyone is willing to test the binaries compiled with mingw-w64 toolchain I can provide the necessary msys2/mingw headers & crt packages from CI.

sezero commented 2 years ago

Is it not more appropriate that the confusions are addressed in the idls and headers themselves, e.g. by proper defines?

Biswa96 commented 2 years ago

Is it not more appropriate that the confusions are addressed in the idls

Hence my first statement, "I considered it as a workaround and not an issue of SDL code". I have asked wine developers about this issue and they will be working on this but it may take time.

slouken commented 2 years ago

Patch added, thanks!

sezero commented 2 years ago

The patch isn't really a fix, and the new wgi headers are not in any mingw-w64 releases as far as I know: Remember to revert it when things get fixed in wine and mingw-w64

slouken commented 2 years ago

Yep, will do.

slouken commented 2 years ago

Actually, if the headers aren't in any release, I'll go ahead and revert this change and report it upstream.

slouken commented 2 years ago

Okay, I put in a better fix in d2c4d74dd0302369251dce9375b49f394e54f76a