How can I make the "__stdcall" function to be local?
-
Hi, In my application, I need to call ::EnumChildWindows(m_hWnd, SetButtonState, (LPARAM)(Info)); How can make the following function to be local: BOOL __stdcall SetButtonState(HWND hwnd, LPARAM lparam) to be someclass' member function like: BOOL __stdcall CMyApp::SetButtonState(HWND hwnd, LPARAM lparam) -----> this is wrong! Some code sample will be much appreciated!!! Thank you very much!
-
Hi, In my application, I need to call ::EnumChildWindows(m_hWnd, SetButtonState, (LPARAM)(Info)); How can make the following function to be local: BOOL __stdcall SetButtonState(HWND hwnd, LPARAM lparam) to be someclass' member function like: BOOL __stdcall CMyApp::SetButtonState(HWND hwnd, LPARAM lparam) -----> this is wrong! Some code sample will be much appreciated!!! Thank you very much!
You don't. You can't pass a non-static member function because the parameter list doesn't match (remember in C++ all non-static member functions receive a hidden first parameter, the "this" pointer). What you can do is declare write your callback like this: BOOl __stdcall SetButtonState (HWND hwnd, LPARAM lparam) { CMyApp* app = (CMyApp*)lparam; ASSERT (app != NULL); app->SetButtonState (hwnd, lparam); } Then call EnumChildWindows with the global SetButtonState, like this: ::EnumChildWindows (m_hWnd, ::SetButtonState, (LPARAM)&myApp); The global SetButtonState just redirects each call back to the object that you specified in the call to EnumChildWindows You could also make the global SetButtonState a static member of your class. Cheers, Eric Tetz