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. Release build problem

Release build problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
9 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.
  • W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #1

    I am having a strange problem with the following dialog callback function:

    BOOL CALLBACK MergeProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    static int MostRooms;
    bool bError;
    char *room,*year,*exam;

    switch(Message)
    {
        case WM\_INITDIALOG:
            if (strlen(dlgdata\[0\])) {
                year = new char \[10\];
                strncpy(year,dlgdata\[0\]+2,4);
                strcpy(year+4,"\\0");
    
    
                SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,    WM\_SETTEXT,20,(LPARAM) year);
                delete year;
            }
    
            SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,    EM\_LIMITTEXT,4,0);
            SendDlgItemMessage(hwnd,SD\_MERGE\_ROOM,    EM\_LIMITTEXT,30,0);
            SendDlgItemMessage(hwnd,SD\_MERGE\_EXAM,    EM\_LIMITTEXT,10,0);
    
            MostRooms = atoi(dlgdata\[1\]);
    
            EnumChildWindows(hwnd,EnumChildProc,(LPARAM)hFnt);
        return TRUE;
    
        case WM\_COMMAND:
            switch (LOWORD(wParam)) {
                case IDOK:
                    bError = false;
    
                    room = new char \[30\];
                    year = new char \[10\];
                    exam = new char \[30\];
    
                    room\[0\] = (char)10;
                    year\[0\] = (char)10;
                    exam\[0\] = (char)30;
    
                    SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,EM\_GETLINE,0,(LPARAM)year);
                    SendDlgItemMessage(hwnd,SD\_MERGE\_ROOM,EM\_GETLINE,0,(LPARAM)room);
                    SendDlgItemMessage(hwnd,SD\_MERGE\_EXAM,EM\_GETLINE,0,(LPARAM)exam);
    
                    if (strlen(room) > 0) {
                        if (!count\_rooms(room,MostRooms+1) ) {
                            char tmp \[128\];
                            sprintf(tmp,"Please enter rooms between 0 and %i!",MostRooms+1);
                            MessageBox(0,tmp,0,0);
                            bError = true;
                        }
                    }
                    else if (!bError) {
                        MessageBox(hwnd,"Please enter a room!",0,0);
                        SetFocus(GetDlgItem(hwnd,SD\_MERGE\_ROOM));
                        bError = true;
                    }
    
                    if ( (strlen(year) > 0) && (!bError) ) {
                        if ((atoi(year) > 2000)&&(atoi(year) < 2100)) {
                            char \*text = new char \[10\];
                            strcpy(text,"¸ß");
                            strcat(text,year);
    
    R 1 Reply Last reply
    0
    • W Waldermort

      I am having a strange problem with the following dialog callback function:

      BOOL CALLBACK MergeProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
      {
      static int MostRooms;
      bool bError;
      char *room,*year,*exam;

      switch(Message)
      {
          case WM\_INITDIALOG:
              if (strlen(dlgdata\[0\])) {
                  year = new char \[10\];
                  strncpy(year,dlgdata\[0\]+2,4);
                  strcpy(year+4,"\\0");
      
      
                  SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,    WM\_SETTEXT,20,(LPARAM) year);
                  delete year;
              }
      
              SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,    EM\_LIMITTEXT,4,0);
              SendDlgItemMessage(hwnd,SD\_MERGE\_ROOM,    EM\_LIMITTEXT,30,0);
              SendDlgItemMessage(hwnd,SD\_MERGE\_EXAM,    EM\_LIMITTEXT,10,0);
      
              MostRooms = atoi(dlgdata\[1\]);
      
              EnumChildWindows(hwnd,EnumChildProc,(LPARAM)hFnt);
          return TRUE;
      
          case WM\_COMMAND:
              switch (LOWORD(wParam)) {
                  case IDOK:
                      bError = false;
      
                      room = new char \[30\];
                      year = new char \[10\];
                      exam = new char \[30\];
      
                      room\[0\] = (char)10;
                      year\[0\] = (char)10;
                      exam\[0\] = (char)30;
      
                      SendDlgItemMessage(hwnd,SD\_MERGE\_YEAR,EM\_GETLINE,0,(LPARAM)year);
                      SendDlgItemMessage(hwnd,SD\_MERGE\_ROOM,EM\_GETLINE,0,(LPARAM)room);
                      SendDlgItemMessage(hwnd,SD\_MERGE\_EXAM,EM\_GETLINE,0,(LPARAM)exam);
      
                      if (strlen(room) > 0) {
                          if (!count\_rooms(room,MostRooms+1) ) {
                              char tmp \[128\];
                              sprintf(tmp,"Please enter rooms between 0 and %i!",MostRooms+1);
                              MessageBox(0,tmp,0,0);
                              bError = true;
                          }
                      }
                      else if (!bError) {
                          MessageBox(hwnd,"Please enter a room!",0,0);
                          SetFocus(GetDlgItem(hwnd,SD\_MERGE\_ROOM));
                          bError = true;
                      }
      
                      if ( (strlen(year) > 0) && (!bError) ) {
                          if ((atoi(year) > 2000)&&(atoi(year) < 2100)) {
                              char \*text = new char \[10\];
                              strcpy(text,"¸ß");
                              strcat(text,year);
      
      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      waldermort wrote:

      only with a release build,

      Debug builds set local variables to zero (false) - release builds don't (so what you have is basically indeterminate). It's important to always initialize your local variables to a known state. I'd start by setting bError to false when you declare it and check if the problem reccurs. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      W 1 Reply Last reply
      0
      • R Ravi Bhavnani

        waldermort wrote:

        only with a release build,

        Debug builds set local variables to zero (false) - release builds don't (so what you have is basically indeterminate). It's important to always initialize your local variables to a known state. I'd start by setting bError to false when you declare it and check if the problem reccurs. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        W Offline
        W Offline
        Waldermort
        wrote on last edited by
        #3

        I have already tried this. When declaring the berror variable I origionaly set it to false. Though thinking this may be a cause of the problem I removed it and instead set it to false in the IDOK handler. Like I said in my post, bError is false right up until the final test, where for some reason it is being set to true. The problem lies here somewhere

        if ((strlen(exam) > 0) && (!bError) ) {
        }
        else if (!bError) {
        MessageBox(hwnd,"Please enter an exam name!",0,0);
        SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
        bError = true;
        }

        However the "Please enter an exam name!" is never shown, suggesting the bError = true; line is never executed either.

        Richard Andrew x64R 1 Reply Last reply
        0
        • W Waldermort

          I have already tried this. When declaring the berror variable I origionaly set it to false. Though thinking this may be a cause of the problem I removed it and instead set it to false in the IDOK handler. Like I said in my post, bError is false right up until the final test, where for some reason it is being set to true. The problem lies here somewhere

          if ((strlen(exam) > 0) && (!bError) ) {
          }
          else if (!bError) {
          MessageBox(hwnd,"Please enter an exam name!",0,0);
          SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
          bError = true;
          }

          However the "Please enter an exam name!" is never shown, suggesting the bError = true; line is never executed either.

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Sometimes it helps to rewrite the logic tests to be more affirmative. In the example you show, you're making use of what I call "testing for a negative" which can be very hard to follow. Try rewriting the tests like this:

          if ( (strlen(exam) <= 0) && ( bError == false ) )
          {
          MessageBox(hwnd,"Please enter an exam name!",0,0);
          SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
          bError = true;

          }

          This way is simpler, clearer, and easier to follow mentally.

          W 2 Replies Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            Sometimes it helps to rewrite the logic tests to be more affirmative. In the example you show, you're making use of what I call "testing for a negative" which can be very hard to follow. Try rewriting the tests like this:

            if ( (strlen(exam) <= 0) && ( bError == false ) )
            {
            MessageBox(hwnd,"Please enter an exam name!",0,0);
            SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
            bError = true;

            }

            This way is simpler, clearer, and easier to follow mentally.

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #5

            I understand your logic, but I need it the way it is. I will later be adding code into that empty if statement which will check for previous instances of the entered text. Though out of sheer baldness, I will test the change.

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              Sometimes it helps to rewrite the logic tests to be more affirmative. In the example you show, you're making use of what I call "testing for a negative" which can be very hard to follow. Try rewriting the tests like this:

              if ( (strlen(exam) <= 0) && ( bError == false ) )
              {
              MessageBox(hwnd,"Please enter an exam name!",0,0);
              SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
              bError = true;

              }

              This way is simpler, clearer, and easier to follow mentally.

              W Offline
              W Offline
              Waldermort
              wrote on last edited by
              #6

              This is just bizzare. Your advice works, as it should do, but then again, my code should also work. I also tried the following

              if ((strlen(exam) > 0) && (!bError) ) {
              int i = 0;
              }
              else if (!bError) {
              MessageBox(hwnd,"Please enter an exam name!",0,0);
              SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
              bError = true;
              }

              Which also works. So the ultimate question is, why the hell is an empty if statement causeing bError to become true?

              Richard Andrew x64R 1 Reply Last reply
              0
              • W Waldermort

                This is just bizzare. Your advice works, as it should do, but then again, my code should also work. I also tried the following

                if ((strlen(exam) > 0) && (!bError) ) {
                int i = 0;
                }
                else if (!bError) {
                MessageBox(hwnd,"Please enter an exam name!",0,0);
                SetFocus(GetDlgItem(hwnd,SD_MERGE_EXAM));
                bError = true;
                }

                Which also works. So the ultimate question is, why the hell is an empty if statement causeing bError to become true?

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #7

                Wow. If it suddenly starts working just with the addition of the int i = 0; , then I can't claim to know what is causing the problem. Perhaps the issue has to do with optimizations applied by the compiler. Try this: Go back to the original (non-working) code, and then go into the Project Properties, and turn OFF all compiler and linker optimizations. Then build it and see if it works.

                W 1 Reply Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  Wow. If it suddenly starts working just with the addition of the int i = 0; , then I can't claim to know what is causing the problem. Perhaps the issue has to do with optimizations applied by the compiler. Try this: Go back to the original (non-working) code, and then go into the Project Properties, and turn OFF all compiler and linker optimizations. Then build it and see if it works.

                  W Offline
                  W Offline
                  Waldermort
                  wrote on last edited by
                  #8

                  I have played with all the project setting that I dare and nothing changes the fact that an empty if statement is causing me problems. You won't believe how embaressed I was today when my boss asked for a demonstration. The whole thing came to a standstill simply because data could not be merged.

                  K 1 Reply Last reply
                  0
                  • W Waldermort

                    I have played with all the project setting that I dare and nothing changes the fact that an empty if statement is causing me problems. You won't believe how embaressed I was today when my boss asked for a demonstration. The whole thing came to a standstill simply because data could not be merged.

                    K Offline
                    K Offline
                    koothkeeper
                    wrote on last edited by
                    #9

                    I would really think that the compiler is doing this to you. Set the optimization to DEBUG on your release build and rebuild everything. Are you stepping through this with the debugger?

                    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