2013-10-17 107 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 ... –

相關問題