Exemple #1
0
 internal static T Invoke <T>(SafeFileHandle handle, int ioControlCode) where T : struct
 {
     using (var output = new HGlobal(GetActualSize <T>(handle, ioControlCode)))
     {
         NativeMethods.ThrowIfSetLastError(NativeMethods.DeviceIoControl(
                                               handle, ioControlCode, IntPtr.Zero, 0, output.Value, output.Size, out var _, IntPtr.Zero));
         return(Marshal.PtrToStructure <T>(output.Value));
     }
 }
Exemple #2
0
 internal static T Invoke <T>(SafeFileHandle handle, int ioControlCode, T inputAndOutputStruct) where T : struct
 {
     using (var inputAndOutputPtr = new HGlobal <T>(inputAndOutputStruct))
     {
         NativeMethods.ThrowIfSetLastError(NativeMethods.DeviceIoControl(
                                               handle, ioControlCode, inputAndOutputPtr.Value, inputAndOutputPtr.Size,
                                               inputAndOutputPtr.Value, inputAndOutputPtr.Size, out var _, IntPtr.Zero));
         return(Marshal.PtrToStructure <T>(inputAndOutputPtr.Value));
     }
 }