cwinapibitflags

CreateFile - dwDesiredAccess


As said here Microsoft docs - CreateFileA function

dwDesiredAccess

The requested access to the file or device, which can be summarized as read, write, both or neither zero).

The most commonly used values are GENERIC_READ, GENERIC_WRITE, or both (GENERIC_READ | GENERIC_WRITE)

When using both READ and WRITE permissions, why is it written GENERIC_READ | GENERIC_WRITE and not GENERIC_READ && GENERIC_WRITE? Does the | has anything to do with the bitwise OR operator? if yes, why do we use that instead of &&?


Solution

  • GENERIC_READ and GENERIC_WRITE are bit flags - values that only have one bit set. To combine them you use the bitwise or operator |. && is not a bitwise operator, but a logic operator.