//根据文件句柄,获取文件名 #include <windows.h> #include <stdio.h> #include <tchar.h> #include <string.h> #include <psapi.h> #define BUFSIZE 512 BOOL GetFileNameFromHandle(HANDLE hFile) { BOOL bSuccess = FALSE; TCHAR pszFilename[MAX_PATH+1]; HANDLE hFileMap; // Get the file size. DWORD dwFileSizeHi = 0; DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi); if( dwFileSizeLo == 0 && dwFileSizeHi == 0 ) { printf("Cannot map a file with a length of zero. "); return FALSE; } // Create a file mapping object. hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 1, NULL); if (hFileMap) { // Create a file mapping to get the file name. void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1); if (pMem) { if (GetMappedFileName (GetCurrentProcess(), pMem, pszFilename, MAX_PATH)) { // Translate path with device name to drive letters. TCHAR szTemp[BUFSIZE]; szTemp[0] = '