// @pymethod (int,str,str)|win32wnet|WNetGetLastError|Retrieves extended error information set by a network provider when one of the WNet* functions fails // @rdesc Returns the error code, a text description of the error, and the name of the network provider // @comm The error description or the network provider name may be truncated if they exceed 1024 and 256 characters, respectively PyObject *PyWNetGetLastError(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":WNetGetLastError")) return NULL; DWORD err, extendederr; TCHAR errstr[1024], provider[256]; Py_BEGIN_ALLOW_THREADS err=WNetGetLastError(&extendederr, errstr, sizeof(errstr)/sizeof(TCHAR), provider, sizeof(provider)/sizeof(TCHAR)); Py_END_ALLOW_THREADS if (err==NO_ERROR) return Py_BuildValue("kNN", extendederr, PyWinObject_FromTCHAR(errstr), PyWinObject_FromTCHAR(provider)); return ReturnNetError("WNetGetLastError", err); }
PyObject *PyDISPLAY_DEVICE::getattro(PyObject *self, PyObject *obname) { PDISPLAY_DEVICE pdisplay_device=&((PyDISPLAY_DEVICE *)self)->display_device; char *name=PYWIN_ATTR_CONVERT(obname); if (name==NULL) return NULL; if (strcmp(name,"DeviceName")==0) if (pdisplay_device->DeviceName[31]==0) // in case DeviceName fills space and has no trailing NULL return PyWinObject_FromTCHAR(pdisplay_device->DeviceName); else return PyWinObject_FromTCHAR(pdisplay_device->DeviceName, 32); if (strcmp(name,"DeviceString")==0) if (pdisplay_device->DeviceString[127]==0) // in case DeviceString fills space and has no trailing NULL return PyWinObject_FromTCHAR(pdisplay_device->DeviceString); else return PyWinObject_FromTCHAR(pdisplay_device->DeviceString, 128); if (strcmp(name,"DeviceID")==0) if (pdisplay_device->DeviceID[127]==0) // in case DeviceID fills space and has no trailing NULL return PyWinObject_FromTCHAR(pdisplay_device->DeviceID); else return PyWinObject_FromTCHAR(pdisplay_device->DeviceID, 128); if (strcmp(name,"DeviceKey")==0) if (pdisplay_device->DeviceKey[127]==0) // in case DeviceKey fills space and has no trailing NULL return PyWinObject_FromTCHAR(pdisplay_device->DeviceKey); else return PyWinObject_FromTCHAR(pdisplay_device->DeviceKey, 128); return PyObject_GenericGetAttr(self,obname); }
static PyObject * py_get_clipboard_formatName(PyObject* self, PyObject* args) { // @pyparm int|format||Specifies the type of format to be retrieved. This // parameter must not specify any of the predefined clipboard formats. int format; if (!PyArg_ParseTuple(args, "i:GetClipboardFormatName", &format)) { return NULL; } TCHAR buf[256]; int rc; Py_BEGIN_ALLOW_THREADS; rc = GetClipboardFormatName((UINT)format, buf, 255); Py_END_ALLOW_THREADS; if (!rc) { return ReturnAPIError("GetClipboardFormatName"); } return PyWinObject_FromTCHAR(buf); // @pyseeapi GetClipboardFormatName // @rdesc If the function succeeds, the return value is the string containing // the format.<nl> // If the function fails, win32api.error is raised with the GetLastError // info. }
// @pymethod str|PyIShellLink|GetArguments|Retrieves the command-line arguments associated with a shell link object. PyObject *PyIShellLink::GetArguments(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; // @pyparm int|cchMaxName|1024|Number of characters to fetch. int cchMaxName = 1024; if ( !PyArg_ParseTuple(args, "|i:GetArguments", &cchMaxName) ) return NULL; HRESULT hr; TCHAR *pszName = (TCHAR *)malloc(cchMaxName * sizeof(TCHAR) ); if (pszName==NULL) { PyErr_SetString(PyExc_MemoryError, "allocating string buffer"); return NULL; } PY_INTERFACE_PRECALL; hr = pISL->GetArguments( pszName, cchMaxName ); PY_INTERFACE_POSTCALL; PyObject *ret; if ( FAILED(hr) ) ret = OleSetOleError(hr); else ret = PyWinObject_FromTCHAR(pszName); free(pszName); return ret; }
// @pymethod str|PyIShellLink|GetIconLocation|Retrieves the location (path and index) of the icon for a shell link object. PyObject *PyIShellLink::GetIconLocation(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; // @pyparm int|cchMaxPath|_MAX_PATH|Number of characters to allocate for the result string. int cchIconPath = _MAX_PATH; if ( !PyArg_ParseTuple(args, "|i:GetIconLocation", &cchIconPath) ) return NULL; TCHAR *pszIconPath = (TCHAR *)malloc(cchIconPath * sizeof(TCHAR) ); if (pszIconPath==NULL) { PyErr_SetString(PyExc_MemoryError, "allocating string buffer"); return NULL; } HRESULT hr; int iIcon; PY_INTERFACE_PRECALL; hr = pISL->GetIconLocation( pszIconPath, cchIconPath, &iIcon ); PY_INTERFACE_POSTCALL; PyObject *ret; if ( FAILED(hr) ) ret = OleSetOleError(hr); else ret = Py_BuildValue("Ni", PyWinObject_FromTCHAR(pszIconPath), iIcon); free(pszIconPath); return ret; }
PyObject *PyNETRESOURCE::getattro(PyObject *self, PyObject *obname) { char *name=PYWIN_ATTR_CONVERT(obname); if (name==NULL) return NULL; PyNETRESOURCE *This = (PyNETRESOURCE *)self; if (strcmp(name, "lpProvider")==0) return PyWinObject_FromTCHAR(This->m_nr.lpProvider); if (strcmp(name, "lpRemoteName")==0) return PyWinObject_FromTCHAR(This->m_nr.lpRemoteName); if (strcmp(name, "lpLocalName")==0) return PyWinObject_FromTCHAR(This->m_nr.lpLocalName); if (strcmp(name, "lpComment")==0) return PyWinObject_FromTCHAR(This->m_nr.lpComment); return PyObject_GenericGetAttr(self, obname); }
// @pymethod string|PyCDocument|GetTitle|Returns the title of the current document. // This will often be the file name portion of the path name. PyObject * ui_doc_get_title(PyObject *self, PyObject *args) { CDocument *pDoc; if (!(pDoc=PyCDocument::GetDoc(self))) return NULL; CHECK_NO_ARGS2(args,GetTitle); GUI_BGN_SAVE; CString path = pDoc->GetTitle(); // @pyseemfc CDocument|GetTitle GUI_END_SAVE; return PyWinObject_FromTCHAR(path); }
// @pymethod string|PyCMenu|GetMenuString|Returns the string for a specified menu item. PyObject *PyCMenu::GetMenuString(PyObject *self, PyObject *args) { HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; int id,flags = MF_BYCOMMAND; if (!PyArg_ParseTuple(args,"i|i", &id, // @pyparm int|id||The id of the item being requested. &flags)) // @pyparm int|flags|win32con.MF_BYCOMMAND|Specifies how the id parameter is interpreted. It must be one of win32con.MF_BYCOMMAND or win32con.MF_BYPOSITION. return NULL; TCHAR buf[128]; if (::GetMenuString(hMenu, id, buf, sizeof(buf)/sizeof(TCHAR), flags)==0) buf[0] = 0; return PyWinObject_FromTCHAR(buf); }
// @pymethod int|PyCListCtrl|GetItemText|Retrieves the text of a list view item or subitem. PyObject *PyCListCtrl_GetItemText( PyObject *self, PyObject *args ) { int item, sub; // TCHAR buf[256]; if (!PyArg_ParseTuple( args, "ii:GetItemText", &item, // @pyparm int|item||The index of the item whose text is to be retrieved. &sub)) // @pyparm int|sub||Specifies the subitem whose text is to be retrieved. return NULL; CListCtrl *pList = GetListCtrl(self); if (!pList) return NULL; GUI_BGN_SAVE; // int len = pList->GetItemText(item, sub, buf, sizeof(buf)/sizeof(TCHAR)); CString s = pList->GetItemText(item, sub); GUI_END_SAVE; return PyWinObject_FromTCHAR(s); }
// @pymethod int|PyCTreeCtrl|GetItemText|Retrieves the text of a list view item or subitem. PyObject *PyCTreeCtrl_GetItemText( PyObject *self, PyObject *args ) { PyObject *obItem; if (!PyArg_ParseTuple( args, "O:GetItemText", &obItem)) // @pyparm HTREEITEM|item||The item whose text is to be retrieved. return NULL; CTreeCtrl *pList = GetTreeCtrl(self); if (!pList) return NULL; HTREEITEM item; if (!PyWinObject_AsHANDLE(obItem, (HANDLE *)&item)) return NULL; GUI_BGN_SAVE; CString csText = pList->GetItemText(item); GUI_END_SAVE; return PyWinObject_FromTCHAR(csText); }
// @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; }
// @pymethod string|win32wnet|WNetGetUser|Retrieves the current default user name, or the user name used to establish a network connection. static PyObject * PyWNetGetUser(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 specifies either the name of a local device that has been redirected to a network resource, or the remote name of a network resource to which a connection has been made without redirecting a local device. // If this parameter is None, the system returns the name of the current user for the process. 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=WNetGetUser(szConnection, NULL, &length); Py_END_ALLOW_THREADS } if (length==0) { ReturnNetError("WNetGetUser", 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 = WNetGetUser(szConnection, buf, &length); Py_END_ALLOW_THREADS if (0 != errcode) { ReturnNetError("WNetGetUser", 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; }
// @pymethod string|win32lz|GetExpandedName|Retrieves the original name of an expanded file, static PyObject * PyGetExpandedName(PyObject *self, PyObject *args) { TCHAR outName[_MAX_PATH+1]; TCHAR *nameIn; PyObject *obnameIn; if (!PyArg_ParseTuple(args, "O:GetExpandedName", &obnameIn )) // @pyparm str|Source||Name of a compressed file return NULL; if (!PyWinObject_AsTCHAR(obnameIn, &nameIn, FALSE)) return NULL; // @pyseeapi GetExpandedName int ret = GetExpandedName(nameIn, outName); PyWinObject_FreeTCHAR(nameIn); if (ret!=1) return ReturnLZError("GetExpandedName", ret); return PyWinObject_FromTCHAR(outName); }
// @pymethod (<o PyNETRESOURCE>, str)|win32wnet|WNetGetResourceInformation|Finds the type and provider of a network resource // @rdesc Returns a NETRESOURCE and a string containing the trailing part of the remote path PyObject * PyWNetGetResourceInformation(PyObject *self, PyObject *args) { PyObject *NRT, *ret=NULL; //object placeholder for incoming NETRESOURCE object NETRESOURCE *nrin, *nrout=NULL; // buffer holds a NETRESOURCE struct and all its string members DWORD bufsize=sizeof(NETRESOURCE)+256; DWORD err; LPTSTR szFilePath = NULL; #ifdef Py_DEBUG bufsize=sizeof(NETRESOURCE); // make sure it loops thru again in debug mode #endif if (!PyArg_ParseTuple(args, "O!", &PyNETRESOURCEType, &NRT)) // @pyparm <o PyNETRESOURCE>|NetResource||Describes a network resource. lpRemoteName is required, dwType and lpProvider can be supplied if known return NULL; if (!PyWinObject_AsNETRESOURCE(NRT, &nrin, FALSE)) return NULL; while (1){ // function will not take NULL to return the buffer size, always pass in a valid buffer if (nrout) free(nrout); nrout=(NETRESOURCE *)malloc(bufsize); if (nrout==NULL) return PyErr_Format(PyExc_MemoryError,"Unable to allocate %d bytes", bufsize); Py_BEGIN_ALLOW_THREADS err = WNetGetResourceInformation(nrin, nrout, &bufsize, &szFilePath); Py_END_ALLOW_THREADS if (err == NO_ERROR){ ret=Py_BuildValue("NN", PyWinObject_FromNETRESOURCE(nrout), PyWinObject_FromTCHAR(szFilePath)); break; } else if (err!=ERROR_MORE_DATA){ ReturnNetError("WNetGetResourceInformation", err); break; } } if (nrout) free(nrout); return ret; }
// @pymethod int|PyCEdit|GetLine|Returns the text in a specified line. static PyObject * PyCEdit_get_line(PyObject *self, PyObject *args) { CEdit *pEdit = GetEditCtrl(self); if (!pEdit) return NULL; GUI_BGN_SAVE; int lineNo = pEdit->LineFromChar(); GUI_END_SAVE; // @pyparm int|lineNo|current|Contains the zero-based index value for the desired line. // @comm This function is not an MFC wrapper. if (!PyArg_ParseTuple(args, "|i:GetLine", &lineNo)) return NULL; int size = 1024; // ahhhhh-this fails with 128, even when line len==4! // god damn it - try and write a fairly efficient normal case, // and handle worst case, and look what happens! CString csBuffer; // use dynamic mem for buffer TCHAR *buf; int bytesCopied; // this TRACE _always_ returns the length of the first line - hence the // convaluted code below. // TRACE("LineLength for line %d is %d\n", lineNo, pView->GetEditCtrl().LineLength(lineNo)); // loop if buffer too small, increasing each time. while (size<0x7FFF) // reasonable line size max? - maxuint on 16 bit. { buf = csBuffer.GetBufferSetLength(size); if (buf==NULL) RETURN_ERR("Out of memory getting Edit control line value"); GUI_BGN_SAVE; bytesCopied = pEdit->GetLine(lineNo, buf, size); GUI_END_SAVE; if (bytesCopied!=size) // ok - get out. break; // buffer too small size += size; // try doubling! TRACE0("Doubling buffer for GetLine value\n"); } if (bytesCopied==size) // hit max. --bytesCopied; // so NULL doesnt overshoot. if (buf[bytesCopied-1]=='\r' || buf[bytesCopied-1]=='\n') // kill newlines. --bytesCopied; buf[bytesCopied] = '\0'; return PyWinObject_FromTCHAR(buf); }
// This function sets a basic COM error - it is a valid COM // error, but may not contain rich error text about the error. // Designed to be used before pythoncom has been loaded. // If a COM extension wants to raise a COM error, it should use // the "real" functions exposed via pythoncom. PyObject *PyWin_SetBasicCOMError(HRESULT hr) { TCHAR buf[255]; int bufSize = sizeof(buf)/sizeof(TCHAR); int numCopied = ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, buf, bufSize, NULL ); if (numCopied>0) { if (numCopied<bufSize) { // trim trailing crap if (numCopied>2 && (buf[numCopied-2]==_T('\n')||buf[numCopied-2]==_T('\r'))) buf[numCopied-2] = _T('\0'); } } else { wsprintf(buf, _T("COM Error 0x%x"), hr); } PyObject *evalue = Py_BuildValue("iNzz", hr, PyWinObject_FromTCHAR(buf), NULL, NULL); PyErr_SetObject(PyWinExc_COMError, evalue); Py_XDECREF(evalue); return NULL; }
// @pymethod str, <o WIN32_FIND_DATA>|PyIShellLink|GetPath|Retrieves the target path and file name of a shell link object // @comm The AlternateFileName (8.3) member of WIN32_FIND_DATA does not return information PyObject *PyIShellLink::GetPath(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; WIN32_FIND_DATA fd; // @pyparm int|fFlags||One of the following values: // @flagh Value|Description // @flag SLGP_SHORTPATH|Retrieves the standard short (8.3 format) file name. // @flag SLGP_UNCPRIORITY|Retrieves the Universal Naming Convention (UNC) path name of the file. // @flag SLGP_RAWPATH|Retrieves the raw path name. A raw path is something that might not exist and may include environment variables that need to be expanded. // @pyparm int|cchMaxPath|_MAX_PATH|Number of characters to allocate for returned filename int cchMaxPath = _MAX_PATH; DWORD fFlags; if ( !PyArg_ParseTuple(args, "l|i:GetPath", &fFlags, &cchMaxPath) ) return NULL; HRESULT hr; TCHAR *pszFile = (TCHAR *)malloc(cchMaxPath * sizeof(TCHAR)); if (pszFile==NULL) { PyErr_SetString(PyExc_MemoryError, "allocating string buffer"); return NULL; } ZeroMemory(&fd, sizeof(fd)); PY_INTERFACE_PRECALL; hr = pISL->GetPath( pszFile, cchMaxPath, &fd, fFlags ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) { free(pszFile); return OleSetOleError(hr); } PyObject *ret = Py_BuildValue("NN", PyWinObject_FromTCHAR(pszFile), PyObject_FromWIN32_FIND_DATA(&fd)); free(pszFile); return ret; }
/* error helper - GetLastError() is provided, but this is for exceptions */ PyObject *PyWin_SetAPIError(char *fnName, long err /*= 0*/) { DWORD errorCode = err == 0 ? GetLastError() : err; DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | \ FORMAT_MESSAGE_IGNORE_INSERTS; // try and find the hmodule providing this error. HMODULE hmodule = PyWin_GetErrorMessageModule(errorCode); if (hmodule) flags |= FORMAT_MESSAGE_FROM_HMODULE; TCHAR *buf = NULL; BOOL free_buf = TRUE; if (errorCode) ::FormatMessage(flags, hmodule, errorCode, 0, (LPTSTR)&buf, 0, NULL ); if (!buf) { buf = _T("No error message is available"); free_buf = FALSE; } /* strip trailing cr/lf */ size_t end = _tcslen(buf)-1; if (end>1 && (buf[end-1]==_T('\n') || buf[end-1]==_T('\r'))) buf[end-1] = _T('\0'); else if (end>0 && (buf[end]==_T('\n') || buf[end]==_T('\r'))) buf[end]=_T('\0'); PyObject *v = Py_BuildValue("(iNN)", errorCode, PyWinCoreString_FromString(fnName), PyWinObject_FromTCHAR(buf)); if (free_buf && buf) LocalFree(buf); if (v != NULL) { PyErr_SetObject(PyWinExc_ApiError, v); Py_DECREF(v); } return NULL; }
// @pymethod dict|win32api|GetMonitorInfo|Retrieves information for a monitor by handle // @rdesc Returns a dictionary representing a MONITORINFOEX structure // @comm Accepts keyword args PyObject *PyGetMonitorInfo(PyObject *self, PyObject *args, PyObject *kwargs) { CHECK_PFN(GetMonitorInfo); static char *keywords[]={"hMonitor", NULL}; PyObject *obhMonitor; HMONITOR hMonitor; MONITORINFOEX mi; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GetMonitorInfo", keywords, &obhMonitor)) // @pyparm <o PyHANDLE>|hMonitor||Handle to a monitor return NULL; if (!PyWinObject_AsHANDLE(obhMonitor, (HANDLE *)&hMonitor)) return NULL; ZeroMemory(&mi, sizeof(mi)); mi.cbSize=sizeof(mi); if (!(*pfnGetMonitorInfo)(hMonitor, &mi)){ PyWin_SetAPIError("GetMonitorInfo"); return NULL; } return Py_BuildValue("{s:O&,s:O&,s:k,s:N}", "Monitor", PyWinObject_FromRECT, &mi.rcMonitor, "Work", PyWinObject_FromRECT, &mi.rcWork, "Flags", mi.dwFlags, "Device", PyWinObject_FromTCHAR(mi.szDevice)); }
// @pymethod string/tuple|win32wnet|WNetGetUniversalName|Takes a drive-based path for a network resource and returns an information structure that contains a more universal form of the name. static PyObject * PyWNetGetUniversalName(PyObject *self, PyObject *args) { int level = UNIVERSAL_NAME_INFO_LEVEL; TCHAR *szLocalPath = NULL; PyObject *obLocalPath; void *buf = NULL; DWORD length = 0; PyObject *ret = NULL; DWORD errcode; if (!PyArg_ParseTuple(args, "O|i:WNetGetUniversalName", &obLocalPath, &level)) return NULL; if (!PyWinObject_AsTCHAR(obLocalPath, &szLocalPath, FALSE)) return NULL; // @pyparm string|localPath||A string that is a drive-based path for a network resource. // <nl>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. // @pyparm int|infoLevel|UNIVERSAL_NAME_INFO_LEVEL|Specifies the type of structure that the function stores in the buffer pointed to by the lpBuffer parameter. // This parameter can be one of the following values. // @flagh Value|Meaning // @flag UNIVERSAL_NAME_INFO_LEVEL (=1)|The function returns a simple string with the UNC name. // @flag REMOTE_NAME_INFO_LEVEL (=2)|The function returns a tuple based in the Win32 REMOTE_NAME_INFO data structure. // @rdesc If the infoLevel parameter is REMOTE_NAME_INFO_LEVEL, the result is a tuple of 3 strings: (UNCName, connectionName, remainingPath) // First get the buffer size. { Py_BEGIN_ALLOW_THREADS char temp_buf[] = ""; // doesnt appear to like NULL!! errcode = WNetGetUniversalName( szLocalPath, level, &temp_buf, &length); Py_END_ALLOW_THREADS } if (errcode != ERROR_MORE_DATA || length == 0) { ReturnNetError("WNetGetUniversalName (for buffer size)", errcode); goto done; } buf = malloc(length); if (buf==NULL) goto done; errcode = WNetGetUniversalName( szLocalPath, level, buf, &length); if (errcode != 0) { ReturnNetError("WNetGetUniversalName", errcode); goto done; } switch (level) { case UNIVERSAL_NAME_INFO_LEVEL: ret = PyWinObject_FromTCHAR( ((UNIVERSAL_NAME_INFO *)buf)->lpUniversalName ); break; case REMOTE_NAME_INFO_LEVEL: { REMOTE_NAME_INFO *r = (REMOTE_NAME_INFO *)buf; ret = PyTuple_New(3); if (ret==NULL) goto done; PyTuple_SET_ITEM(ret, 0, PyWinObject_FromTCHAR( r->lpUniversalName) ); PyTuple_SET_ITEM(ret, 1, PyWinObject_FromTCHAR( r->lpConnectionName) ); PyTuple_SET_ITEM(ret, 2, PyWinObject_FromTCHAR( r->lpRemainingPath) ); break; } default: PyErr_SetString(PyExc_TypeError, "Unsupported infoLevel"); } done: PyWinObject_FreeTCHAR(szLocalPath); if (buf) free(buf); return ret; }