Skip to main content
GameDev.net gamedev.net
🔒 Locked

Direct Input and Joystick

Started by Danny Gilbert Aug 23, 2006 at 8:07 AM 0 replies 900+ views
Original Post
Danny Gilbert
Danny Gilbert
Hi ! I have a problem with my function EnumDevice for listing of joystick. I do the same thing than many samples I see on the web. The error from Visual-Studio is... \joystick.cpp(22): error C2664: 'IDirectInput8A::EnumDevices' : cannot convert parameter 2 from 'BOOL (const DIDEVICEINSTANCE *,void *)' to 'LPDIENUMDEVICESCALLBACKA' My 2 functions are.... ----------------------- bool CJoystick::Create(LPDIRECTINPUT8 pDI) { DIPROPRANGE DIprg; DIPROPDWORD DIpdw; if( pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ) return false; if( m_pDIJoystick->SetDataFormat( &c_dfDIJoystick ) != DI_OK ) return false; if( m_pDIJoystick->SetCooperativeLevel( GetUserInputs()->GetEngine()->GetWindows(), DISCL_FOREGROUND | DISCL_EXCLUSIVE) != DI_OK ) return false; .... bla bla.... and my Callback function is.... -------------------------------- BOOL CALLBACK CJoystick::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext) { UNREFERENCED_PARAMETER( pContext ); // Create a joystick interface. if( m_pUserInputs->m_pDI->CreateDevice( pdidInstance->guidInstance, &m_pDIJoystick, NULL) != DI_OK ) return DIENUM_CONTINUE; return DIENUM_STOP; } I found on the web that error C2664 is a Microsoft bug with VS 2003. Problem of call of good constructor... and don't really understand the issue or the solution. Can someone has encountered this error and what was your solution ? Thank you.
Illco
Illco
DirectInput requires you to adhere to the specified callback function signature, defined as
LPDIENUMDEVICESCALLBACK

Your function:
BOOL CALLBACK CJoystick::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext)

does not adhere to it. Because it is a class member function, it has a hidden first parameter of type CJoystick*.

Solutions:
- use a static member functions (which doesn't have the parameter) and pass your class instance through the pContext pointer.
- you can use the static member function to call the non-static callback as pContext->EnumJoysticksCallback(...)

Greetz,

Illco

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.