[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.40,1.41
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-09-24 06:38:19
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16743 Modified Files: win32apimodule.cpp Log Message: Add GetComputerObjectName() Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** win32apimodule.cpp 22 Sep 2004 04:39:01 -0000 1.40 --- win32apimodule.cpp 24 Sep 2004 06:38:10 -0000 1.41 *************** *** 37,40 **** --- 37,41 ---- static BOOL (WINAPI *myGetUserNameEx)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG)=NULL; static BOOL (WINAPI *myGetComputerNameEx)(COMPUTER_NAME_FORMAT, LPWSTR, LPDWORD)=NULL; + static BOOL (WINAPI *myGetComputerObjectName)(EXTENDED_NAME_FORMAT, LPWSTR, LPDWORD)=NULL; static BOOL (WINAPI *myGetLongPathNameA)(LPCSTR, LPSTR, DWORD)=NULL; static BOOL (WINAPI *myGetLongPathNameW)(LPCWSTR, LPWSTR, DWORD)=NULL; *************** *** 790,793 **** --- 791,827 ---- } + // @pymethod string|win32api|GetComputerObjectName|Retrieves the local computer's name in a specified format. + static PyObject * + PyGetComputerObjectName(PyObject *self, PyObject *args) + { + if (myGetComputerObjectName==NULL) + return ReturnError("GetComputerObjectName is not supported on current platform","GetComputerNameEx"); + + WCHAR *formattedname=NULL; + EXTENDED_NAME_FORMAT fmt; + PyObject *ret = NULL; + ULONG nSize=0; + if (!PyArg_ParseTuple (args, "i:GetComputerObjectName", &fmt)) + return NULL; + // @pyseeapi GetComputerObjectName + // We always get into trouble with WinXP vs 2k error codes. + // Simply assume that if we have a size, the function gave us the correct one. + myGetComputerObjectName(fmt,formattedname,&nSize); + if (!nSize) + return PyWin_SetAPIError("GetComputerObjectName"); + formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR)); + if (!formattedname) + return PyErr_NoMemory(); + if (!myGetComputerObjectName(fmt,formattedname,&nSize)){ + PyWin_SetAPIError("GetComputerObjectName"); + goto done; + } + ret=PyWinObject_FromWCHAR(formattedname); + done: + if (formattedname!=NULL) + free(formattedname); + return ret; + } + // @pymethod string|win32api|GetUserName|Returns the current user name static PyObject * *************** *** 4392,4395 **** --- 4426,4430 ---- {"GetComputerName", PyGetComputerName, 1}, // @pymeth GetComputerName|Returns the local computer name {"GetComputerNameEx", PyGetComputerNameEx, 1}, // @pymeth GetComputerNameEx|Retrieves a NetBIOS or DNS name associated with the local computer + {"GetComputerObjectName",PyGetComputerObjectName, 1}, // @pymeth GetComputerObjectName|Retrieves the local computer's name in a specified format {"GetUserName", PyGetUserName, 1}, // @pymeth GetUserName|Returns the current user name. {"GetUserNameEx", PyGetUserNameEx, 1}, // @pymeth GetUserNameEx|Returns the current user name in format specified by Name* constants *************** *** 4589,4592 **** --- 4624,4630 ---- if (fp!=NULL) myGetUserNameEx=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp); + fp = GetProcAddress(hmodule,"GetComputerObjectNameW"); + if (fp!=NULL) + myGetComputerObjectName=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp); } hmodule = LoadLibrary("kernel32.dll"); |