[pywin32-checkins] pywin32/win32/src win32pipe.i,1.15,1.16
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-09-09 01:38:07
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26532/win32/src Modified Files: win32pipe.i Log Message: Add GetNamedPipeClientProcessId and GetNamedPipeServerProcessId Index: win32pipe.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32pipe.i,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** win32pipe.i 6 Jun 2007 21:41:46 -0000 1.15 --- win32pipe.i 9 Sep 2007 01:38:09 -0000 1.16 *************** *** 14,17 **** --- 14,21 ---- %{ + #define CHECK_PFN(fname)if (pfn##fname==NULL) return PyErr_Format(PyExc_NotImplementedError,"%s is not available on this platform", #fname); + typedef BOOL (WINAPI *GetNamedPipeClientProcessIdfunc)(HANDLE, PULONG); + static GetNamedPipeClientProcessIdfunc pfnGetNamedPipeClientProcessId = NULL; + static GetNamedPipeClientProcessIdfunc pfnGetNamedPipeServerProcessId = NULL; // Global used to determine if Win9x win32pipe hack is necessary. *************** *** 113,116 **** --- 117,127 ---- } } + HMODULE hmod=GetModuleHandle("Kernel32.dll"); + if (!hmod) + hmod=LoadLibrary("Kernel32.dll"); + if (hmod){ + pfnGetNamedPipeClientProcessId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeClientProcessId"); + pfnGetNamedPipeServerProcessId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeServerProcessId"); + } %} *************** *** 456,457 **** --- 467,509 ---- %native(PeekNamedPipe) MyPeekNamedPipe; + + %{ + // @pyswig int|GetNamedPipeClientProcessId|Returns the process id of client that is connected to a named pipe + // @comm Requires Vista or later + PyObject *MyGetNamedPipeClientProcessId(PyObject *self, PyObject *args) + { + CHECK_PFN(GetNamedPipeClientProcessId); + HANDLE hNamedPipe; + DWORD pid; + PyObject *obhNamedPipe; + // @pyparm <o PyHANDLE>|hPipe||The handle to the pipe. + if (!PyArg_ParseTuple(args, "O:GetNamedPipeClientProcessId", &obhNamedPipe)) + return NULL; + if (!PyWinObject_AsHANDLE(obhNamedPipe, &hNamedPipe)) + return NULL; + if (!(*pfnGetNamedPipeClientProcessId)(hNamedPipe, &pid)) + return PyWin_SetAPIError("GetNamedPipeClientProcessId"); + return PyLong_FromUnsignedLong(pid); + } + + // @pyswig int|GetNamedPipeServerProcessId|Returns pid of server process that created a named pipe + // @comm Requires Vista or later + PyObject *MyGetNamedPipeServerProcessId(PyObject *self, PyObject *args) + { + CHECK_PFN(GetNamedPipeServerProcessId); + HANDLE hNamedPipe; + DWORD pid; + PyObject *obhNamedPipe; + // @pyparm <o PyHANDLE>|hPipe||The handle to the pipe. + if (!PyArg_ParseTuple(args, "O:GetNamedPipeServerProcessId", &obhNamedPipe)) + return NULL; + if (!PyWinObject_AsHANDLE(obhNamedPipe, &hNamedPipe)) + return NULL; + if (!(*pfnGetNamedPipeServerProcessId)(hNamedPipe, &pid)) + return PyWin_SetAPIError("GetNamedPipeServerProcessId"); + return PyLong_FromUnsignedLong(pid); + } + %} + %native(GetNamedPipeClientProcessId) MyGetNamedPipeClientProcessId; + %native(GetNamedPipeServerProcessId) MyGetNamedPipeServerProcessId; + |