[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.39,1.40
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-09-22 04:39:10
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18955 Modified Files: win32apimodule.cpp Log Message: Add GetComputerNameEx, and remove "(for buffer size)" from the GetUserNameEx() error message Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** win32apimodule.cpp 7 Sep 2004 04:27:04 -0000 1.39 --- win32apimodule.cpp 22 Sep 2004 04:39:01 -0000 1.40 *************** *** 29,33 **** --- 29,40 ---- #define PyW32_BLOCK_THREADS Py_BLOCK_THREADS + #if (_WIN32_WINNT < 0x0500) + // We don't get COMPUTER_NAME_FORMAT unless we bump this. + // As we use it dynamically, we don't *need* to bump it. + typedef int COMPUTER_NAME_FORMAT; + #endif + static BOOL (WINAPI *myGetUserNameEx)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG)=NULL; + static BOOL (WINAPI *myGetComputerNameEx)(COMPUTER_NAME_FORMAT, LPWSTR, LPDWORD)=NULL; static BOOL (WINAPI *myGetLongPathNameA)(LPCSTR, LPSTR, DWORD)=NULL; static BOOL (WINAPI *myGetLongPathNameW)(LPCWSTR, LPWSTR, DWORD)=NULL; *************** *** 750,753 **** --- 757,793 ---- } + // @pymethod string|win32api|GetComputerNameEx|Retrieves a NetBIOS or DNS name associated with the local computer + static PyObject * + PyGetComputerNameEx(PyObject *self, PyObject *args) + { + if (myGetComputerNameEx==NULL) + return ReturnError("GetComputerNameEx is not supported on current platform","GetComputerNameEx"); + + WCHAR *formattedname=NULL; + COMPUTER_NAME_FORMAT fmt; + PyObject *ret = NULL; + ULONG nSize=0; + if (!PyArg_ParseTuple (args, "i:GetComputerNameEx", &fmt)) + return NULL; + // @pyseeapi GetComputerNameEx + // 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. + myGetComputerNameEx(fmt,formattedname,&nSize); + if (!nSize) + return PyWin_SetAPIError("GetComputerNameExW"); + formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR)); + if (!formattedname) + return PyErr_NoMemory(); + if (!myGetComputerNameEx(fmt,formattedname,&nSize)){ + PyWin_SetAPIError("GetComputerNameEx"); + 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 * *************** *** 782,786 **** myGetUserNameEx(fmt,formattedname,&nSize); if (!nSize) ! return PyWin_SetAPIError("GetUserNameEx (for buffer size)"); formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR)); if (!formattedname) --- 822,826 ---- myGetUserNameEx(fmt,formattedname,&nSize); if (!nSize) ! return PyWin_SetAPIError("GetUserNameExW"); formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR)); if (!formattedname) *************** *** 4351,4354 **** --- 4391,4395 ---- {"GetCommandLine", PyGetCommandLine, 1}, // @pymeth GetCommandLine|Return the application's command line. {"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 {"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 *************** *** 4557,4560 **** --- 4598,4604 ---- if (fp!=NULL) myGetLongPathNameW=(BOOL (WINAPI *)(LPCWSTR, LPWSTR, DWORD))(fp); + fp = GetProcAddress(hmodule,"GetComputerNameExW"); + if (fp!=NULL) + myGetComputerNameEx=(BOOL (WINAPI *)(COMPUTER_NAME_FORMAT, LPWSTR, LPDWORD))(fp); } } |