How to use member function of a C++ class as a callback function 
Author Message
 How to use member function of a C++ class as a callback function

 Check th MSDN for Q130866: "INFO: Using a TimerProc Function in MFC Application".

.h:
 static void CALLBACK  TimerProc(HWND hwnd, UINT msg, UINT idTimer,
                            DWORD dwTime);

.cpp
void CALLBACK  CTmrprocView::TimerProc(HWND hwnd, UINT msg, UINT idTimer,  DWORD dwTime)



Fri, 13 Aug 2004 19:31:26 GMT  
 How to use member function of a C++ class as a callback function


Quote:
>Hi all,
>I am trying to write a C++ class that have a protected member function

which is used as a callback function in the Windows ::SetTimer() function. I
always get the >compiling error:

Hi,
The error occurs because the calling conventions are different.
WinApi function use the stdcall convention while C++ uses cdecl and thiscall

To use a member function as a cllaback you would have to make the member as
a static function
or use a global function. But remember that a static function cannot access
the normal member variables of the class.

I would suggest to use a global function which is a friend of the class.

HTH
Raghu



Fri, 13 Aug 2004 19:41:31 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing C++ Class Member Function to as a C Callback Function Parameter

2. class member function as callback function

3. Calling C++ member function through C function callback

4. Using Non-Static Callback Functions as member Functions VC5.0

5. Using a C++ member function as a Timer callback

6. Using a C++ member function as a Timer callback

7. Using class member function as a thread function

8. Using class member function as a thread function

9. Accessing class member functions from Global Callback

10. Getting pointer to non-static member function from C callback function

11. Callback functions as member functions

12. CALLBACK Functions as Class Members

 

 
Powered by phpBB® Forum Software