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


C# SafeObjectHandle类代码示例

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


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

示例1: DeviceIoControl

 public static extern unsafe bool DeviceIoControl(
     SafeObjectHandle hDevice,
     uint dwIoControlCode,
     IntPtr inBuffer,
     int nInBufferSize,
     IntPtr outBuffer,
     int nOutBufferSize,
     out int pBytesReturned,
     OVERLAPPED* lpOverlapped);
开发者ID:vbfox,项目名称:U2FExperiments,代码行数:9,代码来源:Kernell32DllNativeMethods.cs

示例2: HidD_GetManufacturerString

        public static string HidD_GetManufacturerString(SafeObjectHandle hidDeviceObject)
        {
            string result;
            if (!HidD_GetManufacturerString(hidDeviceObject, out result))
            {
                throw new Win32Exception();
            }

            return result;
        }
开发者ID:Eucaly,项目名称:pinvoke,代码行数:10,代码来源:Hid.Helpers.cs

示例3: HidD_GetPreparsedData

        public static SafePreparsedDataHandle HidD_GetPreparsedData(SafeObjectHandle hDevice)
        {
            SafePreparsedDataHandle preparsedDataHandle;
            if (!HidD_GetPreparsedData(hDevice, out preparsedDataHandle))
            {
                throw new Win32Exception();
            }

            return preparsedDataHandle;
        }
开发者ID:Eucaly,项目名称:pinvoke,代码行数:10,代码来源:Hid.Helpers.cs

示例4: HidD_GetAttributes

        public static HiddAttributes HidD_GetAttributes(SafeObjectHandle hFile)
        {
            var result = HiddAttributes.Create();
            if (!HidD_GetAttributes(hFile, ref result))
            {
                throw new Win32Exception();
            }

            return result;
        }
开发者ID:Eucaly,项目名称:pinvoke,代码行数:10,代码来源:Hid.Helpers.cs

示例5: IsWow64Process

        public static bool IsWow64Process(SafeObjectHandle hProcess)
        {
            bool result;
            if (!IsWow64Process(hProcess, out result))
            {
                throw new Win32Exception();
            }

            return result;
        }
开发者ID:vcsjones,项目名称:pinvoke,代码行数:10,代码来源:Kernel32.Helpers.cs

示例6: Process32Enumerate

        /// <summary>Retrieves information about next process encountered in a system snapshot.</summary>
        /// <param name="hSnapshot">
        ///     A handle to the snapshot returned from a previous call to the
        ///     <see cref="CreateToolhelp32Snapshot" /> function.
        /// </param>
        /// <returns>
        ///     An enumeration of all the <see cref="PROCESSENTRY32" /> present in the snapshot.
        /// </returns>
        /// <exception cref="Win32Exception">Thrown if any error occurs.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="hSnapshot" /> is <see langword="null" />.</exception>
        public static IEnumerable<PROCESSENTRY32> Process32Enumerate(SafeObjectHandle hSnapshot)
        {
            if (hSnapshot == null)
            {
                throw new ArgumentNullException(nameof(hSnapshot));
            }

            var entry = Process32First(hSnapshot);

            while (entry != null)
            {
                yield return entry;
                entry = Process32Next(hSnapshot);
            }
        }
开发者ID:vcsjones,项目名称:pinvoke,代码行数:25,代码来源:Kernel32.Helpers.cs

示例7: ReadFile

        /// <summary>Reads data synchronously from the specified file or input/output (I/O) device.</summary>
        /// <param name="hFile">
        ///     A handle to the device (for example, a file, file stream, physical disk, volume, console buffer,
        ///     tape drive, socket, communications resource, mailslot, or pipe).
        ///     <para>The hFile parameter must have been created with read access.</para>
        /// </param>
        /// <param name="lpBuffer">A pointer to the buffer that receives the data read from a file or device.</param>
        /// <param name="nNumberOfBytesToRead">The maximum number of bytes to be read.</param>
        /// <returns>The number of bytes read.</returns>
        /// <exception cref="Win32Exception">Thrown if the native method return false (Read failed).</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="hFile" /> is <see langword="null" />.</exception>
        public static unsafe uint ReadFile(SafeObjectHandle hFile, void* lpBuffer, uint nNumberOfBytesToRead)
        {
            if (hFile == null)
            {
                throw new ArgumentNullException(nameof(hFile));
            }

            var bytesRead = (NullableUInt32)0;
            if (!ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, bytesRead, null))
            {
                throw new Win32Exception();
            }

            return (uint)bytesRead;
        }
开发者ID:vcsjones,项目名称:pinvoke,代码行数:26,代码来源:Kernel32.Helpers.cs

