1
有關藍牙API的Microsoft文檔(如BluetoothGetDeviceInfo
)提供了使用靜態或動態導入調用這些函數的說明。LoadLibrary(「bthprops.dll」)失敗,未找到文件
靜態導入,與bthprops.lib
連接,工作正常。
#include <windows.h>
#include <BluetoothAPIs.h>
#include <iostream>
int main(int argc, char** argv)
{
BLUETOOTH_DEVICE_INFO binfo = {};
binfo.dwSize = sizeof binfo;
binfo.Address.ullLong = 0xBAADDEADF00Dull;
auto result = ::BluetoothGetDeviceInfo(nullptr, &binfo);
std::wcout << L"BluetoothGetDeviceInfo returned " << result
<< L"\nand the name is \"" << binfo.szName << "\"\n";
return 0;
}
但是這在超便攜代碼中並不理想,因爲文檔說他們在Windows XP SP2之前不受支持。所以應該使用動態鏈接並從缺失的函數中恢復。但是,動態加載bthprops.dll
的指示通過MSDN文檔失敗:
decltype(::BluetoothGetDeviceInfo)* pfnBluetoothGetDeviceInfo;
bool LoadBthprops(void)
{
auto dll = ::LoadLibraryW(L"bthprops.dll");
if (!dll) return false;
pfnBluetoothGetDeviceInfo = reinterpret_cast<decltype(pfnBluetoothGetDeviceInfo)>(::GetProcAddress(dll, "BluetoothGetDeviceInfo"));
return pfnBluetoothGetDeviceInfo != nullptr;
}
一個應該如何動態鏈接到這些功能呢?
謝謝。 MSDN的漂亮桌子仍然保持它的.DLL ... –