当前位置: 首页>>代码示例>>C#>>正文


C# SafeHandles.SafeFileHandle类代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeFileHandle的典型用法代码示例。如果您正苦于以下问题:C# SafeFileHandle类的具体用法?C# SafeFileHandle怎么用?C# SafeFileHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SafeFileHandle类属于Microsoft.Win32.SafeHandles命名空间,在下文中一共展示了SafeFileHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

            ///  <summary>
            ///  reads a Feature report from the device.
            ///  </summary>
            ///  
            ///  <param name="hidHandle"> the handle for learning about the device and exchanging Feature reports. </param>
            ///  <param name="readHandle"> the handle for reading Input reports from the device. </param>
            ///  <param name="writeHandle"> the handle for writing Output reports to the device. </param>
            ///  <param name="myDeviceDetected"> tells whether the device is currently attached.</param>
            ///  <param name="inFeatureReportBuffer"> contains the requested report.</param>
            ///  <param name="success"> read success</param>

            public override void Read(SafeFileHandle hidHandle, SafeFileHandle readHandle, SafeFileHandle writeHandle, ref Boolean myDeviceDetected, ref Byte[] inFeatureReportBuffer, ref Boolean success) 
            {                 
                try 
                { 
                    //  ***
                    //  API function: HidD_GetFeature
                    //  Attempts to read a Feature report from the device.
                    
                    //  Requires:
                    //  A handle to a HID
                    //  A pointer to a buffer containing the report ID and report
                    //  The size of the buffer. 
                    
                    //  Returns: true on success, false on failure.
                    //  ***                    
                   
                    success = HidD_GetFeature(hidHandle, ref inFeatureReportBuffer[0], inFeatureReportBuffer.Length); 
                                        
                    Debug.Print( "HidD_GetFeature success = " + success );                     
                } 
                catch ( Exception ex ) 
                { 
                    DisplayException( MODULE_NAME, ex ); 
                    throw ; 
                }                 
            }             
开发者ID:raipat,项目名称:nia-brew,代码行数:37,代码来源:Hid.cs

示例2: FlushQueue

        ///  <summary>
        ///  Remove any input reports waiting in the buffer.
        ///  </summary>
        ///
        ///  <param name="hidHandle">A handle to a device.</param>
        ///
        ///  <returns>True on success. False on failure.</returns>
        internal Boolean FlushQueue(SafeFileHandle hidHandle)
        {
            Boolean success = false;

             traceSource.TraceEvent(TraceEventType.Verbose, 1, "FlushQueue");

             try
             {
            //  ***
            //  API function: HidD_FlushQueue

            //  Purpose: Removes any Input reports waiting in the buffer.

            //  Accepts: a handle to the device.

            //  Returns: True on success, False on failure.
            //  ***

            success = NativeMethods.HidD_FlushQueue(hidHandle);
             }
             catch (Exception ex)
             {
            DisplayException(MethodBase.GetCurrentMethod().Name, ex, ShowMsgBoxOnException);
             }

             return success;
        }
开发者ID:sky8273,项目名称:GenericHid,代码行数:34,代码来源:Hid.cs

示例3: WriteFile

 public static extern bool WriteFile(
     SafeFileHandle hFile,
     IntPtr pBuffer,
     int nNumberOfBytesToWrite,
     ref uint lpNumberOfBytesWritten,
     IntPtr overlapped
     );
开发者ID:Bia10,项目名称:clrn,代码行数:7,代码来源:Win32.cs

示例4: WriteFile

        public static extern bool WriteFile(
			SafeFileHandle hFile,
			byte[] lpBuffer,
			uint nNumberOfBytesToWrite,
			out uint lpNumberOfBytesWritten,
			IntPtr lpOverlapped
		);
开发者ID:fparaggio,项目名称:atmo,代码行数:7,代码来源:Kernel32.cs

示例5: CreatePipeWithSecurityAttributes

 private static void CreatePipeWithSecurityAttributes(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes, uint nSize)
 {
     if ((!Kernel32.CreatePipe(out hReadPipe, out hWritePipe, ref lpPipeAttributes, nSize) || hReadPipe.IsInvalid) || hWritePipe.IsInvalid)
     {
         throw new Win32Exception();
     }
 }
