Exemplo n.º 1
0
        public override Win32BluetoothDeviceInfo[] DiscoverDevices(int maxDevices, bool authenticated, bool remembered, bool unknown)
        {
            List <Win32BluetoothDeviceInfo> devices = new List <Win32BluetoothDeviceInfo>();
            BLUETOOTH_DEVICE_SEARCH_PARAMS  search  = BLUETOOTH_DEVICE_SEARCH_PARAMS.Create();

            search.cTimeoutMultiplier   = 8;
            search.fReturnAuthenticated = authenticated;
            search.fReturnRemembered    = remembered;
            search.fReturnUnknown       = unknown;
            search.fReturnConnected     = true;
            search.fIssueInquiry        = unknown;

            BLUETOOTH_DEVICE_INFO device = BLUETOOTH_DEVICE_INFO.Create();
            IntPtr searchHandle          = NativeMethods.BluetoothFindFirstDevice(ref search, ref device);

            if (searchHandle != IntPtr.Zero)
            {
                devices.Add(new Win32BluetoothDeviceInfo(device));

                while (NativeMethods.BluetoothFindNextDevice(searchHandle, ref device) && devices.Count <= maxDevices)
                {
                    devices.Add(new Win32BluetoothDeviceInfo(device));
                }

                NativeMethods.BluetoothFindDeviceClose(searchHandle);
            }
            return(devices.ToArray());
        }
        public Win32BluetoothWin32Authentication(BluetoothAddress address, string pin)
        {
            Address = address;
            _pin    = pin;
            BLUETOOTH_DEVICE_INFO device = BLUETOOTH_DEVICE_INFO.Create();

            device.Address = address;
            NativeMethods.BluetoothGetDeviceInfo(IntPtr.Zero, ref device);
            _callback = new NativeMethods.BluetoothAuthenticationCallbackEx(Callback);

            NativeMethods.BluetoothRegisterForAuthenticationEx(ref device, out _handle, _callback, IntPtr.Zero);
        }
Exemplo n.º 3
0
 public Win32BluetoothDeviceInfo(BluetoothAddress address)
 {
     _info         = BLUETOOTH_DEVICE_INFO.Create();
     _info.Address = address;
     NativeMethods.BluetoothGetDeviceInfo(IntPtr.Zero, ref _info);
 }