DInput EnumDevices() woes...

Started by
0 comments, last by HBringer 23 years, 4 months ago
*sigh* Okay, to use EnumDevices you must have a Callback function, right? So here it is, along with the EnumDevices call:
      

BOOL CALLBACK DIJoystick::TheCallback(LPCDIDEVICEINSTANCE lpDIDE, LPVOID guidPtr)
{

	mJoyGUID = lpDIDE->guidInstance;

	strcpy(mJoyName, (char *)lpDIDE->tszProductName);

	return(DIENUM_STOP);

}



int DIJoystick::ScanForDevices(LPDIRECTINPUT7 lpDI)
{

	if(lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, TheCallback, &mJoyGUID, 
					DIEDFL_ATTACHEDONLY) != DI_OK)
		return(0);
	
	return(1);

}

  
Compiling this, I get the following error:


C:\Projects\spritemover\input.cpp(403) : error C2664: 'EnumDevices' : cannot convert parameter 2 from 
'int (const struct DIDEVICEINSTANCEA *,void *)' to 
'int (__stdcall *)(const struct DIDEVICEINSTANCEA *,void *)'
        None of the functions with this name in scope match the target type
  
 
I've tried "DIJoystick::TheCallback", "this->TheCallback", and a whole host of other things; but it still insists that the callback function is out of scope (I'm guessing, based on the error there)... Help? Please? Thanks! --HB Edited by - HBringer on 11/28/00 3:57:26 PM
Advertisement
Like almost all callbacks, they are defined static...
This is what you need to do:
  static BOOL CALLBACK DIJoystick::TheCallback(LPCDIDEVICEINSTANCE lpDIDE, LPVOID self){	mJoyGUID = lpDIDE->guidInstance;	strcpy(((DIJoystick*)self)->mJoyName, (char *)lpDIDE->tszProductName);	return(DIENUM_STOP);}int DIJoystick::ScanForDevices(LPDIRECTINPUT7 lpDI){	if(lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, TheCallback, this, DIEDFL_ATTACHEDONLY) != DI_OK)return(0);		return(1);}    

This will allow you to call the callback, while keeping it ''classy''. Remember you need to change the def. in the .H and add a ''friend static'' to the def. of the callback.

------------------------------
BCB DX Library - RAD C++ Game development for BCB

This topic is closed to new replies.

Advertisement