Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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);
        }