Skip to main content
GameDev.net gamedev.net
🔒 Locked

problems wrapping Direct Input

Started by soddy Oct 28, 2005 at 5:20 PM 1 replies 650+ views
Original Post
soddy
soddy
I'm trying to wrap direct input in one InputManager class but am having problems setting up callback functions. I want the enumDevicesCallBack and the enumObjectsCallBack to be member functions in the InputManager class but i keep getting compile errors.

hr = m_lpDirectInputInterface->EnumDevices( DI8DEVCLASS_GAMECTRL,							    enumControllersCB,
					    NULL, 
					    DIEDFL_ATTACHEDONLY );


The error i get is, "error C2664: 'IDirectInput8A::EnumDevices' : cannot convert parameter 2 from 'BOOL (const DIDEVICEINSTANCE *,void *)' to 'LPDIENUMDEVICESCALLBACKA' None of the functions with this name in scope match the target type" I have declared the function in the header as,

	BOOL CALLBACK enumControllersCB(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext);
I've tried changing paramater 2 to cInputManager::enumControllersCB, but that doesnt help, same error message. also, doing this C style (ie declaring the function outside of the class as a standalone function) works fine, - why? Maybe this is a C/C++ question rather than DX, sorry if i misplaced it. [Edited by - Coder on October 28, 2005 11:37:11 PM]
jollyjeffers
jollyjeffers
Quote:
doing this C style (ie declaring the function outside of the class as a standalone function) works fine, - why?

It's quite possible you've stumbled across a fundamental problem here [smile] At which point it is a C vs C++ problem.

Callbacks for regular "C style" functions defined outside a class are different to those defined "C++ style" inside a class. I forget all of the precise rules, but for the most part a function call into a C++ class requires a reference to "this" - the instance of the class that the function is being invoked against.

You might want to do some research into the topic of "functors".

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
soddy
soddy
Quote:
Original post by jollyjeffers
Callbacks for regular "C style" functions defined outside a class are different to those defined "C++ style" inside a class.
Jack


yup thats where the problem was, had to declare it as static within the class definition in header file.

cheers

Topic Locked

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

Sign in to reply to this topic.