GetFileType() 개인적인 메소드

private GetFileType ( SafeFileHandle handle ) : int
handle SafeFileHandle
리턴 int
예제 #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);
        }