[pywin32-checkins] /hgroot/pywin32/pywin32: Add SHCreateStreamOnFileEx
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-18 16:59:41
|
changeset 93262002f506 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=93262002f506 summary: Add SHCreateStreamOnFileEx diffstat: com/win32comext/shell/src/shell.cpp | 43 +++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diffs (74 lines): diff -r 1f6c4ba7e469 -r 93262002f506 com/win32comext/shell/src/shell.cpp --- a/com/win32comext/shell/src/shell.cpp Thu Aug 16 17:55:01 2012 -0400 +++ b/com/win32comext/shell/src/shell.cpp Sat Aug 18 12:54:34 2012 -0400 @@ -163,6 +163,8 @@ typedef HRESULT (WINAPI *PFNSHOpenFolderAndSelectItems)(PCIDLIST_ABSOLUTE,UINT,PCUITEMID_CHILD_ARRAY,DWORD); static PFNSHOpenFolderAndSelectItems pfnSHOpenFolderAndSelectItems = NULL; +typedef HRESULT (WINAPI *PFNSHCreateStreamOnFileEx)(LPCWSTR, DWORD, DWORD, BOOL, IStream *, IStream **); +static PFNSHCreateStreamOnFileEx pfnSHCreateStreamOnFileEx = NULL; // Some magic hackery macros :-) #define _ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb)) @@ -3247,6 +3249,45 @@ return ret; } +// @pymethod <o PyIStream>|shell|SHCreateStreamOnFileEx|Creates an IStream interface that reads and writes to a file +static PyObject *PySHCreateStreamOnFileEx(PyObject *self, PyObject *args, PyObject *kwargs) +{ + // @comm Accepts keyword args. + // @comm This function is only available on WinXP and later. + // COM exception with E_NOTIMPL will be thrown if the function can't be located. + if (pfnSHCreateStreamOnFileEx==NULL) + return PyCom_BuildPyException(E_NOTIMPL); + static char *keywords[] = {"File", "Mode", "Attributes", "Create", "Template", NULL}; + PyObject *obfname, *obtemplate = Py_None; + TmpWCHAR fname; + DWORD mode, attributes; + BOOL create; + IStream *ret; + // @pyparm str|File||Name of file to be connected to the stream + // @pyparm int|Mode||Combination of storagecon.STGM_* flags specifying the access mode + // @pyparm int|Attributes||Combination of win32con.FILE_ATTRIBUTE_* flags + // @pyparm bool|Create||Determines if function should fail when file exists (see MSDN docs for full explanation) + // @pyparm None|Template|None|Reserved, use only None + + if(!PyArg_ParseTupleAndKeywords(args, kwargs, "Okkl|O:SHCreateStreamOnFileEx", keywords, + &obfname, &mode, &attributes, &create, &obtemplate)) + return NULL; + if (obtemplate != Py_None){ + PyErr_SetString(PyExc_ValueError, "Template is reserved and must be None"); + return NULL; + } + if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = (*pfnSHCreateStreamOnFileEx)(fname, mode, attributes, create, NULL, &ret); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) + return PyCom_BuildPyException(hr); + return PyCom_PyObjectFromIUnknown(ret, IID_IStream, FALSE); +} + /* List of module functions */ // @module shell|A module wrapping Windows Shell functions and interfaces @@ -3306,6 +3347,7 @@ { "SHILCreateFromPath", PySHILCreateFromPath, METH_VARARGS}, // @pymeth SHILCreateFromPath|Returns the PIDL and attributes of a path { "SHCreateShellItem", PySHCreateShellItem, METH_VARARGS}, // @pymeth SHCreateShellItem|Creates an IShellItem interface from a PIDL { "SHOpenFolderAndSelectItems", (PyCFunction)PySHOpenFolderAndSelectItems, METH_VARARGS|METH_KEYWORDS}, // @pymeth SHOpenFolderAndSelectItems|Displays a shell folder with items pre-selected + { "SHCreateStreamOnFileEx", (PyCFunction)PySHCreateStreamOnFileEx, METH_VARARGS|METH_KEYWORDS}, // @pymeth SHCreateStreamOnFileEx|Creates a <o PyIStream> that reads and writes to a file { NULL, NULL }, }; @@ -3458,6 +3500,7 @@ if (shlwapi!=NULL){ pfnSHGetViewStatePropertyBag=(PFNSHGetViewStatePropertyBag)GetProcAddress(shlwapi, "SHGetViewStatePropertyBag"); pfnAssocCreate=(PFNAssocCreate)GetProcAddress(shlwapi, "AssocCreate"); + pfnSHCreateStreamOnFileEx = (PFNSHCreateStreamOnFileEx)GetProcAddress(shlwapi, "SHCreateStreamOnFileEx"); } ADD_CONSTANT(SLR_NO_UI); |