windows下动态加载BLE DLL函数
windows10支持BLE,而Windows7不支持,故需要BLE函数设计成动态加载
头文件中
#include <bthdef.h>
#include <bluetoothleapis.h>
typedef int (WINAPI *HN_BluetoothGATTGetServices)(_In_ HANDLE hDevice, _In_ USHORT ServicesBufferCount, _Out_writes_to_opt_(ServicesBufferCount, *ServicesBufferActual) PBTH_LE_GATT_SERVICE ServicesBuffer, _Out_ USHORT* ServicesBufferActual, _In_ ULONG Flags);
typedef int (WINAPI *HN_BluetoothGATTGetCharacteristics)(_In_ HANDLE hDevice, _In_opt_ PBTH_LE_GATT_SERVICE Service, _In_ USHORT CharacteristicsBufferCount, _Out_writes_to_opt_(CharacteristicsBufferCount, *CharacteristicsBufferActual) PBTH_LE_GATT_CHARACTERISTIC CharacteristicsBuffer, _Out_ USHORT* CharacteristicsBufferActual, _In_ ULONG Flags);
typedef int (WINAPI *HN_BluetoothGATTRegisterEvent)(_In_ HANDLE hService, _In_ BTH_LE_GATT_EVENT_TYPE EventType, _In_ PVOID EventParameterIn, _In_ PFNBLUETOOTH_GATT_EVENT_CALLBACK Callback, _In_opt_ PVOID CallbackContext, _Out_ BLUETOOTH_GATT_EVENT_HANDLE * pEventHandle, _In_ ULONG Flags);
typedef int (WINAPI *HN_BluetoothGATTUnregisterEvent)(_In_ BLUETOOTH_GATT_EVENT_HANDLE EventHandle, _In_ ULONG Flags);
typedef int (WINAPI *HN_BluetoothGATTSetCharacteristicValue)(_In_ HANDLE hDevice, _In_ PBTH_LE_GATT_CHARACTERISTIC Characteristic, _In_ PBTH_LE_GATT_CHARACTERISTIC_VALUE CharacteristicValue, _In_opt_ BTH_LE_GATT_RELIABLE_WRITE_CONTEXT ReliableWriteContext, _In_ ULONG Flags);
HN_BluetoothGATTGetServices QC_BluetoothGATTGetServices;
HN_BluetoothGATTGetCharacteristics QC_BluetoothGATTGetCharacteristics;
HN_BluetoothGATTUnregisterEvent QC_BluetoothGATTUnregisterEvent;
HN_BluetoothGATTSetCharacteristicValue QC_BluetoothGATTSetCharacteristicValue;
HN_BluetoothGATTRegisterEvent QC_BluetoothGATTRegisterEvent;
函数实现
bool LoadBLEDllsFunctions(void)
{
m_hDll = LoadLibrary(L"BluetoothApis.dll");
if (m_hDll)
{
QC_BluetoothGATTGetServices = (HN_BluetoothGATTGetServices)GetProcAddress(m_hDll, "BluetoothGATTGetServices");
QC_BluetoothGATTGetCharacteristics = (HN_BluetoothGATTGetCharacteristics)GetProcAddress(m_hDll, "BluetoothGATTGetCharacteristics");
QC_BluetoothGATTUnregisterEvent = (HN_BluetoothGATTUnregisterEvent)GetProcAddress(m_hDll, "BluetoothGATTUnregisterEvent");
QC_BluetoothGATTSetCharacteristicValue = (HN_BluetoothGATTSetCharacteristicValue)GetProcAddress(m_hDll, "BluetoothGATTSetCharacteristicValue");
QC_BluetoothGATTRegisterEvent = (HN_BluetoothGATTRegisterEvent)GetProcAddress(m_hDll, "BluetoothGATTRegisterEvent");
return true;
}
return false;
};