How to establish a connection from windows 8 PC to a Bluetooth low energy device? RRS feed

  • Question

  • Hi,

    I need to establish a connection to a remote Bluetooth low energy device from my windows 8 PC ( I have a Bluetooth USB Dongle to connect to the PC). I already know the BLE device's ID. Now I just have to make a connection and send some data to the device from PC.

    I searched this blog and perused through the Bluetooth LE samples given here "" but did not find the method I want. I should be able to connect to the device by providing the device ID by myself. But the samples have  a method that enumerates the available devices and then connects to the required device. I am working on Visual C++ (Win32 application). 

    Any sample would be very really helpful. 

    Thanks in advance for your response.

    • Edited by phanitk Thursday, February 21, 2013 10:58 AM
    Thursday, February 21, 2013 10:43 AM


All replies

  • Hi,

    The Windows 8 Bluetooth GATT apis requires that the device be paired using the built-in UI and does not allow application to connect to an arbitrary Bluetooth LE device.  Please refer to the Bluetooth Low Energy documentation for more details.

    This whitepaper might also be useful:

    Alain Michaud [MSFT]

    Thursday, February 21, 2013 3:17 PM
  • Hi Alain,

    Thank you for your help!!

    Friday, February 22, 2013 4:14 AM
  • Hi Alain,

    As you suggested, I was able to pair with Bluetooth Low energy device using built UI and installation functions available from          

    I am able to get a handle to the device and use it in the GATT APIs ( get services and get characteristics) and the buffers obtained were correct.

    Everything went well till I tried to send a value to the device using set characteristic value. It is giving an error as ACCESS DENIED where as the same device handle worked well with  earlier functions.

    When I tried to give Service Buffer from get services functionas a handle ( as it asked for a service handle) I am getting an error as INVALID_HANDLE.

    If you need further information or the code I have written let me know..

    Please help with this..

    Thanks in advance


    • Edited by phanitk Thursday, February 28, 2013 2:07 PM
    Thursday, February 28, 2013 2:06 PM
  • Hi,

    I have the same problem here:

    First, I connect to a BT LE device using the Windows 8  UI. => OK

    Then I run my own program, that:

    * Enumerates the devices, which implement the bluetooth LE interface class. OK => my program finds one device.

    * Enumerates the interfaces for this device. OK => my program finds one interface. 

    * Then it gets the device interface path and does a CreateFile to get the device hande. OK => I get a valid path & handle.

    * It uses the handle to call the BluetoothGATTGetServices & characteristics. So far all OK => I can enumerate the services & characteristics.

    From the moment I try to read a value, register for an event, ... I get an ACCESS DENIED error. (I guess in general I get this error as soon as I make an API  call which requires communication with the BT LE device over the air??).

    The msdn API documentation makes distinction between a device and a service handle. How to get a service handle?

    Furthermore, what parameters do I have to give to CreateFile regarding permissions/sharing/security ?

    Any idea what could be wrong?



    Friday, March 8, 2013 3:00 PM
  • Hi,

    I think you might have already found a solution

    If not...

    How it worked for me is, I tried enumerating the devices using Service Id, instead of Bluetooth LE interface class GUID..

    I think you should be able to get service ID from device manager...

    Thursday, March 21, 2013 8:01 AM
  • Hi,

    Nice to hear that it is working for you!

    For me it is still not clear where to get the "service ID"... 

    And are you using this service ID as a parameter to "SetupDIGetClassDevs" ?

    Are you prepared to share some pieces of your code?



    • Proposed as answer by powerboy_zds Wednesday, April 2, 2014 7:35 AM
    • Unproposed as answer by powerboy_zds Wednesday, April 2, 2014 7:35 AM
    Thursday, March 21, 2013 12:10 PM
  • Hi,

    Download GUID explorer and check for UID of the device service from which you want to read a value...

    Yes, you have to give this as a parameter to SetupDIGetClassDevs and also SetupDIEnumDeviceInterfaces..

    Friday, March 22, 2013 4:07 AM
  • Hello,

    Is there a way for me to create my own application that can discover Bluetooth LE devices and has its own custom pairing sequence?

    Part of my BLE device's pairing sequence requires the Windows 8 side to input the passkey displayed on the device. Windows 8 skips this part and continues with adding the device to its list of paired devices. Resulting in pairing failure for the device's side.

    Wednesday, March 27, 2013 7:49 AM
  • Hi, 

    I have the same proble and I am trying to implement your solution but I have problems trying to open the resulting devicepath. 

    my code is 

    HANDLE TICC2540SimpleKeysServiceContent::getServiceHandle(){
    // char DeviceName[255] = "";
    // char DevicePath[500] = "";
     HRESULT hr = E_FAIL;
     CHECK_HR(hr, "get service handle");
      CHECK_HR(hr, "post setupdigetclassdevs");
     deviceInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
    // ULONG nGuessCount = MAXLONG;
    // for(ULONG iDevIndex=0; iDevIndex {
     ULONG iDevIndex = 0;
     CHECK_HR(hr, "pre if");
     while(iDevIndex < 10 ){
    	 if(SetupDiEnumDeviceInterfaces(hDevInfo, 0, &SERVICE_TICC2540SimpleKeysService, iDevIndex, &deviceInfoData))
    		CHECK_HR(hr, "dentro if");
    		DWORD cbRequired = 0;
    		CHECK_HR(hr, "Required %d ", cbRequired);
            if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
              CHECK_HR(hr, "post local alloc ");
              if (pdidd)
                pdidd->cbSize = sizeof(*pdidd);
                if (SetupDiGetDeviceInterfaceDetail(hDevInfo,
    				 CHECK_HR(hr, "post get device path %ls", pdidd->DevicePath);
                                     GENERIC_READ | GENERIC_WRITE,
                                     FILE_SHARE_READ | FILE_SHARE_WRITE,
    				 CHECK_HR(hr, "post open path ");
    	 else if(GetLastError() == ERROR_NO_MORE_ITEMS) //No more items
    			 CHECK_HR(hr, "else if");
         CHECK_HR(hr, "post setup di");
     return hOut; 

    Any comment would be helpful... 



    Wednesday, April 3, 2013 6:12 AM
  • By the way, the 2 device path retrieved are: 




    Wednesday, April 3, 2013 2:35 PM
  • Hi,

    I have to write a BLE-Application for university. Can you send me a code example how you established the connection?

    Thank you very much!

    Friday, April 12, 2013 11:57 AM
  • Hi,

    Windows 8's IO capabilities is set to DisplayYesNo.  The device should respect Io Capability to pairing sequence as defined in the Bluetooth Core specification.

    In recognition that this problem exists in several device implementation, especially the TI CC2540 based solution, Windows 8.1 has changed its IO capabilities to KeyboardDisplay which addresses this problem.

    For others in this thread above which seems to have problems opening up the service handle to do Get/Set value operations, this is most likely the same problem.

    So you have a few options to proceed:

    1. Get the latest TI FW for the CC2540 from TI.
    2. Update to Windows 8.1


    Tuesday, April 15, 2014 5:39 PM
  • Hi

    Suggesting to play with gatttool first. It will help a lot. :

    I went to Ubuntu:

    installed latest bluze-5.

    hcitool lescan

    -> got mac address of the BLE device in question

    gatttool -b -I

    -> got all primary serices uuids.

    Then in Windows 8 I (after pairing, or just connect)  enumerated and created file for each of the uuid's until succeeded.



    Wednesday, August 19, 2015 10:28 AM
  • Hi,

    I want to know if this still applies to updated APIs for BLE?

    Best regards, Daniel

    Wednesday, October 5, 2016 9:21 AM