LoadLibrary(“bthprops.dll”)失败,找不到文件

时间:2013-10-17 20:19:57

标签: winapi dll bluetooth

蓝牙API的Microsoft文档(例如BluetoothGetDeviceInfo)提供了使用静态或动态导入来调用这些函数的说明。

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之前不受支持。因此,应该使用动态链接并从缺少的函数中恢复。但是,MSDN文档指示的动态加载bthprops.dll失败:

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;
}

如何动态链接到这些功能?

1 个答案:

答案 0 :(得分:2)

显然这个事实对谷歌来说是众所周知的,而不是MSDN。如果要动态加载这些函数,请使用{strong} LoadLibrary("bthprops. cpl这是正确的DLL名称,与函数文档中的nice表相反。< / p>

这有效:

")