This topic is now archived and is closed to further replies.


DirectInput Error

Recommended Posts

Hi all. Why do I get an error on this line? nEvents = Mouse.GetDeviceData(DevData, DIGDD_DEFAULT) The DevData buffer is set to 10, and it''s not helping to increse the buffer. I use Directinput for both Mouse and Keyboard. My cooperativelevels is set as following: Keyboard: DISCL_FOREGROUND Or DISCL_NONEXCLUSIVE Or DISCL_NOWINKEY Mouse: DISCL_FOREGROUND Or DISCL_EXCLUSIVE I''ve tried other cooperativelevels without success. The error occurs when the app is loaded or when I move the mouse. I use a temporary solution with an ''On Error Resume Next'' line and that solves the prob. and give me the desierd mouse-move most of the time. I cant however figure out how to eliminate this error. If you know, please help!

Share this post

Link to post
Share on other sites
The GetDeviceData() function is a buffered instruction. If you only wish to retrieve the state of the mouse at that moment in time, use GetDeviceState(). You can find this in the MSDN help for DirectInput. The parameters that you are passing to the function indicate that you only want the snapshot state.

GetDeviceData returns a buffer that is setup with the following code. Execute this code before you acquire the mouse.

//Setup the buffer on the device
m_BufferDesc.diph.dwSize = sizeof(DIPROPDWORD);
m_BufferDesc.diph.dwHeaderSize = sizeof(DIPROPHEADER);
m_BufferDesc.diph.dwObj = 0;
m_BufferDesc.diph.dwHow = DIPH_DEVICE;
m_BufferDesc.dwData = MAX_UIBUFFERSIZE;

if (FAILED(m_Mouse->SetProperty(DIPROP_BUFFERSIZE, &m_BufferDesc.diph)))
return false;

To read the data you will need to call GetDeviceData() and pass it parameters. See the following code.

DWORD m_MouseBufferElements;

if (FAILED(m_Mouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),
m_MouseBuffer, &dwItems, 0)))
m_MouseBufferElements = 0;
m_MouseBufferElements = dwItems;

To process the data returned you will need to create a for loop and cycle through the buffer based on the number of elements the GetDeviceData() function returns. I have other code checking to see if the mouse is acquired and am assuming you have that under control.

Hope this helps.
ps All of this is in the MSDN help on Direct Input and can be found online as well. I searched for Direct Input in google and was also able to find a bit more information on running Direct Input.

[edited by - kressilac on November 11, 2002 1:27:09 AM]

Share this post

Link to post
Share on other sites