[pywin32-checkins] /hgroot/pywin32/pywin32: Add PSCreatePropertyStoreFromPropertySe...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-07-24 04:48:36
|
changeset 433b264e9fbe in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=433b264e9fbe summary: Add PSCreatePropertyStoreFromPropertySetStorage, PSLookupPropertyHandlerCLSID, and SHGetPropertyStoreForWindow to propsys diffstat: com/win32comext/propsys/pscon.py | 9 ++ com/win32comext/propsys/src/propsys.cpp | 101 ++++++++++++++++++++++++++- com/win32comext/shell/shellcon.py | 42 +++++++++++ com/win32comext/shell/src/PyIContextMenu.cpp | 13 ++- 4 files changed, 160 insertions(+), 5 deletions(-) diffs (256 lines): diff -r 7a8b207998e0 -r 433b264e9fbe com/win32comext/propsys/pscon.py --- a/com/win32comext/propsys/pscon.py Fri Jul 20 10:23:03 2012 -0400 +++ b/com/win32comext/propsys/pscon.py Mon Jul 23 23:13:52 2012 -0400 @@ -705,3 +705,12 @@ PKEY_Volume_FileSystem = (IID('{9B174B35-40FF-11D2-A27E-00C04FC30871}'), 4) PKEY_Volume_IsMappedDrive = (IID('{149C0B69-2C2D-48FC-808F-D318D78C4636}'), 2) PKEY_Volume_IsRoot = (IID('{9B174B35-40FF-11D2-A27E-00C04FC30871}'), 10) + +PKEY_AppUserModel_RelaunchCommand = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 2) +PKEY_AppUserModel_RelaunchIconResource = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 3) +PKEY_AppUserModel_RelaunchDisplayNameResource = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 4) +PKEY_AppUserModel_ID = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 5) +PKEY_AppUserModel_IsDestListSeparator = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 6) +PKEY_AppUserModel_ExcludeFromShowInNewInstall = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 8) +PKEY_AppUserModel_PreventPinning = (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'), 9) + diff -r 7a8b207998e0 -r 433b264e9fbe com/win32comext/propsys/src/propsys.cpp --- a/com/win32comext/propsys/src/propsys.cpp Fri Jul 20 10:23:03 2012 -0400 +++ b/com/win32comext/propsys/src/propsys.cpp Mon Jul 23 23:13:52 2012 -0400 @@ -34,6 +34,11 @@ #include "propvarutil.h" #include "Shobjidl.h" +#define CHECK_PFN(fname)if (pfn##fname==NULL) return PyErr_Format(PyExc_NotImplementedError,"%s is not available on this platform", #fname); +// Not available on Vista or earlier +typedef HRESULT (WINAPI *PFNSHGetPropertyStoreForWindow)(HWND, REFIID, void **); +static PFNSHGetPropertyStoreForWindow pfnSHGetPropertyStoreForWindow = NULL; + // @object PyPROPERTYKEY|A tuple of a fmtid and property id (IID, int) that uniquely identifies a property BOOL PyWinObject_AsPROPERTYKEY(PyObject *obkey, PROPERTYKEY *pkey) { @@ -280,7 +285,9 @@ // @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 = PyString_FromStringAndSize((char *)pspv, bufsize); @@ -301,7 +308,9 @@ // @pyparm bytes|prop||Buffer or bytes object (or str in Python 2) containing a serialized value if (!PyWinObject_AsReadBuffer(ob, (void **)&pspv, &bufsize)) return NULL; + PY_INTERFACE_PRECALL; hr = StgDeserializePropVariant(pspv, bufsize, &pv); + PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); return PyWinObject_FromPROPVARIANT(&pv); @@ -316,7 +325,89 @@ // @pyparm <o PyIID>|riid|IID_IPropertyStore|The interface to create if (!PyArg_ParseTuple(args, "|O&:PSCreateMemoryPropertyStore", PyWinObject_AsIID, &riid)) return NULL; - HRESULT hr = PSCreateMemoryPropertyStore(riid, &ret); + 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>||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 +// @comm Requires Windows 7 or later. +// @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) +{ + CHECK_PFN(SHGetPropertyStoreForWindow); + HWND hwnd; + IID riid = IID_IPropertyStore; + void *ret; + // @pyparm <o PyHANDLE>||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 = (*pfnSHGetPropertyStoreForWindow)(hwnd, riid, &ret); + PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); return PyCom_PyObjectFromIUnknown((IUnknown *) ret, riid); @@ -339,6 +430,9 @@ { "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 { NULL, NULL }, }; @@ -380,5 +474,10 @@ if (PyCom_RegisterExtensionSupport(dict, g_interfaceSupportData, sizeof(g_interfaceSupportData)/sizeof(PyCom_InterfaceSupportInfo)) != 0) PYWIN_MODULE_INIT_RETURN_ERROR; + + HMODULE hmod = GetModuleHandle(L"shell32.dll"); + if (hmod) + pfnSHGetPropertyStoreForWindow = (PFNSHGetPropertyStoreForWindow)GetProcAddress(hmod, "SHGetPropertyStoreForWindow"); + PYWIN_MODULE_INIT_RETURN_SUCCESS; } diff -r 7a8b207998e0 -r 433b264e9fbe com/win32comext/shell/shellcon.py --- a/com/win32comext/shell/shellcon.py Fri Jul 20 10:23:03 2012 -0400 +++ b/com/win32comext/shell/shellcon.py Mon Jul 23 23:13:52 2012 -0400 @@ -1244,3 +1244,45 @@ GPS_DELAYCREATION = 0x20 GPS_BESTEFFORT = 0x40 GPS_MASK_VALID = 0x7f + +## Bind context parameter names, used with IBindCtx::RegisterObjectParam +STR_AVOID_DRIVE_RESTRICTION_POLICY = "Avoid Drive Restriction Policy" +STR_BIND_DELEGATE_CREATE_OBJECT = "Delegate Object Creation" +STR_BIND_FOLDERS_READ_ONLY = "Folders As Read Only" +STR_BIND_FOLDER_ENUM_MODE = "Folder Enum Mode" +STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE = "Force Folder Shortcut Resolve" +STR_DONT_PARSE_RELATIVE = "Don't Parse Relative" +STR_DONT_RESOLVE_LINK = "Don't Resolve Link" +## STR_ENUM_ITEMS_FLAGS +STR_FILE_SYS_BIND_DATA = "File System Bind Data" +STR_GET_ASYNC_HANDLER = "GetAsyncHandler" +STR_GPS_BESTEFFORT = "GPS_BESTEFFORT" +STR_GPS_DELAYCREATION = "GPS_DELAYCREATION" +STR_GPS_FASTPROPERTIESONLY = "GPS_FASTPROPERTIESONLY" +STR_GPS_HANDLERPROPERTIESONLY = "GPS_HANDLERPROPERTIESONLY" +STR_GPS_NO_OPLOCK = "GPS_NO_OPLOCK" +STR_GPS_OPENSLOWITEM = "GPS_OPENSLOWITEM" +STR_IFILTER_FORCE_TEXT_FILTER_FALLBACK = "Always bind persistent handlers" +STR_IFILTER_LOAD_DEFINED_FILTER = "Only bind registered persistent handlers" +STR_INTERNAL_NAVIGATE = "Internal Navigation" +STR_INTERNETFOLDER_PARSE_ONLY_URLMON_BINDABLE = "Validate URL" +STR_ITEM_CACHE_CONTEXT = "ItemCacheContext" +STR_NO_VALIDATE_FILENAME_CHARS = "NoValidateFilenameChars" +STR_PARSE_ALLOW_INTERNET_SHELL_FOLDERS = "Allow binding to Internet shell folder handlers and negate STR_PARSE_PREFER_WEB_BROWSING" +STR_PARSE_AND_CREATE_ITEM = "ParseAndCreateItem" +STR_PARSE_DONT_REQUIRE_VALIDATED_URLS = "Do not require validated URLs" +STR_PARSE_EXPLICIT_ASSOCIATION_SUCCESSFUL = "ExplicitAssociationSuccessful" +STR_PARSE_PARTIAL_IDLIST = "ParseOriginalItem" +STR_PARSE_PREFER_FOLDER_BROWSING = "Parse Prefer Folder Browsing" +STR_PARSE_PREFER_WEB_BROWSING = "Do not bind to Internet shell folder handlers" +STR_PARSE_PROPERTYSTORE = "DelegateNamedProperties" +STR_PARSE_SHELL_PROTOCOL_TO_FILE_OBJECTS = "Parse Shell Protocol To File Objects" +STR_PARSE_SHOW_NET_DIAGNOSTICS_UI = "Show network diagnostics UI" +STR_PARSE_SKIP_NET_CACHE = "Skip Net Resource Cache" +STR_PARSE_TRANSLATE_ALIASES = "Parse Translate Aliases" +STR_PARSE_WITH_EXPLICIT_ASSOCAPP = "ExplicitAssociationApp" +STR_PARSE_WITH_EXPLICIT_PROGID = "ExplicitProgid" +STR_PARSE_WITH_PROPERTIES = "ParseWithProperties" +## STR_PROPERTYBAG_PARAM +STR_SKIP_BINDING_CLSID = "Skip Binding CLSID" +STR_TRACK_CLSID = "Track the CLSID" diff -r 7a8b207998e0 -r 433b264e9fbe com/win32comext/shell/src/PyIContextMenu.cpp --- a/com/win32comext/shell/src/PyIContextMenu.cpp Fri Jul 20 10:23:03 2012 -0400 +++ b/com/win32comext/shell/src/PyIContextMenu.cpp Mon Jul 23 23:13:52 2012 -0400 @@ -24,7 +24,7 @@ return (IContextMenu *)PyIUnknown::GetI(self); } -// @pymethod |PyIContextMenu|QueryContextMenu|Adds options to a context menu +// @pymethod int|PyIContextMenu|QueryContextMenu|Adds options to a context menu PyObject *PyIContextMenu::QueryContextMenu(PyObject *self, PyObject *args) { IContextMenu *pICM = GetI(self); @@ -83,7 +83,7 @@ } -// @pymethod |PyIContextMenu|GetCommandString|Retrieves verb or help text for a context menu option +// @pymethod str|PyIContextMenu|GetCommandString|Retrieves verb or help text for a context menu option PyObject *PyIContextMenu::GetCommandString(PyObject *self, PyObject *args) { IContextMenu *pICM = GetI(self); @@ -97,7 +97,8 @@ UINT cchMax = 2048; if ( !PyArg_ParseTuple(args, "OI|I:GetCommandString", &obCmd, &uType, &cchMax) ) return NULL; - + if (uType & GCS_UNICODE) + cchMax *= sizeof(WCHAR); // buffer size is in characters UINT_PTR idCmd; if (!PyWinLong_AsULONG_PTR(obCmd, (ULONG_PTR *)&idCmd)) return NULL; @@ -114,7 +115,11 @@ free(buf); return PyCom_BuildPyException(hr, pICM, IID_IContextMenu ); } - PyObject *ret = PyString_FromString(buf); + PyObject *ret; + if (uType & GCS_UNICODE) + ret = PyWinObject_FromWCHAR((WCHAR *)buf); + else + ret = PyString_FromString(buf); free(buf); return ret; |