What's wrong with this codes? But it generates Stack Overflow exception.
-
After initializing the timer by: SetTimer(ID_PLAYTIME_EVENT, 1000, NULL); The following codes will result in exception: 0XC00000FD: stack overflow? void CCPPPLAYERDlg::OnTimer (UINT nIDEvent) { MSG msg={0}; switch (nIDEvent) { case ID_PLAYTIME_EVENT: if(g_hwndMain) { // Main message loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; } CDialog::OnTimer(nIDEvent); } DJ
-
After initializing the timer by: SetTimer(ID_PLAYTIME_EVENT, 1000, NULL); The following codes will result in exception: 0XC00000FD: stack overflow? void CCPPPLAYERDlg::OnTimer (UINT nIDEvent) { MSG msg={0}; switch (nIDEvent) { case ID_PLAYTIME_EVENT: if(g_hwndMain) { // Main message loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; } CDialog::OnTimer(nIDEvent); } DJ
Don't put such a loop into a timer function. They were not designed to co-exist. The code you put into a timer function must be short, sweet and to the point, consuming as little CPU as possible.
-
After initializing the timer by: SetTimer(ID_PLAYTIME_EVENT, 1000, NULL); The following codes will result in exception: 0XC00000FD: stack overflow? void CCPPPLAYERDlg::OnTimer (UINT nIDEvent) { MSG msg={0}; switch (nIDEvent) { case ID_PLAYTIME_EVENT: if(g_hwndMain) { // Main message loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; } CDialog::OnTimer(nIDEvent); } DJ
If my brain is thinking right, if there are too many messages in the queue, this code will never finish and end up basically calling itself. (I am baffled as to why you need to do a message look anyway.) Finally, why use switch? Why not use
if (nIDEvent == ID_PLAYTIME_EVENT)