Skip to main content
gamedev.net
🔒 Locked

enumerating devices and creating interface using callback function

Started by 2DamnFunky Jul 22, 2003 at 12:55 PM 1 replies 550+ views
Original Post
2DamnFunky
2DamnFunky
I have been following the sdk docs to the letter yet for some reason it doesnt like the callback function EnumJoysticksCallback() im using when trying to enumerate any joysticks that may be attached to the comp. Im wrapping all the DInput init in a class. Heres the prototype for the callback function
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE *pdidInstance, VOID *pContext ); 
//callback function for use in DInput8::DI_JoystickDevice_Create

and here is the declaration in the source file
BOOL CALLBACK DInput8::EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
{
	HRESULT hr;

	//found a joystick so need to create a new joystick object for our list

	JoystickDI8_headNode->Joystick_DI8_Insert(&JoystickDI8_headNode, &numOfJoysticks);
	//the newly created joystick automatically becomes the new headNode by design

	//so pass nodeHead address to aquire an interface for new joystick object.

    //...Obtain an interface to the enumerated joystick.

    hr = lpDI->CreateDevice(pdidInstance->guidInstance,  
                                &JoystickDI8_headNode->lpDIDevice_Joystick, NULL);

	if (FAILED(hr))
	{
		//could not create an interface for this joystick

		//so delete this redundant object from list

		JoystickDI8_headNode->Joystick_DI8_Delete(&JoystickDI8_headNode, &JoystickDI8_headNode, &numOfJoysticks);
	}

	//get next joystick if one is available.

	return DIENUM_CONTINUE; 
}

and now hear it is in use
if (FAILED ( hr = lpDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,
                       NULL, DIEDFL_ATTACHEDONLY)))
	{
		adamsDXErrorLog("Unable to Enumerate Joystick(s) in DInput8::DI_JoystickDevice_Create()", hr);
	}

And this is what the compilers says c:\data files\programming\games programming\gameprojects\code\dinput8\dinput8.cpp(223) : error C2664: ''EnumDevices'' : cannot convert parameter 2 from ''int (const struct DIDEVICEINSTANCEA *,void *)'' to ''int (__stdcall *)(const struct DIDEVICEINSTANCE A *,void *)'' basically suggesting the return type is not correct yet ive checked and checked the docs and both prototype and declaration matche word for word what it states in the docs which is BOOL CALLBACK. Any help greatly appreciated. Regards 2DamnFunky
Boogiemike
Boogiemike
The callback should not be a member of your class just a global function.

// Don´t do this

BOOL CALLBACK DInput8::EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
// Better try this

BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
2DamnFunky
2DamnFunky
i was just thinking that might be causing a problem
ill give it a go now.
thanks for that in advance
Regards
2DamnFunky

Topic Locked

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

Sign in to reply to this topic.