// 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 <list>
using std::list;
#include "stdafx.h"
#include "FileOper.h"
HANDLE g_bulkPropertyOperationEvent = nullptr;
bool IsProcess = false;
// A helper function contained in ContentEnumeration.cpp which
// will recursively enumerate all objects and return an
// IPortableDevicePropVariantCollection containing the values.
HRESULT CreateIPortableDevicePropVariantCollectionWithAllObjectIDs(
_In_ IPortableDeviceContent* content,
IPortableDevicePropVariantCollection** objectIDs);
// Displays a property assumed to be in error code form.
void DisplayErrorResultProperty(
_In_ IPortableDeviceValues* properties,
_In_ REFPROPERTYKEY key,
_In_ PCWSTR keyName)
{
HRESULT error = S_OK;
HRESULT hr = properties->GetErrorValue(key, &error);
if (SUCCEEDED(hr))
{
wprintf(L"%ws: HRESULT = (0x%lx)\n", keyName, error);
}
else
{
wprintf(L"%ws: <Not Found>\n", keyName);
}
}
// Displays a property assumed to be in string form.
void DisplayStringProperty(
_In_ IPortableDeviceValues* properties,
_In_ REFPROPERTYKEY key,
_In_ PCWSTR keyName)
{
PWSTR value = nullptr;
HRESULT hr = properties->GetStringValue(key, &value);
if (SUCCEEDED(hr))
{
// Get the length of the string value so we
// can output <empty string value> if one
// is encountered.
if (wcsnlen(value, MAX_PATH) > 0)
{
wprintf(L"%ws: %ws\n", keyName, value);
}
else
{
wprintf(L"%ws: <empty string value>\n", keyName);
}
}
else
{
wprintf(L"%ws: <Not Found>\n", keyName);
}
// Free the allocated string returned from the
// GetStringValue method
CoTaskMemFree(value);
value = nullptr;
}
// Displays a property assumed to be in GUID form.
void DisplayGuidProperty(
_In_ IPortableDeviceValues* properties,
_In_ REFPROPERTYKEY key,
_In_ PCWSTR keyName)
{
GUID value = GUID_NULL;
HRESULT hr = properties->GetGuidValue(key, &value);
if (SUCCEEDED(hr))
{
wprintf(L"%ws: %ws\n", keyName, (PCWSTR)CGuidToString(value));
}
else
{
wprintf(L"%ws: <Not Found>\n", keyName);
}
}
// Reads properties for the user specified object.
void ReadContentProperties(
_In_ IPortableDevice* device)
{
HRESULT hr = S_OK;
WCHAR selection[SELECTION_BUFFER_SIZE] = {0};
IPortableDeviceProperties *properties;
IPortableDeviceValues *objectProperties;
IPortableDeviceContent *content;
IPortableDeviceKeyCollection *propertiesToRead;
// Prompt user to enter an object identifier on the device to read properties from.
wprintf(L"Enter the identifer of the object you wish to read properties from.\n>");
hr = StringCchGetsW(selection, ARRAYSIZE(selection));
if (FAILED(hr))
{
wprintf(L"An invalid object identifier was specified, aborting property reading\n");
}
// 1) Get an IPortableDeviceContent interface from the IPortableDevice interface to
// access the content-specific methods.
if (SUCCEEDED(hr))
{
hr = device->Content(&content);
if (FAILED(hr))
{
wprintf(L"! Failed to get IPortableDeviceContent from IPortableDevice, hr = 0x%lx\n", hr);
}
}
// 2) Get an IPortableDeviceProperties interface from the IPortableDeviceContent interface
// to access the property-specific methods.
if (SUCCEEDED(hr))
{
hr = content->Properties(&properties);
if (FAILED(hr))
{
wprintf(L"! Failed to get IPortableDeviceProperties from IPortableDevice, hr = 0x%lx\n", hr);
}
}
// 3) CoCreate an IPortableDeviceKeyCollection interface to hold the the property keys
// we wish to read.
//<SnippetContentProp1>
hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&propertiesToRead));
if (SUCCEEDED(hr))
{
// 4) Populate the IPortableDeviceKeyCollection with the keys we wish to read.
// NOTE: We are not handling any special error cases here so we can proceed with
// adding as many of the target properties as we can.
HRESULT tempHr = propertiesToRead->Add(WPD_OBJECT_PARENT_ID);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_PARENT_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
tempHr = propertiesToRead->Add(WPD_OBJECT_NAME);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_NAME to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
tempHr = propertiesToRead->Add(WPD_OBJECT_SIZE);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_SIZE to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
tempHr = propertiesToRead->Add(WPD_OBJECT_PERSISTENT_UNIQUE_ID);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
tempHr = propertiesToRead->Add(WPD_OBJECT_FORMAT);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_FORMAT to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
tempHr = propertiesToRead->Add(WPD_OBJECT_CONTENT_TYPE);
if (FAILED(tempHr))
{
wprintf(L"! Failed to add WPD_OBJECT_CONTENT_TYPE to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
}
}
//</SnippetContentProp1>
// 5) Call GetValues() passing the collection of specified PROPERTYKEYs.
//<SnippetContentProp2>
if (SUCCEEDED(hr))
{
hr = properties->GetValues(selection, // The object whose properties we are reading
propertiesToRead, // The properties we want to read
&objectProperties); // Driver supplied property values for the specified object
if (FAILED(hr))
{
wprintf(L"! Failed to get all properties for object '%ws', hr= 0x%lx\n", selection, hr);
}
}
//</SnippetContentProp2>
// 6) Display the returned property values to the user
if (SUCCEEDED(hr))
{
DisplayStringProperty(objectProperties, WPD_OBJECT_PARENT_ID, L"WPD_OBJECT_PARENT_ID");
DisplayStringProperty(objectProperties, WPD_OBJECT_NAME, L"WPD_OBJECT_NAME");
DisplayStringProperty(objectProperties, WPD_OBJECT_PERSISTENT_UNIQUE_ID, L"WPD_OBJECT_PERSISTENT_UNIQUE_ID");
DisplayGuidProperty (objectProperties, WPD_OBJECT_CONTENT_TYPE, L"WPD_OBJECT_CONTENT_TYPE");
DisplayGuidProperty (objectProperties, WPD_OBJECT_FORMAT, L"WPD_OBJECT_FORMAT");
}
}
// Writes properties on the user specified object.
void WriteContentProperties(
_In_ IPortableDevice* device)
{
//<SnippetContentProp3>
HRESULT hr = S_OK;
BOOL canWrite = FALSE;
WCHAR selection[SELECTION_BUFFE
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
FindFiler.7z (82个子文件)
FindFiler
FileFinder
FileFinder
EnumDevice.cpp 15KB
MainDlg.cpp 15KB
FileOper.h 3KB
Release
DeviceCapabilities.obj 262KB
ContentEnumeration.obj 220KB
FileOper.obj 255KB
CL.write.1.tlog 4KB
FileFinder.log 23KB
CL.read.1.tlog 122KB
mt.read.1.tlog 1KB
ContentProperties.obj 385KB
rc.write.1.tlog 302B
rc.read.1.tlog 2KB
FileFinder.lastbuildstate 73B
EnumDevice.obj 231KB
MainDlg.obj 296KB
mt.command.1.tlog 726B
cl.command.1.tlog 5KB
link-cvtres.read.1.tlog 2B
FileFinder.write.1.tlog 0B
link.write.1.tlog 2KB
WndBase.obj 219KB
link-cvtres.write.1.tlog 2B
link.command.1.tlog 3KB
rc.command.1.tlog 500B
link.read.1.tlog 5KB
FileFinder.res 872B
mt.write.1.tlog 496B
FileFinder.Build.CppClean.log 1KB
vc100.pdb 244KB
FileFinder.exe.intermediate.manifest 381B
MtpTrans.cpp 11KB
MTPTrans.h 992B
FileFinder.vcxproj.user 143B
WndBase.h 8KB
stdafx.h 407B
FileFinder.aps 35KB
FrameWnd.cpp 13KB
WndBase.cpp 5KB
FileFinder.vcxproj 4KB
visual_style.manifest 394B
DeviceCapabilities.cpp 36KB
ContentEnumeration.cpp 12KB
FileOper.cpp 9KB
resource.h 2KB
ContentProperties.cpp 50KB
FileFinder.rc 7KB
FileFinder.vcxproj.filters 2KB
FileOperation.h 4KB
Debug
vc100.idb 875KB
DeviceCapabilities.obj 100KB
ContentEnumeration.obj 51KB
FileOper.obj 139KB
CL.write.1.tlog 4KB
FileFinder.log 27KB
CL.read.1.tlog 122KB
mt.read.1.tlog 1KB
ContentProperties.obj 133KB
rc.write.1.tlog 298B
rc.read.1.tlog 2KB
FileFinder.lastbuildstate 71B
EnumDevice.obj 59KB
MainDlg.obj 114KB
mt.command.1.tlog 714B
cl.command.1.tlog 4KB
link-cvtres.read.1.tlog 2B
FileFinder.write.1.tlog 0B
link.write.1.tlog 2KB
WndBase.obj 77KB
link-cvtres.write.1.tlog 2B
link.command.1.tlog 3KB
rc.command.1.tlog 492B
link.read.1.tlog 5KB
FileFinder.res 872B
mt.write.1.tlog 488B
FileFinder.vcxprojResolveAssemblyReference.cache 707B
FileFinder.Build.CppClean.log 2KB
vc100.pdb 572KB
FileFinder.exe.intermediate.manifest 381B
CommonFunctions.h 1KB
FileFinder.sln 897B
FileFinder.suo 31KB
共 82 条
- 1
资源评论
- 深蓝2582015-12-31有参考价值。
- anticevc2014-08-21根本就不能访问MTP下手机的文件!
河静水深-人静心深
- 粉丝: 2
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功