Click here to Skip to main content
14,696,278 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: prob with dns query Pin
ThatsAlok26-Jan-05 18:59
MemberThatsAlok26-Jan-05 18:59 
GeneralRe: prob with dns query Pin
Ankit Aneja27-Jan-05 4:05
MemberAnkit Aneja27-Jan-05 4:05 
GeneralRe: prob with dns query Pin
ThatsAlok27-Jan-05 20:12
MemberThatsAlok27-Jan-05 20:12 
GeneralFileName from File Handle Pin
Jijo.Raj26-Jan-05 18:00
MemberJijo.Raj26-Jan-05 18:00 
GeneralRe: FileName from File Handle Pin
ThatsAlok26-Jan-05 18:15
MemberThatsAlok26-Jan-05 18:15 
GeneralRe: FileName from File Handle Pin
22491726-Jan-05 19:01
Member22491726-Jan-05 19:01 
GeneralRe: FileName from File Handle Pin
ThatsAlok26-Jan-05 19:44
MemberThatsAlok26-Jan-05 19:44 
GeneralRe: FileName from File Handle Pin
22491726-Jan-05 19:06
Member22491726-Jan-05 19:06 
#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.\n");
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] = '\0';

if (GetLogicalDriveStrings(BUFSIZE-1, szTemp))
{
TCHAR szName[MAX_PATH];
TCHAR szDrive[3] = TEXT(" :");
BOOL bFound = FALSE;
TCHAR* p = szTemp;

do
{
// Copy the drive letter to the template string
*szDrive = *p;

// Look up each device name
if (QueryDosDevice(szDrive, szName, BUFSIZE))
{
UINT uNameLen = _tcslen(szName);

if (uNameLen < MAX_PATH)
{
bFound = _tcsnicmp(pszFilename, szName,
uNameLen) == 0;

if (bFound)
{
// Reconstruct pszFilename using szTemp
// Replace device path with DOS path
TCHAR szTempFile[MAX_PATH];
_stprintf(szTempFile,
TEXT("%s%s"),
szDrive,
pszFilename+uNameLen);
_tcsncpy(pszFilename, szTempFile, MAX_PATH);
}
}
}

// Go to the next NULL character.
while (*p++);
} while (!bFound && *p); // end of string
}
}
bSuccess = TRUE;
UnmapViewOfFile(pMem);
}

CloseHandle(hFileMap);
}
printf("File name is %s\n", pszFilename);
return(bSuccess);
}

the above code is from msdn.




Suhredayan
GeneralRe: FileName from File Handle Pin
Jijo.Raj27-Jan-05 19:43
MemberJijo.Raj27-Jan-05 19:43 
GeneralRe: FileName from File Handle Pin
22491727-Jan-05 20:20
Member22491727-Jan-05 20:20 
Questioncan a protectecd class be inherited by derived class Pin
phijophlip26-Jan-05 17:53
Memberphijophlip26-Jan-05 17:53 
AnswerRe: can a protectecd class be inherited by derived class Pin
Ryan Binns26-Jan-05 18:28
MemberRyan Binns26-Jan-05 18:28 
GeneralRe: can a protectecd class be inherited by derived class Pin
Aamir Butt26-Jan-05 19:44
MemberAamir Butt26-Jan-05 19:44 
AnswerRe: can a protectecd class be inherited by derived class Pin
toxcct26-Jan-05 23:02
Membertoxcct26-Jan-05 23:02 
QuestionDo you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 17:00
Memberbobi_zcl26-Jan-05 17:00 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
Ken Mazaika26-Jan-05 17:39
MemberKen Mazaika26-Jan-05 17:39 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 17:45
Memberbobi_zcl26-Jan-05 17:45 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
JKallen26-Jan-05 17:45
MemberJKallen26-Jan-05 17:45 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 20:52
Memberbobi_zcl26-Jan-05 20:52 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
22491726-Jan-05 19:15
Member22491726-Jan-05 19:15 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
rwestgraham26-Jan-05 21:26
Memberrwestgraham26-Jan-05 21:26 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 22:11
Memberbobi_zcl26-Jan-05 22:11 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
rwestgraham26-Jan-05 23:37
Memberrwestgraham26-Jan-05 23:37 
GeneralPS: Pin
rwestgraham26-Jan-05 23:59
Memberrwestgraham26-Jan-05 23:59 
Generallittle OLE DB question Pin
lisoft26-Jan-05 16:47
Memberlisoft26-Jan-05 16:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.