1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include "stdafx.h"
#include "WpdStorage.tmh"
WpdStorage::WpdStorage()
{
}
WpdStorage::~WpdStorage()
{
}
HRESULT WpdStorage::Initialize(_In_ FakeDevice *pFakeDevice)
{
HRESULT hr = S_OK;
if(pFakeDevice == NULL)
{
hr = E_POINTER;
CHECK_HR(hr, "Cannot have NULL parameter");
return hr;
}
m_pFakeDevice = pFakeDevice;
return hr;
}
HRESULT WpdStorage::DispatchWpdMessage(_In_ REFPROPERTYKEY Command,
_In_ IPortableDeviceValues* pParams,
_In_ IPortableDeviceValues* pResults)
{
HRESULT hr = S_OK;
if (hr == S_OK)
{
if (Command.fmtid != WPD_CATEGORY_STORAGE)
{
hr = E_INVALIDARG;
CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid));
}
}
if (hr == S_OK)
{
if (IsEqualPropertyKey(Command, WPD_COMMAND_STORAGE_FORMAT))
{
hr = OnFormat(pParams, pResults);
CHECK_HR(hr, "Failed to format storage");
}
else
{
hr = E_NOTIMPL;
CHECK_HR(hr, "This object does not support this command id %d", Command.pid);
}
}
return hr;
}
/**
* This method is called when we receive a WPD_COMMAND_STORAGE_FORMAT
* command.
*
* The parameters sent to us are:
* - WPD_PROPERTY_STORAGE_OBJECT_ID: identifies the storage object to format.
*
* The driver should:
* - Format the storage identified by WPD_PROPERTY_STORAGE_OBJECT_ID.
*/
HRESULT WpdStorage::OnFormat(
_In_ IPortableDeviceValues* pParams,
_In_ IPortableDeviceValues* pResults)
{
HRESULT hr = S_OK;
LPWSTR pszObjectID = NULL;
UNREFERENCED_PARAMETER(pResults);
// Get the Object ID
hr = pParams->GetStringValue(WPD_PROPERTY_STORAGE_OBJECT_ID, &pszObjectID);
if (hr != S_OK)
{
hr = E_INVALIDARG;
CHECK_HR(hr, "Missing string value for WPD_PROPERTY_STORAGE_OBJECT_ID");
}
// Format this storage
if (hr == S_OK)
{
hr = m_pFakeDevice->FormatStorage(pszObjectID, pParams);
CHECK_HR(hr, "Failed to process format command on [%ws]", pszObjectID);
}
// Free the memory. CoTaskMemFree ignores NULLs so no need to check.
CoTaskMemFree(pszObjectID);
return hr;
}
|