uses
jwaBluetoothApis;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
hRadio,hDeviceFind : THANDLE;
hfind : HBLUETOOTH_RADIO_FIND;
btfrp : TBlueToothFindRadioParams;
radioInfo : BLUETOOTH_RADIO_INFO;
deviceInfo : BLUETOOTH_DEVICE_INFO;
deviceSearchParams : BLUETOOTH_DEVICE_SEARCH_PARAMS;
Err, x : integer;
begin
Memo1.Lines.Clear;
x := 0;
RefreshBtDevices;
try
try
btfrp.dwSize := sizeof(btfrp);
hFind := BluetoothFindFirstRadio(@btfrp, hRadio);
BluetoothEnableDiscovery(hRadio,True);
if (hFind > 0)
then begin
repeat
BluetoothEnableDiscovery(hRadio,True);
radioInfo.dwSize := sizeof(radioInfo);
if (ERROR_SUCCESS = BluetoothGetRadioInfo(hRadio, radioInfo))
then Memo1.Lines.Add('
Radio: '+ radioInfo.szName)
else Memo1.Lines.Add('
unknown error');
deviceInfo.dwSize := sizeof(deviceInfo);
deviceSearchParams.dwSize := sizeof(deviceSearchParams);
deviceSearchParams.fReturnUnknown := true;
deviceSearchParams.fReturnRemembered := true;
deviceSearchParams.hRadio := hRadio;
hDeviceFind := BluetoothFindFirstDevice(deviceSearchParams, deviceInfo);
BluetoothUpdateDeviceRecord(deviceInfo);
Memo1.Lines.Add('
Device: '+deviceInfo.szName);
if deviceInfo.fConnected
then Memo1.Lines.Add('
Device is connected')
else Memo1.Lines.Add('
Device is not connected');
try
Memo1.Lines.Add('
Last seen: '+ DateTimeToStr(SystemTimeToDateTime(deviceInfo.stLastSeen)));
except
end;
try
Memo1.Lines.Add('
Class of Device: ' + IntToStr(deviceInfo.ulClassofDevice));
except
end;
if (hDeviceFind>0)
then begin
while(BluetoothFindNextDevice(hDeviceFind, deviceInfo))
do begin
BluetoothGetDeviceInfo(hRadio, deviceInfo);
BluetoothUpdateDeviceRecord(deviceInfo);
Memo1.Lines.Add('
Device: '+deviceInfo.szName);
if deviceInfo.fConnected
then Memo1.Lines.Add('
Device is connected')
else Memo1.Lines.Add('
Device is not connected');
try
Memo1.Lines.Add('
Last seen: '+ DateTimeToStr(SystemTimeToDateTime(deviceInfo.stLastSeen)));
except
end;
try
Memo1.Lines.Add('
Class of Device: ' + IntToStr(deviceInfo.ulClassofDevice));
except
end;
end;
BluetoothFindDeviceClose(hDeviceFind);
end;
x := x+1;
until
(BluetoothFindNextRadio(hFind, hRadio))
or (x > 0);
BluetoothFindRadioClose(hFind);
end
else begin
Err := GetLastError;
Memo1.Lines.Add(SysErrorMessage(Err)+'
('+inttostr(Err)+'
)');
end;
except
on E:
Exception do Memo1.Lines.Add('
error'+e.
Message);
end;
finally
end;
end;