You might think that if you want to get read/write access, you could pass
STGM_. You would be wrong. You have to pass
The three flags
STGM_ are mutually exclusive. If you try to combine them, you get a weird mess.
In particular, since the numerical value of
STGM_ is zero, passing
STGM_ is numerically equivalent to passing
STGM_, which grants write-only access.
The documentation for the
STGM_* constants specifically says “It is not valid to use more than one element from a single group,” and
STGM_ belong to the Access group (as does
These values date back to the days of MS-DOS, where function 3Dh (Open File) passed an access mode in the AL register.
The bottom three bits specified the requested access (0 = read-only, 1 = write-only, 2 = read/write), and the remaining bits were reserved.
Later, when networking support was added in approximately MS-DOS 3.5, three more bits were pressed into service:
Sharing modes were 0 = compatibility mode, 1 = deny all, 2 = deny write, 3 = deny read, 4 = deny none.
These values were carried forward into Windows as flags to the
||Opens a file for reading only.|
||Opens a file for write access only.|
||Opens a file with read/write permissions.|
||Opens a file with compatibility mode, allows any process on a specified computer to open the file any number of times.|
||Opens a file with exclusive mode and denies both read/write ccess to other processes.|
||Opens a file and denies write access to other processes.|
||Opens a file and denies read access to other processes.|
||Opens a file without denying read or write access to other processes.|
These flags were then carried forward into the STGM constants with the same numerical values.