Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Inc/GamePad.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#ifdef USING_GAMEINPUT
#include <GameInput.h>
#if !defined(_GAMING_XBOX) && defined(_MSC_VER)
#if defined(_MSC_VER) && (defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION))
#pragma comment(lib,"gameinput.lib")
#endif

Expand Down Expand Up @@ -335,6 +335,8 @@ namespace DirectX
using GameInputDevice_t = GameInput::v1::IGameInputDevice;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
using GameInputDevice_t = GameInput::v2::IGameInputDevice;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 3)
using GameInputDevice_t = GameInput::v3::IGameInputDevice;
#else
using GameInputDevice_t = ::IGameInputDevice;
#endif
Expand Down
5 changes: 4 additions & 1 deletion Inc/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

#endif // !USING_XINPUT && !USING_GAMEINPUT && !USING_WINDOWS_GAMING_INPUT

#if defined(USING_GAMEINPUT) && !defined(_GAMING_XBOX) && defined(_MSC_VER)
#ifdef USING_GAMEINPUT
#include <GameInput.h>
#if defined(_MSC_VER) && (defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION))
#pragma comment(lib,"gameinput.lib")
#endif
#endif

#include <cstdint>
#include <memory>
Expand Down
5 changes: 4 additions & 1 deletion Inc/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

#endif // !USING_XINPUT && !USING_GAMEINPUT && !USING_WINDOWS_GAMING_INPUT

#if defined(USING_GAMEINPUT) && !defined(_GAMING_XBOX) && defined(_MSC_VER)
#ifdef USING_GAMEINPUT
#include <GameInput.h>
#if defined(_MSC_VER) && (defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION))
#pragma comment(lib,"gameinput.lib")
#endif
#endif

#include <cstdint>
#include <memory>
Expand Down
45 changes: 39 additions & 6 deletions Src/GamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ namespace
#pragma region Implementations
#ifdef USING_GAMEINPUT

//======================================================================================
// GameInput
//======================================================================================

#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
using namespace GameInput::v1;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
using namespace GameInput::v2;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 3)
using namespace GameInput::v3;
#endif

//======================================================================================
// GameInput
//======================================================================================
using GameInputCreateFn = HRESULT(*)(IGameInput**);

class GamePad::Impl
{
Expand All @@ -110,7 +114,26 @@ class GamePad::Impl

s_gamePad = this;

#if defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION)
HRESULT hr = GameInputCreate(mGameInput.GetAddressOf());
#else
if (!s_gameInputCreate)
{
s_gameInputModule = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (s_gameInputModule)
{
s_gameInputCreate = reinterpret_cast<GameInputCreateFn>(static_cast<void*>(GetProcAddress(s_gameInputModule, "GameInputCreate")));
}

if (!s_gameInputCreate)
{
DebugTrace("ERROR: GetProcAddress GameInputCreate failed\n");
throw std::runtime_error("GameInput.dll is not installed on this system");
}
}

HRESULT hr = s_gameInputCreate(mGameInput.GetAddressOf());
#endif
if (SUCCEEDED(hr))
{
ThrowIfFailed(mGameInput->RegisterDeviceCallback(
Expand All @@ -126,10 +149,10 @@ class GamePad::Impl
{
DebugTrace("ERROR: GameInputCreate [gamepad] failed with %08X\n", static_cast<unsigned int>(hr));
#ifdef _GAMING_XBOX
ThrowIfFailed(hr);
#elif defined(_DEBUG)
throw com_exception(hr);
#else
DebugTrace(
"\t**** Check that the 'GameInput Service' is running on this system. ****\n"
"\t**** Install the latest GameInputRedist package on this system. ****\n"
"\t**** NOTE: All calls to GetState will be reported as 'not connected'. ****\n");
#endif
}
Expand Down Expand Up @@ -417,10 +440,20 @@ class GamePad::Impl
SetEvent(impl->mCtrlChanged);
}
}

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
static HMODULE s_gameInputModule;
static GameInputCreateFn s_gameInputCreate;
#endif
};

GamePad::Impl* GamePad::Impl::s_gamePad = nullptr;

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
HMODULE GamePad::Impl::s_gameInputModule = nullptr;
GameInputCreateFn GamePad::Impl::s_gameInputCreate = nullptr;
#endif

void GamePad::RegisterEvents(HANDLE ctrlChanged) noexcept
{
pImpl->mCtrlChanged = (!ctrlChanged) ? INVALID_HANDLE_VALUE : ctrlChanged;
Expand Down
49 changes: 38 additions & 11 deletions Src/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ namespace
#pragma region Implementations
#ifdef USING_GAMEINPUT

#include <GameInput.h>
//======================================================================================
// GameInput
//======================================================================================

#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
using namespace GameInput::v1;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
using namespace GameInput::v2;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 3)
using namespace GameInput::v3;
#endif


//======================================================================================
// GameInput
//======================================================================================
using GameInputCreateFn = HRESULT(*)(IGameInput**);

class Keyboard::Impl
{
Expand All @@ -80,7 +81,26 @@ class Keyboard::Impl

s_keyboard = this;

#if defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION)
HRESULT hr = GameInputCreate(mGameInput.GetAddressOf());
#else
if (!s_gameInputCreate)
{
s_gameInputModule = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (s_gameInputModule)
{
s_gameInputCreate = reinterpret_cast<GameInputCreateFn>(static_cast<void*>(GetProcAddress(s_gameInputModule, "GameInputCreate")));
}

if (!s_gameInputCreate)
{
DebugTrace("ERROR: GetProcAddress GameInputCreate failed\n");
throw std::runtime_error("GameInput.dll is not installed on this system");
}
}

HRESULT hr = s_gameInputCreate(mGameInput.GetAddressOf());
#endif
if (SUCCEEDED(hr))
{
ThrowIfFailed(mGameInput->RegisterDeviceCallback(
Expand All @@ -96,12 +116,11 @@ class Keyboard::Impl
{
DebugTrace("ERROR: GameInputCreate [keyboard] failed with %08X\n", static_cast<unsigned int>(hr));
#ifdef _GAMING_XBOX
ThrowIfFailed(hr);
#elif defined(_DEBUG)
throw com_exception(hr);
#else
DebugTrace(
"\t**** Check that the 'GameInput Service' is running on this system. ****\n"
"\t**** NOTE: No keys will be returned and IsConnected will return false. ****\n"
);
"\t**** Install the latest GameInputRedist package on this system. ****\n"
"\t**** NOTE: All calls to GetState will be reported as 'not connected'. ****\n");
#endif
}
}
Expand Down Expand Up @@ -208,11 +227,19 @@ class Keyboard::Impl
--impl->mConnected;
}
}
};

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
static HMODULE s_gameInputModule;
static GameInputCreateFn s_gameInputCreate;
#endif
};

