Exemple #1
0
        public static string SetupDiGetDeviceInterfaceDetail(
            SafeDeviceInfoSetHandle lpDeviceInfoSet,
            DeviceInterfaceData oInterfaceData,
            IntPtr lpDeviceInfoData)
        {
            var requiredSize = new NullableUInt32();

            // First call to get the size to allocate
            SetupDiGetDeviceInterfaceDetail(
                lpDeviceInfoSet,
                ref oInterfaceData,
                IntPtr.Zero,
                0,
                requiredSize,
                null);

            // As we passed an empty buffer we know that the function will fail, not need to check the result.
            var lastError = GetLastError();
            if (lastError != Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER)
            {
                throw new Win32Exception(lastError);
            }

            var buffer = Marshal.AllocHGlobal((int)requiredSize.Value);

            try
            {
                Marshal.WriteInt32(buffer, DeviceInterfaceDetailDataSize.Value);

                // Second call to get the value
                var success = SetupDiGetDeviceInterfaceDetail(
                    lpDeviceInfoSet,
                    ref oInterfaceData,
                    buffer,
                    (uint)requiredSize,
                    null,
                    null);

                if (!success)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    return null;
                }

                var strPtr = new IntPtr(buffer.ToInt64() + 4);
                return Marshal.PtrToStringAuto(strPtr);
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
Exemple #2
0
 public static extern bool SetNamedPipeHandleState(
     SafeObjectHandle hNamedPipe,
     NullablePipeMode lpMode,
     NullableUInt32 lpMaxCollectionCount,
     NullableUInt32 lpCollectDataTimeout);
Exemple #3
0
 public static unsafe extern bool WriteFile(
     SafeObjectHandle hFile,
     void* lpBuffer,
     uint nNumberOfBytesToWrite,
     NullableUInt32 lpNumberOfBytesWritten,
     OVERLAPPED* lpOverlapped);
Exemple #4
0
 public static unsafe extern bool ReadFile(
     SafeObjectHandle hFile,
     void* lpBuffer,
     uint nNumberOfBytesToRead,
     NullableUInt32 lpNumberOfBytesRead,
     OVERLAPPED* lpOverlapped);
		unsafe public bool ReadFile(
            SafeObjectHandle hFile,
            void* lpBuffer,
            uint nNumberOfBytesToRead,
            NullableUInt32 lpNumberOfBytesRead,
            OVERLAPPED* lpOverlapped)
			=> ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
		public bool SetupDiGetDeviceInterfaceDetail(
            SafeDeviceInfoSetHandle deviceInfoSet,
            ref DeviceInterfaceData deviceInterfaceData,
            IntPtr deviceInterfaceDetailData,
            uint deviceInterfaceDetailDataSize,
            NullableUInt32 requiredSize,
            DeviceInfoData deviceInfoData)
			=> SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref deviceInterfaceData, deviceInterfaceDetailData, deviceInterfaceDetailDataSize, requiredSize, deviceInfoData);
        /// <summary>
        ///     Writes data to the specified file or input/output (I/O) device.
        ///     <para>
        ///         This function is designed for both synchronous and asynchronous operation. For a similar function designed
        ///         solely for asynchronous operation, see WriteFileEx.
        ///     </para>
        /// </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>
        ///     <para>
        ///         For asynchronous write operations, hFile can be any handle opened with the CreateFile function using the
        ///         FILE_FLAG_OVERLAPPED flag or a socket handle returned by the socket or accept function.
        ///     </para>
        /// </param>
        /// <param name="lpBuffer">
        ///     A pointer to the buffer containing the data to be written to the file or device.
        ///     <para>
        ///         This buffer must remain valid for the duration of the write operation. The caller must not use this buffer
        ///         until the write operation is completed.
        ///     </para>
        /// </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>
        /// <param name="lpNumberOfBytesWritten">
        ///     A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter.
        ///     WriteFile sets this value to zero before doing any work or error checking. Use <see langword="null" />
        ///     for this parameter if this is an asynchronous operation to avoid potentially erroneous results.
        ///     <para>
        ///         This parameter can be NULL only when the <paramref name="lpOverlapped" /> parameter is not
        ///         <see langword="null" />.
        ///     </para>
        /// </param>
        /// <param name="lpOverlapped">
        ///     A pointer to an <see cref="OVERLAPPED" /> structure is required if the hFile parameter was opened with
        ///     FILE_FLAG_OVERLAPPED, otherwise this parameter can be NULL.
        ///     <para>
        ///         For an hFile that supports byte offsets, if you use this parameter you must specify a byte offset at which to
        ///         start writing to the file or device. This offset is specified by setting the Offset and OffsetHigh members of
        ///         the <see cref="OVERLAPPED" /> structure. For an hFile that does not support byte offsets, Offset and OffsetHigh
        ///         are ignored.
        ///     </para>
        ///     <para>
        ///         To write to the end of file, specify both the Offset and OffsetHigh members of the <see cref="OVERLAPPED" />
        ///         structure as 0xFFFFFFFF. This is functionally equivalent to previously calling the CreateFile function to open
        ///         hFile using FILE_APPEND_DATA access.
        ///     </para>
        /// </param>
        /// <returns>
        ///     If the function succeeds, the return value is <see langword="true" />.
        ///     <para>
        ///         If the function fails, or is completing asynchronously, the return value is <see langword="false" />. To get
        ///         extended error information, call the GetLastError function.
        ///     </para>
        ///     <para>
        ///         Note: The <see cref="GetLastError" /> code <see cref="Win32ErrorCode.ERROR_IO_PENDING" /> is not a failure;
        ///         it designates the write operation is pending completion asynchronously.
        ///     </para>
        /// </returns>
        public bool InvokeWriteFile(
            SafeObjectHandle hFile,
            void* lpBuffer,
            uint nNumberOfBytesToWrite,
            NullableUInt32 lpNumberOfBytesWritten,
            OVERLAPPED* lpOverlapped)
			=> WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
Exemple #8
0
 public static extern bool SetupDiGetDeviceInterfaceDetail(
     SafeDeviceInfoSetHandle deviceInfoSet,
     ref DeviceInterfaceData deviceInterfaceData,
     IntPtr deviceInterfaceDetailData,
     int deviceInterfaceDetailDataSize,
     NullableUInt32 requiredSize,
     DeviceInfoData deviceInfoData);
Exemple #9
0
 public static extern unsafe bool WriteFile(
     SafeObjectHandle hFile,
     void *lpBuffer,
     int nNumberOfBytesToWrite,
     NullableUInt32 lpNumberOfBytesWritten,
     OVERLAPPED *lpOverlapped);
Exemple #10
0
 public static extern unsafe bool ReadFile(
     SafeObjectHandle hFile,
     void *lpBuffer,
     int nNumberOfBytesToRead,
     NullableUInt32 lpNumberOfBytesRead,
     OVERLAPPED *lpOverlapped);