示例8: WriteFile

        /// <summary>Writes data synchronously to the specified file or input/output (I/O) device.</summary>
        /// <param name="hFile">
        ///     A handle to the file or I/O device (for example, a file, file stream, physical disk, volume, console buffer, tape
        ///     drive, socket, communications resource, mailslot, or pipe).
        ///     <para>
        ///         The hFile parameter must have been created with the write access. For more information, see Generic Access
        ///         Rights and File Security and Access Rights.
        ///     </para>
        /// </param>
        /// <param name="lpBuffer">A pointer to the buffer containing the data to be written to the file or device.</param>
        /// <param name="nNumberOfBytesToWrite">
        ///     The number of bytes to be written to the file or device.
        ///     <para>
        ///         A value of zero specifies a null write operation. The behavior of a null write operation depends on the
        ///         underlying file system or communications technology.
        ///     </para>
        /// </param>
        /// <returns>The number of bytes written.</returns>
        /// <exception cref="Win32Exception">Thrown if the native method return false (Write failed).</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="hFile" /> is <see langword="null" />.</exception>
        public static unsafe int WriteFile(SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToWrite)
        {
            if (hFile == null)
            {
                throw new ArgumentNullException(nameof(hFile));
            }

            var bytesWritten = (NullableUInt32)0;
            if (!WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, bytesWritten, null))
            {
                throw new Win32Exception();
            }

            return (int)bytesWritten.Value;
        }
开发者ID:fearthecowboy,项目名称:pinvoke,代码行数:35,代码来源:Kernel32.Helpers.cs

示例9: Process32Next

        /// <summary>Retrieves information about the next process encountered in a system snapshot.</summary>
        /// <param name="hSnapshot">
        ///     A handle to the snapshot returned from a previous call to the
        ///     <see cref="CreateToolhelp32Snapshot" /> function.
        /// </param>
        /// <returns>
        ///     The next <see cref="PROCESSENTRY32" /> if there was any or <see langword="null" /> otherwise (No more values
        ///     in the snapshot).
        /// </returns>
        /// <exception cref="Win32Exception">Thrown if any error occurs.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="hSnapshot" /> is <see langword="null" />.</exception>
        public static PROCESSENTRY32 Process32Next(SafeObjectHandle hSnapshot)
        {
            if (hSnapshot == null)
            {
                throw new ArgumentNullException(nameof(hSnapshot));
            }

            var entry = new PROCESSENTRY32();
            if (Process32Next(hSnapshot, entry))
            {
                return entry;
            }

            var lastError = GetLastError();
            if (lastError != Win32ErrorCode.ERROR_NO_MORE_FILES)
            {
                throw new Win32Exception(lastError);
            }

            return null;
        }
开发者ID:fearthecowboy,项目名称:pinvoke,代码行数:32,代码来源:Kernel32.Helpers.cs

示例10: OpenProcessToken

 public static extern bool OpenProcessToken(
     IntPtr processHandle,
     TokenAccessRights desiredAccess,
     out SafeObjectHandle tokenHandle);
开发者ID:fearthecowboy,项目名称:pinvoke,代码行数:4,代码来源:AdvApi32.cs

示例11: ReadFile

        /// <summary>Reads data synchronously from the specified file or input/output (I/O) device.</summary>
        /// <param name="hFile">
        ///     A handle to the device (for example, a file, file stream, physical disk, volume, console buffer,
        ///     tape drive, socket, communications resource, mailslot, or pipe).
        ///     <para>The hFile parameter must have been created with read access.</para>
        /// </param>
        /// <param name="nNumberOfBytesToRead">The maximum number of bytes to be read.</param>
        /// <returns>
        ///     The data that has been read. The segment returned might have a size smaller than
        ///     <paramref name="nNumberOfBytesToRead" /> if less bytes than requested have been read.
        /// </returns>
        /// <exception cref="Win32Exception">Thrown if the native method return false (Read failed).</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="hFile" /> is <see langword="null" />.</exception>
        public static ArraySegment<byte> ReadFile(SafeObjectHandle hFile, int nNumberOfBytesToRead)
        {
            var buffer = new byte[nNumberOfBytesToRead];
            var segment = new ArraySegment<byte>(buffer);

            var bytesRead = ReadFile(hFile, segment);
            return new ArraySegment<byte>(buffer, 0, bytesRead);
        }
开发者ID:jmelosegui,项目名称:pinvoke,代码行数:21,代码来源:Kernel32.Helpers.cs

示例12: ConnectNamedPipe

 public static extern unsafe bool ConnectNamedPipe(
     SafeObjectHandle hNamedPipe,
     OVERLAPPED* lpOverlapped);
开发者ID:Eucaly,项目名称:pinvoke,代码行数:3,代码来源:Kernel32.cs

示例13: CreatePipe

 public static extern bool CreatePipe(
     out SafeObjectHandle hReadPipe,
     out SafeObjectHandle hWritePipe,
     SECURITY_ATTRIBUTES lpPipeAttributes,
     int nSize);
开发者ID:Eucaly,项目名称:pinvoke,代码行数:5,代码来源:Kernel32.cs

示例14: CancelIo

 public static extern bool CancelIo(SafeObjectHandle hFile);
开发者ID:Eucaly,项目名称:pinvoke,代码行数:1,代码来源:Kernel32.cs

示例15: QueryFullProcessImageName

 public static extern bool QueryFullProcessImageName(
     SafeObjectHandle hProcess,
     QueryFullProcessImageNameFlags dwFlags,
     StringBuilder lpExeName,
     ref int lpdwSize);
开发者ID:Eucaly,项目名称:pinvoke,代码行数:5,代码来源:Kernel32.cs


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