DirectInput help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 200dogz
    New Member
    • Oct 2008
    • 52

    DirectInput help

    I'm trying to use DirectInput in the DirectX SDK to do USB
    reading (a device as joystick). There's no error when compiling the codes but whenever it
    tries to excecute:

    g_pDI->EnumDevices(DI 8DEVCLASS_GAMEC TRL, EnumJoysticksCa llback,
    NULL, DIEDFL_ATTACHED ONLY);

    where

    BOOL CALLBACK EnumJoysticksCa llback(const DIDEVICEINSTANC E*
    pdidInstance, VOID* pContext)
    {
    HRESULT hr;

    // Obtain an interface to the enumerated joystick.
    hr = g_pDI->CreateDevice(p didInstance->guidInstance ,
    &joystick, NULL);
    if(FAILED(hr))
    return DIENUM_CONTINUE ;

    return DIENUM_STOP;
    }

    ...I get "A first chance exception of
    type 'System.NullRef erenceException ' occurred in test.exe" error
    message; the program could still continue but it would just throw
    the exception and doesn't do what it is supposed to do.

    I've tested it by placing a flag in EnumJoysticksCa llback and it
    seems to me that it is not the callback function that is causing
    the problem.

    Appreciate any suggestion :]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you Googled NullReferenceEx ception?

    Comment

    • 200dogz
      New Member
      • Oct 2008
      • 52

      #3
      Originally posted by weaknessforcats
      Have you Googled NullReferenceEx ception?
      Yea, one of the answer I found was to disable it completely when compiling the program. However, when I ran the program it stills threw an exception in that line so I'd imagine I need to try and fix it somehow.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        g_pDI, pdidInstance, and guidInstance are all non-zero?

        Comment

        • 200dogz
          New Member
          • Oct 2008
          • 52

          #5
          Originally posted by weaknessforcats
          g_pDI, pdidInstance, and guidInstance are all non-zero?
          I don't think I initialised those...so that might be the problem.

          Anyway I was told that the way I was doing (following a directInput tutorial) would not work for Form Application that I'm using.

          It seems that I need to use something like
          virtual void Form1::WndProc( Message% m) override {
          if(m.Msg == WM_DEVICECHANGE ) {
          //do stuff
          instead....

          Thanks for your help tho =]]

          Comment

          • 200dogz
            New Member
            • Oct 2008
            • 52

            #6
            Perhaps instead of trying to fix the codes I have here that might be completely wrong, I should just ask method of reaching the goal...

            I have a Form application with one button and a textbox. How should I approach if I want the program to display the X value of a joystick plugged in the USB port of the PC when the button is pressed? I heard from a friend it should only take around 20 lines to do so.

            Thanks for helping :)

            Comment

            Working...