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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
#include "stdafx.h"
#include "FakeContactContent.tmh"
// Properties supported by a contact
const PropertyAttributeInfo g_SupportedContactProperties[] =
{
// Standard WPD properties.
{&WPD_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ObjectID},
{&WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_PersistentUID},
{&WPD_OBJECT_PARENT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ParentID},
{&WPD_OBJECT_NAME, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_Name},
{&WPD_OBJECT_FORMAT, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ObjectFormat},
{&WPD_OBJECT_CONTENT_TYPE, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ObjectContentType"},
{&WPD_OBJECT_CAN_DELETE, VT_BOOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ObjectCanDelete"},
{&WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"StorageID"},
// Contact Service extension properties
{&PKEY_ContactObj_GivenName, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_ContactObj_GivenName},
{&PKEY_ContactObj_FamilyName, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_ContactObj_FamilyName},
// Custom property used to store the version of this object
{&MyContactVersionIdentifier, VT_UI4, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ContactVersionIdentifier"},
};
HRESULT GetSupportedContactProperties(
_In_ IPortableDeviceKeyCollection *pKeys)
{
HRESULT hr = S_OK;
if(pKeys == NULL)
{
hr = E_POINTER;
CHECK_HR(hr, "Cannot have NULL collection parameter");
return hr;
}
for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedContactProperties); dwIndex++)
{
hr = pKeys->Add(*g_SupportedContactProperties[dwIndex].pKey);
CHECK_HR(hr, "Failed to add custom contacts property");
}
return hr;
}
HRESULT GetContactPropertyAttributes(
_In_ REFPROPERTYKEY Key,
_In_ IPortableDeviceValues* pAttributes)
{
HRESULT hr = S_OK;
if(pAttributes == NULL)
{
hr = E_POINTER;
CHECK_HR(hr, "Cannot have NULL parameter");
return hr;
}
hr = SetPropertyAttributes(Key, &g_SupportedContactProperties[0], ARRAYSIZE(g_SupportedContactProperties), pAttributes);
return hr;
}
// For this object, the supported properties are the same as the supported
// format properties.
// This is where customization for supported properties per object can happen
HRESULT FakeContactContent::GetSupportedProperties(
_In_ IPortableDeviceKeyCollection *pKeys)
{
return GetSupportedContactProperties(pKeys);
}
HRESULT FakeContactContent::GetValue(
_In_ REFPROPERTYKEY Key,
_In_ IPortableDeviceValues* pStore)
{
HRESULT hr = S_OK;
PropVariantWrapper pvValue;
if(pStore == NULL)
{
hr = E_POINTER;
CHECK_HR(hr, "Cannot have NULL parameter");
return hr;
}
if (IsEqualPropertyKey(Key, WPD_OBJECT_ID))
{
// Add WPD_OBJECT_ID
pvValue = ObjectID;
hr = pStore->SetValue(WPD_OBJECT_ID, &pvValue);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_ID"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID))
{
// Add WPD_OBJECT_PERSISTENT_UNIQUE_ID
pvValue = this->PersistentUniqueID;
hr = pStore->SetValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pvValue);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID))
{
// Add WPD_OBJECT_PARENT_ID
pvValue = ParentID;
hr = pStore->SetValue(WPD_OBJECT_PARENT_ID, &pvValue);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_PARENT_ID"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME))
{
// Add WPD_OBJECT_NAME
pvValue = Name;
hr = pStore->SetValue(WPD_OBJECT_NAME, &pvValue);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_NAME"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE))
{
// Add WPD_OBJECT_CONTENT_TYPE
hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTENT_TYPE"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT))
{
// Add WPD_OBJECT_FORMAT
hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_FORMAT"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE))
{
// Add WPD_OBJECT_CAN_DELETE
hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_CAN_DELETE"));
}
else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID))
{
// Add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID
hr = pStore->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, ContainerFunctionalObjectID);
CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"));
}
else if (IsEqualPropertyKey(Key, PKEY_ContactObj_GivenName))
{
// Add PKEY_ContactObj_GivenName
pvValue = GivenName;
hr = pStore->SetValue(PKEY_ContactObj_GivenName, &pvValue);
CHECK_HR(hr, ("Failed to set PKEY_ContactObj_GivenName"));
}
else if (IsEqualPropertyKey(Key, PKEY_ContactObj_FamilyName))
{
// Add PKEY_ContactObj_FamilyName
pvValue = FamilyName;
hr = pStore->SetValue(PKEY_ContactObj_FamilyName, &pvValue);
CHECK_HR(hr, ("Failed to set PKEY_ContactObj_FamilyName"));
}
else if (IsEqualPropertyKey(Key, MyContactVersionIdentifier))
{
// Add MyContactVersionIdentifier
pvValue = VersionIdentifier;
hr = pStore->SetValue(MyContactVersionIdentifier, &pvValue);
CHECK_HR(hr, ("Failed to set MyContactVersionIdentifier"));
}
else
{
hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
CHECK_HR(hr, "Property {%ws}.%d is not supported", CComBSTR(Key.fmtid), Key.pid);
}
return hr;
}
HRESULT FakeContactContent::WriteValue(
_In_ REFPROPERTYKEY Key,
_In_ REFPROPVARIANT Value)
{
HRESULT hr = S_OK;
PropVariantWrapper pvValue;
if(IsEqualPropertyKey(Key, PKEY_ContactObj_FamilyName))
{
if(Value.vt == VT_LPWSTR)
{
FamilyName = Value.pwszVal;
}
else
{
hr = E_INVALIDARG;
CHECK_HR(hr, "Failed to set PKEY_ContactObj_FamilyName because type was not VT_LPWSTR");
}
}
else if(IsEqualPropertyKey(Key, PKEY_ContactObj_GivenName))
{
if(Value.vt == VT_LPWSTR)
{
GivenName = Value.pwszVal;
}
else
{
hr = E_INVALIDARG;
CHECK_HR(hr, "Failed to set PKEY_ContactObj_GivenName because type was not VT_LPWSTR");
}
}
else
{
hr = E_ACCESSDENIED;
CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(Key.fmtid), Key.pid, ObjectID);
}
return hr;
}
HRESULT FakeContactContent::GetPropertyAttributes(
_In_ REFPROPERTYKEY Key,
_In_ IPortableDeviceValues* pAttributes)
{
HRESULT hr = S_OK;
if(pAttributes == NULL)
{
hr = E_POINTER;
CHECK_HR(hr, "Cannot have NULL attributes parameter");
return hr;
}
hr = GetContactPropertyAttributes(Key, pAttributes);
CHECK_HR(hr, "Failed to add property attributes for %ws.%d", CComBSTR(Key.fmtid), Key.pid);
// Some of our properties have extra attributes on top of the ones that are common to all
if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME))
{
CAtlStringW strDefaultName;
strDefaultName.Format(L"%ws%ws", L"Name", ObjectID.GetString());
hr = pAttributes->SetStringValue(WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE, strDefaultName.GetString());;
CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE");
}
return hr;
}
HRESULT FakeContactContent::WriteValues(
_In_ IPortableDeviceValues* pValues,
_In_ IPortableDeviceValues* pResults,
_Out_ bool* pbObjectChanged)
{
HRESULT hr = FakeContent::WriteValues(pValues, pResults, pbObjectChanged);
if (SUCCEEDED(hr) && (*pbObjectChanged == true))
{
UpdateVersion();
}
return hr;
}
void FakeContactContent::UpdateVersion()
{
if (VersionIdentifier < ULONG_MAX)
{
VersionIdentifier++;
}
else
{
VersionIdentifier = 0;
}
}
|