[pywin32-checkins] pywin32/win32/src/win32wnet win32wnet.cpp, 1.19, 1.20
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2010-02-05 21:54:03
|
Update of /cvsroot/pywin32/pywin32/win32/src/win32wnet In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv27054 Modified Files: win32wnet.cpp Log Message: Add WNetGetConnection (feature req 2803660) Patch from bbondy Index: win32wnet.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/win32wnet.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** win32wnet.cpp 31 Jan 2009 05:48:36 -0000 1.19 --- win32wnet.cpp 5 Feb 2010 21:53:55 -0000 1.20 *************** *** 671,674 **** --- 671,722 ---- + // @pymethod string|win32wnet|WNetGetConnection|Retrieves the name of the network resource associated with a local device. + static + PyObject * + PyWNetGetConnection(PyObject *self, PyObject *args) + { + PyObject *ret = NULL; + PyObject *obConnection = Py_None; + DWORD length = 0; + DWORD errcode; + TCHAR *szConnection = NULL; + TCHAR *buf = NULL; + + // @pyparm string|connection|None|A string that is a drive-based path for a network resource. + // For example, if drive H has been mapped to a network drive share, and the network resource of interest is a file named Sample.doc in the directory \Win32\Examples on that share, the drive-based path is H:\Win32\Examples\Sample.doc. + if (!PyArg_ParseTuple(args, "|O", &obConnection)) + return NULL; + if (!PyWinObject_AsTCHAR(obConnection, &szConnection, TRUE)) + goto done; + // get the buffer size + { + Py_BEGIN_ALLOW_THREADS + errcode=WNetGetConnection(szConnection, NULL, &length); + Py_END_ALLOW_THREADS + } + if (length==0) { + ReturnNetError("WNetGetConnection", errcode); + goto done; + } + buf = (TCHAR *)malloc( sizeof( TCHAR) * length); + if (buf == NULL){ + PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", sizeof(TCHAR)*length); + goto done; + } + Py_BEGIN_ALLOW_THREADS + errcode = WNetGetConnection(szConnection, buf, &length); + Py_END_ALLOW_THREADS + if (0 != errcode) { + ReturnNetError("WNetGetConnection", errcode); + goto done; + } + // length includes the NULL - drop it (safely!) + ret = PyWinObject_FromTCHAR(buf, (length > 0) ? length-1 : 0); + done: + PyWinObject_FreeTCHAR(szConnection); + if (buf) free(buf); + return ret; + } + // @module win32wnet|A module that exposes the Windows Networking API. static PyMethodDef win32wnet_functions[] = { *************** *** 701,704 **** --- 749,756 ---- // @pymeth WNetGetResourceParent|Finds the parent resource of a network resource {"WNetGetResourceParent", PyWNetGetResourceParent, 1, "Finds the parent resource of a network resource"}, + // @pymeth WNetGetConnection|Retrieves the name of the network resource associated with a local device. + {"WNetGetConnection", PyWNetGetConnection, 1, "Retrieves the name of the network resource associated with a local device"}, + + {NULL, NULL} }; |