Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I cast a bool to a BOOL?

Am I safe in casting a C++ bool to a Windows API BOOL via this construct

bool mybool = true;
BOOL apiboolean = mybool ? TRUE : FALSE;

I'd assume this is a yes because I don't see any obvious problems but I wanted to take a moment to ask only because this may be more subtle than it appears.

Thanks to Dima for (gently) pointing out my carelessness in the way I'd originally phrased the question.

like image 934
Onorio Catenacci Avatar asked Dec 09 '22 22:12

Onorio Catenacci


2 Answers

Do you mean


bool b;
...
BOOL apiboolean = b ? TRUE : FALSE;

If so, then yes, this will work.

like image 188
Dima Avatar answered Dec 20 '22 19:12

Dima


Yes, that will work, but

bool b;
...
BOOL apiboolean = (BOOL) b;

should work just as well, as does the reverse:

bool bb = (bool) apiboolean;
like image 21
James Curran Avatar answered Dec 20 '22 17:12

James Curran