• ### Announcements

#### Archived

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 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.

DIPROPDWORD m_BufferDesc;//Setup the buffer on the devicem_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.
DIDEVICEOBJECTDATA m_MouseBuffer[MAX_UIBUFFERSIZE];DWORD m_MouseBufferElements;DWORD dwItems = MAX_UIBUFFERSIZE;if (FAILED(m_Mouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), 				m_MouseBuffer, &dwItems, 0)))	m_MouseBufferElements = 0;else	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.
Kressilac
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]

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627674
• Total Posts
2978558

• 11
• 11
• 10
• 12
• 22