Original Post
This is my function for getting the state of the keyboard HRESULT Input::UpdateKeyboard() { HRESULT hr; // What? if( NULL == m_pKeyboard ) return S_OK; // Get the input's device state, and put the state in dims memcpy(m_OldKeys, m_Keys, 256); ZeroMemory( m_Keys, 256 ); hr = m_pKeyboard->GetDeviceState( sizeof(m_Keys), m_Keys ); if( FAILED(hr) ) { // DirectInput may be telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. // We just re-acquire and try again. // If input is lost then acquire and keep trying // can this cause an endless loop hr = m_pKeyboard->Acquire(); while( hr == DIERR_INPUTLOST ) hr = m_pKeyboard->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } for(int iIndex = 0; iIndex < 256 ; iIndex++) { if(!m_OldKeys[iIndex] && m_Keys[iIndex]) { m_bWasKeyHit = true; m_PressedKeys[iIndex] = m_Keys[iIndex]; } if(m_OldKeys[iIndex] && !m_Keys[iIndex]) { m_bWasKeyReleased = true; m_ReleasedKeys[iIndex] = m_OldKeys[iIndex]; } } return S_OK; } My app crashes after running for about 20 seconds from an access violation at the following line. hr = m_pKeyboard->GetDeviceState( sizeof(m_Keys), m_Keys ); Here is the info from the debug window DINPUT8: Acquire: Previous owner pid=0x00000EDC mysteriously died; stealing 'Ares.exe': Loaded 'C:\Program Files\Common Files\Logitech\Scrolling\LGMSGHK.DLL', No symbols loaded. DINPUT8: Acquire: Previous owner pid=0x00000EDC mysteriously died; stealing 'Ares.exe': Unloaded 'C:\Program Files\Musicmatch\Musicmatch Jukebox\KeyboardHookDll.dll' 'Ares.exe': Unloaded 'C:\WINDOWS\system32\msvcr71.dll' First-chance exception at 0x6d30f73e in Ares.exe: 0xC0000005: Access violation reading location 0x3f500028. Unhandled exception at 0x6d30f73e in Ares.exe: 0xC0000005: Access violation reading location 0x3f500028. Why is this happening?