bool CG27::InitializeG27() { HRESULT hr; // Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use. // Create a DInput object //initialize directinput library if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) ) return false; LPDIRECTINPUTDEVICE8 joystick; // Look for the first simple joystick we can find. if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, NULL, DIEDFL_ATTACHEDONLY))) { return false; } if (g_pJoystick == NULL) { // ShowMessageBox("g27 not found, please check the connection, exiting........"); qDebug() << "fucklrl"; return false; } if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2))) { // ShowMessageBox(" set g27 data format error, exiting......."); qDebug() << "fuckld"; return false; } g_pJoystick->SetCooperativeLevel(NULL, DISCL_EXCLUSIVE|DISCL_FOREGROUND); DIDEVCAPS capabilities; capabilities.dwSize = sizeof(DIDEVCAPS); g_pJoystick->GetCapabilities(&capabilities); if (FAILED(hr=g_pJoystick->EnumObjects(enumAxesCallback, NULL, DIDFT_AXIS))) { } qDebug() << "initializing succeeded"; return true; }
void initKeyboard( HWND hWnd ) { // create the keyboard device din->CreateDevice( GUID_SysKeyboard, // the default keyboard ID being used &dinKeyboard, // the pointer to the device interface NULL // COM stuff, so we'll set it to NULL ); dinKeyboard->SetDataFormat( &c_dfDIKeyboard ); // set the data format to keyboard format // set the control you will have over the keyboard dinKeyboard->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ); char** kn = keyNames; for ( unsigned short i = 0; i < MAX_KEYS; i++ ) *kn++ = ""; numKeys = 0; dinKeyboard->EnumObjects( &EnumKeysCallback, NULL, DIDFT_ALL ); }
void CJoystick::Initialize() { if (!IsEnabled()) return; HRESULT hr; // clear old joystick names ReleaseJoysticks(); CSingleLock lock(m_critSection); if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&m_pDI, NULL ) ) ) { CLog::Log(LOGDEBUG, __FUNCTION__" : Failed to create DirectInput"); return; } if( FAILED( hr = m_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, this, DIEDFL_ATTACHEDONLY ) ) ) return; if(m_pJoysticks.size() == 0) { CLog::Log(LOGDEBUG, __FUNCTION__" : No Joystick found"); return; } for(std::vector<LPDIRECTINPUTDEVICE8>::iterator it = m_pJoysticks.begin(); it != m_pJoysticks.end(); ++it) { LPDIRECTINPUTDEVICE8 pJoy = (*it); // Enumerate the joystick objects. The callback function enabled user // interface elements for objects that are found, and sets the min/max // values property for discovered axes. if( FAILED( hr = pJoy->EnumObjects( EnumObjectsCallback, pJoy, DIDFT_ALL ) ) ) CLog::Log(LOGDEBUG, __FUNCTION__" : Failed to enumerate objects"); } m_JoyId = -1; // Set deadzone range SetDeadzone(g_advancedSettings.m_controllerDeadzone); }
// コンストラクタ Gamepad::Gamepad(LPDIRECTINPUT8 dInput, HWND hWnd) { if (FAILED(dInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumGamepad, nullptr, DIEDFL_ATTACHEDONLY))) { return; } if (FAILED(dpad->SetDataFormat(&c_dfDIJoystick2))) { return; } if (FAILED(dpad->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND))) { return; } if (FAILED(dpad->EnumObjects(EnumAxis, nullptr, DIDFT_AXIS))) { return; } }
bool initKeyboard( HWND hWnd ) { // create the keyboard device HRESULT result = din->CreateDevice( GUID_SysKeyboard, // the default keyboard ID being used &dinKeyboard, // the pointer to the device interface NULL // COM stuff, so we'll set it to NULL ); if ( FAILED( result ) ) { logg( " ERROR: Unable to initialize keyboard." ); return ( false ); } if ( FAILED( dinKeyboard->SetDataFormat( &c_dfDIKeyboard ) ) ) // set the data format to keyboard format { logg( " ERROR: Unable to set keyboard data format." ); return ( false ); } // set the control you will have over the keyboard if ( FAILED( dinKeyboard->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ) ) ) { logg( " ERROR: Unable to set keyboard cooperative level." ); return ( false ); } char** kn = keyNames; for ( unsigned short i = 0; i < MAX_KEYS; i++ ) *kn++ = ""; numKeys = 0; if ( FAILED( dinKeyboard->EnumObjects( &EnumKeysCallback, NULL, DIDFT_ALL ) ) ) { logg( " ERROR: Unable to enumerate keyboard keys." ); return ( false ); } return ( true ); }
BOOL CALLBACK nxInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pInstance,VOID* ptData ) { // Skip XInput devices if (nxXInputDevice::IsXInputDevice(pInstance->guidProduct)) return DIENUM_CONTINUE; nxInputManager&objManager = nxInputManager::instance(); LPDIRECTINPUTDEVICE8 ptDevice; // Attempt to create a device interface for the joystick if (objManager.pDI->CreateDevice( pInstance->guidInstance, &ptDevice, NULL ) == DI_OK) { /*TODO: Set the range for axis and buttons DIPROPRANGE diPropRange; diPropRange.diph.dwSize = sizeof(DIPROPRANGE); diPropRange.diph.dwHeaderSize = sizeof(DIPROPHEADER);*/ // Set the device parameters if( ptDevice->SetDataFormat( &c_dfDIJoystick ) != DI_OK || ptDevice->SetCooperativeLevel(NULL,DISCL_BACKGROUND|DISCL_NONEXCLUSIVE) != DI_OK || ptDevice->EnumObjects(EnumObjectsCallback,reinterpret_cast<VOID*>(ptDevice),DIDFT_AXIS) != DI_OK) { ptDevice->Release(); } else { // Create the interface to device id mapping nxDeviceId uDevId = objManager.CreateDeviceId(); // Add the handle to device id mapping objManager.mpHandleId[ptDevice] = uDevId; // Add the device to the list of DInput devices (used for polling) objManager.stDInputDevices.insert(ptDevice); // Map the GUID to the device id objManager.SetGUIDMapping(uDevId,GUIDToString(pInstance->guidInstance)); } } return DIENUM_CONTINUE; }
BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE* instance, VOID* context) { HRESULT hr; LPDIRECTINPUTDEVICE8 lpdid; if (GET_DIDEVICE_TYPE(instance->dwDevType) == DI8DEVTYPE_MOUSE || GET_DIDEVICE_TYPE(instance->dwDevType) == DI8DEVTYPE_KEYBOARD ) return DIENUM_CONTINUE; hr = gp_DI->CreateDevice(instance->guidInstance, &lpdid, NULL); if(SUCCEEDED(hr)) { _dump_DIDEVICEINSTANCE(instance); printf("Objects:\n"); lpdid->EnumObjects(enumObjectsCallback, NULL, DIDFT_ALL); } else { printf("Error\n"); HRNAME(hr); } return DIENUM_CONTINUE; }
C_RESULT open_dx_gamepad(void) { HRESULT hr; HWND hDlg = GetConsoleHwnd(); // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. // Create a DInput object if (g_pDI==NULL) if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) ) return hr; if( g_bFilterOutXinputDevices ) SetupForIsXInputDevice(); DIJOYCONFIG PreferredJoyCfg = {0}; DI_ENUM_CONTEXT enumContext; enumContext.pPreferredJoyCfg = &PreferredJoyCfg; enumContext.bPreferredJoyCfgValid = false; IDirectInputJoyConfig8* pJoyConfig = NULL; if( VP_FAILED( hr = g_pDI->QueryInterface( IID_IDirectInputJoyConfig8, ( void** )&pJoyConfig ) ) ) return hr; PreferredJoyCfg.dwSize = sizeof( PreferredJoyCfg ); if( SUCCEEDED( pJoyConfig->GetConfig( 0, &PreferredJoyCfg, DIJC_GUIDINSTANCE ) ) ) // This function is expected to fail if no g_pJoystick is attached enumContext.bPreferredJoyCfgValid = true; SAFE_RELEASE( pJoyConfig ); // Look for a simple g_pJoystick we can use for this sample program. if( VP_FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, Enumg_pJoysticksCallback, &enumContext, DIEDFL_ATTACHEDONLY ) ) ) return hr; if( g_bFilterOutXinputDevices ) CleanupForIsXInputDevice(); // Make sure we got a g_pJoystick if( g_pJoystick == NULL ) { //MessageBox( NULL, TEXT( "Joystick not found." ), // TEXT( "A.R. Drone"), // MB_ICONERROR | MB_OK ); // EndDialog( hDlg, 0 ); return C_FAIL; } // Set the data format to "simple g_pJoystick" - a predefined data format // // A data format specifies which controls on a device we are interested in, // and how they should be reported. This tells DInput that we will be // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState(). if( VP_FAILED( hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) return C_FAIL; // Set the cooperative level to let DInput know how this device should // interact with the system and with other DInput applications. if( VP_FAILED( hr = g_pJoystick->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_FOREGROUND ) ) ) return C_FAIL; // Enumerate the g_pJoystick objects. The callback function enabled user // interface elements for objects that are found, and sets the min/max // values property for discovered axes. if( VP_FAILED( hr = g_pJoystick->EnumObjects( EnumObjectsCallback, ( VOID* )hDlg, DIDFT_ALL ) ) ) return C_FAIL; return C_OK; }
HRESULT InitDirectInput2( HWND hDlg ) { HRESULT hr; DIPROPDWORD dipdw; // Setup the g_EffectsList circular linked list ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) ); g_EffectsList.pNext = &g_EffectsList; // Create a DInput object if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) { ctx->OutputToConsole("PlayFFE :: DirectInput8Create"); return hr; } // Get the first enumerated force feedback device if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumFFDevicesCallback2, 0, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK ) ) ) { ctx->OutputToConsole("PlayFFE :: EnumDevices failed"); return hr; } if( g_pFFDevice == NULL ) { ctx->OutputToConsole("PlayFFE :: No force feedback device found."); return -1; } // Set the data format if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) ) return hr; // Set the coop level //hr = g_pFFDevice->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_FOREGROUND) ; hr = g_pFFDevice->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_BACKGROUND) ; //DISCL_NONEXCLUSIVE // Since we will be playing force feedback effects, we should disable the // auto-centering spring. dipdw.diph.dwSize = sizeof( DIPROPDWORD ); dipdw.diph.dwHeaderSize = sizeof( DIPROPHEADER ); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = FALSE; if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) ) return hr; // Enumerate and count the axes of the joystick if( FAILED( hr = g_pFFDevice->EnumObjects( EnumAxesCallback, ( VOID* )&g_dwNumForceFeedbackAxis, DIDFT_AXIS ) ) ) return hr; // This simple sample only supports one or two axis joysticks if( g_dwNumForceFeedbackAxis > 2 ) g_dwNumForceFeedbackAxis = 2; // This application needs only one effect: Applying raw forces. DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; LONG rglDirection[2] = { 0,0 }; DICONSTANTFORCE cf = { 0 }; cf.lMagnitude = 0; DIEFFECT eff; ZeroMemory( &eff, sizeof( eff ) ); eff.dwSize = sizeof( DIEFFECT ); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwDuration = INFINITE; eff.dwSamplePeriod = 0; eff.dwGain = DI_FFNOMINALMAX; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = g_dwNumForceFeedbackAxis; eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = 0; eff.cbTypeSpecificParams = sizeof( DICONSTANTFORCE ); eff.lpvTypeSpecificParams = &cf; eff.dwStartDelay = 0; // Create the prepared effect if( FAILED( hr = g_pFFDevice->CreateEffect( GUID_ConstantForce, &eff, &g_pEffect, NULL ) ) ) { return hr; } if( NULL == g_pEffect ) return E_FAIL; return S_OK; }
HRESULT InitDirectInput(unsigned int joystick_index) { HRESULT hr; state.is_initialized = false; // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. // Create a DInput object if (FAILED(hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, nullptr))) return hr; if (g_bFilterOutXinputDevices) SetupForIsXInputDevice(); enumContext.pPreferredJoyCfg = &PreferredJoyCfg; enumContext.bPreferredJoyCfgValid = false; IDirectInputJoyConfig8* pJoyConfig = nullptr; if (FAILED(hr = g_pDI->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig))) { state.message = "QueryInterface on IID_IDirectInputJoyConfig8 failed"; return hr; } PreferredJoyCfg.dwSize = sizeof(PreferredJoyCfg); if (SUCCEEDED(pJoyConfig->GetConfig(joystick_index, &PreferredJoyCfg, DIJC_GUIDINSTANCE))) { // This function is expected to fail if no joystick is attached enumContext.bPreferredJoyCfgValid = true; joystick_info.is_valid = true; joystick_info.instance_guide = toDIGUID(PreferredJoyCfg.guidInstance); joystick_info.pid_vid = toString(PreferredJoyCfg.wszType); } DIJT_SAFE_RELEASE(pJoyConfig); // Look for a simple joystick we can use for this sample program. if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, DirectInputJoyStick::impl::EnumJoysticksCallback, this, DIEDFL_ATTACHEDONLY))) { state.message = "EnumDevices failed"; return hr; } if (g_bFilterOutXinputDevices) CleanupForIsXInputDevice(); // Make sure we got a joystick if (!g_pJoystick) { state.message = "Joystick at index " + std::to_string(joystick_index) + " is not available"; return S_FALSE; } // Set the data format to "simple joystick" - a predefined data format // // A data format specifies which controls on a device we are interested in, // and how they should be reported. This tells DInput that we will be // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState(). if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2))) { state.message = "Device does not support DIJOYSTATE2"; return hr; } // Set the cooperative level to let DInput know how this device should // interact with the system and with other DInput applications. if (FAILED(hr = g_pJoystick->SetCooperativeLevel(NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) { state.message = "SetCooperativeLevel failed"; return hr; } // Enumerate the joystick objects. The callback function enabled user // interface elements for objects that are found, and sets the min/max // values property for discovered axes. if (FAILED(hr = g_pJoystick->EnumObjects(DirectInputJoyStick::impl::EnumObjectsCallback, (VOID*) this, DIDFT_ALL))) { state.message = "EnumObjects failed"; return hr; } InitForceFeedback(); state.is_initialized = true; return S_OK; }
HRESULT _stdcall EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKW a,LPVOID b,DWORD c) { return RealDevice->EnumObjects(a,b,c); }
// Create a force feedback effect handle and downloads the effect. Parameters are self-explanatory. bool CreateEffectHandle( HWND hWnd, LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LPDIRECTINPUTEFFECT &pDIEffect, BYTE bRumbleTyp, long lStrength ) { if( pDIEffect ) ReleaseEffect( pDIEffect ); if( !lpDirectInputDevice || bRumbleTyp == RUMBLE_DIRECT ) return false; DWORD nAxes = 0; DWORD rgdwAxes[] = { DIJOFS_X, DIJOFS_Y }; HRESULT hResult; // count the FF - axes of the joystick lpDirectInputDevice->EnumObjects( EnumCountFFAxes, &nAxes, DIDFT_FFACTUATOR | DIDFT_AXIS ); if( nAxes == 0 ) return false; nAxes = min( nAxes, 2 ); // Must be unaquired for setting stuff like Co-op Level hResult = lpDirectInputDevice->Unacquire(); //FF Requires EXCLUSIVE LEVEL, took me hours to find the reason why it wasnt working hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, DIB_FF ); // fail if we can't set coop level --rabid if (hResult != DI_OK) { DebugWriteA("CreateEffectHandle: couldn't set coop level: %08X\n", hResult); return false; } // Since we will be playing force feedback effects, we should disable the // auto-centering spring. DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = FALSE; hResult = lpDirectInputDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ); long rglDirection[] = { 1, 1 }; LPGUID EffectGuid; DIEFFECT eff; ZeroMemory( &eff, sizeof(eff) ); eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwGain = lStrength * 100; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = nAxes; //Number of Axes eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = NULL; eff.dwStartDelay = 0; DICONSTANTFORCE cf; DIRAMPFORCE rf; DIPERIODIC pf; switch( bRumbleTyp ) { case RUMBLE_CONSTANT: EffectGuid = (GUID*)&GUID_ConstantForce; eff.dwDuration = 150000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); eff.lpvTypeSpecificParams = &cf; cf.lMagnitude = 10000; break; case RUMBLE_RAMP: EffectGuid = (GUID*)&GUID_RampForce; eff.dwDuration = 300000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); eff.lpvTypeSpecificParams = &rf; rf.lStart = 10000; rf.lEnd = 2000; break; case RUMBLE_CONDITION: case RUMBLE_PERIODIC: EffectGuid = (GUID*)&GUID_Sine; eff.dwDuration = 150000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DIPERIODIC); eff.lpvTypeSpecificParams = &pf; pf.dwMagnitude = 10000; pf.lOffset = 0; pf.dwPhase = 0; pf.dwPeriod = 2000; break; case RUMBLE_NONE: case RUMBLE_CUSTOM: default: return false; } hResult = lpDirectInputDevice->CreateEffect( *EffectGuid, &eff, &pDIEffect, NULL ); if (hResult == DI_OK) { hResult = lpDirectInputDevice->Acquire(); hResult = pDIEffect->Download(); } else { DebugWriteA("CreateEffectHandle: didn't CreateEffect: %08X\n", hResult); } return SUCCEEDED( hResult ); }
// **if passed an existing DirectInputDevice which matches gGuid // unacquires it, and sets its cooperative level (reinitialize) // **if the existing device does not match the passed gGuid, the existing device is released // **if no device was passed or gGuid did not match // searches for the controller matching gGuid in connected and available devices // creates a DirectInputDevice // sets its data format // sets its cooperative level // for joysticks, calls EnumSetObjectsAxis for each axis // GetInputDevice always leaves the returned device in an UNACQUIRED state. bool GetInputDevice( HWND hWnd, LPDIRECTINPUTDEVICE8 &lpDirectInputDevice, GUID gGuid, DWORD dwDevType, DWORD dwCooperativeLevel ) { DebugWriteA("GetInputDevice: gGuid is {%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}\n", gGuid.Data1, gGuid.Data2, gGuid.Data3, gGuid.Data4[0], gGuid.Data4[1], gGuid.Data4[2], gGuid.Data4[3], gGuid.Data4[4], gGuid.Data4[5], gGuid.Data4[6], gGuid.Data4[7]); if( lpDirectInputDevice != NULL) { DIDEVICEINSTANCE didDev; didDev.dwSize = sizeof(DIDEVICEINSTANCE); lpDirectInputDevice->GetDeviceInfo( &didDev ); if( didDev.guidInstance == gGuid ) { // we've already gotten this device; unacquire it and initialize DebugWriteA("GetInputDevice: already created, attempting to reinit\n"); lpDirectInputDevice->Unacquire(); lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); return true; } else ReleaseDevice( lpDirectInputDevice ); } HRESULT hResult; LPCDIDATAFORMAT ppDiDataFormat = NULL; bool Success = false; switch( LOBYTE(dwDevType) ) { case DI8DEVTYPE_KEYBOARD: ppDiDataFormat = &c_dfDIKeyboard; break; case DI8DEVTYPE_MOUSE: ppDiDataFormat = &c_dfDIMouse2; break; //case DI8DEVTYPE_GAMEPAD: //case DI8DEVTYPE_JOYSTICK: //case DI8DEVTYPE_DRIVING: //case DI8DEVTYPE_1STPERSON: //case DI8DEVTYPE_FLIGHT: default: // assume everything else is a gamepad; probably not the best idea but it works ppDiDataFormat = &c_dfDIJoystick; break; } bool bDeviceAvailable = false; VOID* aRef[2] = { &gGuid, &bDeviceAvailable }; // for each available device in our dwDevType category, run EnumIsDeviceAvailable with params "aRef" g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumIsDeviceAvailable, (LPVOID)aRef, DIEDFL_ATTACHEDONLY ); if( !bDeviceAvailable ) { DebugWriteA("GetInputDevice: Device does not appear available\n"); return false; } hResult = g_pDIHandle->CreateDevice( gGuid, &lpDirectInputDevice, NULL ); if( SUCCEEDED( hResult )) { hResult = lpDirectInputDevice->SetDataFormat( ppDiDataFormat ); hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); Success = SUCCEEDED( hResult ); if (!Success) { DebugWriteA("GetInputDevice: SetCooperativeLevel failed\n"); } } else DebugWriteA("GetInputDevice: CreateDevice failed\n"); if( Success && ( ppDiDataFormat == &c_dfDIJoystick )) lpDirectInputDevice->EnumObjects( EnumSetObjectsAxis, lpDirectInputDevice, DIDFT_AXIS ); return Success; }