windows - 如何使用 Delphi 列出蓝牙 radio /设备?

标签 windows delphi bluetooth

在 Delphi 下使用蓝牙时,列出所有已连接的蓝牙设备到某个蓝牙 radio (主机设备)可能很方便。所以问题是:

如何使用 Delphi 列出蓝牙 radio /设备?

最佳答案

这可以通过 JEDI API JwaBluetoothAPIs(在这里找到它:http://sourceforge.net/projects/jedi-apilib/)和下面的代码片段来完成:

uses
  JwaBluetoothAPIs;

procedure ScanBluetoothRadiosDevices;
var
  RadioHandle, DeviceFindHandle: THandle;
  FindHandle: HBLUETOOTH_RADIO_FIND;
  BtFrp: TBlueToothFindRadioParams;
  RadioInfo: BLUETOOTH_RADIO_INFO;
  DeviceInfo: BLUETOOTH_DEVICE_INFO;
  DeviceSearchParams: BLUETOOTH_DEVICE_SEARCH_PARAMS;
  Err : integer;
begin
  // specify record sizes
  BtFrp.dwSize := SizeOf(BtFrp);
  DeviceInfo.dwSize := SizeOf(DeviceInfo);
  RadioInfo.dwSize := SizeOf(RadioInfo);

  FindHandle := BluetoothFindFirstRadio(@BtFrp, RadioHandle);
  if (FindHandle = 0) then
    RaiseLastOSError;

  repeat
    BluetoothEnableDiscovery(RadioHandle, True);
    if BluetoothGetRadioInfo(RadioHandle, RadioInfo) = ERROR_SUCCESS then
      ShowMessage('Radio found: '+ RadioInfo.szName);

    with DeviceSearchParams do
    begin
      dwSize := SizeOf(DeviceSearchParams);
      fReturnUnknown := True;
      fReturnRemembered := True;
      hRadio := RadioHandle;
    end;

    DeviceFindHandle := BluetoothFindFirstDevice(DeviceSearchParams, DeviceInfo);
    if DeviceFindHandle = 0 then
      Continue;

    repeat
      if BluetoothGetDeviceInfo(RadioHandle, DeviceInfo) = ERROR_SUCCESS then
      begin
        BluetoothUpdateDeviceRecord(DeviceInfo);
        if DeviceInfo.fConnected then
          ShowMessageFmt('Device %s is connected', [DeviceInfo.szName])
        else
          ShowMessageFmt('Device %s is not connected', [DeviceInfo.szName]);
      end;
    until not BluetoothFindNextDevice(DeviceFindHandle, DeviceInfo);
    BluetoothFindDeviceClose(DeviceFindHandle)
  until not (BluetoothFindNextRadio(FindHandle, RadioHandle));
  BluetoothFindRadioClose(FindHandle);
end;

从那时起,可以轻松替换 ShowMessageFmt(..) 调用并将其替换为自定义代码。

关于windows - 如何使用 Delphi 列出蓝牙 radio /设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21497453/

相关文章:

c++ - 是否可以使用 C++/WinRT 创建 Windows 服务应用程序?

德尔福ADO : Locate with dataset filter on bug

android - 使用旧版本然后 Android 4.3 检测信标

python - 为 Windows 构建 Vulkan 工具

android - react 原生 : Could not initialize class org. codehaus.groovy.reflection.ReflectionCache

delphi - 在运行时遵循设计时规则重新排列组件位置、大小、所有权(一般属性)的某种方法

arrays - Tarray构造函数可以中止以不添加新记录吗?

android - 发送和接收数据报包

Android 蓝牙 RFCOMM 直接连接树莓派无需配对

c - x86-64下的快速堆栈切换