Jump to content
  • Advertisement

Archived

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

Igrum

DirectInput problem

This topic is 5558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!