none
Program with Bluetooth Low Energy. RRS feed

  • Question

  • I'm learning about BLE. i write a C++ example with VS2010 on Windows 8.1. Very simple. It's find device which support BLE. After connect my Pc with my device , in my code, I can't run. Visual 2010 show me a error "cannot open file 'BluetoothApis.lib'". Who can tell me reason?

    thanks for watching

    Tuesday, March 31, 2015 4:09 AM

All replies

  • I'm learning about BLE. i write a C++ example with VS2010 on Windows 8.1. Very simple. It's find device which support BLE. After connect my Pc with my device , in my code, I can't run. Visual 2010 show me a error "cannot open file 'BluetoothApis.lib'". Who can tell me reason?

    thanks for watching

    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    #include <setupapi.h>
    #include <BluetoothApis.h>
    
    #pragma comment(lib, "SetupAPI")
    #pragma comment(lib, "BluetoothApis.lib")
    #define TO_SEARCH_DEVICE_UUID "{0000180D-0000-1000-8000-00805F9B34FB}" //we use UUID for an HR BLE device 
    HANDLE GetBLEHandle(__in GUID AGuid)
    {
        HDEVINFO hDI;
        SP_DEVICE_INTERFACE_DATA did;
        SP_DEVINFO_DATA dd;
        GUID BluetoothInterfaceGUID = AGuid;
        HANDLE hComm = NULL;
    
        hDI = SetupDiGetClassDevs(&BluetoothInterfaceGUID, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
    
        if( hDI == INVALID_HANDLE_VALUE ) return NULL;
    
        did.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
        dd.cbSize = sizeof(SP_DEVINFO_DATA);
    
        for(DWORD i = 0; SetupDiEnumDeviceInterfaces(hDI, NULL, &BluetoothInterfaceGUID, i, &did); i++)
        {
        	SP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData;
    
        	DeviceInterfaceDetailData.cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
    
        	DWORD size = 0;
    
        	if(!SetupDiGetDeviceInterfaceDetail(hDI, &did, NULL, 0, &size, 0) )
        	{
        		int err = GetLastError();
    
        		if( err == ERROR_NO_MORE_ITEMS ) break;
    
        		PSP_DEVICE_INTERFACE_DETAIL_DATA pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)GlobalAlloc(GPTR , size);
    
        		pInterfaceDetailData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
    
        		if( !SetupDiGetDeviceInterfaceDetail(hDI, &did, pInterfaceDetailData, size, &size, &dd) )
        			break;
    
        		hComm = CreateFile(
        			pInterfaceDetailData->DevicePath,
        			GENERIC_WRITE | GENERIC_READ,
        			FILE_SHARE_READ | FILE_SHARE_WRITE,
        			NULL,
        			OPEN_EXISTING,
        			0,
        			NULL);
    
        		GlobalFree(pInterfaceDetailData);
        	}
        }
    
        SetupDiDestroyDeviceInfoList(hDI);
        return hComm;
    }
    
    
    int main( int argc, char *argv[ ], char *envp[ ] )
    {
        //Step 1: find the BLE device handle from its GUID
        GUID AGuid;
        //GUID can be constructed from "{xxx....}" string using CLSID
        CLSIDFromString(TEXT(TO_SEARCH_DEVICE_UUID), &AGuid);
    
        //now get the handle 
        HANDLE hLEDevice = GetBLEHandle(AGuid);
    
    
        return 0;
    }

    My code
    Tuesday, March 31, 2015 4:10 AM