Click here to Skip to main content
15,902,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: reading file 's header Pin
John M. Drescher20-Jun-03 5:12
John M. Drescher20-Jun-03 5:12 
GeneralRe: reading file 's header Pin
pnpfriend20-Jun-03 5:22
pnpfriend20-Jun-03 5:22 
GeneralRe: reading file 's header Pin
John M. Drescher20-Jun-03 5:41
John M. Drescher20-Jun-03 5:41 
GeneralRe: reading file 's header Pin
John M. Drescher20-Jun-03 5:58
John M. Drescher20-Jun-03 5:58 
GeneralRe: reading file 's header Pin
John M. Drescher20-Jun-03 6:04
John M. Drescher20-Jun-03 6:04 
GeneralRe: reading file 's header Pin
pnpfriend20-Jun-03 6:43
pnpfriend20-Jun-03 6:43 
GeneralRe: reading file 's header Pin
John M. Drescher20-Jun-03 6:52
John M. Drescher20-Jun-03 6:52 
GeneralFile Reading Problem In Release Only Pin
John R. Shaw13-Jun-03 7:07
John R. Shaw13-Jun-03 7:07 
While working on a Win16 to Win32 convertion I was asked to modify the origanal Win16 (Ver 2.1) of the software. During testing of the Win16 (Ver2.2) we noticed a problem and upon look at the Win32 port we saw that it also the same problem.

Confused | :confused: Problem: We have a simple little loop that reads data from a file with out errors, but when the memory contains of the array of data is dumped to disk it contains no data. It is as if the file was full of 0x00. The test file only contains 2048 bytes of data. The Win16 code for reading is the same in both Ver 2.1 and Ver 2.2 [NO CHANGE], but it works in Ver 2.1. Also checking the Win32 beta port I have descover it to has the same problem.

Quesion: Does anyone have an idea of what is going on?
(Yes the file does contain valid data and can be view with an hex editor)

// WIN32 CODE

BOOL File_Read(
  HANDLE hFile,                // handle to file
  LPVOID lpBuffer,             // data buffer
  DWORD nNumberOfBytesToRead,  // number of bytes to read
  LPDWORD lpNumberOfBytesRead, // number of bytes read
  LPOVERLAPPED lpOverlapped    // overlapped buffer
)
{
  if( !ReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,NULL) )
  {
    TCHAR szError[512];
    // Format error message
    DWORD dwLen = FormatMessage(
            FORMAT_MESSAGE_FROM_SYSTEM
            | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
            GetLastError(),
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // User default language
            szError, sizeof(szError)/sizeof(TCHAR), NULL);
    if( dwLen )
        Vsl_MessageBox(ghwnd,szError,gszAppName,MB_OK|MB_ICONSTOP);
    return FALSE;
  }
  return TRUE;
}

// CODE THAT DOES NOT FAIL BUT NO DATA IS READ INTO THE BUFFER.
// CONTAINS ALL 0x00 BEFORE AND AFTER READING (RELEASE ONLY)

// Allocate binary font storage space
lpBinFont = (LPBIN_FONT)GlobalAllocPtr(GPTR,(DWORD)sizeof(BIN_FONT)+dwFLen);
if( !lpBinFont )
	return(NULL);

.....

// 0x800 = smallest font file size ?
DWORD nNumberOfBytesToRead = 0x0800L;
SetFilePointer(hFontFile,0,NULL,FILE_BEGIN);
dwRead = 0;
for( dwOffset=0;dwOffset<dwFLen;dwOffset+=dwRead )
{
  if( nNumberOfBytesToRead > (dwFLen-dwOffset) )
    nNumberOfBytesToRead = dwFLen - dwOffset;

  if( !File_Read(hFontFile,(LPVOID)((lpBinFont->DataBits)+dwOffset),
    nNumberOfBytesToRead,&dwRead,NULL) )
  {
    break;
  }

  if( dwRead < nNumberOfBytesToRead )
  {
    dwOffset += dwRead;
    break;
  }
}

/********************************************************************/

// WIN16
// CODE THAT DOES NOT FAIL BUT NO DATA IS READ INTO THE BUFFER.
// CONTAINS ALL 0x00 BEFORE AND AFTER READING (RELEASE ONLY)

// Allocate binary font storage space
lpBinFont = (LPBIN_FONT)GlobalAllocPtr(GPTR,(DWORD)sizeof(BIN_FONT)+dwFLen);
if( !lpBinFont )
  return(NULL);

.....

_llseek(hFontFile,0,0);
for( dwOffset=0;dwOffset<dwFLen;dwOffset+=uRet )
{
  // 0x800 = smallest font file size ?
  uRet = _lread(hFontFile,(lpBinFont->DataBits)+dwOffset,0x0800U);
  if( uRet == HFILE_ERROR )
    break;

  if( uRet < 0x0800U )
  {
    dwOffset += uRet;
    break;
  }
}



Trust in the code Luke. Yea right!
GeneralRe: File Reading Problem In Release Only Pin
John R. Shaw13-Jun-03 8:23
John R. Shaw13-Jun-03 8:23 
GeneralSolved Pin
John R. Shaw13-Jun-03 8:32
John R. Shaw13-Jun-03 8:32 
Generalmaking a 64 bit long out of 2-32 bit doubles Pin
johnstonsk13-Jun-03 6:56
johnstonsk13-Jun-03 6:56 
GeneralRe: making a 64 bit long out of 2-32 bit doubles Pin
Nitron13-Jun-03 7:38
Nitron13-Jun-03 7:38 
GeneralListBox with Columns Pin
Hosam Aly Mahmoud13-Jun-03 6:48
Hosam Aly Mahmoud13-Jun-03 6:48 
GeneralRe: ListBox with Columns Pin
David Crow13-Jun-03 7:38
David Crow13-Jun-03 7:38 
GeneralRe: ListBox with Columns Pin
Hosam Aly Mahmoud14-Jun-03 5:30
Hosam Aly Mahmoud14-Jun-03 5:30 
GeneralRe: ListBox with Columns Pin
David Crow16-Jun-03 2:34
David Crow16-Jun-03 2:34 
GeneralProblem with serial communication Pin
justin22313-Jun-03 6:15
justin22313-Jun-03 6:15 
GeneralLogging Tools for C++ Pin
Anonymous13-Jun-03 6:10
Anonymous13-Jun-03 6:10 
GeneralRe: Logging Tools for C++ Pin
David Crow13-Jun-03 7:40
David Crow13-Jun-03 7:40 
GeneralRe: Logging Tools for C++ Pin
Anonymous13-Jun-03 7:52
Anonymous13-Jun-03 7:52 
GeneralRe: Logging Tools for C++ Pin
David Crow13-Jun-03 8:00
David Crow13-Jun-03 8:00 
GeneralRe: Logging Tools for C++ Pin
Anonymous13-Jun-03 8:57
Anonymous13-Jun-03 8:57 
GeneralRe: Logging Tools for C++ Pin
David Crow13-Jun-03 9:06
David Crow13-Jun-03 9:06 
GeneralRe: Logging Tools for C++ Pin
cmk13-Jun-03 8:03
cmk13-Jun-03 8:03 
GeneralRe: Logging Tools for C++ Pin
Anonymous13-Jun-03 8:58
Anonymous13-Jun-03 8:58 

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.