Extracting flag from DWORD?

Suppose that a DWORD has the value of (FLAG_ONE | FLAG_TWO | FLAG_3). How can I tell if it DWORD contains the value of FLAG_TWO or not?

In other words, how do I separate a DWORD into its '|'-delimited flags?

Here's pseudo-code for I want:
1
2
3
4
if(dwFlags.contains(PROCESS_TERMINATE)) // if PROCESS_TERMINATE is one of its flags
	printf("yay, you can terminate the process!");
else
	printf("nope, you can't terminate it.");
1
2
3
if(dwFlags & PROCESS_TERMINATE)
{
}


EDIT: This only works if the flag is an individual bit (which is typically the case), however if you have a compound flag that is really several bits, this won't work.

A "safer" way is:

1
2
3
if((dwFlags & PROCESS_TERMINATE) == PROCESS_TERMINATE)
{
}
Last edited on
Thanks, that really helped! (:
Topic archived. No new replies allowed.