CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Error checking

  1. #1
    Join Date
    Apr 2007
    Location
    South Africa
    Posts
    86

    Error checking

    I'm having trouble understanding the following piece of code:

    PHP Code:
    if (!RegisterClass (&wndclass))
    {
        
    MessageBox (NULLTEXT ("This program requires Windows NT!"),
        
    szAppNameMB_ICONERROR) ;
        return 
    ;

    If I'm correct this is C-style error checking?
    Would a C++ programmer use an exception here? How would that look?
    Will someone please be so kind to explain this code to me? I understand an if (x != 0) check, but I don't understand the !Function check in the code above.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Error checking

    The if(X) statement in C/C++ just checks whether X is 0 or not 0.
    Checking the MSDN you see that:
    Quote Originally Posted by MSDN
    If the function fails, the return value is zero. To get extended error information, call GetLastError.
    So, checking if (!RegisterClass(&wndclass)) will execute the RegisterClass function and when it returns 0 the body of the if is executed.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Apr 2007
    Location
    South Africa
    Posts
    86

    Re: Error checking

    I thought it might have something to do with the return value. Thanks for explaining it so clearly Marc.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Error checking

    You're welcome
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Nov 2007
    Posts
    28

    Re: Error checking

    Quote Originally Posted by links
    I'm having trouble understanding the following piece of code:

    PHP Code:
    if (!RegisterClass (&wndclass))
    {
        
    MessageBox (NULLTEXT ("This program requires Windows NT!"),
        
    szAppNameMB_ICONERROR) ;
        return 
    ;

    If I'm correct this is C-style error checking?
    Would a C++ programmer use an exception here? How would that look?
    Will someone please be so kind to explain this code to me? I understand an if (x != 0) check, but I don't understand the !Function check in the code above.

    Thanks in advance.
    It has nothing to do with style, winprogramming goes that way,
    people don't tend to write exception code since it is NOT NECESSARY IN THE "MIDDLE CLASS" CODING COMMUNITY.
    There are people who might think of writing code in hard ways to make it stylish, but the more they try to decorate themselves their code, the uglier their program looks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured