I am writing a program for a Win 8 tablet. I need to connect an external BLE device. The device is already paired with Windows, and I see it in the Device Manager. But I canβt figure out how to connect it.
With SetupDiEnumDeviceInfo and SetupDiGetDeviceProperty . I can get some information about the BLE device, but execute, for example. BluetoothGATTGetServices A handheld device is required. I do not know where to get it. Maybe I can use CreateFile , but it's unclear what to replace it with as the first argument to lpFileName.
Here is the code snippet I'm looking for my device with.
HDEVINFO hDevInfo; SP_DEVINFO_DATA DeviceInfoData; DWORD i; // Create a HDEVINFO with all present devices. hDevInfo = SetupDiGetClassDevs( &BluetoothClassGUID, /* GUID_DEVCLASS_BLUETOOTH */ 0, 0, DIGCF_PRESENT); if (hDevInfo == INVALID_HANDLE_VALUE) { // Insert error handling here. return ;//1; } // Enumerate through all devices in Set. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i, &DeviceInfoData);i++) { DWORD DataT; LPTSTR buffer = NULL; DWORD buffersize = 0; while (!SetupDiGetDeviceRegistryProperty( hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buffer, buffersize, &buffersize)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER){ // Change the buffer size. if (buffer) delete(buffer); // Double the size to avoid problems on // W2k MBCS systems per KB 888609. buffer = new wchar_t[buffersize * 2]; }else{ // Insert error handling here. break; } } /* Here i just compare by name is this my device or not */ ... /* Here i just compare by name is this my device or not */ if (buffer) delete(buffer); } if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS ) { // Insert error handling here. return; //1; } // Cleanup SetupDiDestroyDeviceInfoList(hDevInfo); return;// 0;
I moved a little further, but still I can not get data from the device.
To get the "Device Interface", you had to use other functions: SetupDiGetClassDevs , SetupDiEnumDeviceInterfaces and SetupDiGetDeviceInterfaceDetail .
Next, with CreateFile I get a HANDLE BLE device.
hComm = CreateFile (pInterfaceDetailData-> DevicePath, GENERIC_WRITE | GENERIC_READ, NULL, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
Then using WinAPI BluetoothGATTGetServices and BluetoothGATTGetCharacteristics I get the corresponding structures.
But when I try to get the property value with BluetoothGATTGetCharacteristicsValue , I get ERROR_ACCESS_DENIED .
And then I do not know what to do. What could be wrong?
source share