Keyboard::Impl* Keyboard::Impl::s_keyboard = nullptr;

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
HMODULE Keyboard::Impl::s_gameInputModule = nullptr;
GameInputCreateFn Keyboard::Impl::s_gameInputCreate = nullptr;
#endif

void Keyboard::ProcessMessage(UINT, WPARAM, LPARAM) noexcept
{
Expand Down
48 changes: 38 additions & 10 deletions Src/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ using Microsoft::WRL::ComPtr;
#pragma region Implementations
#ifdef USING_GAMEINPUT

#include <GameInput.h>
//======================================================================================
// Win32 + GameInput implementation
//======================================================================================

#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
using namespace GameInput::v1;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
using namespace GameInput::v2;
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 3)
using namespace GameInput::v3;
#endif

//======================================================================================
// Win32 + GameInput implementation
//======================================================================================
using GameInputCreateFn = HRESULT(*)(IGameInput**);

//
// Call this static function from your Window Message Procedure
Expand Down Expand Up @@ -83,7 +85,26 @@ class Mouse::Impl

s_mouse = this;

#if defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION)
HRESULT hr = GameInputCreate(mGameInput.GetAddressOf());
#else
if (!s_gameInputCreate)
{
s_gameInputModule = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (s_gameInputModule)
{
s_gameInputCreate = reinterpret_cast<GameInputCreateFn>(static_cast<void*>(GetProcAddress(s_gameInputModule, "GameInputCreate")));
}

if (!s_gameInputCreate)
{
DebugTrace("ERROR: GetProcAddress GameInputCreate failed\n");
throw std::runtime_error("GameInput.dll is not installed on this system");
}
}

HRESULT hr = s_gameInputCreate(mGameInput.GetAddressOf());
#endif
if (SUCCEEDED(hr))
{
ThrowIfFailed(mGameInput->RegisterDeviceCallback(
Expand All @@ -99,12 +120,11 @@ class Mouse::Impl
{
DebugTrace("ERROR: GameInputCreate [mouse] failed with %08X\n", static_cast<unsigned int>(hr));
#ifdef _GAMING_XBOX
ThrowIfFailed(hr);
#elif defined(_DEBUG)
throw com_exception(hr);
#else
DebugTrace(
"\t**** Check that the 'GameInput Service' is running on this system. ****\n"
"\t**** NOTE: No relative movement be returned and IsConnected will return false. ****\n"
);
"\t**** Install the latest GameInputRedist package on this system. ****\n"
"\t**** NOTE: All calls to GetState will be reported as 'not connected'. ****\n");
#endif
}

Expand Down Expand Up @@ -367,12 +387,20 @@ class Mouse::Impl
ClipCursor(&rect);
#endif
}

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
static HMODULE s_gameInputModule;
static GameInputCreateFn s_gameInputCreate;
#endif
};

#if !defined(_GAMING_XBOX) && !defined(GAMEINPUT_API_VERSION)
HMODULE Mouse::Impl::s_gameInputModule = nullptr;
GameInputCreateFn Mouse::Impl::s_gameInputCreate = nullptr;
#endif

Mouse::Impl* Mouse::Impl::s_mouse = nullptr;


void Mouse::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
auto pImpl = Impl::s_mouse;
Expand Down
Loading