@@ -19,17 +19,19 @@ using Microsoft::WRL::ComPtr;
1919#pragma region Implementations
2020#ifdef USING_GAMEINPUT
2121
22- #include < GameInput.h>
22+ // ======================================================================================
23+ // Win32 + GameInput implementation
24+ // ======================================================================================
2325
2426#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
2527using namespace GameInput ::v1;
2628#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
2729using namespace GameInput ::v2;
30+ #elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 3)
31+ using namespace GameInput ::v3;
2832#endif
2933
30- // ======================================================================================
31- // Win32 + GameInput implementation
32- // ======================================================================================
34+ using GameInputCreateFn = HRESULT(*)(IGameInput**);
3335
3436//
3537// Call this static function from your Window Message Procedure
@@ -83,7 +85,26 @@ class Mouse::Impl
8385
8486 s_mouse = this ;
8587
88+ #if defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION)
8689 HRESULT hr = GameInputCreate (mGameInput .GetAddressOf ());
90+ #else
91+ if (!s_gameInputCreate)
92+ {
93+ s_gameInputModule = LoadLibraryExW (L" GameInput.dll" , nullptr , LOAD_LIBRARY_SEARCH_SYSTEM32);
94+ if (s_gameInputModule)
95+ {
96+ s_gameInputCreate = reinterpret_cast <GameInputCreateFn>(static_cast <void *>(GetProcAddress (s_gameInputModule, " GameInputCreate" )));
97+ }
98+
99+ if (!s_gameInputCreate)
100+ {
101+ DebugTrace (" ERROR: GetProcAddress GameInputCreate failed\n " );
102+ throw std::runtime_error (" GameInput.dll is not installed on this system" );
103+ }
104+ }
105+
106+ HRESULT hr = s_gameInputCreate (mGameInput .GetAddressOf ());
107+ #endif
87108 if (SUCCEEDED (hr))
88109 {
89110 ThrowIfFailed (mGameInput ->RegisterDeviceCallback (
@@ -99,12 +120,11 @@ class Mouse::Impl
99120 {
100121 DebugTrace (" ERROR: GameInputCreate [mouse] failed with %08X\n " , static_cast <unsigned int >(hr));
101122 #ifdef _GAMING_XBOX
102- ThrowIfFailed (hr);
103- #elif defined(_DEBUG)
123+ throw com_exception (hr);
124+ #else
104125 DebugTrace (
105- " \t **** Check that the 'GameInput Service' is running on this system. ****\n "
106- " \t **** NOTE: No relative movement be returned and IsConnected will return false. ****\n "
107- );
126+ " \t **** Install the latest GameInputRedist package on this system. ****\n "
127+ " \t **** NOTE: All calls to GetState will be reported as 'not connected'. ****\n " );
108128 #endif
109129 }
110130
@@ -367,12 +387,20 @@ class Mouse::Impl
367387 ClipCursor (&rect);
368388 #endif
369389 }
390+
391+ #if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
392+ static HMODULE s_gameInputModule;
393+ static GameInputCreateFn s_gameInputCreate;
394+ #endif
370395};
371396
397+ #if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
398+ HMODULE Mouse::Impl::s_gameInputModule = nullptr ;
399+ GameInputCreateFn Mouse::Impl::s_gameInputCreate = nullptr ;
400+ #endif
372401
373402Mouse::Impl* Mouse::Impl::s_mouse = nullptr ;
374403
375-
376404void Mouse::ProcessMessage (UINT message, WPARAM wParam, LPARAM lParam)
377405{
378406 auto pImpl = Impl::s_mouse;
0 commit comments