Question regarding DirectX
-
Hi I am new with DirectX and I need to get access to a joystick. So I have written the following code, but I am getting an error when I try to SetCooperativeLevel the return is E_HANDLE. I have checked the sample code and I am doing everything the same, and yet I am getting these error. Can anyone tell me why. I have attached the code:
HRESULT hr; if ( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**) &di, NULL ) ) ) { return hr; } if ( FAILED( hr = di->EnumDevices( DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY ) ) ) { // MessageBox( NULL, "An error has occurred while enumeration joysticks", NULL, MB_OK ); return ; } if ( joystick == NULL ) { //MessageBox( NULL, "Joysticks not Found", NULL, MB_OK ); return ; } if ( FAILED( hr = joystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) { //MessageBox( NULL, "An error has occurred while setting data format", NULL, MB_OK ); return ; } if ( FAILED( hr = joystick->SetCooperativeLevel( this->GetSafeHwnd(), DISCL_EXCLUSIVE | DISCL_FOREGROUND ) ) ) { //MessageBox( NULL, "An error occurred while setting cooperation levels", NULL, MB_OK ); int test = 0; // It dies here!!!!!!!!!!!! return ; }
-
Hi I am new with DirectX and I need to get access to a joystick. So I have written the following code, but I am getting an error when I try to SetCooperativeLevel the return is E_HANDLE. I have checked the sample code and I am doing everything the same, and yet I am getting these error. Can anyone tell me why. I have attached the code:
HRESULT hr; if ( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**) &di, NULL ) ) ) { return hr; } if ( FAILED( hr = di->EnumDevices( DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY ) ) ) { // MessageBox( NULL, "An error has occurred while enumeration joysticks", NULL, MB_OK ); return ; } if ( joystick == NULL ) { //MessageBox( NULL, "Joysticks not Found", NULL, MB_OK ); return ; } if ( FAILED( hr = joystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) { //MessageBox( NULL, "An error has occurred while setting data format", NULL, MB_OK ); return ; } if ( FAILED( hr = joystick->SetCooperativeLevel( this->GetSafeHwnd(), DISCL_EXCLUSIVE | DISCL_FOREGROUND ) ) ) { //MessageBox( NULL, "An error occurred while setting cooperation levels", NULL, MB_OK ); int test = 0; // It dies here!!!!!!!!!!!! return ; }
E_HANDLE "The HWND parameter is not a valid top-level window that belongs to the process" What window are you calling this from? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
E_HANDLE "The HWND parameter is not a valid top-level window that belongs to the process" What window are you calling this from? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I created a SDI application in MFC and passed in a viewclass's hwnd. Is this not correct. Thanks for the help
-
I created a SDI application in MFC and passed in a viewclass's hwnd. Is this not correct. Thanks for the help
It should be a top-level window. The main frame window should work. One way to get it is AfxGetApp()->GetMainWnd()->GetSafeHwnd() Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: