Jump to content
  • Advertisement

Archived

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

HBringer

DInput EnumDevices() woes...

This topic is 6415 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

*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

Share this post


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

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!