I cant interpret this snippet of code.
I suspect its
if GetLastError() returns ERROR_SUCCESS then assign something to bRet
But where is the if() statement?
Code:BOOL bRet=FALSE; bRet=(GetLastError() == ERROR_SUCCESS);
I cant interpret this snippet of code.
I suspect its
if GetLastError() returns ERROR_SUCCESS then assign something to bRet
But where is the if() statement?
Code:BOOL bRet=FALSE; bRet=(GetLastError() == ERROR_SUCCESS);
Using Windows 10 with Code Blocks and MingW.
Can't tell without knowing how BOOL is defined. The return of "==" maybe automatically converted to BOOL. This can be risky. It's best to use C++ type "bool". Best guess is that BOOL is defined with int 0 and 1 or unsigned 0 and 1. Then C++'s bool true/false returned by "==" is converted to 0/1.
Last edited by nimitzhunter; 05-11-2011 at 12:56 PM.
"All that we see or seem
Is but a dream within a dream." - Poe
BOOL is defined as an integral type and everybody who has ever touched WinAPI knows this. This isn't risky, it's good to stay with WinAPI types when writing Win code.
bRet is assigned to the result of expression (GetLastError() == ERROR_SUCCESS). So, if the condition is true (read: error code equals 0) the return value is true (read: success), otherwise it is false (read: failure).
Last edited by kmdv; 05-11-2011 at 01:30 PM.
Thank you for the explanation!
So it can be used instead of if() statement.
Using Windows 10 with Code Blocks and MingW.
Think of it with a different kind of operation:
The "5 + 7" is evaluated and assigns the result (12) to "a".Code:int a = 5 + 7;
The == operator works the same way. It takes two operands, compares their equality, and evaluates to either 0 (false) or 1 (true):
5 does not equal 7, so "a" is assigned the value 0 (false).Code:int a = 5 == 7;
If you understand what you're doing, you're not learning anything.
Yes, thats right, i understand now, great, thank you!
Using Windows 10 with Code Blocks and MingW.