public static IntPtr Open(String filename, FileMode mode, FileAccess access, FileShare share) { var fileHandle = WindowsNativeMethods.CreateFile(filename, access, share, IntPtr.Zero, mode, FileAttributes.Normal, IntPtr.Zero); if (fileHandle == INVALID_HANDLE_VALUE) { throw new Exception(String.Format("CreateFile '{0}' (mode={1}, access={2}, share={3}) failed (error={4})", filename, mode, access, share, WindowsNativeMethods.GetLastError())); } return(fileHandle); }
public static IntPtr TryOpen(String filename, FileMode mode, FileAccess access, FileShare share) { return(WindowsNativeMethods.CreateFile(filename, access, share, IntPtr.Zero, mode, FileAttributes.Normal, IntPtr.Zero)); }