I would like to know how does CLR match GENERIC_READ with FileAccess.Read, for instance. I had marshalled this parameter as UnmanagedType.U4
#define GENERIC_READ (0x80000000L)
but
FileAccess.Read = 1
How does marshaler know what is required?
CreateFile's dwDesiredAccessMode argument is too out of whack to cleanly map to an enum. So FileAccess is mapped in code to an int. From the Reference Source's FileStream.cs source code file, FileStream.Init() method:
int fAccess;
...
fAccess = access == FileAccess.Read? GENERIC_READ:
access == FileAccess.Write? GENERIC_WRITE:
GENERIC_READ | GENERIC_WRITE;
...
_handle = Win32Native.SafeCreateFile(tempPath, fAccess, ...etc)
Original indenting reproduced, odd as it looks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With