示例#1
0
        private DeviceAsyncResult <T> AsyncControl <T>(DeviceControlCode deviceControlCode,
                                                       Object inBuffer, T outBuffer, AsyncCallback asyncCallback, Object state)
        {
            SafePinnedObject      inDeviceBuffer  = SafePinnedObject.FromObject(inBuffer);
            SafePinnedObject      outDeviceBuffer = SafePinnedObject.FromObject(outBuffer);
            DeviceAsyncResult <T> asyncResult     = new DeviceAsyncResult <T>(inDeviceBuffer, outDeviceBuffer, asyncCallback, state);

            unsafe {
                Int32 bytesReturned;
                NativeControl(deviceControlCode, inDeviceBuffer, outDeviceBuffer,
                              out bytesReturned, asyncResult.GetNativeOverlapped());
            }
            return(asyncResult);
        }
示例#2
0
        private Object SyncControl(DeviceControlCode deviceControlCode,
                                   Object inBuffer, Object outBuffer, out Int32 bytesReturned)
        {
            using (SafePinnedObject inDeviceBuffer = SafePinnedObject.FromObject(inBuffer))
                using (SafePinnedObject outDeviceBuffer = SafePinnedObject.FromObject(outBuffer)) {
                    unsafe {
                        NativeControl(deviceControlCode, inDeviceBuffer, outDeviceBuffer,
                                      out bytesReturned, null);
                    }
                }

            // When passed, the argument for outBuffer got boxed so we return a reference
            // to the object that contains the data returned from DeviceIoControl.
            return(outBuffer);
        }