COM and Timer
-
In my COM object with MFC support I want to install a timer: ::SetTimer(NULL, TIMER_ID, 1000, (TIMERPROC)TimerProc); Then I declare TimerProc() in COM class as: VOID CALLBACK TimerProc( HWND hwnd, // handle to window for timer messages UINT message, // WM_TIMER message UINT idTimer, // timer identifier DWORD dwTime) ; // current system time and define as: VOID CALLBACK TimerProc( HWND hwnd, // handle to window for timer messages UINT message, // WM_TIMER message UINT idTimer, // timer identifier DWORD dwTime) // current system time { // Do something } But I've got a compiler error: error C2440: 'type cast' : cannot convert from '' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)' None of the functions with this name in scope match the target type What am I doing wrong ?
-
In my COM object with MFC support I want to install a timer: ::SetTimer(NULL, TIMER_ID, 1000, (TIMERPROC)TimerProc); Then I declare TimerProc() in COM class as: VOID CALLBACK TimerProc( HWND hwnd, // handle to window for timer messages UINT message, // WM_TIMER message UINT idTimer, // timer identifier DWORD dwTime) ; // current system time and define as: VOID CALLBACK TimerProc( HWND hwnd, // handle to window for timer messages UINT message, // WM_TIMER message UINT idTimer, // timer identifier DWORD dwTime) // current system time { // Do something } But I've got a compiler error: error C2440: 'type cast' : cannot convert from '' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)' None of the functions with this name in scope match the target type What am I doing wrong ?
1. If you really "declare TimerProc() in COM class as:... " - this is a mistake, you cannot use in such way member fuction as a callback. 2. If not so, just void CALLBACK TimerProcedure(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTimer) { //some_action; } STDMETHODIMP CZZZControl::SomeMethod() { m_nEvent = ::SetTimer(some_params); } 3. May be you are trying to use not ::SetTimer, but CWindow::SetTimer Wish you luck!
-
1. If you really "declare TimerProc() in COM class as:... " - this is a mistake, you cannot use in such way member fuction as a callback. 2. If not so, just void CALLBACK TimerProcedure(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTimer) { //some_action; } STDMETHODIMP CZZZControl::SomeMethod() { m_nEvent = ::SetTimer(some_params); } 3. May be you are trying to use not ::SetTimer, but CWindow::SetTimer Wish you luck!