DirectInput problem

Started by
1 comment, last by Igrum 21 years ago
I''m having a problem when I try and retrieve input from a gamepad. When I poll the gamepad prior to getting its state, the poll fails. It returns an S_FALSE COM error, and I''m not sure why. If anyone wants to see code, let me know, but does anyone have some general ideas about what might cause that error?
Advertisement
Here is how I handle gamepad, and it works well (note that I use buffered data):

if(!diJoyDevice)
return;

//Get joystick state and fill buffer
if(FAILED(diJoyDevice->Poll())) {
HRESULT hr = diJoyDevice->Acquire();
while(hr==DIERR_INPUTLOST) hr = diJoyDevice->Acquire();}

int mx = (int)joystickState.lX, my = (int)joystickState.lY;
int btns = joystickState.btns;
DWORD dwElements = IGE_DI_BUFFER_SIZE; // max number of items to be retrieved

DIDEVICEOBJECTDATA od[IGE_DI_BUFFER_SIZE];

// Retreive the mouse input elements (buffered data)
HRESULT hr = diJoyDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), od, &dwElements, 0);

// Save the joystick input elements to our joystick state structure
for(int i=0;i<(int)dwElements;i++)
{
// Do your specific stuffs here ...
}

www.mpw2002.fr.st
www.mpw2002.fr.st
Here''s the code I use to set up the gamepad. I think the poll might be failing because of something I did wrong when I initialize the device.


  	GUID gamepadGUID;	if (FAILED(lpdimain->EnumDevices(DI8DEVTYPE_GAMEPAD, 								 DInput_Enum_Gamepads, 								 &gamepadGUID, 								 DIEDFL_ATTACHEDONLY)))	{		Log_File("Failed to enumerate or create gamepad.");		return(0);	}	if (FAILED(lpdigamepad1->SetCooperativeLevel(window_handle, 												DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))	{		Log_File("Failed to set gamepad''s cooperative level.");		return(0);	}	if (FAILED(lpdigamepad1->SetDataFormat(&c_dfDIJoystick)))	{		Log_File("Failed to set gamepad''s data format.");		return(0);	}	if (FAILED(lpdigamepad1->Acquire()))	{		Log_File("Failed to acquire gamepad.");		return(0);	}	return(1);  


And here''s the code for the callback function


  BOOL CALLBACK DInput_Enum_Gamepads(const DIDEVICEINSTANCE*                                            pdidInstance, VOID* pContext){    HRESULT hr;    // Obtain an interface to the enumerated joystick.    hr = lpdimain->CreateDevice(pdidInstance->guidInstance,                                  &lpdigamepad1, NULL);    if(FAILED(hr)) 		return DIENUM_CONTINUE;	Log_File("Gamepad device created.");    return DIENUM_STOP;}  

This topic is closed to new replies.

Advertisement