예제 #1
0
            internal void btRegister(IntPtr bluetoothRadioHandle)
            {
                Debug.Assert(_hDevNotification == null, "btRegister, already set.");
                Debug.Assert(_hDevNotification == null || _hDevNotification.IsInvalid, "btRegister, already registered.");
                IntPtr windowHandle            = this.Handle;
                DEV_BROADCAST_HANDLE devHandle = new DEV_BROADCAST_HANDLE(bluetoothRadioHandle);
                RegisterDeviceNotificationSafeHandle hDevNotification
                    = UnsafeNativeMethods.RegisterDeviceNotification_SafeHandle(windowHandle,
                                                                                ref devHandle, RegisterDeviceNotificationFlags.DEVICE_NOTIFY_WINDOW_HANDLE);

                if (hDevNotification.IsInvalid)
                {
                    throw new Win32Exception(/*error code from GetLastError*/);
                }
                _hDevNotification = hDevNotification;
            }
예제 #2
0
        internal void btRegister(IntPtr bluetoothRadioHandle)
        {
            Debug.Assert(_hDevNotification == null, "btRegister, already set.");
            Debug.Assert(_hDevNotification == null || _hDevNotification.IsInvalid, "btRegister, already registered.");
            IntPtr windowHandle            = _wndProc.WindowHandle;
            DEV_BROADCAST_HANDLE devHandle = new DEV_BROADCAST_HANDLE(bluetoothRadioHandle);
            RegisterDeviceNotificationSafeHandle hDevNotification
                = RegisterDeviceNotification_SafeHandle(windowHandle,
                                                        ref devHandle, RegisterDeviceNotificationFlags.DEVICE_NOTIFY_WINDOW_HANDLE);

            if (hDevNotification.IsInvalid)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            _hDevNotification = hDevNotification;
        }