Thread: unknown MessageBox error

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    12

    Unhappy unknown MessageBox error

    During my current job, I was assigned the task of converting a program from MS VC++ to Dev-CPP because my boss wants to get rid of our dependency on MS. After I finished, I found that the program itself worked correctly but no Message Boxes displayed when errors were encountered!

    Here is an example of how I used the function...

    Code:
    // abort imaging if frame trigger is not detected...
    if (!ftflag)
    {
         MessageBox(NULL, "No frame trigger found...", "Error", MB_OK);
         exit(1);
    }
    To my knowledge, this should work. But for some reason, no message box pops up at all. The program just skips right over it.

    I Tried specifying a window handle, but the same problem still happened.
    I also tried creating a external hello world program with the messagebox call, and it worked, but not my internal code...


    Note: I made sure the conditions were met so the message box would call. In the example above, i made sure the frame trigger was not connected so the MessageBox would be called. Also, no errors or warnings occur during compiling.

    The worst part is, VC++ will show the boxes when i run it through the enviroment, but not mine from dev-cpp.

    Does anyone have any idea why this would happen?

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    wow thats an odd problem. So you are saying that:
    Code:
    BOOL ftflag = FALSE;
     
    if(!ftflag){
         MessageBox(NULL , "No Frame Trigger Found..." , "Error" , MB_OK);
         Exit(1);
         }
    will not produce a messagebox?

    The problem has to be somewhere besides that code. Perhaps the problem lies in the code that sets ftflag TRUE or FALSE.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    try using a different error output:

    Code:
    // abort imaging if frame trigger is not detected...
    { //a little diagnostics
    FILE *err;
    err = fopen("./err", "wt");
    if(!err) exit(2);
    
    if ( (!ftflag) != (!(ftflag)) )
        fputs("is it a define?", err);
    
    
    if (!ftflag)
    {
        fputs("Entered if", err);
         MessageBox(NULL, "No frame trigger found...", "Error", MB_OK);
        fputs("called MessageBox", err);
         exit(1);
    } else fputs("Entered else", err);
    
    fclose(err);
    }
    change the exit values to unique values and check them.

    if ftflag is a bitfield, make sure the unused bits are set to zero.
    Last edited by robwhit; 07-09-2007 at 06:11 PM.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    12
    Quote Originally Posted by abachler View Post
    The problem has to be somewhere besides that code. Perhaps the problem lies in the code that sets ftflag TRUE or FALSE.
    Deep in the code, it says that if the ftflag variable is equal to 1, then the program knows that the frame trigger is present. So, i changed the code to
    Code:
    if(ftflag != 1){
         MessageBox(NULL , "No Frame Trigger Found..." , "Error" , MB_OK);
         Exit(1);
         }
    That still didn't work. Same error as the first post.

    Could this be a translation issue from VC++ to dev-cpp?

    Also, robwhit

    I tried your method, which is quite cool, I will remember that for the future...

    anyway, when I read the file that created by your code, this is what i got.

    "Entered ifcalled MessageBox"

    So the MessageBox is getting called, it just isn't showing on the screen...

    I will continue to mess around with it, but as of right now i am pretty stumped...
    Last edited by bowluswj; 07-10-2007 at 10:27 AM. Reason: Needed to add something...

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Try using a variable (rather than a constant) for the strings/text displayed in the msgbox.

    MessageBox(NULL, szMessage, szError, MB_OK);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    try this:
    Code:
    if(ftflag != 1){
         MessageBox(NULL , _T("Unicode is a tough mistress") , _T("Error") , MB_OK);
         Exit(1);
         }
    http://msdn2.microsoft.com/en-us/library/ms776453.aspx

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    12
    I tried both Novacain's method and Robwhits, both didn't work. I am not sure exactly what has gone on here. My boss said to move on, so i am implementing a different message system in my program which is currently working just fine. But, i am going to continue to look into this problem so we can maybe find a solution. It would be a shame to stop now...

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Out of interest, have you tried missing the call to "exit()" and posting a WM_CLOSE or something instead? Does that make a difference?

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    12
    Quote Originally Posted by Fordy View Post
    Out of interest, have you tried missing the call to "exit()" and posting a WM_CLOSE or something instead? Does that make a difference?
    I would love to try this, but the program that my boss uses is weird. Basically the main program does all the calculations that it needs to and calls another program called "simple windows app". This cpp file creates the window and takes the commands for it. I personally don't understand how it links with this program yet, especially because i am not the one who wrote any of this software. Once i figure that out, i will try it.

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    12
    I found the function in the app that posts WM_CLOSE. I called the app, but it did the same thing as the exit(). It just closes the window without showing the messagebox.

  11. #11
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    What does MessageBox() return? If MessageBox() is returning 0, what does GetLastError() return?

    Additionally, place a blank line right before or after the MessageBox() call, (but inside the if()) - if you set a breakpoint there while debugging, is it triggered?
    Last edited by Cactus_Hugger; 07-12-2007 at 03:30 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM