找到一段 VC 的代码. 哪位兄弟帮翻译下?<br><br>#include <windows.h><br>#include <stdio.h><br>#include <tchar.h><br>#include <string.h><br>#include <psapi.h><br><br>#define BUFSIZE 512<br><br>BOOL GetFileNameFromHandle(HANDLE hFile) <br>{<br> BOOL bSuccess = FALSE;<br> TCHAR pszFilename[MAX_PATH+1];<br> HANDLE hFileMap;<br><br> // Get the file size.<br> DWORD dwFileSizeHi = 0;<br> DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi); <br><br> if( dwFileSizeLo == 0 && dwFileSizeHi == 0 )<br> {<br> printf("Cannot map a file with a length of zero./n"
;<br> return FALSE;<br> }<br><br> // Create a file mapping object.<br> hFileMap = CreateFileMapping(hFile, <br> NULL, <br> PAGE_READONLY,<br> 0, <br> 1,<br> NULL);<br><br> if (hFileMap) <br> {<br> // Create a file mapping to get the file name.<br> void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);<br><br> if (pMem) <br> {<br> if (GetMappedFileName (GetCurrentProcess(), <br> pMem, <br> pszFilename,<br> MAX_PATH)) <br> {<br><br> // Translate path with device name to drive letters.<br> TCHAR szTemp[BUFSIZE];<br> szTemp[0] = '/0';<br><br> if (GetLogicalDriveStrings(BUFSIZE-1, szTemp)) <br> {<br> TCHAR szName[MAX_PATH];<br> TCHAR szDrive[3] = TEXT(" :"
;<br> BOOL bFound = FALSE;<br> TCHAR* p = szTemp;<br><br> do <br> {<br> // Copy the drive letter to the template string<br> *szDrive = *p;<br><br> // Look up each device name<br> if (QueryDosDevice(szDrive, szName, BUFSIZE))<br> {<br> UINT uNameLen = _tcslen(szName);<br><br> if (uNameLen < MAX_PATH) <br> {<br> bFound = _tcsnicmp(pszFilename, szName, <br> uNameLen) == 0;<br><br> if (bFound) <br> {<br> // Reconstruct pszFilename using szTemp<br> // Replace device path with DOS path<br> TCHAR szTempFile[MAX_PATH];<br> _stprintf(szTempFile,<br> TEXT("%s%s"
,<br> szDrive,<br> pszFilename+uNameLen);<br> _tcsncpy(pszFilename, szTempFile, MAX_PATH);<br> }<br> }<br> }<br><br> // Go to the next NULL character.<br> while (*p++);<br> } while (!bFound && *p); // end of string<br> }<br> }<br> bSuccess = TRUE;<br> UnmapViewOfFile(pMem);<br> } <br><br> CloseHandle(hFileMap);<br> }<br> printf("File name is %s/n", pszFilename);<br> return(bSuccess);<br>}