[pywin32-checkins] /hgroot/pywin32/pywin32: Add IPersistSerializedPropStorage, PSGe...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-07-26 15:06:44
|
changeset 06fd2a416c94 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=06fd2a416c94 summary: Add IPersistSerializedPropStorage, PSGetPropertyFromPropertyStorage, and PSGetNamedPropertyFromPropertyStorage to propsys diffstat: com/win32comext/propsys/pscon.py | 3 + com/win32comext/propsys/src/PyIPersistSerializedPropStorage.cpp | 106 ++++++++++ com/win32comext/propsys/src/PyIPersistSerializedPropStorage.h | 22 ++ com/win32comext/propsys/src/propsys.cpp | 62 +++++- com/win32comext/shell/src/PyIShellFolder.cpp | 30 +- setup.py | 2 + 6 files changed, 209 insertions(+), 16 deletions(-) diffs (truncated from 343 to 300 lines): diff -r 170f15c339fb -r 06fd2a416c94 com/win32comext/propsys/pscon.py --- a/com/win32comext/propsys/pscon.py Tue Jul 24 21:58:50 2012 -0400 +++ b/com/win32comext/propsys/pscon.py Thu Jul 26 11:01:58 2012 -0400 @@ -138,6 +138,9 @@ COP_WORD_STARTSWITH = 13 COP_APPLICATION_SPECIFIC = 14 +## PERSIST_SPROPSTORE_FLAGS, used with IPersistSerializedPropStorage +FPSPS_READONLY = 1 + PKEY_PIDSTR_MAX = 10 # will take care of any long integer value #define GUIDSTRING_MAX (1 + 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1) // "{12345678-1234-1234-1234-123456789012}" GUIDSTRING_MAX = (1 + 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1) # hrm ??? diff -r 170f15c339fb -r 06fd2a416c94 com/win32comext/propsys/src/PyIPersistSerializedPropStorage.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/com/win32comext/propsys/src/PyIPersistSerializedPropStorage.cpp Thu Jul 26 11:01:58 2012 -0400 @@ -0,0 +1,106 @@ +// This file implements the IPersistSerializedPropStorage Interface for Python. +// Generated by makegw.py +#include "PythonCOM.h" +#include "propsys.h" +#include "PyIPersistSerializedPropStorage.h" + +// @doc - This file contains autoduck documentation +// --------------------------------------------------- +// +// Interface Implementation + +PyIPersistSerializedPropStorage::PyIPersistSerializedPropStorage(IUnknown *pdisp): + PyIUnknown(pdisp) +{ + ob_type = &type; +} + +PyIPersistSerializedPropStorage::~PyIPersistSerializedPropStorage() +{ +} + +/* static */ IPersistSerializedPropStorage *PyIPersistSerializedPropStorage::GetI(PyObject *self) +{ + return (IPersistSerializedPropStorage *)PyIUnknown::GetI(self); +} + +// @pymethod |PyIPersistSerializedPropStorage|SetFlags|Sets flags for the store +PyObject *PyIPersistSerializedPropStorage::SetFlags(PyObject *self, PyObject *args) +{ + IPersistSerializedPropStorage *pIPSPS = GetI(self); + if ( pIPSPS == NULL ) + return NULL; + PERSIST_SPROPSTORE_FLAGS flags; + // @pyparm int|flags||Combination of pscon.FPSPS_* values + if (!PyArg_ParseTuple(args, "i:SetFlags", &flags)) + return NULL; + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pIPSPS->SetFlags( flags ); + PY_INTERFACE_POSTCALL; + + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pIPSPS, IID_IPersistSerializedPropStorage ); + Py_INCREF(Py_None); + return Py_None; +} + +// @pymethod |PyIPersistSerializedPropStorage|SetPropertyStorage|Initializes the store with a serialized buffer +PyObject *PyIPersistSerializedPropStorage::SetPropertyStorage(PyObject *self, PyObject *args) +{ + IPersistSerializedPropStorage *pIPSPS = GetI(self); + if ( pIPSPS == NULL ) + return NULL; + PyObject *obbuf; + void *buf; + DWORD bufsize; + // @pyparm buffer|ps||Bytes or buffer object containing a serialized property store + if (!PyArg_ParseTuple(args, "O:SetPropertyStorage", &obbuf)) + return NULL; + if (!PyWinObject_AsReadBuffer(obbuf, &buf, &bufsize)) + return NULL; + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pIPSPS->SetPropertyStorage((PUSERIALIZEDPROPSTORAGE)buf, bufsize); + PY_INTERFACE_POSTCALL; + + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pIPSPS, IID_IPersistSerializedPropStorage ); + Py_INCREF(Py_None); + return Py_None; +} + +// @pymethod buffer|PyIPersistSerializedPropStorage|GetPropertyStorage|Retrieves the current contents of the property store +PyObject *PyIPersistSerializedPropStorage::GetPropertyStorage(PyObject *self, PyObject *args) +{ + IPersistSerializedPropStorage *pIPSPS = GetI(self); + if ( pIPSPS == NULL ) + return NULL; + PUSERIALIZEDPROPSTORAGE buf; + DWORD bufsize; + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pIPSPS->GetPropertyStorage(&buf, &bufsize); + PY_INTERFACE_POSTCALL; + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pIPSPS, IID_IPersistSerializedPropStorage ); + PyObject *ret = PyString_FromStringAndSize((char *)buf, bufsize); + CoTaskMemFree(buf); + return ret; +} + +// @object PyIPersistSerializedPropStorage|Allows a property store to be marshalled into a single buffer. +// Primarily used with property stores created using <om propsys.PSCreateMemoryPropertyStore>. +static struct PyMethodDef PyIPersistSerializedPropStorage_methods[] = +{ + { "SetFlags", PyIPersistSerializedPropStorage::SetFlags, 1 }, // @pymeth SetFlags|Sets flags for the store + { "SetPropertyStorage", PyIPersistSerializedPropStorage::SetPropertyStorage, 1 }, // @pymeth SetPropertyStorage|Initializes the store with a serialized buffer + { "GetPropertyStorage", PyIPersistSerializedPropStorage::GetPropertyStorage, METH_NOARGS }, // @pymeth GetPropertyStorage|Retrieves the current contents of the property store + { NULL } +}; + +PyComTypeObject PyIPersistSerializedPropStorage::type("PyIPersistSerializedPropStorage", + &PyIUnknown::type, + sizeof(PyIPersistSerializedPropStorage), + PyIPersistSerializedPropStorage_methods, + GET_PYCOM_CTOR(PyIPersistSerializedPropStorage)); diff -r 170f15c339fb -r 06fd2a416c94 com/win32comext/propsys/src/PyIPersistSerializedPropStorage.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/com/win32comext/propsys/src/PyIPersistSerializedPropStorage.h Thu Jul 26 11:01:58 2012 -0400 @@ -0,0 +1,22 @@ +// This file declares the IPersistSerializedPropStorage Interface for Python. +// Generated by makegw.py +// --------------------------------------------------- +// +// Interface Declaration + +class PyIPersistSerializedPropStorage : public PyIUnknown +{ +public: + MAKE_PYCOM_CTOR(PyIPersistSerializedPropStorage); + static IPersistSerializedPropStorage *GetI(PyObject *self); + static PyComTypeObject type; + + // The Python methods + static PyObject *SetFlags(PyObject *self, PyObject *args); + static PyObject *SetPropertyStorage(PyObject *self, PyObject *args); + static PyObject *GetPropertyStorage(PyObject *self, PyObject *args); + +protected: + PyIPersistSerializedPropStorage(IUnknown *pdisp); + ~PyIPersistSerializedPropStorage(); +}; diff -r 170f15c339fb -r 06fd2a416c94 com/win32comext/propsys/src/propsys.cpp --- a/com/win32comext/propsys/src/propsys.cpp Tue Jul 24 21:58:50 2012 -0400 +++ b/com/win32comext/propsys/src/propsys.cpp Thu Jul 26 11:01:58 2012 -0400 @@ -29,6 +29,7 @@ #include "PyIPropertyDescriptionAliasInfo.h" #include "PyIPropertyEnumType.h" #include "PyIPropertyEnumTypeList.h" +#include "PyIPersistSerializedPropStorage.h" #include "delayimp.h" #include "propvarutil.h" @@ -344,7 +345,7 @@ DWORD mode; IID riid = IID_IPropertyStore; void *ret; - // @pyparm <o PyIPropertySetStorage>||Property container to be adapted + // @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", @@ -397,7 +398,7 @@ HWND hwnd; IID riid = IID_IPropertyStore; void *ret; - // @pyparm <o PyHANDLE>||Handle to a window + // @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, @@ -414,6 +415,60 @@ }; +// @pymethod <o PyPROPVARIANT>|propsys|PSGetPropertyFromPropertyStorage|Extracts a property value from a serialized buffer by key +static PyObject *PyPSGetPropertyFromPropertyStorage(PyObject *self, PyObject *args) +{ + PROPERTYKEY key; + void *buf; + DWORD bufsize; + 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; + if (!PyWinObject_AsReadBuffer(obbuf, &buf, &bufsize, FALSE)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + // PCUSERIALIZEDPROPSTORAGE psps, // IPersistSerializedPropStorage::GetPropertyStorage + hr = PSGetPropertyFromPropertyStorage((PCUSERIALIZEDPROPSTORAGE)buf, bufsize, 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; + void *buf; + DWORD bufsize; + 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; + if (!PyWinObject_AsReadBuffer(obbuf, &buf, &bufsize, FALSE)) + return NULL; + if (!PyWinObject_AsWCHAR(obname, &name, FALSE)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = PSGetNamedPropertyFromPropertyStorage((PCUSERIALIZEDPROPSTORAGE)buf, bufsize, name, &val); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) + return PyCom_BuildPyException(hr); + return PyWinObject_FromPROPVARIANT(val); +} + + /* List of module functions */ // @module propsys|A module, encapsulating the Vista Property System interfaces static struct PyMethodDef propsys_methods[]= @@ -433,6 +488,8 @@ { "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 { NULL, NULL }, }; @@ -452,6 +509,7 @@ PYCOM_INTERFACE_CLIENT_ONLY (PropertySystem), PYCOM_INTERFACE_CLIENT_ONLY (PropertyEnumType), PYCOM_INTERFACE_CLIENT_ONLY (PropertyEnumTypeList), + PYCOM_INTERFACE_CLIENT_ONLY (PersistSerializedPropStorage), }; /* Module initialisation */ diff -r 170f15c339fb -r 06fd2a416c94 com/win32comext/shell/src/PyIShellFolder.cpp --- a/com/win32comext/shell/src/PyIShellFolder.cpp Tue Jul 24 21:58:50 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellFolder.cpp Thu Jul 26 11:01:58 2012 -0400 @@ -298,6 +298,7 @@ } // @pymethod int, <o PyIUnknown>|PyIShellFolder|GetUIObjectOf|Creates an interface to one or more items in a shell folder +// @rdesc Returns the Reserved parameter and the requested interface PyObject *PyIShellFolder::GetUIObjectOf(PyObject *self, PyObject *args) { IShellFolder *pISF = GetI(self); @@ -306,7 +307,11 @@ // @pyparm <o PyHANDLE>|hwndOwner||Specifies a window in which to display any required dialogs or errors, can be 0 // @pyparm (<o PyIDL>,...)|pidl||A sequence of single-level pidls identifying items in the folder // @pyparm <o PyIID>|riid||The interface to create, one of IID_IContextMenu, IID_IContextMenu2, IID_IDataObject, IID_IDropTarget, IID_IExtractIcon, IID_IQueryInfo - // @pyparm int|rgfReserved|0|Reserved, use 0 if passed in + // @pyparm int|Reserved|0|Reserved, use 0 if passed in + // @pyparm <o PyIID>|iidout|riid|The interface to return. Can be used in the case where there is not a + // python wrapper for the desired interface. You must make certain that the interface identified by riid + // actually supports the iidout interface, or Bad Things Will Happen. + // It should always be safe to return <o PyIUnknown>, which is the base for all interfaces. PyObject *obpidl; PyObject *obriid; PyObject *obiidout = NULL; @@ -315,20 +320,22 @@ UINT cidl; LPCITEMIDLIST *pidl; IID riid, iidout; - UINT rgfInOut; + UINT rgfInOut = 0; void * out; - if ( !PyArg_ParseTuple(args, "OOOl|O:GetUIObjectOf", &obhwndOwner, &obpidl, &obriid, &rgfInOut, &obiidout) ) + if ( !PyArg_ParseTuple(args, "OOO|lO:GetUIObjectOf", &obhwndOwner, &obpidl, &obriid, &rgfInOut, &obiidout) ) return NULL; if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner)) return NULL; - BOOL bPythonIsHappy = TRUE; - if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; + if (!PyWinObject_AsIID(obriid, &riid)) + return NULL; if (obiidout==NULL) iidout = riid; else - if (!PyWinObject_AsIID(obiidout, &iidout)) bPythonIsHappy = FALSE; |