Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What's wrong with this codes? But it generates Stack Overflow exception.

What's wrong with this codes? But it generates Stack Overflow exception.

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DengJW
    wrote on last edited by
    #1

    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

    D J 2 Replies Last reply
    0
    • D DengJW

      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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D DengJW

        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

        J Offline
        J Offline
        Joe Woodbury
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups