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 ... –