1

I'm currently creating a program that's divided in two parts, one where I detect nearby bluetooth devices and connect them to the pc if the name match and the other where I search for the device with setupapi and get an handle for HID comunication.
My problem is that I cannot find anything that tells me that the device I just connected is the same I found in setupapi.
So in the first part I have something like this:

BLUETOOTH_DEVICE_INFO btdi;
//--- Code omitted ---
BluetoothGetDeviceInfo(radio_handle, &btdi);
if(std::wstring(btdi.szName) == /*my name*/)
    // Device found! now connect
    BluetoothSetServiceState(radio_handle, &btdi, &HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE);

And the setupapi related code:

SP_DEVICE_INTERFACE_DATA device_data;
device_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//--- Code omitted ---
SetupDiEnumDeviceInterfaces(device_infos, NULL, &hid_guid, index, &device_data);

I was thinking about using the bluetooth address of the device but there seem to be no way to get that from setupapi.
So, to recap, is there any way to get the address of the device from setupi? And, if not, is there any other way to be sure that they're both the same device?

Davide Mor
  • 83
  • 7
  • There is a way: look in the Registry. Unfortunately I can not provide more information because code is commercial. – Mike Petrichenko Mar 02 '19 at 15:48
  • @MikePetrichenko I see what you mean ... I would basically have to dig up the value manually (by manually I mean by not not using any clean api) from the registry, but that doesn't seem very robust and hacky... am I right? – Davide Mor Mar 02 '19 at 16:36

1 Answers1

1

Here I posted the code how to find Wiimote connected as HID using its MAC. You have to rework that code so it can use your HID device (change VID and PID).

  • Great answer! ... thanks to you I found (maybe) an even better way to do it, it involves using `SetupDiGetDevicePropertyW` with `DEVPKEY_Device_Parent` as the key, to me it returns a path wich can be used to check the mac, but still I need some testing, I might write another answer if this method turns out to be better – Davide Mor Mar 02 '19 at 18:36