We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3168 - xinput build failure with dxsdk
Summary: xinput build failure with dxsdk
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-08 22:15 UTC by Ozkan Sezer
Modified: 2015-11-17 05:22 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ozkan Sezer 2015-11-08 22:15:36 UTC
Latest hg (rev. 9901 as of this writing) fails building whichever source
includes SDL_xinput.h against DXSDK June 2010 version.  The xinput.h in
the mentioned dxsdk does define struct _XINPUT_BATTERY_INFORMATION, but
it is guarded with #ifndef XINPUT_USE_9_1_0 and SDL sources and headers
do not define XINPUT_USE_9_1_0, so msvc fails when it finds the duplicated
typedef. This I experienced with MSVC-2005. Possibly the solution would
be defining XINPUT_USE_9_1_0 at top of SDL_xinput.h before xinput.h is
included.

In SDL_xinput.h, also had to replace _In_ with __in and _Out_ with __out
in XInputGetBatteryInformation_t definition, otherwise my MSVC-2005 had
some trouble. (This part might be something to do with my setup, not sure.)
Comment 1 Ozkan Sezer 2015-11-09 08:48:55 UTC
OK, the following change fixes the build for me. Tested with VS2005, 2008 and 2013.

--- SDL2/src/core/windows/SDL_xinput.h~
+++ SDL2/src/core/windows/SDL_xinput.h
@@ -26,6 +26,7 @@
 #ifdef HAVE_XINPUT_H
 
 #include "SDL_windows.h"
+#define XINPUT_USE_9_1_0 /* dxsdk compatibility */
 #include <xinput.h>
 
 #ifndef XUSER_MAX_COUNT
@@ -146,9 +147,9 @@
 
 typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
     (
-    _In_  DWORD                      dwUserIndex,
-    _In_  BYTE                       devType,
-    _Out_ XINPUT_BATTERY_INFORMATION *pBatteryInformation
+    __in  DWORD                      dwUserIndex,
+    __in  BYTE                       devType,
+    __out XINPUT_BATTERY_INFORMATION *pBatteryInformation
     );
 
 extern int WIN_LoadXInputDLL(void);


MinGW build is broken due to the same struct redifinition and also
because of the _In_/_Out_ or __in/__out stuff, but I don't have a
fix for it.
Comment 2 Ozkan Sezer 2015-11-09 10:15:11 UTC
OK, the following version fixes MinGW case, too.

--- SDL2/src/core/windows/SDL_xinput.h~
+++ SDL2/src/core/windows/SDL_xinput.h
@@ -26,6 +26,7 @@
 #ifdef HAVE_XINPUT_H
 
 #include "SDL_windows.h"
+#define XINPUT_USE_9_1_0 /* dxsdk compatibility */
 #include <xinput.h>
 
 #ifndef XUSER_MAX_COUNT
@@ -118,11 +119,13 @@
     XINPUT_GAMEPAD_EX Gamepad;
 } XINPUT_STATE_EX;
 
+#ifndef __MINGW32__
 typedef struct _XINPUT_BATTERY_INFORMATION
 {
     BYTE BatteryType;
     BYTE BatteryLevel;
 } XINPUT_BATTERY_INFORMATION, *PXINPUT_BATTERY_INFORMATION;
+#endif
 
 /* Forward decl's for XInput API's we load dynamically and use if available */
 typedef DWORD (WINAPI *XInputGetState_t)
@@ -144,11 +147,19 @@
     XINPUT_CAPABILITIES* pCapabilities  /* [out] Receives the capabilities */
     );
 
+#ifndef _MSC_VER
+#ifndef __in
+#define __in
+#endif
+#ifndef __out
+#define __out
+#endif
+#endif
 typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
     (
-    _In_  DWORD                      dwUserIndex,
-    _In_  BYTE                       devType,
-    _Out_ XINPUT_BATTERY_INFORMATION *pBatteryInformation
+    __in  DWORD                      dwUserIndex,
+    __in  BYTE                       devType,
+    __out XINPUT_BATTERY_INFORMATION *pBatteryInformation
     );
 
 extern int WIN_LoadXInputDLL(void);
Comment 3 Philipp Wiesemann 2015-11-15 18:26:35 UTC
This building failure was maybe fixed here:
https://hg.libsdl.org/SDL/rev/31b7adf67756
Comment 4 Ozkan Sezer 2015-11-15 20:01:32 UTC
Only the structure redefinition error is fixed, so not fully fixed:

1.  Older MinGW-w64 versions doesn't handle _In_/_Out_ and __in/__out 
 stuff, so they need defining.

2.  VS2005 still fails unless I replace those _In_/_Out_ with __in/__out.

So I suggest the following.

--- SDL2/src/core/windows/SDL_xinput.h~
+++ SDL2/src/core/windows/SDL_xinput.h
@@ -144,11 +144,19 @@
     XINPUT_CAPABILITIES* pCapabilities  /* [out] Receives the capabilities */
     );
 
+#ifndef _MSC_VER
+#ifndef __in
+#define __in
+#endif
+#ifndef __out
+#define __out
+#endif
+#endif /* ! _MSC_VER */
 typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
     (
-    _In_  DWORD                         dwUserIndex,
-    _In_  BYTE                          devType,
-    _Out_ XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
+    __in  DWORD                         dwUserIndex,
+    __in  BYTE                          devType,
+    __out XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
     );
 
 extern int WIN_LoadXInputDLL(void);
Comment 5 Alex Szpakowski 2015-11-16 03:24:54 UTC
Could the '_In_' and '_Out_' parts of the declaration simply be removed from SDL's code without issue, instead of making different compilers recognize them? From what I can tell (correct me if I'm wrong though), they're just macros that expand to nothing in normal circumstances.
Comment 6 Ozkan Sezer 2015-11-16 06:43:15 UTC
Yes, the annotations can actually be removed.  They are used only by MSVC and aren't vital.
Comment 7 Sam Lantinga 2015-11-17 05:22:09 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/ac5490d5aefc