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. Please try this ,simple and it has bug.

Please try this ,simple and it has bug.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingtutorialquestion
6 Posts 4 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.
  • A Offline
    A Offline
    anju
    wrote on last edited by
    #1

    Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju

    A T B A 4 Replies Last reply
    0
    • A anju

      Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju

      A Offline
      A Offline
      AlexO
      wrote on last edited by
      #2

      try the following: anju wrote: char szVal[20];

      A 1 Reply Last reply
      0
      • A AlexO

        try the following: anju wrote: char szVal[20];

        A Offline
        A Offline
        anju
        wrote on last edited by
        #3

        Hi Alexo, There is nothing in it r u Missed? anju

        1 Reply Last reply
        0
        • A anju

          Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju

          T Offline
          T Offline
          Ted Ferenc
          wrote on last edited by
          #4

          Instead of sscanf(szVal,"%X",&byByteCmd); why not use atol()? What I think your code is doing is that you are reading an int value (%X) into a BYTE variable and overwriting the next location(s) in memory you could try using %c


          If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676

          1 Reply Last reply
          0
          • A anju

            Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju

            B Offline
            B Offline
            Brian Shifrin
            wrote on last edited by
            #5

            BYTE byByteCmd; .... sscanf(szVal,"%X",&byByteCmd); And types %X and %x require int or int alike (DWORD) argument, you are using byte. 1 byte vs 4 bytes... Due to debug mode padding you don't get an error.

            1 Reply Last reply
            0
            • A anju

              Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju

              A Offline
              A Offline
              anju
              wrote on last edited by
              #6

              Hi, Thanks your comments. but,what is the relation between " CString strTemp and sscanf(...)". If i didn't used CString object this code doesn't give me an error. regrads anju:rose: anju

              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