Jump to content
  • Advertisement

Archived

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

jpardon

DInput / C++ syntax problem

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

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]

Share this post


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

Share this post


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

Share this post


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!