windows下动态加载BLE DLL函数

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;
};
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值