簡體   English   中英

WPD API檢測設備是否是電話?

[英]WPD API Detect if Device is a Phone?

編輯:請求完整的源代碼。 下面是一個准系統實現,以便復制該錯誤。 刪除內容枚舉 ,但無論如何崩潰都會在第一個對象調用上發生。 在這種情況下,WPD_DEVICE_OBJECT_ID對象。

鏈接到CPP (Bug從第103行開始)

鏈接到QMAKE.PRO (我正在使用Qt)


在我的項目中,我使用WPD API來讀取移動設備的內容。 我遵循API到tee並成功實現了內容枚舉。

但是,如果連接了USB驅動器,WPD API有時也會將其檢測為設備。 無論如何,我的程序將繼續進行內容枚舉。 我不希望這樣。 我只想枚舉移動設備。

問題是在內容枚舉期間,當我的程序試圖檢索USB驅動器上的對象的屬性時,它會崩潰。 以下是崩潰詳情:

Problem Event Name: BEX
Application Name:   UniversalMC.exe
Application Version:    0.0.0.0
Application Timestamp:  5906a8a3
Fault Module Name:  MSVCR100.dll
Fault Module Version:   10.0.40219.325
Fault Module Timestamp: 4df2be1e
Exception Offset:   0008af3e
Exception Code: c0000417
Exception Data: 00000000
OS Version: 6.1.7601.2.1.0.768.3
Locale ID:  1033
Additional Information 1:   185e
Additional Information 2:   185ef2beb7eb77a8e39d1dada57d0d11
Additional Information 3:   a852
Additional Information 4:   a85222a7fc0721be22726bd2ca6bc946

此次調用發生崩潰:

hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);

hr返回FAILED,然后程序崩潰。

經過一些研究,我發現異常代碼c0000417意味着發生了緩沖區溢出? 如果我錯了,請糾正我,但這是WPD API中的漏洞嗎? 如果是這樣,我怎么能提前發現該設備不是移動設備?

謝謝你的時間!

我最終付錢給某人幫助我查明問題。

問題是根對象(WPD_DEVICE_OBJECT_ID)無論如何都不會返回對象名稱(對於所有設備都不是)。

解決方案是簡單地從根對象開始內容枚舉,並僅檢查其子項的名稱。 在我最初的實現中,我假設每個對象都有一個名稱,但顯然情況並非如此。 根對象是例外。

這是一個片段:

CComPtr<IEnumPortableDeviceObjectIDs> pEnumObjectIDs;

// Print the object identifier being used as the parent during enumeration.
//qDebug("%ws\n",pszObjectID);

// Get an IEnumPortableDeviceObjectIDs interface by calling EnumObjects with the
// specified parent object identifier.
hr = pContent->EnumObjects(0,               // Flags are unused
                                   WPD_DEVICE_OBJECT_ID,     // Starting from the passed in object
                                   NULL,            // Filter is unused
                                   &pEnumObjectIDs);

// Enumerate content starting from the "DEVICE" object.
if (SUCCEEDED(hr))
{
    // Loop calling Next() while S_OK is being returned.
    while(hr == S_OK)
    {
        DWORD  cFetched = 0;
        PWSTR  szObjectIDArray[NUM_OBJECTS_TO_REQUEST] = {0};
        hr = pEnumObjectIDs->Next(NUM_OBJECTS_TO_REQUEST,   // Number of objects to request on each NEXT call
                                  szObjectIDArray,          // Array of PWSTR array which will be populated on each NEXT call
                                  &cFetched);               // Number of objects written to the PWSTR array
        if (SUCCEEDED(hr))
        {
            // Traverse the results of the Next() operation and recursively enumerate
            // Remember to free all returned object identifiers using CoTaskMemFree()
            for (DWORD dwIndex = 0; dwIndex < cFetched; dwIndex++)
            {
                //RECURSIVE CONTENT ENUMERATION CONTINUES HERE
                //OBJECT NAME CHECKING CONTINUES IN THE RECURSIVE FUNCTION

                // Free allocated PWSTRs after the recursive enumeration call has completed.
                CoTaskMemFree(szObjectIDArray[dwIndex]);
                szObjectIDArray[dwIndex] = NULL;
            }
        }
    }

}

解決方案正是示例項目顯示的內容,但是,我錯誤地檢查了根對象的名稱。 所以不要這樣做。

如果沒有“原始文件名”,請獲取對象名稱

hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);

if(FAILED(hr)) {
   hr = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &objectName);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM