BOOLEAN
The BOOLEAN type is a basic data type used in Windows programming to represent a boolean value.
Namespace: Microsoft.Win32 (or globally available in C/C++)
Defined in: WinNT.h
Syntax
typedef unsigned char BOOLEAN;
Description
The BOOLEAN type is an alias for an unsigned character (unsigned char) and is used to store logical true or false values.
TRUE(typically defined as 1) indicates a true condition.FALSE(typically defined as 0) indicates a false condition.
While the underlying type is unsigned char, the intended use is for boolean logic. It's important to note the distinction between BOOLEAN and the BOOL type, which can return non-zero values other than 1 to indicate success or specific error conditions.
Values
- 0: Represents
FALSE. - 1: Represents
TRUE.
Remarks
The BOOLEAN type is part of the core Windows API and is widely used in function return values and parameters where a simple true/false indication is required, without the additional semantic meaning that BOOL might carry.
Difference from BOOL
It is crucial to understand the difference between BOOLEAN and BOOL:
BOOLEANis strictly 0 for false and 1 for true.BOOLis also defined as an integer type (usuallyint), but non-zero values (not just 1) are considered TRUE. This allowsBOOLto convey more information (e.g., specific error codes).
Example
Here's a simple C++ example demonstrating the use of BOOLEAN:
#include <windows.h>
#include <iostream>
int main() {
BOOLEAN isFeatureEnabled = TRUE; // Set to TRUE or FALSE
if (isFeatureEnabled == TRUE) {
std::cout << "Feature is enabled." << std::endl;
} else {
std::cout << "Feature is disabled." << std::endl;
}
BOOLEAN anotherFlag = FALSE;
if (!anotherFlag) {
std::cout << "Another flag is false." << std::endl;
}
return 0;
}