Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Question regarding DirectX

Question regarding DirectX

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    godspeed123
    wrote on last edited by
    #1

    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 ; }

    M 1 Reply Last reply
    0
    • G godspeed123

      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 ; }

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      G 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        G Offline
        G Offline
        godspeed123
        wrote on last edited by
        #3

        I created a SDI application in MFC and passed in a viewclass's hwnd. Is this not correct. Thanks for the help

        M 1 Reply Last reply
        0
        • G godspeed123

          I created a SDI application in MFC and passed in a viewclass's hwnd. Is this not correct. Thanks for the help

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups