void GetCapabilities( int player, _Out_ Capabilities& caps ) { using namespace Microsoft::WRL; using namespace ABI::Windows::Xbox::Input; if ( WaitForSingleObjectEx( mChanged.get(), 0, FALSE ) == WAIT_OBJECT_0 ) { ScanGamePads(); } if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) ) { if ( mGamePad[ player ] ) { caps.connected = true; caps.gamepadType = Capabilities::UNKNOWN; ComPtr<IController> ctrl; HRESULT hr = mGamePad[ player ].As( &ctrl ); if ( SUCCEEDED(hr) && ctrl ) { hr = ctrl->get_Id( &caps.id ); if ( FAILED(hr) ) caps.id = 0; Wrappers::HString str; hr = ctrl->get_Type(str.GetAddressOf()); if ( SUCCEEDED(hr) ) { const wchar_t* typeStr = str.GetRawBuffer(nullptr); if ( _wcsicmp(typeStr, L"Windows.Xbox.Input.Gamepad") == 0 ) { caps.gamepadType = Capabilities::GAMEPAD; } else if ( _wcsicmp(typeStr, L"Microsoft.Xbox.Input.ArcadeStick") == 0 ) { caps.gamepadType = Capabilities::ARCADE_STICK; } else if ( _wcsicmp(typeStr, L"Microsoft.Xbox.Input.Wheel") == 0 ) { caps.gamepadType = Capabilities::WHEEL; } } } else caps.id = 0; return; } } memset( &caps, 0, sizeof(Capabilities) ); }
void GetCapabilities( int player, _Out_ Capabilities& caps ) { using namespace Microsoft::WRL; using namespace ABI::Windows::System; using namespace ABI::Windows::Gaming::Input; if ( WaitForSingleObjectEx( mChanged.get(), 0, FALSE ) == WAIT_OBJECT_0 ) { ScanGamePads(); } if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) ) { if ( mGamePad[ player ] ) { caps.connected = true; caps.gamepadType = Capabilities::GAMEPAD; caps.id.clear(); ComPtr<IGameController> ctrl; HRESULT hr = mGamePad[player].As(&ctrl); if (SUCCEEDED(hr) && ctrl) { ComPtr<IUser> user; hr = ctrl->get_User(user.GetAddressOf()); if (SUCCEEDED(hr)) { Wrappers::HString str; hr = user->get_NonRoamableId(str.GetAddressOf()); if (SUCCEEDED(hr)) { caps.id = str.GetRawBuffer(nullptr); } } } return; } } caps.id.clear(); caps = {}; }