in tools/ExeView/res.cpp [29:123]
BOOL LoadResourcePacket(PEXEINFO pExeInfo, PRESTYPE prt, PRESINFO pri, LPRESPACKET lprp)
{
int fFile;
OFSTRUCT of;
int nErr = 0;
LONG lSize;
LONG lOffset;
HANDLE hMem;
LPSTR lpMem;
char *lpTMem;
if (!pExeInfo || !prt || !pri)
{
MessageBox(ghWndMain,"Unable to display resource!","EXEVIEW",MB_OK);
return FALSE;
}
if (pExeInfo->NewHdr.wExpVersion < 0x0300) // Win 2.x app??
{
MessageBox(ghWndMain,"Unable to display resource! Windows 2.X app.","EXEVIEW",MB_OK);
return FALSE;
}
fFile = OpenFile( pExeInfo->pFilename, &of, OF_READ );
if (!fFile)
{
MessageBox(ghWndMain,"Could not open file!","EXEVIEW",MB_OK);
return FALSE;
}
// Calculate the position in the the file and move file pointer
lOffset = ((LONG)pri->wOffset)<<(pExeInfo->wShiftCount);
_llseek( fFile, lOffset, 0 );
// Allocate memory for resource
lSize = ((LONG)pri->wLength)<<(pExeInfo->wShiftCount);
hMem = GlobalAlloc( GHND, lSize );
if (!hMem)
{
_lclose( fFile );
MessageBox(ghWndMain,"Could not allocate memory for resource!","EXEVIEW",MB_OK);
return FALSE;
}
lpMem = (LPSTR)GlobalLock(hMem);
if (!lpMem)
{
_lclose( fFile );
MessageBox(ghWndMain,"Could not lock memory for resource!","EXEVIEW",MB_OK);
GlobalFree( hMem );
return FALSE;
}
// Read in resource from file
lpTMem = (char *)lpMem;
SetCursor( LoadCursor(NULL, IDC_WAIT) );
while (lSize)
{
WORD wSize;
if (lSize>=32767)
wSize = 32767;
else
wSize = (WORD)lSize;
// _lread is limited to 32K chunks, thus these gyrations
if (_lread(fFile, (LPSTR)lpTMem, wSize) != wSize)
{
_lclose( fFile );
MessageBox(ghWndMain,"Error reading from file!","EXEVIEW",MB_OK);
GlobalUnlock( hMem );
GlobalFree( hMem );
return FALSE;
}
lSize -= wSize;
lpTMem += wSize;
}
SetCursor( LoadCursor(NULL, IDC_ARROW) );
// Build a resource packet. This allows the passing of all the
// the needed info with one 32 bit pointer.
lprp->pExeInfo = pExeInfo;
lprp->prt = prt;
lprp->pri = pri;
lprp->lSize = ((LONG)pri->wLength)<<(pExeInfo->wShiftCount);
lprp->lpMem = lpMem;
lprp->fFile = fFile;
lprp->hMem = hMem;
return TRUE;
}