2013-10-17 108 views
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; 
} 

一个应该如何动态链接到这些功能呢?

回答

2

很明显,这个事实对Google来说是非常熟悉的,但对于MSDN来说却并非如此。如果要动态加载这些函数,请使用LoadLibrary("bthprops.cpl")这是正确的DLL名称,与函数文档中的漂亮表格相反。

这工作:

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

谢谢。 MSDN的漂亮桌子仍然保持它的.DLL ... –

相关问题