[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.27,1.28
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: <mha...@us...> - 2003-10-23 01:53:20
|
Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv13992
Modified Files:
win32apimodule.cpp
Log Message:
Added GetLongPathName and GetLongPAthNameW
Index: win32apimodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** win32apimodule.cpp 21 Oct 2003 02:06:45 -0000 1.27
--- win32apimodule.cpp 23 Oct 2003 01:20:20 -0000 1.28
***************
*** 38,41 ****
--- 38,43 ----
static BOOL (WINAPI *myGetUserNameEx)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG)=NULL;
+ static BOOL (WINAPI *myGetLongPathNameA)(LPCSTR, LPSTR, DWORD)=NULL;
+ static BOOL (WINAPI *myGetLongPathNameW)(LPCWSTR, LPWSTR, DWORD)=NULL;
/* error helper */
***************
*** 1572,1575 ****
--- 1574,1624 ----
}
+ // @pymethod string|win32api|GetLongPathName|Converts the specified path to its long form.
+ static PyObject *
+ PyGetLongPathNameA (PyObject *self, PyObject *args)
+ {
+ char pathBuf[MAX_PATH];
+ char *fileName;
+ if (!myGetLongPathNameA)
+ PyErr_SetString(PyExc_NotImplementedError, "GetLongPathNameA does not exist in this version of Windows");
+ // @pyparm string|fileName||The file name.
+ if (!PyArg_ParseTuple (args, "s:GetLongPathName", &fileName))
+ return NULL;
+ PyW32_BEGIN_ALLOW_THREADS
+ BOOL ok = (*myGetLongPathNameA)(fileName, pathBuf, sizeof(pathBuf));
+ PyW32_END_ALLOW_THREADS
+ if (!ok)
+ return ReturnAPIError("GetLongPathName");
+ return Py_BuildValue("s", pathBuf);
+ // @comm This function may raise a NotImplementedError exception if the version
+ // of Windows does not support this function.
+ }
+
+ // @pymethod unicode|win32api|GetLongPathNameW|Converts the specified path to its long form.
+ static PyObject *
+ PyGetLongPathNameW (PyObject *self, PyObject *args)
+ {
+ WCHAR pathBuf[MAX_PATH];
+ WCHAR *fileName;
+ if (!myGetLongPathNameW)
+ PyErr_SetString(PyExc_NotImplementedError, "GetLongPathNameW does not exist in this version of Windows");
+ // @pyparm string|fileName||The file name.
+ PyObject *obFileName;
+ if (!PyArg_ParseTuple (args, "O:GetLongPathNameW", &obFileName))
+ return NULL;
+ if (!PyWinObject_AsWCHAR(obFileName, &fileName))
+ return NULL;
+ PyW32_BEGIN_ALLOW_THREADS
+ BOOL ok = (*myGetLongPathNameW)(fileName, pathBuf, sizeof(pathBuf)/sizeof(pathBuf[0]));
+ PyW32_END_ALLOW_THREADS
+ PyWinObject_FreeWCHAR(fileName);
+ if (!ok)
+ return ReturnAPIError("GetLongPathName");
+ return PyWinObject_FromWCHAR(pathBuf);
+ // @comm This function may raise a NotImplementedError exception if the version
+ // of Windows does not support this function.
+ }
+
+
// @pymethod string|win32api|GetTickCount|Returns the number of milliseconds since windows started.
static PyObject *
***************
*** 4213,4216 ****
--- 4262,4267 ----
{"GetLastError", PyGetLastError, 1}, // @pymeth GetLastError|Retrieves the last error code known by the system.
{"GetLocalTime", PyGetLocalTime, 1}, // @pymeth GetLocalTime|Returns the current local time.
+ {"GetLongPathName", PyGetLongPathNameA, 1}, // @pymeth GetLongPathName|Converts the specified path to its long form.
+ {"GetLongPathNameW", PyGetLongPathNameW, 1}, // @pymeth GetLongPathNameW|Converts the specified path to its long form.
{"GetLogicalDrives", PyGetLogicalDrives, 1}, // @pymeth GetLogicalDrives|Returns a bitmask representing the currently available disk drives.
{"GetLogicalDriveStrings", PyGetLogicalDriveStrings, 1}, // @pymeth GetLogicalDriveStrings|Returns a list of strings for all the drives.
***************
*** 4387,4392 ****
FARPROC fp = GetProcAddress(hmodule,"GetUserNameExW");
if (fp!=NULL)
! myGetUserNameEx=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp);
! }
}
--- 4438,4452 ----
FARPROC fp = GetProcAddress(hmodule,"GetUserNameExW");
if (fp!=NULL)
! myGetUserNameEx=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp);
! }
! hmodule = LoadLibrary("kernel32.dll");
! if (hmodule!=NULL){
! FARPROC fp = GetProcAddress(hmodule,"GetLongPathNameA");
! if (fp!=NULL)
! myGetLongPathNameA=(BOOL (WINAPI *)(LPCSTR, LPSTR, DWORD))(fp);
! fp = GetProcAddress(hmodule,"GetLongPathNameW");
! if (fp!=NULL)
! myGetLongPathNameW=(BOOL (WINAPI *)(LPCWSTR, LPWSTR, DWORD))(fp);
! }
}
|