Skip to main content
gamedev.net
🔒 Locked

DInput / C++ syntax problem

Started by jpardon Feb 28, 2004 at 8:52 AM 4 replies 750+ views
Original Post
jpardon
jpardon
Hi, I'm trying to tidy up my dinput code by creating a nice input controller class. I have come unstuck with a bit of C++ syntax shenanigans and wondered if anyone could help me. I am using the call below to enumerate joysticks. I'd like the EnumJoysticks function to be a function of the class instead of a standard C function. Is this possible? hr = m_directInput->EnumDevices(DI8DEVCLASS_GAMECTRL,EnumJoysticks,this,DIEDFL_ATTACHEDONLY); // this is a pointer to my currrent InputController class The reason I'd like to do ths is so that I can store the enumerated data into the object directly without having to pass pointers to the function, and secondly because it'd be nice and tidy that way. Here's the current EnumJoysticks function that I'm currently using... BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCE* pdidInstance,VOID* pContext) { HRESULT hr; InputController *pIC = (InputController *)pContext; // Get Joystick Device // hr = pIC->m_directInput->CreateDevice(pdidInstance->guidInstance,&pIC->m_joystickDevice,NULL); if(hr != DI_OK) return DIENUM_CONTINUE; // Return first Joystick Only // return DIENUM_STOP; } Thanks in advance for any suggestions [edited by - jpardon on February 28, 2004 9:56:28 AM]
www.JeremyPardon.com
Muhammad Haggag
Muhammad Haggag
quote:
Original post by jpardon
I am using the call below to enumerate joysticks. I''d like the EnumJoysticks function to be a function of the class instead of a standard C function. Is this possible?

Make it a static method.

Muhammad Haggag

jpardon
jpardon
Cheers, I''ll give that a whirl.
www.JeremyPardon.com
mr_jrt
mr_jrt
quote:
Original post by DrunkenHyena
NOTE: Any member data will have to be static as well or the static function will not be able to access it.


...unless you pass an instance pointer to the callback function in using the void pointer and a cast.

Waassaap!!
jpardon
jpardon
Cheers everyone, I ended up doing excately the same as I did in the C function but it''s now part of the Class. A tiny bit tidier but not what I was hoping to do because the variables have to be static, which they can''t be in this case. Ah well, tidy code is better than nothing
www.JeremyPardon.com

Topic Locked

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

Sign in to reply to this topic.