• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SafeHandles.SafeFileHandle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MapViewOfFile

 public static extern SafeFileMapViewHandle MapViewOfFile(
     SafeFileHandle hFileMappingObject,
     FileMapAccess dwDesiredAccess,
     uint dwFileOffsetHigh,
     uint dwFileOffsetLow,
     uint dwNumberOfBytesToMap
     );
开发者ID:schmich,项目名称:debuggernaut,代码行数:7,代码来源:Platform.cs


示例17: CreateCore

        private static SafeMemoryMappedFileHandle CreateCore(
            SafeFileHandle fileHandle, string mapName, HandleInheritability inheritability,
            MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
        {
            Interop.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);

            // split the long into two ints
            int capacityLow = unchecked((int)(capacity & 0x00000000FFFFFFFFL));
            int capacityHigh = unchecked((int)(capacity >> 32));

            SafeMemoryMappedFileHandle handle = fileHandle != null ?
                Interop.mincore.CreateFileMapping(fileHandle, ref secAttrs, GetPageAccess(access) | (int)options, capacityHigh, capacityLow, mapName) :
                Interop.mincore.CreateFileMapping(Interop.INVALID_HANDLE_VALUE, ref secAttrs, GetPageAccess(access) | (int)options, capacityHigh, capacityLow, mapName);

            int errorCode = Marshal.GetLastWin32Error();
            if (!handle.IsInvalid)
            {
                if (errorCode == Interop.ERROR_ALREADY_EXISTS)
                {
                    handle.Dispose();
                    throw Win32Marshal.GetExceptionForWin32Error(errorCode);
                }
            }
            else if (handle.IsInvalid)
            {
                throw Win32Marshal.GetExceptionForWin32Error(errorCode);
            }

            return handle;
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:30,代码来源:MemoryMappedFile.Windows.cs


示例18: ReadFile

		public static extern bool ReadFile (
			SafeFileHandle hFile,
			byte[] lpBuffer,
			int nNumberOfBytesToRead,
			out int lpNumberOfBytesRead,
			IntPtr lpOverlapped
		);
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:DebuggerExtensions.cs


示例19: DeviceIoControl

 private static extern bool DeviceIoControl(
   SafeFileHandle handle,
   [MarshalAs(UnmanagedType.U4)] IoCtrl ioControlCode,
   IntPtr inBuffer, int inBufferSize,
   IntPtr outBuffer, int outBufferSize,
   out int bytesReturned,
   IntPtr overlapped);
开发者ID:Azzuro,项目名称:IR-Server-Suite,代码行数:7,代码来源:DriverVista.cs


示例20: CreatePipe

        public static void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs)
        {
            AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes = new AdvApi32PInvoke.SECURITY_ATTRIBUTES();
            lpPipeAttributes.bInheritHandle = true;
            SafeFileHandle hWritePipe = null;
            try
            {
                if (parentInputs)
                {
                    CreatePipeWithSecurityAttributes(out childHandle, out hWritePipe, lpPipeAttributes, 0);
                }
                else
                {
                    CreatePipeWithSecurityAttributes(out hWritePipe, out childHandle, lpPipeAttributes, 0);
                }

                if (!Kernel32.DuplicateHandle(Kernel32.GetCurrentProcess(), hWritePipe, Kernel32.GetCurrentProcess(), out parentHandle,
                    0, false, Kernel32.DUPLICATE_SAME_ACCESS))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                if ((hWritePipe != null) && !hWritePipe.IsInvalid)
                {
                    hWritePipe.Close();
                }
            }
        }
开发者ID:fschwiet,项目名称:PShochu,代码行数:30,代码来源:Win32Pipe.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SafeHandles.SafeNCryptKeyHandle类代码示例发布时间:2022-05-26
下一篇:
C# SafeHandles.SafeBioHandle类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap