CloseHandle() private method

private CloseHandle ( IntPtr handle ) : bool
handle IntPtr
return bool
Beispiel #1
0
        internal static IntPtr SafeCreateFile(String lpFileName,
                                              int dwDesiredAccess, System.IO.FileShare dwShareMode,
                                              SECURITY_ATTRIBUTES securityAttrs, System.IO.FileMode dwCreationDisposition,
                                              int dwFlagsAndAttributes, IntPtr hTemplateFile)
        {
            IntPtr handle = CreateFile(lpFileName, dwDesiredAccess, dwShareMode,
                                       securityAttrs, dwCreationDisposition,
                                       dwFlagsAndAttributes, hTemplateFile);

            if (handle != Win32Native.INVALID_HANDLE_VALUE)
            {
                int fileType = Win32Native.GetFileType(handle);
                if (fileType != Win32Native.FILE_TYPE_DISK)
                {
                    Win32Native.CloseHandle(handle);
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_FileStreamOnNonFiles"));
                }
            }

            return(handle);
        }