Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv19016
Modified Files:
win32apimodule.cpp
Log Message:
GetUserNameEx() was failing on XP.
Index: win32apimodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** win32apimodule.cpp 23 Oct 2003 01:20:20 -0000 1.28
--- win32apimodule.cpp 26 Oct 2003 03:59:51 -0000 1.29
***************
*** 782,797 ****
return NULL;
// @pyseeapi GetUserNameEx
if (!myGetUserNameEx(fmt,formattedname,&nSize)){
! // returned string includes trailing null, so should always fail with 0 len
! if (GetLastError()!=ERROR_MORE_DATA){
! PyWin_SetAPIError("GetUserNameEx");
! goto done;
! }
! formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR));
! if (!myGetUserNameEx(fmt,formattedname,&nSize)){
! PyWin_SetAPIError("GetUserNameEx");
! goto done;
! }
! }
ret=PyWinObject_FromWCHAR(formattedname);
done:
--- 782,797 ----
return NULL;
// @pyseeapi GetUserNameEx
+ // 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.
+ myGetUserNameEx(fmt,formattedname,&nSize);
+ if (!nSize)
+ return PyWin_SetAPIError("GetUserNameEx (for buffer size)");
+ formattedname=(WCHAR *)malloc(nSize*sizeof(WCHAR));
+ if (!formattedname)
+ return PyErr_NoMemory();
if (!myGetUserNameEx(fmt,formattedname,&nSize)){
! PyWin_SetAPIError("GetUserNameEx");
! goto done;
! }
ret=PyWinObject_FromWCHAR(formattedname);
done:
|