开发者ID:fschwiet,项目名称:PShochu,代码行数:7,代码来源:Win32Pipe.cs

示例6: Open

        /// <summary>Opens the specified file with the requested flags and mode.</summary>
        /// <param name="path">The path to the file.</param>
        /// <param name="flags">The flags with which to open the file.</param>
        /// <param name="mode">The mode for opening the file.</param>
        /// <returns>A SafeFileHandle for the opened file.</returns>
        internal static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int mode)
        {
            Debug.Assert(path != null);

            SafeFileHandle handle = new SafeFileHandle(ownsHandle: true);

            // If we fail to open the file due to a path not existing, we need to know whether to blame
            // the file itself or its directory.  If we're creating the file, then we blame the directory,
            // otherwise we blame the file.
            bool enoentDueToDirectory = (flags & Interop.Sys.OpenFlags.O_CREAT) != 0;

            // Open the file. 
            int fd;
            while (Interop.CheckIo(fd = Interop.Sys.Open(path, flags, mode), path, isDirectory: enoentDueToDirectory,
                errorRewriter: e => (e.Error == Interop.Error.EISDIR) ? Interop.Error.EACCES.Info() : e)) ;
            handle.SetHandle(fd);

            // Make sure it's not a directory; we do this after opening it once we have a file descriptor 
            // to avoid race conditions.
            Interop.Sys.FileStatus status;
            if (Interop.Sys.FStat(fd, out status) != 0)
            {
                handle.Dispose();
                throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), path);
            }
            if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
            {
                handle.Dispose();
                throw Interop.GetExceptionForIoErrno(Interop.Error.EACCES.Info(), path, isDirectory: true);
            }

            return handle;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:38,代码来源:SafeFileHandle.Unix.cs

示例7: FlushQueue

        ///  <summary>
        ///  Remove any Input reports waiting in the buffer.
        ///  </summary>
        ///  
        ///  <param name="hidHandle"> a handle to a device.   </param>
        ///  
        ///  <returns>
        ///  True on success, False on failure.
        ///  </returns>
        internal Boolean FlushQueue( SafeFileHandle hidHandle )
        {
            Boolean success = false;

            try
            {
                //  ***
                //  API function: HidD_FlushQueue

                //  Purpose: Removes any Input reports waiting in the buffer.

                //  Accepts: a handle to the device.

                //  Returns: True on success, False on failure.
                //  ***

                success = HidD_FlushQueue( hidHandle );

                return success;
            }
            catch ( Exception ex )
            {
                DisplayException( MODULE_NAME, ex );
                throw ;
            }
        }
开发者ID:rbray89,项目名称:usbpov,代码行数:35,代码来源:Hid.cs

示例8: InitConsole

    void InitConsole()
    {
#if UNITY_STANDALONE

        FreeConsole();
        AllocConsole();
        IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
        Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(stdHandle, true);
        System.IO.FileStream fileStream = new System.IO.FileStream(safeFileHandle, System.IO.FileAccess.Write);
        System.Text.Encoding encoding = System.Text.Encoding.ASCII;
        System.IO.StreamWriter standardOutput = new System.IO.StreamWriter(fileStream, encoding);
        standardOutput.AutoFlush = true;
        Console.SetOut(standardOutput);
        Application.RegisterLogCallbackThreaded((text, trace, type) =>
        {
            if (type == LogType.Error)
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            else if (type == LogType.Warning)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine(text);
        });
#endif

    }
开发者ID:GraphicGame,项目名称:CSLightStudio,代码行数:32,代码来源:mode2.cs

示例9: STARTUPINFO

 public STARTUPINFO()
 {
     this.cb = Marshal.SizeOf(this);
     this.hStdInput = new SafeFileHandle(new IntPtr(0), false);
     this.hStdOutput = new SafeFileHandle(new IntPtr(0), false);
     this.hStdError = new SafeFileHandle(new IntPtr(0), false);
 }
开发者ID:chrisforbes,项目名称:dbgtool,代码行数:7,代码来源:StartupInfo.cs

