• Advertisement

Archived

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

Direct Input Joystick Class

This topic is 5069 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 tyring to create a wrapper class for the directinput api. The code compiles fine but I crash when i run my app. here''s the part of the class method.. bool Input::InitJoystick( DWORD Coop ) { if ( FAILED( m_dInput->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ) ) return false; // ... } here''s the callback function where it is crashing: BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { // HERE''S WHERE IT CRASHED if( FAILED( ((Input*)pContext)->GetDInputObject( )->CreateDevice( pdidInstance->guidInstance, &((Input*)pContext)->GetJoystickDevice( ), NULL ) ) ) return DIENUM_CONTINUE; ((Input*)pContext)->SetJoystickInit( true ); return DIENUM_STOP; } any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
cool, another crash but on a different line

bool Input::InitJoystick( DWORD Coop )
{
//..

if( FAILED( m_joystickDevice->EnumObjects( EnumObjectsCallback, (VOID*)m_hwnd, DIDFT_ALL ) ) )
return false;

//...
}

the callback function

BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext )
{
//...
if( pdidoi->dwType & DIDFT_AXIS )
{
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
diprg.lMin = -1000;
diprg.lMax = +1000;

// Dies here
if( FAILED( ((Input*)pContext)->GetJoystickDevice( )->SetProperty( DIPROP_RANGE, &diprg.diph ) ) )
return DIENUM_STOP;

}
//...
}

..yeah i know, my kung fu sucks but thanks for the help

Share this post


Link to post
Share on other sites
I really meant "this", not the HWND handle.

You''re expecting a pointer to a Input class so you gotta put one in there.

Make the line


if ( FAILED( m_dInput->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, this, DIEDFL_ATTACHEDONLY ) ) )

Share this post


Link to post
Share on other sites
this is a different line and different call back function. i put this in both spots, doesnt crash anymore. altough im getting errors saying that i cant poll the joystick. these are my error messages, so the callback functions did execute but i dont think it properly set up the joystick device.

[edited by - jackiechan on June 8, 2004 1:47:11 PM]

Share this post


Link to post
Share on other sites

  • Advertisement