Sign in to follow this  
GavRobbs

DirectInput problem

Recommended Posts

DirectInput8Create(h,DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)m_pDI,NULL); if(FAILED(m_pDI->CreateDevice(GUID_SysKeyboard,&m_pDIKeyboard,NULL))) { MessageBox(NULL,"Error with keyboard","Info",MB_OK); }; m_pDIKeyboard->SetDataFormat(&c_dfDIKeyboard); m_pDIKeyboard->SetCooperativeLevel(m_window,DISCL_NONEXCLUSIVE|DISCL_BACKGROUND); m_pDIKeyboard->Acquire(); I have a problem with this code, as it throws a memory error when it runs.I think it has something to do with not creating DirectInput, from my own debugging.Can someone please help me and tell me whats wrong? Thanks in advance.

Share this post


Link to post
Share on other sites
Try this:

DirectInput8Create(h,DIRECTINPUT_VERSION,IID_IDirectInput8,(void**) &m_pDI,NULL);

I believe this might be the problem (Notice the address-of (&) operator.)

(I have not used DirectX in awhile, so please correct me if I am wrong[smile])

Share this post


Link to post
Share on other sites
Crypter is correct. However, DON'T USE DIRECT INPUT FOR KEYBOARD OR MOUSE INPUT! It's a horrific idea. You might as well try to use BIOS interupts to read keyboard input.

  • Window messages are faster (DirectInput just creates another thread to read window messages)
  • Window messages give you things like key repeat for free, DirectInput doesn't (Which I think is the problem you're seeing)
  • Window messages handle shifted letters and caps/num/scroll lock properly, DirectInput doesn't
  • Window message obey the users control pannel settings, DirectInput does not
  • Window messages are "free". They get sent to your window without you having to write pages and pages of code to initialise a DirectInput device
  • Microsoft recommend that you do not use DierctInput for keyboard or mouse input:
    Quote:
    Overall, using DirectInput offers no advantages when reading data from mouse or keyboard devices, and the use of DirectInput in these scenarios is discouraged.


    In short: Don't use DirectInput for keyboard or mouse input.

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this