コード例 #1
0
        private void SendListeningRequestToDriver()
        {
            //
            // Step 1
            // Open the handle to the driver with Overlapped async I/O flagged
            //
            SafeFileHandle device = null;

            try
            {
                device = DeviceIO.OpenDevice("\\\\.\\IPv6ToBle", true);
            }
            catch
            {
                int code = Marshal.GetLastWin32Error();

                DisplayErrorDialog("Could not open a handle to the driver, " +
                                   "error code: " + code.ToString()
                                   );
                return;
            }

            lock (numThreadsActiveLock)
            {
                NumThreadsActive++;
            }

            IAsyncResult result = DeviceIO.BeginGetPacketFromDriverAsync <byte[]>(device,
                                                                                  IPv6ToBleIoctl.IOCTL_IPV6_TO_BLE_LISTEN_NETWORK_V6,
                                                                                  1280,
                                                                                  IPv6ToBleListenCompletionCallback,
                                                                                  null
                                                                                  );
        }
コード例 #2
0
        private void SendListenRequestToDriver()
        {
            //
            // Step 1
            // Open an async handle to the driver
            //
            SafeFileHandle device = null;

            try
            {
                device = DeviceIO.OpenDevice("\\\\.\\IPv6ToBle",
                                             true    // async
                                             );
            }
            catch (Win32Exception e)
            {
                Debug.WriteLine("Error opening handle to the driver. " +
                                "Error code: " + e.NativeErrorCode
                                );
                return;
            }

            //
            // Step 2
            // Begin an asynchronous operation to get a packet from the driver
            //
            IAsyncResult listenResult = DeviceIO.BeginGetPacketFromDriverAsync <byte[]>(
                device,
                IPv6ToBleIoctl.IOCTL_IPV6_TO_BLE_LISTEN_NETWORK_V6,
                1280,                            // 1280 bytes max
                PacketListenCompletionCallback,
                null                             // no specific state to track
                );

            if (listenResult == null)
            {
                Debug.WriteLine("Invalid request to listen for a packet.");
            }
        }