Archived

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

DirectInput and Callbacks

This topic is 5501 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 all, I am having problems with C++''s use of member function pointers and the DirectInput callbacks. I have a class with the function i want to use: class CInput { public: BOOL CALLBACK EnumDevicesSemanticsCallback(LPCDIDEVICEINSTANCE,LPDIRECTINPUTDEVICE8,DWORD,DWORD,LPVOID); } and in one of my functions, I need to tell Dinput to use this function for callback. BOOL (CALLBACK CNemInput::*Call)(LPCDIDEVICEINSTANCE,LPDIRECTINPUTDEVICE8,DWORD,DWORD,LPVOID); Call = &CInput::EnumDevicesSemanticsCallback; hr = lpdi->EnumDevicesBySemantics(NULL, &m_ActionMap,Call,this, 0L); However, I get this error message: error C2664: ''IDirectInput8A::EnumDevicesBySemantics'' : cannot convert parameter 3 from ''BOOL (__stdcall CInput::* )(LPCDIDEVICEINSTANCE,LPDIRECTINPUTDEVICE8,DWORD,DWORD,LPVOID)'' to ''LPDIENUMDEVICESBYSEMANTICSCBA'' Any Ideas? Thanks using visual studio .net

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
C++ is very type-safe. that''s the reason for the error.

a generic solution to almost all Windows API functions that make use of callbacks:

1) make 2 callbacks for your class, one that''s static and one that''s not,
2) pass your "this" pointer via the API function parm that is typically labeled as user-supplied or application-supplied value. in the case of EnumDevicesBySemantics this is the pvRef parm,
3) in your static callback member function, use reinterpret_cast to re-cast the pvRef parm to a pointer to your class,
4) use the re-cast pointer to call the non-static callback member function of your class, in a return statement.

hope i got all of this right. if it doesn''t work/make sense then post back and i''ll/someone will supply some code.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
that should read "a generic for using class-based member function callbacks for almost all Windows API functions that make use of callbacks".

Share this post


Link to post
Share on other sites