forked from mhammond/pywin32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropsys.cpp
More file actions
624 lines (571 loc) · 25.5 KB
/
propsys.cpp
File metadata and controls
624 lines (571 loc) · 25.5 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// propsys.cpp :
// $Id$
// Implements wrappers for the Property System functions and interfaces.
// This source file contains autoduck documentation.
// @doc
// Any python API functions that use 's#' format must use Py_ssize_t for length
#define PY_SSIZE_T_CLEAN
#include "PythonCOM.h"
#include "PythonCOMServer.h"
#include "PythonCOMRegister.h"
#include "PyIInitializeWithFile.h"
#include "PyIInitializeWithStream.h"
#include "PyIPropertyStoreCache.h"
#include "PyIPropertyStoreCapabilities.h"
#include "PyIPropertySystem.h"
#include "PyIPropertyDescriptionList.h"
#include "PyINamedPropertyStore.h"
#include "PyIPropertyDescription.h"
#include "PyIPropertyDescriptionSearchInfo.h"
#include "PyIPropertyDescriptionAliasInfo.h"
#include "PyIPropertyEnumType.h"
#include "PyIPropertyEnumTypeList.h"
#include "PyIPersistSerializedPropStorage.h"
#include "PyIObjectWithPropertyKey.h"
#include "PyIPropertyChange.h"
#include "PyIPropertyChangeArray.h"
#include "delayimp.h"
#include "propvarutil.h"
#include "Shobjidl.h"
// @object PyPROPERTYKEY|A tuple of a fmtid and property id (IID, int) that uniquely identifies a property
BOOL PyWinObject_AsPROPERTYKEY(PyObject *obkey, PROPERTYKEY *pkey)
{
return PyArg_ParseTuple(obkey, "O&k:PROPERTYKEY", PyWinObject_AsIID, &pkey->fmtid, &pkey->pid);
}
PyObject *PyWinObject_FromPROPERTYKEY(REFPROPERTYKEY key)
{
return Py_BuildValue("Nk", PyWinObject_FromIID(key.fmtid), key.pid);
}
// @pymethod <o PyIPropertyDescription>|propsys|PSGetPropertyDescription|Gets a description interface for a property
// @comm Possible interfaces include IPropertyDescription, IPropertyDescriptionAliasInfo, and
// IPropertyDescriptionSearchInfo
PyObject *PyPSGetPropertyDescription(PyObject *self, PyObject *args)
{
PROPERTYKEY key;
void *ret;
IID riid = IID_IPropertyDescription;
// @pyparm <o PyPROPERTYKEY>|Key||A property key identifier
// @pyparm <o PyIID>|riid|IID_IPropertyDescription|The interface to return
if (!PyArg_ParseTuple(args, "O&|O&:PSGetPropertyDescription", PyWinObject_AsPROPERTYKEY, &key, PyWinObject_AsIID,
&riid))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetPropertyDescription(key, riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
// @pymethod string|propsys|PSGetNameFromPropertyKey|Retrieves the canonical name of a property
PyObject *PyPSGetNameFromPropertyKey(PyObject *self, PyObject *args)
{
PROPERTYKEY key;
WCHAR *name = NULL;
// @pyparm <o PyPROPERTYKEY>|Key||A property key
if (!PyArg_ParseTuple(args, "O&:PSGetNameFromPropertyKey", PyWinObject_AsPROPERTYKEY, &key))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetNameFromPropertyKey(key, &name);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
PyObject *ret = PyWinObject_FromWCHAR(name);
CoTaskMemFree(name);
return ret;
}
// @pymethod <o PyPROPERTYKEY>|propsys|PSGetPropertyKeyFromName|Retrieves the property key by canonical name
PyObject *PyPSGetPropertyKeyFromName(PyObject *self, PyObject *args)
{
PROPERTYKEY key;
TmpWCHAR name;
PyObject *obname;
// @pyparm str|Name||The canonical name of a property (eg System.Author)
if (!PyArg_ParseTuple(args, "O:PSGetPropertyKeyFromName", &obname))
return NULL;
if (!PyWinObject_AsWCHAR(obname, &name, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetPropertyKeyFromName(name, &key);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyWinObject_FromPROPERTYKEY(key);
}
// @pymethod <o PyIPropertySystem>|propsys|PSGetPropertySystem|Creates an IPropertySystem interface
PyObject *PyPSGetPropertySystem(PyObject *self, PyObject *args)
{
void *ret;
IID riid = IID_IPropertySystem;
// @pyparm <o PyIID>|riid|IID_IPropertySystem|The interface to return
if (!PyArg_ParseTuple(args, "|O&:PSGetPropertySystem", PyWinObject_AsIID, &riid))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetPropertySystem(riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
// @pymethod |propsys|PSRegisterPropertySchema|Registers a group of properties described in a schema file
static PyObject *PyPSRegisterPropertySchema(PyObject *self, PyObject *args)
{
PyObject *obfname;
// @pyparm unicode|filename||An XML file that defines a property schema (*.propdesc)
if (!PyArg_ParseTuple(args, "O:PSRegisterPropertySchema", &obfname))
return NULL;
WCHAR *sz;
if (!PyWinObject_AsWCHAR(obfname, &sz, FALSE))
return FALSE;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSRegisterPropertySchema(sz);
PY_INTERFACE_POSTCALL;
PyWinObject_FreeWCHAR(sz);
if (FAILED(hr))
return PyCom_BuildPyException(hr);
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |propsys|PSUnregisterPropertySchema|Removes a property schema definition
static PyObject *PyPSUnregisterPropertySchema(PyObject *self, PyObject *args)
{
PyObject *obfname;
// @pyparm unicode|filename||A previously registered schema definition file
if (!PyArg_ParseTuple(args, "O:PSUnregisterPropertySchema", &obfname))
return NULL;
WCHAR *sz;
if (!PyWinObject_AsWCHAR(obfname, &sz, FALSE))
return FALSE;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSUnregisterPropertySchema(sz);
PY_INTERFACE_POSTCALL;
PyWinObject_FreeWCHAR(sz);
if (FAILED(hr))
return PyCom_BuildPyException(hr);
Py_INCREF(Py_None);
return Py_None;
}
// Does not exist on XP, shell32 is /delayload'ed
// @pymethod <o PyIPropertyStore>|propsys|SHGetPropertyStoreFromParsingName|Retrieves the property store for an item by
// path
static PyObject *PySHGetPropertyStoreFromParsingName(PyObject *self, PyObject *args)
{
// @comm This function does not exist on XP, even with Desktop Search installed
PyObject *obpath, *obbindctx = Py_None;
TmpWCHAR path;
GETPROPERTYSTOREFLAGS flags = GPS_DEFAULT;
IID riid = IID_IPropertyStore;
IBindCtx *bindctx = NULL;
void *ret = NULL;
// @pyparm string|Path||Path to file
// @pyparm <o PyIBindCtx>|BindCtx|None|Bind context, or None
// @pyparm int|Flags|GPS_DEFAULT|Combination of GETPROPERTYSTOREFLAGS values (shellcon.GPS_*)
// @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to return
if (!PyArg_ParseTuple(args, "O|OkO&:SHGetPropertyStoreFromParsingName", &obpath, &obbindctx, &flags,
PyWinObject_AsIID, &riid))
return NULL;
if (!PyWinObject_AsWCHAR(obpath, &path, FALSE))
return NULL;
if (!PyCom_InterfaceFromPyInstanceOrObject(obbindctx, IID_IBindCtx, (void **)&bindctx))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = SHGetPropertyStoreFromParsingName(path, bindctx, flags, riid, &ret);
if (bindctx)
bindctx->Release();
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
// ??? needs PyObject_AsPIDL from shell module, or maybe move this function into shell itself ???
/*
#include "..//..//shell//src//shell_pch.h"
// Does not exist on XP, shell32 is /delayload'ed
// @pymethod <o PyIPropertyStore>|propsys|SHGetPropertyStoreFromIDList|Retrieves the property store from an absolute ID
list static PyObject *PySHGetPropertyStoreFromIDList(PyObject *self, PyObject *args)
{
// @comm This function does not exist on XP, even with Desktop Search installed
PyObject *obidl, *obriid=Py_None;
GETPROPERTYSTOREFLAGS flags=GPS_DEFAULT;
IID riid=IID_IPropertyStore;
LPITEMIDLIST pidl;
void *ret=NULL;
// @pyparm <o PyIDL>|pidl||An absolute item identifier list
// @pyparm int|Flags|GPS_DEFAULT|Combination of GETPROPERTYSTOREFLAGS values (shellcon.GPS_*)
// @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to return
if (!PyArg_ParseTuple(args, "O|kO&:SHGetPropertyStoreFromIDList",
&obidl, &flags,
PyWinObject_AsIID, &riid))
return NULL;
if (!PyObject_AsPIDL(obidl, &pidl, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = SHGetPropertyStoreFromIDList(pidl, flags, riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
*/
// @pymethod <o PyIPropertyStore>|propsys|PSGetItemPropertyHandler|Retrieves the property store for a shell item
static PyObject *PyPSGetItemPropertyHandler(PyObject *self, PyObject *args)
{
IShellItem *item = NULL;
IPropertyStore *propertystore;
PyObject *obitem;
BOOL writeable = FALSE;
IID riid = IID_IPropertyStore;
// @pyparm <o PyIShellItem>|Item||A shell item
// @pyparm bool|ReadWrite|False|Pass True for a writeable property store
// @pyparm <o PyIID>|riid|IID_IPropertyStore|Interface to return
if (!PyArg_ParseTuple(args, "O|iO&:PSGetItemPropertyHandler", &obitem, &writeable, PyWinObject_AsIID, &riid))
return NULL;
if (!PyCom_InterfaceFromPyInstanceOrObject(obitem, IID_IShellItem, (void **)&item, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetItemPropertyHandler(item, writeable, riid, (void **)&propertystore);
item->Release();
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)propertystore, riid, FALSE);
}
// @pymethod bytes|propsys|StgSerializePropVariant|Serializes a <o PyPROPVARIANT>
static PyObject *PyStgSerializePropVariant(PyObject *self, PyObject *args)
{
PROPVARIANT *pv;
SERIALIZEDPROPERTYVALUE *pspv = NULL;
ULONG bufsize;
HRESULT hr;
// @pyparm <o PyPROPVARIANT>|propvar||The value to serialize
if (!PyArg_ParseTuple(args, "O&:StgSerializePropVariant", PyWinObject_AsPROPVARIANT, &pv))
return NULL;
PY_INTERFACE_PRECALL;
hr = StgSerializePropVariant(pv, &pspv, &bufsize);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
PyObject *ret = PyBytes_FromStringAndSize((char *)pspv, bufsize);
CoTaskMemFree(pspv);
return ret;
};
// @pymethod <o PyPROPVARIANT>|propsys|StgDeserializePropVariant|Creates a <o PyPROPVARIANT> from a serialized buffer
static PyObject *PyStgDeserializePropVariant(PyObject *self, PyObject *args)
{
PROPVARIANT pv;
PyObject *ob;
HRESULT hr;
if (!PyArg_ParseTuple(args, "O:StgDeserializePropVariant", &ob))
return NULL;
// @pyparm bytes|prop||Buffer or bytes object (or str in Python 2) containing a serialized value
PyWinBufferView pybuf(ob);
if (!pybuf.ok())
return NULL;
PY_INTERFACE_PRECALL;
hr = StgDeserializePropVariant((SERIALIZEDPROPERTYVALUE *)pybuf.ptr(), pybuf.len(), &pv);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyWinObject_FromPROPVARIANT(&pv);
};
// @pymethod <o PyIPropertyStore>|propsys|PSCreateMemoryPropertyStore|Creates a temporary property store that is not
// connected to any backing storage
// @comm May also be used to create <o PyINamedPropertyStore>, <o PyIPropertyStoreCache>, <o PyIPersistStream>, or <o
// PyIPropertyBag>
static PyObject *PyPSCreateMemoryPropertyStore(PyObject *self, PyObject *args)
{
void *ret;
IID riid = IID_IPropertyStore;
// @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to create
if (!PyArg_ParseTuple(args, "|O&:PSCreateMemoryPropertyStore", PyWinObject_AsIID, &riid))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSCreateMemoryPropertyStore(riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
};
// @pymethod <o PyIPropertyStore>|propsys|PSCreatePropertyStoreFromPropertySetStorage|Wraps a <o PyIPropertySetStorage>
// interface in a <o PyIPropertyStore> object
// @comm This function does not work for the NTFS property storage implementation based on
// alternate data streams.
static PyObject *PyPSCreatePropertyStoreFromPropertySetStorage(PyObject *self, PyObject *args)
{
PyObject *obpss;
IPropertySetStorage *pipss;
DWORD mode;
IID riid = IID_IPropertyStore;
void *ret;
// @pyparm <o PyIPropertySetStorage>|pss||Property container to be adapted
// @pyparm int|Mode||Read or write mode, shellcon.STGM_*. Must match mode used to open input interface.
// @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to create
if (!PyArg_ParseTuple(args, "Ok|O&:PSCreatePropertyStoreFromPropertySetStorage", &obpss, &mode, PyWinObject_AsIID,
&riid))
return NULL;
if (!PyCom_InterfaceFromPyInstanceOrObject(obpss, IID_IPropertySetStorage, (void **)&pipss, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSCreateMemoryPropertyStore(riid, &ret);
pipss->Release();
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
};
// @pymethod <o PyIID>|propsys|PSLookupPropertyHandlerCLSID|Returns the GUID of the property handler for a file
// @comm If no handler is found, the returned error code can be deceptive as it seems to indicate
// that the file itself was not found
static PyObject *PyPSLookupPropertyHandlerCLSID(PyObject *self, PyObject *args)
{
PyObject *obfname;
TmpWCHAR fname;
// @pyparm str|FilePath||Name of file
IID iid;
if (!PyArg_ParseTuple(args, "O:PSLookupPropertyHandlerCLSID", &obfname))
return NULL;
if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSLookupPropertyHandlerCLSID(fname, &iid);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyWinObject_FromIID(iid);
};
// @pymethod <o PyIPropertyStore>|propsys|SHGetPropertyStoreForWindow|Retrieves a collection of a window's properties
// @rdesc The returned store can be used to set the System.AppUserModel.ID property that determines how windows
// are grouped on the taskbar
static PyObject *PySHGetPropertyStoreForWindow(PyObject *self, PyObject *args)
{
HWND hwnd;
IID riid = IID_IPropertyStore;
void *ret;
// @pyparm <o PyHANDLE>|hwnd||Handle to a window
// @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to create
if (!PyArg_ParseTuple(args, "O&|O&:SHGetPropertyStoreForWindow", PyWinObject_AsHANDLE, &hwnd, PyWinObject_AsIID,
&riid))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = SHGetPropertyStoreForWindow(hwnd, riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
};
// @pymethod <o PyPROPVARIANT>|propsys|PSGetPropertyFromPropertyStorage|Extracts a property value from a serialized
// buffer by key
static PyObject *PyPSGetPropertyFromPropertyStorage(PyObject *self, PyObject *args)
{
PROPERTYKEY key;
PROPVARIANT val;
PyObject *obbuf;
// @pyparm buffer|ps||Bytes or buffer (or str in Python 2) containing a serialized property set (see <om
// PyIPersistSerializedPropStorage.GetPropertyStorage>)
// @pyparm <o PyPROPERTYKEY>|key||Property to return
if (!PyArg_ParseTuple(args, "OO&:PSGetPropertyFromPropertyStorage", &obbuf, PyWinObject_AsPROPERTYKEY, &key))
return NULL;
PyWinBufferView pybuf(obbuf);
if (!pybuf.ok())
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetPropertyFromPropertyStorage((PCUSERIALIZEDPROPSTORAGE)pybuf.ptr(), pybuf.len(), key, &val);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyWinObject_FromPROPVARIANT(val);
}
// @pymethod <o PyPROPVARIANT>|propsys|PSGetNamedPropertyFromPropertyStorage|Extracts a property value from a serialized
// buffer by name
static PyObject *PyPSGetNamedPropertyFromPropertyStorage(PyObject *self, PyObject *args)
{
TmpWCHAR name;
PROPVARIANT val;
PyObject *obname, *obbuf;
// @pyparm buffer|ps||Bytes or buffer (or str in Python 2) containing a serialized property set (see <om
// PyIPersistSerializedPropStorage.GetPropertyStorage>)
// @pyparm str|name||Property to return
if (!PyArg_ParseTuple(args, "OO:PSGetNamedPropertyFromPropertyStorage", &obbuf, &obname))
return NULL;
PyWinBufferView pybuf(obbuf);
if (!pybuf.ok())
return NULL;
if (!PyWinObject_AsWCHAR(obname, &name, FALSE))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSGetNamedPropertyFromPropertyStorage((PCUSERIALIZEDPROPSTORAGE)pybuf.ptr(), pybuf.len(), name, &val);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyWinObject_FromPROPVARIANT(val);
}
// @pymethod <o PyIPropertyChange>|propsys|PSCreateSimplePropertyChange|Creates an IPropertyChange interface used to
// apply changes to a <o PyPROPVARIANT>
static PyObject *PyPSCreateSimplePropertyChange(PyObject *self, PyObject *args)
{
// @pyparm int|flags||The change operation, pscon.PKA_*
// @pyparm <o PyPROPERTYKEY>|key||The property key
// @pyparm <o PyPROPVARIANT>|val||The value that the change operation will apply
// @pyparm <o PyIID>|riid|IID_IPropertyChange|The interface to return.
PKA_FLAGS flags;
PROPERTYKEY key;
PROPVARIANT *val;
IID riid = IID_IPropertyChange;
void *ret;
if (!PyArg_ParseTuple(args, "lO&O&|O&:PSCreateSimplePropertyChange", &flags, PyWinObject_AsPROPERTYKEY, &key,
PyWinObject_AsPROPVARIANT, &val, PyWinObject_AsIID, &riid))
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSCreateSimplePropertyChange(flags, key, *val, riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
// @pymethod <o PyIPropertyChangeArray>|propsys|PSCreatePropertyChangeArray|Creates an IPropertyChangeArray interface to
// be used with <o PyIFileOperation>
// @comm Currently only creates an empty array to be filled in later
static PyObject *PyPSCreatePropertyChangeArray(PyObject *self, PyObject *args)
{
IID riid = IID_IPropertyChangeArray;
void *ret;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = PSCreatePropertyChangeArray(NULL, NULL, NULL, 0, riid, &ret);
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid);
}
// @pymethod |propsys|SHSetDefaultProperties|Sets the default properties for a file.
// @comm Default properties are registered by filetype under SetDefaultsFor value.
static PyObject *PySHSetDefaultProperties(PyObject *self, PyObject *args)
{
HWND hwnd;
PyObject *obItem, *obSink = Py_None;
DWORD flags = 0;
IShellItem *pItem;
IFileOperationProgressSink *pSink;
// @pyparm <o PyHANDLE>|hwnd||Parent window for any notifications, can be None
// @pyparm <o PyIShellItem>|Item||Shell item whose defaults are to be set
// @pyparm int|FileOpFlags|0|File operation flags, as used with <om PyIFileOperation.SetOperationFlags>
// @pyparm <o PyGFileOperationProgressSink>|Sink|None|Event sink to receive notifications
if (!PyArg_ParseTuple(args, "O&O|kO:SHSetDefaultProperties", PyWinObject_AsHANDLE, &hwnd, &obItem, &flags, &obSink))
return NULL;
if (!PyCom_InterfaceFromPyInstanceOrObject(obItem, IID_IShellItem, (void **)&pItem, FALSE))
return NULL;
if (!PyCom_InterfaceFromPyInstanceOrObject(obSink, IID_IFileOperationProgressSink, (void **)&pSink, TRUE)) {
PYCOM_RELEASE(pItem);
return NULL;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = SHSetDefaultProperties(hwnd, pItem, flags, pSink);
pItem->Release();
if (pSink)
pSink->Release();
PY_INTERFACE_POSTCALL;
if (FAILED(hr))
return PyCom_BuildPyException(hr);
Py_INCREF(Py_None);
return Py_None;
}
/* List of module functions */
// @module propsys|A module, encapsulating the Property System interfaces
static struct PyMethodDef propsys_methods[] = {
// { "SHGetPropertyStoreFromIDList", PySHGetPropertyStoreFromIDList, 1 }, // @pymeth
// SHGetPropertyStoreFromIDList|Retrieves the property store from an absolute ID list
{"PSGetItemPropertyHandler", PyPSGetItemPropertyHandler,
1}, // @pymeth PSGetItemPropertyHandler|Retrieves the property store for a shell item
{"PSGetPropertyDescription", PyPSGetPropertyDescription,
1}, // @pymeth PSGetPropertyDescription|Gets a description interface for a property
{"PSGetPropertySystem", PyPSGetPropertySystem,
1}, // @pymeth PSGetPropertySystem|Creates an IPropertySystem interface
{"PSGetNameFromPropertyKey", PyPSGetNameFromPropertyKey,
1}, // @pymeth PSGetNameFromPropertyKey|Retrieves the canonical name for a property key
{"PSGetPropertyKeyFromName", PyPSGetPropertyKeyFromName,
1}, // @pymeth PSGetPropertyKeyFromName|Retrieves the property key by canonical name
{"PSRegisterPropertySchema", PyPSRegisterPropertySchema,
1}, // @pymeth PSRegisterPropertySchema|Registers a group of properties described in a schema file
{"PSUnregisterPropertySchema", PyPSUnregisterPropertySchema,
1}, // @pymeth PSUnregisterPropertySchema|Removes a property schema definition
{"SHGetPropertyStoreFromParsingName", PySHGetPropertyStoreFromParsingName,
1}, // @pymeth SHGetPropertyStoreFromParsingName|Retrieves the property store for an item by path
{"StgSerializePropVariant", PyStgSerializePropVariant,
1}, // @pymeth StgSerializePropVariant|Serializes a <o PyPROPVARIANT>
{"StgDeserializePropVariant", PyStgDeserializePropVariant,
1}, // @pymeth StgDeserializePropVariant|Creates a <o PyPROPVARIANT> from a serialized buffer
{"PSCreateMemoryPropertyStore", PyPSCreateMemoryPropertyStore,
1}, // @pymeth PSCreateMemoryPropertyStore|Creates a temporary property store that is not connected to any backing
// storage
{"PSCreatePropertyStoreFromPropertySetStorage", PyPSCreatePropertyStoreFromPropertySetStorage,
1}, // @pymeth PSCreatePropertyStoreFromPropertySetStorage|Wraps a <o PyIPropertySetStorage> interface in a <o
// PyIPropertyStore> object
{"PSLookupPropertyHandlerCLSID", PyPSLookupPropertyHandlerCLSID,
1}, // @pymeth PSLookupPropertyHandlerCLSID|Returns the GUID of the property handler for a file
{"SHGetPropertyStoreForWindow", PySHGetPropertyStoreForWindow,
1}, // @pymeth SHGetPropertyStoreForWindow|Retrieves a collection of a window's properties
{"PSGetPropertyFromPropertyStorage", PyPSGetPropertyFromPropertyStorage,
1}, // @pymeth PSGetPropertyFromPropertyStorage|Extracts a property from a serialized buffer by key
{"PSGetNamedPropertyFromPropertyStorage", PyPSGetNamedPropertyFromPropertyStorage,
1}, // @pymeth PSGetNamedPropertyFromPropertyStorage|Extracts a property from a serialized buffer by name
{"PSCreateSimplePropertyChange", PyPSCreateSimplePropertyChange,
1}, // @pymeth PSCreateSimplePropertyChange|Creates a <o PyIPropertyChange> interface used to apply changes to a
// <o PyPROPVARIANT>
{"PSCreatePropertyChangeArray", PyPSCreatePropertyChangeArray,
METH_NOARGS}, // @pymeth PSCreatePropertyChangeArray|Creates a <o PyIPropertyChangeArray> interface to be used
// with <o PyIFileOperation>
{"SHSetDefaultProperties", PySHSetDefaultProperties,
METH_VARARGS}, // @pymeth SHSetDefaultProperties|Sets the default properties for a file.
{NULL, NULL},
};
static const PyCom_InterfaceSupportInfo g_interfaceSupportData[] = {
PYCOM_INTERFACE_FULL(InitializeWithFile),
PYCOM_INTERFACE_FULL(InitializeWithStream),
PYCOM_INTERFACE_FULL(NamedPropertyStore),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyDescription),
PYCOM_INTERFACE_FULL(PropertyDescriptionList),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyDescriptionSearchInfo),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyDescriptionAliasInfo),
PYCOM_INTERFACE_FULL(PropertyStore),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyStoreCache),
PYCOM_INTERFACE_FULL(PropertyStoreCapabilities),
PYCOM_INTERFACE_CLIENT_ONLY(PropertySystem),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyEnumType),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyEnumTypeList),
PYCOM_INTERFACE_CLIENT_ONLY(PersistSerializedPropStorage),
PYCOM_INTERFACE_CLIENT_ONLY(ObjectWithPropertyKey),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyChange),
PYCOM_INTERFACE_CLIENT_ONLY(PropertyChangeArray),
};
/* Module initialisation */
PYWIN_MODULE_INIT_FUNC(propsys)
{
PYWIN_MODULE_INIT_PREPARE(propsys, propsys_methods, "A module, encapsulating the Property System interfaces.");
if (PyDict_SetItemString(dict, "error", PyWinExc_COMError) == -1)
PYWIN_MODULE_INIT_RETURN_ERROR;
if (PyType_Ready(&PyPROPVARIANTType) == -1)
PYWIN_MODULE_INIT_RETURN_ERROR;
if (PyDict_SetItemString(dict, "PROPVARIANTType", (PyObject *)&PyPROPVARIANTType) == -1)
PYWIN_MODULE_INIT_RETURN_ERROR;
// Register all of our interfaces, gateways and IIDs.
if (PyCom_RegisterExtensionSupport(dict, g_interfaceSupportData,
sizeof(g_interfaceSupportData) / sizeof(PyCom_InterfaceSupportInfo)) != 0)
PYWIN_MODULE_INIT_RETURN_ERROR;
PYWIN_MODULE_INIT_RETURN_SUCCESS;
}