Click here to Skip to main content
15,886,095 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: prob with dns query Pin
ThatsAlok26-Jan-05 17:59
ThatsAlok26-Jan-05 17:59 
GeneralRe: prob with dns query Pin
Ankit Aneja27-Jan-05 3:05
Ankit Aneja27-Jan-05 3:05 
GeneralRe: prob with dns query Pin
ThatsAlok27-Jan-05 19:12
ThatsAlok27-Jan-05 19:12 
GeneralFileName from File Handle Pin
Jijo.Raj26-Jan-05 17:00
Jijo.Raj26-Jan-05 17:00 
GeneralRe: FileName from File Handle Pin
ThatsAlok26-Jan-05 17:15
ThatsAlok26-Jan-05 17:15 
GeneralRe: FileName from File Handle Pin
22491726-Jan-05 18:01
22491726-Jan-05 18:01 
GeneralRe: FileName from File Handle Pin
ThatsAlok26-Jan-05 18:44
ThatsAlok26-Jan-05 18:44 
GeneralRe: FileName from File Handle Pin
22491726-Jan-05 18:06
22491726-Jan-05 18: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 18:43
Jijo.Raj27-Jan-05 18:43 
GeneralRe: FileName from File Handle Pin
22491727-Jan-05 19:20
22491727-Jan-05 19:20 
Questioncan a protectecd class be inherited by derived class Pin
phijophlip26-Jan-05 16:53
phijophlip26-Jan-05 16:53 
AnswerRe: can a protectecd class be inherited by derived class Pin
Ryan Binns26-Jan-05 17:28
Ryan Binns26-Jan-05 17:28 
GeneralRe: can a protectecd class be inherited by derived class Pin
Aamir Butt26-Jan-05 18:44
Aamir Butt26-Jan-05 18:44 
AnswerRe: can a protectecd class be inherited by derived class Pin
toxcct26-Jan-05 22:02
toxcct26-Jan-05 22:02 
QuestionDo you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 16:00
bobi_zcl26-Jan-05 16:00 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
Ken Mazaika26-Jan-05 16:39
Ken Mazaika26-Jan-05 16:39 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 16:45
bobi_zcl26-Jan-05 16:45 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
JKallen26-Jan-05 16:45
JKallen26-Jan-05 16:45 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 19:52
bobi_zcl26-Jan-05 19:52 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
22491726-Jan-05 18:15
22491726-Jan-05 18:15 
AnswerRe: Do you still develop by Visual C++ 6.0? Pin
rwestgraham26-Jan-05 20:26
rwestgraham26-Jan-05 20:26 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
bobi_zcl26-Jan-05 21:11
bobi_zcl26-Jan-05 21:11 
GeneralRe: Do you still develop by Visual C++ 6.0? Pin
rwestgraham26-Jan-05 22:37
rwestgraham26-Jan-05 22:37 
GeneralPS: Pin
rwestgraham26-Jan-05 22:59
rwestgraham26-Jan-05 22:59 
Generallittle OLE DB question Pin
lisoft26-Jan-05 15:47
lisoft26-Jan-05 15: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.