[pywin32-checkins] /hgrepo/p/py/pywin32/pywin32: 3 new changesets
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2011-05-30 19:20:44
|
changeset bf45d00d1717 in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=bf45d00d1717 summary: Add some new event log functions for Vista/Windows 7 changeset 7c7b484ae9df in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=7c7b484ae9df summary: Include propsys in chm changeset d7b5e4753239 in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=d7b5e4753239 summary: Add SHCreateShellItem diffstat: AutoDuck/pywin32.mak | 1 + com/win32comext/shell/src/shell.cpp | 61 +++++++++++++++- setup.py | 13 ++- win32/src/win32evtlog.i | 161 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+), 5 deletions(-) diffs (truncated from 330 to 300 lines): diff -r e6ffc1f9d677 -r d7b5e4753239 AutoDuck/pywin32.mak --- a/AutoDuck/pywin32.mak Sun May 29 19:43:15 2011 -0400 +++ b/AutoDuck/pywin32.mak Mon May 30 15:17:46 2011 -0400 @@ -60,6 +60,7 @@ $(WIN32COMEXT_DIR)\authorization\src\*.cpp \ $(WIN32COMEXT_DIR)\authorization\src\*.h \ $(WIN32COMEXT_DIR)\directsound\src\*.cpp \ + $(WIN32COMEXT_DIR)\propsys\src\*.cpp \ $(WIN32COM_DIR)\src\include\*.h \ $(MAPI_DIR)\src\*.cpp \ $(GENDIR)\mapi.d \ diff -r e6ffc1f9d677 -r d7b5e4753239 com/win32comext/shell/src/shell.cpp --- a/com/win32comext/shell/src/shell.cpp Sun May 29 19:43:15 2011 -0400 +++ b/com/win32comext/shell/src/shell.cpp Mon May 30 15:17:46 2011 -0400 @@ -156,6 +156,9 @@ typedef HRESULT (WINAPI *PFNSHGetIDListFromObject)(IUnknown *, PIDLIST_ABSOLUTE *); static PFNSHGetIDListFromObject pfnSHGetIDListFromObject = NULL; +typedef HRESULT (WINAPI *PFNSHCreateShellItem)(PCIDLIST_ABSOLUTE, IShellFolder *, PCUITEMID_CHILD, IShellItem **); +static PFNSHCreateShellItem pfnSHCreateShellItem = NULL; + void PyShell_FreeMem(void *p) { @@ -3184,6 +3187,60 @@ } + + +// @pymethod <o PyIShellItem>|shell|SHCreateShellItem|Creates an IShellItem interface from a PIDL +static PyObject *PySHCreateShellItem(PyObject *self, PyObject *args) +{ + // @comm This function is only available on XP and later; a + // COM exception with E_NOTIMPL will be thrown if the function can't be located. + if (pfnSHCreateShellItem==NULL) + return PyCom_BuildPyException(E_NOTIMPL); + + PyObject *ret = NULL; + PyObject *obparent_pidl, *obparent_folder, *obitem; + // @pyparm <o PyIDL>|pidlParent||PIDL of parent folder, can be None + // @pyparm <o PyIShellFolder>|sfParent||IShellFolder interface of parent folder, can be None + // @pyparm <o PyIDL>|Child||PIDL identifying desired item. Must be an absolute PIDL if parent is not specified. + if(!PyArg_ParseTuple(args, "OOO:SHCreateShellItem", &obparent_pidl, &obparent_folder, &obitem)) + return NULL; + + PIDLIST_ABSOLUTE parent_pidl=NULL; + IShellFolder *parent_folder=NULL; + PUITEMID_CHILD item=NULL; + IShellItem *isi=NULL; + HRESULT hr; + if (!PyObject_AsPIDL(obparent_pidl, &parent_pidl, TRUE)) + goto done; + if (!PyCom_InterfaceFromPyInstanceOrObject(obparent_folder, IID_IShellFolder, (void **)&parent_folder, TRUE)) + goto done; + if (!PyObject_AsPIDL(obitem, &item, FALSE)) + goto done; + + PY_INTERFACE_PRECALL; + hr = (*pfnSHCreateShellItem)(parent_pidl, parent_folder, item, &isi); + PY_INTERFACE_POSTCALL; + + if (FAILED(hr)) { + PyCom_BuildPyException(hr); + goto done; + } + ret = PyCom_PyObjectFromIUnknown((IUnknown *)isi, IID_IShellItem, FALSE); +done: + if (parent_folder) { + PY_INTERFACE_PRECALL; + parent_folder->Release(); + PY_INTERFACE_POSTCALL; + } + if (parent_pidl) + PyObject_FreePIDL(parent_pidl); + if (item) + PyObject_FreePIDL(item); + + return ret; +} + + /* List of module functions */ // @module shell|A module wrapping Windows Shell functions and interfaces static struct PyMethodDef shell_methods[]= @@ -3240,6 +3297,7 @@ { "ShellExecuteEx", (PyCFunction)PyShellExecuteEx, METH_VARARGS|METH_KEYWORDS}, // @pymeth ShellExecuteEx|Performs an action on a file. { "SHGetViewStatePropertyBag", PySHGetViewStatePropertyBag, METH_VARARGS}, // @pymeth SHGetViewStatePropertyBag|Retrieves an interface for a folder's view state { "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 { NULL, NULL }, }; @@ -3297,6 +3355,7 @@ PYCOM_INTERFACE_IID_ONLY(ShellCopyHookW), PYCOM_INTERFACE_IID_ONLY(ShellCopyHook), PYCOM_INTERFACE_FULL(ShellItem), + PYCOM_INTERFACE_CLSID_ONLY(ShellItem), PYCOM_INTERFACE_FULL(ShellItemArray), PYCOM_INTERFACE_CLIENT_ONLY(ShellLinkDataList), PYCOM_INTERFACE_CLIENT_ONLY(UniformResourceLocator), @@ -3371,7 +3430,7 @@ pfnSHCreateItemInKnownFolder =(PFNSHCreateItemInKnownFolder)GetProcAddress(shell32, "SHCreateItemInKnownFolder"); pfnSHCreateItemWithParent =(PFNSHCreateItemWithParent)GetProcAddress(shell32, "SHCreateItemWithParent"); pfnSHGetIDListFromObject =(PFNSHGetIDListFromObject)GetProcAddress(shell32, "SHGetIDListFromObject"); - + pfnSHCreateShellItem =(PFNSHCreateShellItem)GetProcAddress(shell32, "SHCreateShellItem"); } // SHGetFolderPath comes from shfolder.dll on older systems if (pfnSHGetFolderPath==NULL){ diff -r e6ffc1f9d677 -r d7b5e4753239 setup.py --- a/setup.py Sun May 29 19:43:15 2011 -0400 +++ b/setup.py Mon May 30 15:17:46 2011 -0400 @@ -1592,10 +1592,7 @@ """), ("win32event", "user32", None, None, "win32/src/win32event.i"), ("win32clipboard", "gdi32 user32 shell32", None), - ("win32evtlog", "advapi32 oleaut32", None, None, """ - win32\\src\\win32evtlog_messages.mc - win32\\src\\win32evtlog.i - """), + # win32gui handled below ("win32job", "user32", True, 0x0500, 'win32/src/win32job.i'), ("win32lz", "lz32", None), @@ -1651,6 +1648,14 @@ # The few that need slightly special treatment win32_extensions += [ + WinExt_win32("win32evtlog", + sources = """ + win32\\src\\win32evtlog_messages.mc win32\\src\\win32evtlog.i + """.split(), + libraries="advapi32 oleaut32", + delay_load_libraries="wevtapi", + windows_h_version=0x0600 + ), WinExt_win32("win32api", sources = """ win32/src/win32apimodule.cpp win32/src/win32api_display.cpp diff -r e6ffc1f9d677 -r d7b5e4753239 win32/src/win32evtlog.i --- a/win32/src/win32evtlog.i Sun May 29 19:43:15 2011 -0400 +++ b/win32/src/win32evtlog.i Mon May 30 15:17:46 2011 -0400 @@ -12,6 +12,7 @@ #undef PyHANDLE #include "PyWinObjects.h" +#include "WinEvt.h" // @object PyEVTLOG_HANDLE|Object representing a handle to the windows event log. // Identical to <o PyHANDLE>, but calls CloseEventLog() on destruction @@ -30,6 +31,26 @@ return "PyEVTLOG_HANDLE"; } }; + +// @object PyEVT_HANDLE|Handle to an event log, session, query, or any other object used with +// the Evt* event log functions on Vista and later. +// When the object is destroyed, EvtClose is called. +class PyEVT_HANDLE: public PyHANDLE +{ +public: + PyEVT_HANDLE(HANDLE hInit) : PyHANDLE(hInit) {} + virtual BOOL Close(void){ + BOOL ret=EvtClose(m_handle); + if (!ret) + PyWin_SetAPIError("EvtClose"); + m_handle = 0; + return ret; + } + virtual const char *GetTypeName(){ + return "PyEVT_HANDLE"; + } +}; + #define PyHANDLE HANDLE PyObject *PyWinObject_FromEVTLOG_HANDLE(HANDLE h) @@ -40,6 +61,15 @@ return ret; } +PyObject *PyWinObject_FromEVT_HANDLE(HANDLE h) +{ + PyObject *ret=new PyEVT_HANDLE(h); + if (ret==NULL){ + EvtClose(h); + PyErr_NoMemory(); + } + return ret; +} %} %typemap(python,except) PyEVTLOG_HANDLE { @@ -435,4 +465,135 @@ PyObject *obRawData // @pyparm str|RawData||Binary data for event, can be None ); +%{ + +// New event log functions available on Vista and later +// @pyswig <o PyEVT_HANDLE>|EvtOpenChannelEnum|Begins an enumeration of event channels +static PyObject *PyEvtOpenChannelEnum(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[]={"Session", "Flags", NULL}; + EVT_HANDLE session=NULL, enum_handle; + DWORD flags=0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&k:EvtOpenChannelEnum", keywords, + PyWinObject_AsHANDLE, &session, // @pyparm <o PyEVT_HANDLE>|Session|None|Handle to a remote session (see <om win32evtlog.EvtOpenSession>), or None for local machine. + &flags)) // @pyparm int|Flags|0|Reserved, use only 0 + return NULL; + enum_handle=EvtOpenChannelEnum(session, flags); + if (enum_handle==NULL) + return PyWin_SetAPIError("EvtOpenChannelEnum"); + return PyWinObject_FromEVT_HANDLE(enum_handle); +} +PyCFunction pfnPyEvtOpenChannelEnum = (PyCFunction) PyEvtOpenChannelEnum; + +// @pyswig str|EvtNextChannelPath|Retrieves a channel path from an enumeration +// @rdesc Returns None at end of enumeration +static PyObject *PyEvtNextChannelPath(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[]={"ChannelEnum", NULL}; + EVT_HANDLE enum_handle; + DWORD allocated_size=256, returned_size, err; + WCHAR *buf=NULL; + PyObject *ret=NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:EvtNextChannelPath", keywords, + PyWinObject_AsHANDLE, &enum_handle)) // @pyparm <o PyEVT_HANDLE>|ChannelEnum||Handle to an enumeration as returned by <om win32evtlog.EvtOpenChannelEnum> + return NULL; + while (true){ + if (buf) + free(buf); + // MSDN docs say sized are in bytes, but it doesn't seem to be so ??? + WCHAR *buf=(WCHAR *)malloc(allocated_size * sizeof(WCHAR)); + if (!buf) + return NULL; + if (EvtNextChannelPath(enum_handle, allocated_size, buf, &returned_size)){ + ret=PyWinObject_FromWCHAR(buf); + break; + } + err=GetLastError(); + if (err==ERROR_INSUFFICIENT_BUFFER){ + allocated_size=returned_size; + continue; + } + if (err==ERROR_NO_MORE_ITEMS){ + Py_INCREF(Py_None); + ret=Py_None; + break; + } + PyWin_SetAPIError("EvtNextChannelPath", err); + break; + } + if (buf) + free(buf); + return ret; +} +PyCFunction pfnPyEvtNextChannelPath = (PyCFunction) PyEvtNextChannelPath; + +// @pyswig <o PyEVT_HANDLE>|EvtOpenLog|Opens an event log or exported log archive +static PyObject *PyEvtOpenLog(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[]={"Path", "Flags", "Session", NULL}; + EVT_HANDLE session=NULL, log_handle; + DWORD flags=0; + WCHAR *path; + PyObject *obpath; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ok|O&:EvtOpenLog", keywords, + &obpath, // @pyparm str|Path||Event log name or Path of an export file + &flags, // @pyparm int|Flags||EvtOpenChannelPath (1) or EvtOpenFilePath (2) + PyWinObject_AsHANDLE, &session)) // @pyparm <o PyEVT_HANDLE>|Session|None|Handle to a remote session (see <om win32evtlog.EvtOpenSession>), or None for local machine. + return NULL; + if (!PyWinObject_AsWCHAR(obpath, &path, FALSE)) + return NULL; + log_handle=EvtOpenLog(session, path, flags); + PyWinObject_FreeWCHAR(path); + if (log_handle==NULL) + return PyWin_SetAPIError("EvtOpenLog"); + return PyWinObject_FromEVT_HANDLE(log_handle); +} +PyCFunction pfnPyEvtOpenLog = (PyCFunction) PyEvtOpenLog; + +// @pyswig |EvtClearLog|Clears an event log and optionally exports events to an archive +static PyObject *PyEvtClearLog(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[]={"ChannelPath", "TargetFilePath", "Session", "Flags", NULL}; + EVT_HANDLE session=NULL; + DWORD flags=0; + WCHAR *path=NULL, *export_path=NULL; + PyObject *obpath, *obexport_path=Py_None, *ret=NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO&k:EvtClearLog", keywords, + &obpath, // @pyparm str|ChannelPath||Name of event log to be cleared + &obexport_path, // @pyparm str|TargetFilePath|None|Name of file in which cleared events will be archived, or None + PyWinObject_AsHANDLE, &session, // @pyparm <o PyEVT_HANDLE>|Session|None|Handle to a remote session (see <om win32evtlog.EvtOpenSession>), or None for local machine. + &flags)) // @pyparm int|Flags|0|Reserved, use only 0 + return NULL; + if (PyWinObject_AsWCHAR(obpath, &path, FALSE) + &&PyWinObject_AsWCHAR(obexport_path, &export_path, TRUE)){ |