資源簡介
一個實用的Demo,可以通過MTP(多媒體傳輸)協議和便攜設備進行通信交互,讀取便攜設備信息,從便攜設備upload\download文件。(微軟官方例子)

代碼片段和文件信息
//?THIS?CODE?AND?INFORMATION?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF
//?ANY?KIND?EITHER?EXPRESSED?OR?IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO
//?THE?IMPLIED?WARRANTIES?OF?MERCHANTABILITY?AND/OR?FITNESS?FOR?A
//?PARTICULAR?PURPOSE.
//
//?Copyright?(c)?Microsoft?Corporation.?All?rights?reserved.
#include?“stdafx.h“
//?This?number?controls?how?many?object?identifiers?are?requested?during?each?call
//?to?IEnumPortableDeviceobjectIDs::Next()
//
#define?NUM_objectS_TO_REQUEST??10
//?Recursively?called?function?which?enumerates?using?the?specified
//?object?identifier?as?the?parent.
void?RecursiveEnumerate(
????_In_?PCWSTR??????????????????objectID
????_In_?IPortableDeviceContent*?content)
{
????ComPtrjectIDs>?enumobjectIDs;
????//?Print?the?object?identifier?being?used?as?the?parent?during?enumeration.
????wprintf(L“%ws\n“?objectID);
????//?Get?an?IEnumPortableDeviceobjectIDs?interface?by?calling?Enumobjects?with?the
????//?specified?parent?object?identifier.
????HRESULT?hr?=?content->Enumobjects(0????????????????//?Flags?are?unused
??????????????????????????????????????objectID?????????//?Starting?from?the?passed?in?object
??????????????????????????????????????nullptr??????????//?Filter?is?unused
??????????????????????????????????????&enumobjectIDs);
????if?(FAILED(hr))
????{
????????wprintf(L“!?Failed?to?get?IEnumPortableDeviceobjectIDs?from?IPortableDeviceContent?hr?=?0x%lx\n“?hr);
????}
????//?Loop?calling?Next()?while?S_OK?is?being?returned.
????while(hr?==?S_OK)
????{
????????DWORD??numFetched?=?0;
????????PWSTR??objectIDArray[NUM_objectS_TO_REQUEST]?=?{0};
????????hr?=?enumobjectIDs->Next(NUM_objectS_TO_REQUEST????//?Number?of?objects?to?request?on?each?NEXT?call
?????????????????????????????????objectIDArray?????????????//?Array?of?PWSTR?array?which?will?be?populated?on?each?NEXT?call
?????????????????????????????????&numFetched);??????????????//?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?index?=?0;?(index?jectIDArray[index]?!=?nullptr);?index++)
????????????{
????????????????RecursiveEnumerate(objectIDArray[index]?content);
????????????????//?Free?allocated?PWSTRs?after?the?recursive?enumeration?call?has?completed.
????????????????CoTaskMemFree(objectIDArray[index]);
????????????????objectIDArray[index]?=?nullptr;
????????????}
????????}
????}
}
//
//?Enumerate?all?content?on?the?device?starting?with?the
//?“DEVICE“?object
//
void?EnumerateAllContent(
????_In_?IPortableDevice*?device)
{
????HRESULT?????????????????????????hr?=?S_OK;
????ComPtr??content;
????//?Get?an?IPortableDeviceContent?interface?fro
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1268??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\CommonFunctions.h
?????文件??????12498??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\ContentEnumeration.cpp
?????文件??????47717??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\ContentProperties.cpp
?????文件??????69925??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\ContentTransfer.cpp
?????文件????????572??2014-02-16?21:35??Portable?Devices?COM?API?Sample\C++\Debug\WpdApiSample.log
?????文件??????36813??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\DeviceCapabilities.cpp
?????文件??????17887??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\DeviceEnumeration.cpp
?????文件???????4426??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\DeviceEvents.cpp
?????文件???????1930??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\ReadMe.txt
?????文件???????1957??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\stdafx.h
?????文件??????11671??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\WpdApiSample.cpp
?????文件?????479232??2014-02-18?22:51??Portable?Devices?COM?API?Sample\C++\WpdApiSample.sdf
?????文件???????2233??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\WpdApiSample.sln
?????文件???????3584??2014-02-18?22:51??Portable?Devices?COM?API?Sample\C++\WpdApiSample.suo
?????文件??????10399??2013-10-17?17:30??Portable?Devices?COM?API?Sample\C++\WpdApiSample.vcxproj
?????文件????????143??2014-02-16?21:33??Portable?Devices?COM?API?Sample\C++\WpdApiSample.vcxproj.user
?????文件???????5834??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件??????71561??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件??????????0??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件??????????0??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件??????10455??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件???????7344??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件???????1727??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件???????1670??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件??????10721??2013-10-17?17:30??Portable?Devices?COM?API?Sample\desc
?????文件???????4688??2013-10-17?17:30??Portable?Devices?COM?API?Sample\license.rtf
?????目錄??????????0??2014-02-18?20:49??Portable?Devices?COM?API?Sample\C++\ipch\wpdapisample-db914964
?????目錄??????????0??2014-02-16?21:35??Portable?Devices?COM?API?Sample\C++\Debug
?????目錄??????????0??2014-02-18?20:49??Portable?Devices?COM?API?Sample\C++\ipch
?????目錄??????????0??2014-02-18?22:51??Portable?Devices?COM?API?Sample\C++
............此處省略5個文件信息
評論
共有 條評論