Click to See Complete Forum and Search --> : Error checking
links
July 1st, 2008, 06:48 AM
I'm having trouble understanding the following piece of code:
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
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.
Marc G
July 1st, 2008, 08:33 AM
The if(X) statement in C/C++ just checks whether X is 0 or not 0.
Checking the MSDN (http://msdn.microsoft.com/en-us/library/ms633586(VS.85).aspx) you see that:
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.
links
July 1st, 2008, 09:30 AM
I thought it might have something to do with the return value. Thanks for explaining it so clearly Marc.
Marc G
July 3rd, 2008, 07:52 AM
You're welcome :wave:
Username555
July 3rd, 2008, 08:20 AM
I'm having trouble understanding the following piece of code:
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.