LoadLibrary("bthprops.dll") 失败,找不到文件 [英] LoadLibrary("bthprops.dll") fails, file not found

查看:41
本文介绍了LoadLibrary("bthprops.dll") 失败,找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

蓝牙 API 的 Microsoft 文档,例如 BluetoothGetDeviceInfo 提供使用静态或动态导入调用这些函数的说明.

The Microsoft documentation for Bluetooth APIs such as BluetoothGetDeviceInfo provide instructions for calling these functions using either static or dynamic imports.

bthprops.lib 链接的静态导入工作正常.

The static import, linking with bthprops.lib, works fine.

#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 失败:

But this isn't ideal in ultra-portable code, because the documentation says they are not supported prior to Windows XP SP2. So one should use dynamic linking and recover from missing functions. However, dynamic loading bthprops.dll as instructed by the MSDN docs fails:

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

应该如何动态链接到这些函数?

How should one dynamically link to these functions?

推荐答案

显然 Google 非常了解这一事实,但 MSDN 却不知道.如果你想动态加载这些函数,使用 LoadLibrary("bthprops.cpl") 这是正确的DLL 名称,与函数文档中的 nice 表相反.

Apparently this fact is pretty well known to Google but not to MSDN. If you want to dynamically load these functions, use LoadLibrary("bthprops.cpl") which is the correct DLL name, contrary to the nice table in the function documentation.

这有效:

decltype(::BluetoothGetDeviceInfo)* pfnBluetoothGetDeviceInfo;
bool LoadBthprops( void )
{
    auto dll = ::LoadLibraryW(L"bthprops.cpl");
    if (!dll) return false;
    pfnBluetoothGetDeviceInfo = reinterpret_cast<decltype(pfnBluetoothGetDeviceInfo)>(::GetProcAddress(dll, "BluetoothGetDeviceInfo"));
    return pfnBluetoothGetDeviceInfo != nullptr;
}

这篇关于LoadLibrary("bthprops.dll") 失败,找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