示例10: BackupFileStream

        public BackupFileStream(Microsoft.Win32.SafeHandles.SafeFileHandle handle, FileAccess access)
        {
            if (handle == null)
            {
                throw new ArgumentNullException();
            }
            if (handle.IsInvalid)
            {
                throw new ArgumentException();
            }
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new PlatformNotSupportedException();
            }
            switch (access)
            {
                case FileAccess.Read:
                case FileAccess.Write:
                    this.SafeFileHandle = handle;
                    this.Access = access;
                    return;

                case FileAccess.ReadWrite:
                    throw new ArgumentException();
            }
            throw new InvalidEnumArgumentException();
        }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:27,代码来源:BackupFileStream.cs

示例11: CreateSharedBackingObject

        private static FileStream CreateSharedBackingObject(
            Interop.libc.MemoryMappedProtections protections, long capacity,
            out string mapName, out SafeMemoryMappedFileHandle.FileStreamSource fileStreamSource)
        {
            // The POSIX shared memory object name must begin with '/'.  After that we just want something short and unique.
            mapName = "/" + MemoryMapObjectFilePrefix + Guid.NewGuid().ToString("N");
            fileStreamSource = SafeMemoryMappedFileHandle.FileStreamSource.ManufacturedSharedMemory;

            // Determine the flags to use when creating the shared memory object
            Interop.libc.OpenFlags flags = (protections & Interop.libc.MemoryMappedProtections.PROT_WRITE) != 0 ?
                Interop.libc.OpenFlags.O_RDWR :
                Interop.libc.OpenFlags.O_RDONLY;
            flags |= Interop.libc.OpenFlags.O_CREAT | Interop.libc.OpenFlags.O_EXCL; // CreateNew

            // Determine the permissions with which to create the file
            Interop.libc.Permissions perms = default(Interop.libc.Permissions);
            if ((protections & Interop.libc.MemoryMappedProtections.PROT_READ) != 0)
                perms |= Interop.libc.Permissions.S_IRUSR;
            if ((protections & Interop.libc.MemoryMappedProtections.PROT_WRITE) != 0)
                perms |= Interop.libc.Permissions.S_IWUSR;
            if ((protections & Interop.libc.MemoryMappedProtections.PROT_EXEC) != 0)
                perms |= Interop.libc.Permissions.S_IXUSR;

            // Create the shared memory object. Then enlarge it to the requested capacity.
            int fd;
            Interop.CheckIo(fd = Interop.libc.shm_open(mapName, flags, (int)perms), mapName);
            SafeFileHandle fileHandle = new SafeFileHandle((IntPtr)fd, ownsHandle: true);

            // Wrap the handle in a stream and return it.
            var fs = new FileStream(fileHandle, TranslateProtectionsToFileAccess(protections));
            fs.SetLength(capacity);
            return fs;
        }
开发者ID:jsalvadorp,项目名称:corefx,代码行数:33,代码来源:MemoryMappedFile.Linux.cs

示例12: LogonUser

 public static extern Boolean LogonUser(
     String lpszUserName,
     String lpszDomain,
     String lpszPassword,
     LogonType dwLogonType,
     LogonProvider dwLogonProvider,
     out SafeFileHandle phToken);
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:7,代码来源:LogonUser.cs

示例13: DuplicateTokenEx

 public static extern bool DuplicateTokenEx(
     SafeFileHandle hExistingToken,
     uint dwDesiredAccess,
     SecurityAttributes lpTokenAttributes,
     SecurityImpersonationLevel impersonationLevel,
     TokenType tokenType,
     out IntPtr hNewToken);
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:7,代码来源:DuplicateTokenEx.cs

示例14: ReadFile

 public static extern Boolean ReadFile(
     SafeFileHandle hFile,
     IntPtr lpBuffer,
     Int32 nNumberOfBytesToRead,
     ref Int32 lpNumberOfBytesRead,
     IntPtr lpOverlapped
     );
开发者ID:KonstantinKolesnik,项目名称:TyphoonAdapter,代码行数:7,代码来源:Kernel32.cs

示例15: WriteFile

 public static extern Boolean WriteFile(
     SafeFileHandle hFile,
     Byte[] lpBuffer,
     Int32 nNumberOfBytesToWrite,
     ref Int32 lpNumberOfBytesWritten,
     IntPtr lpOverlapped
     );
开发者ID:KonstantinKolesnik,项目名称:TyphoonAdapter,代码行数:7,代码来源:Kernel32.cs


注:本文中的Microsoft.Win32.SafeHandles.SafeFileHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。