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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. a problem about stackoverflow

a problem about stackoverflow

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondatabasedebugging
12 Posts 5 Posters 3 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.
  • N nibabug

    void CSerialRecieveDlg::OnBtnAutosend() { // TODO: Add your control notification handler code here if(!m_ctrlMSCommCOM1.GetPortOpen()) AfxMessageBox("please open the port!"); else { CCreateName Dlg; CString TB_Name; CString mstr; if(Dlg.DoModal()==IDOK) { TB_Name=Dlg.m_TableName; } m_pRecordset->Close(); //// create a new table in SQL mstr.Format("IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = '"); mstr+=TB_Name; mstr+="') CREATE TABLE "; mstr+=TB_Name; mstr+=" (ID INT,FangWei TEXT,FuYang TEXT,QingXie TEXT)"; try { m_pRecordset->Open(mstr.AllocSysString theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } SetTimer(1,500,NULL); } } when debug to the end, appear an error about "stackoverflow" what is the problem??

    wuhuaiji

    J Offline
    J Offline
    Jonathan Darka
    wrote on last edited by
    #3

    Try single stepping through your code in the debugger, it should be obvious then.


    Jonathan Wilkes Darka[Xanya.net]

    1 Reply Last reply
    0
    • D David Crow

      nibabug wrote:

      SetTimer(1,500,NULL);

      What are you doing in response to the WM_TIMER message?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      N Offline
      N Offline
      nibabug
      wrote on last edited by
      #4

      get data from three different tables , and then do something , and then show them, look the flowing: void CSerialRecieveDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString strSql; // int m=atoi(m_strNum); _variant_t var; CString str,strnum; CString strSendFW,strSendFY,strSendQX; CString strSend; str=""; SQLNum++; if(SQLNum==130) SQLNum-=129; strSql.Format("%d",SQLNum); strnum=strSql; strSql.Format("SELECT * FROM TB_FANGWEI WHERE ID = '%s'",strnum); try { //先关闭已经打开的记录集对象 m_pRecordset->Close(); //根据新的Sql查询语句,重新打开记录集对象 m_pRecordset->Open(strSql.AllocSysString(), theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } //在ADO操作中建议语句中要常用try...catch()来捕获错误信息, //因为它有时会经常出现一些想不到的错误。 var = m_pRecordset->GetCollect("Value"); if(var.vt != VT_NULL) str = (LPCSTR)_bstr_t(var); m_strAGFW=str; var = m_pRecordset->GetCollect("HexValue"); if(var.vt != VT_NULL) str = (LPCSTR)_bstr_t(var); strSendFW=str; // char* pszTest = (char*)(LPCTSTR)strSendFW; // unsigned char* ptr=(unsigned char*)pszTest; // unsigned char uchartemp; // unsigned char m=4; unsigned int intFW=(unsigned int)_tcstoul(strSendFW, 0, 16); intFW&=0x3fff; intFW<<=2; intFW|=0x0000; strSql.Format("SELECT * FROM TB_FUYANG WHERE ID = '%s'",strnum); try { //先关闭已经打开的记录集对象 m_pRecordset->Close(); //根据新的Sql查询语句,重新打开记录集对象 m_pRecordset->Open(strSql.AllocSysString(), theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->Err

      D 1 Reply Last reply
      0
      • N nibabug

        get data from three different tables , and then do something , and then show them, look the flowing: void CSerialRecieveDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString strSql; // int m=atoi(m_strNum); _variant_t var; CString str,strnum; CString strSendFW,strSendFY,strSendQX; CString strSend; str=""; SQLNum++; if(SQLNum==130) SQLNum-=129; strSql.Format("%d",SQLNum); strnum=strSql; strSql.Format("SELECT * FROM TB_FANGWEI WHERE ID = '%s'",strnum); try { //先关闭已经打开的记录集对象 m_pRecordset->Close(); //根据新的Sql查询语句,重新打开记录集对象 m_pRecordset->Open(strSql.AllocSysString(), theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } //在ADO操作中建议语句中要常用try...catch()来捕获错误信息, //因为它有时会经常出现一些想不到的错误。 var = m_pRecordset->GetCollect("Value"); if(var.vt != VT_NULL) str = (LPCSTR)_bstr_t(var); m_strAGFW=str; var = m_pRecordset->GetCollect("HexValue"); if(var.vt != VT_NULL) str = (LPCSTR)_bstr_t(var); strSendFW=str; // char* pszTest = (char*)(LPCTSTR)strSendFW; // unsigned char* ptr=(unsigned char*)pszTest; // unsigned char uchartemp; // unsigned char m=4; unsigned int intFW=(unsigned int)_tcstoul(strSendFW, 0, 16); intFW&=0x3fff; intFW<<=2; intFW|=0x0000; strSql.Format("SELECT * FROM TB_FUYANG WHERE ID = '%s'",strnum); try { //先关闭已经打开的记录集对象 m_pRecordset->Close(); //根据新的Sql查询语句,重新打开记录集对象 m_pRecordset->Open(strSql.AllocSysString(), theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->Err

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

        You are doing WAY too much in response to a WM_TIMER message that occurs every 1/2 second.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        T 1 Reply Last reply
        0
        • D David Crow

          nibabug wrote:

          SetTimer(1,500,NULL);

          What are you doing in response to the WM_TIMER message?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          N Offline
          N Offline
          nibabug
          wrote on last edited by
          #6

          it has no businiss with the timer, because when i change it to 2second, it also appear error: (step debug) unhandled exception in SerialRecieve.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ EXCEPTION no matter where the error appears, it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)

          wuhuaiji

          D 1 Reply Last reply
          0
          • N nibabug

            it has no businiss with the timer, because when i change it to 2second, it also appear error: (step debug) unhandled exception in SerialRecieve.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ EXCEPTION no matter where the error appears, it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)

            wuhuaiji

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

            nibabug wrote:

            it has no businiss with the timer...it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)

            Do you see the irony in this statement? Yes, the timer is the problem. Changing the frequency to 2 seconds won't necessarily solve the problem if it takes longer than that to process a single WM_TIMER request. Put a flag in the function indicating whether it is busy or not. Check that flag before continuing.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            M N 2 Replies Last reply
            0
            • D David Crow

              You are doing WAY too much in response to a WM_TIMER message that occurs every 1/2 second.


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #8

              :laugh::laugh::laugh:


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              D 1 Reply Last reply
              0
              • T toxcct

                :laugh::laugh::laugh:


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

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

                What, pray tell, are you finding amusing?


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                T 1 Reply Last reply
                0
                • D David Crow

                  What, pray tell, are you finding amusing?


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #10

                  it was just obvious, but i loved the way you said it


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  1 Reply Last reply
                  0
                  • D David Crow

                    nibabug wrote:

                    it has no businiss with the timer...it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)

                    Do you see the irony in this statement? Yes, the timer is the problem. Changing the frequency to 2 seconds won't necessarily solve the problem if it takes longer than that to process a single WM_TIMER request. Put a flag in the function indicating whether it is busy or not. Check that flag before continuing.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    M Offline
                    M Offline
                    Mike Dimmick
                    wrote on last edited by
                    #11

                    It's not just the timer - a thread hosting Windows UI can only process one message at a time, after all. The problem is that the MessageBox call and the modal dialog create nested message loops, which will process timer messages and thereby cause recursion. Most likely it's one of the AfxMessageBox calls in the exception handlers in the OnTimer routine which is causing OnTimer to go re-entrant.


                    DoEvents: Generating unexpected recursion since 1991

                    1 Reply Last reply
                    0
                    • D David Crow

                      nibabug wrote:

                      it has no businiss with the timer...it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)

                      Do you see the irony in this statement? Yes, the timer is the problem. Changing the frequency to 2 seconds won't necessarily solve the problem if it takes longer than that to process a single WM_TIMER request. Put a flag in the function indicating whether it is busy or not. Check that flag before continuing.


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      N Offline
                      N Offline
                      nibabug
                      wrote on last edited by
                      #12

                      thanks a lot:)

                      wuhuaiji

                      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