when I call a win32 api like CreateFile, I would like to be able to
pass an enumerated value as the parameter value:
hFile = CreateFile(
InPath, GENERIC_READ,
ShareMode.Read, // this is an enum
IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
I know I can cast the enum:
(uint) ShareMode.Read
but I consider that redundant ( and casting makes me nervous! ).
In C#, can I specify that the enum can always be converted to a (uint),
allowing the compiler to implicitly case the enum to a uint?
thanks,
-Steve
public enum ShareMode
{
NotShared = 0,
Read = 0x00000001,
Write = 0x00000002,
Delete = 0x00000004
}
[DllImport("kernel32.dll", SetLastError = true)]
static extern unsafe System.IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);