private static unsafe IAsyncResult BeginDeviceIoControl <TIn, TOut>(SafeFileHandle hDevice, uint dwIoControlCode, byte[] buffer, AsyncCallback userCallback, object userState) where TIn : struct where TOut : struct { var ar = OverlappedAsync.SetupOverlappedFunction(hDevice, userCallback, buffer); var inSz = Marshal.SizeOf(typeof(TIn)); fixed(byte *pIn = buffer, pOut = &buffer[inSz]) { uint bRet; var ret = DeviceIoControl(hDevice, dwIoControlCode, pIn, (uint)inSz, pOut, (uint)(buffer.Length - inSz), out bRet, ar.Overlapped); return(OverlappedAsync.EvaluateOverlappedFunction(ar, ret)); } }
public static TOut?EndDeviceIoControl <TIn, TOut>(IAsyncResult asyncResult) where TIn : struct where TOut : struct { var ret = OverlappedAsync.EndOverlappedFunction(asyncResult); return(Unpack <TIn, TOut>(ret as byte[]).Item2); }