Need Help Reading a Binary File - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need Help Reading a Binary File

licensed2killlicensed2kill Posts: 23Member
Hi guys,

I've problem reading a binary file, however it's successful in reading non-binary files such as text/wri files.
Specifically, the buffer reads NULL bytes and gives me ASSERT(lpBuf != NULL) from filecore.cpp, line 243. But, why is this just happening for binary files and not for the non-binary ones? I've tried the c runtime function fread() and it fails on the 2nd attempt of the loop yielding some 9 odd bytes of read bytes even when reading large files (400kb).

This is the code:


CFile pFile (sFilename, CFile::modeRead);
int iReadSize = 0;
while(true){

iReadSize = pFile.Read(pBuf, 4096);
if(iReadSize == 0)
break;
else{
//my processing goes here
}
}
pFile.Close();


Any suggestions please?
Thank you.

Comments

  • grahamojgrahamoj Posts: 366Member
    : Hi guys,
    :
    : I've problem reading a binary file, however it's successful in reading non-binary files such as text/wri files.
    : Specifically, the buffer reads NULL bytes and gives me ASSERT(lpBuf != NULL) from filecore.cpp, line 243. But, why is this just happening for binary files and not for the non-binary ones? I've tried the c runtime function fread() and it fails on the 2nd attempt of the loop yielding some 9 odd bytes of read bytes even when reading large files (400kb).
    :
    : This is the code:
    :
    :
    : CFile pFile (sFilename, CFile::modeRead);
    : int iReadSize = 0;
    : while(true){
    :
    : iReadSize = pFile.Read(pBuf, 4096);
    : if(iReadSize == 0)
    : break;
    : else{
    : //my processing goes here
    : }
    : }
    : pFile.Close();
    :
    :
    : Any suggestions please?
    : Thank you.
    :
    :

    hiya try using the flag "CFile::typeBinary", for binary files.
    if this doesn't work try looking at the CFile class in MSDN for help.

    good luck.

  • licensed2killlicensed2kill Posts: 23Member
    : : Hi guys,
    : :
    : : I've problem reading a binary file, however it's successful in
    : hiya try using the flag "CFile::typeBinary", for binary files.
    : if this doesn't work try looking at the CFile class in MSDN for help.
    :
    : good luck.
    :


    I tried this even b4 you suggested it. :) Thanks for replying though. :)

    Jey

  • C_ProC_Pro Posts: 5Member
    I use VS 2008. This is how I proced:

    char unsigned buf[20000];
    CFile f;
    f.Open(CString("C:\Downloads\steg_1.bmp"), CFile::modeReadWrite|CFile::typeBinary);
    UINT bytesRead = f.Read(buf, 20000);
    f.Close();
  • C_ProC_Pro Posts: 5Member
    I use VS 2008. This is how I proced:

    char unsigned buf[20000];
    CFile f;
    f.Open(CString("C:\Downloads\steg_1.bmp"), CFile::modeReadWrite|CFile::typeBinary);
    UINT bytesRead = f.Read(buf, 20000);
    f.Close();
  • C_ProC_Pro Posts: 5Member
    I use VS 2008. This is how I proced:

    char unsigned buf[20000];
    CFile f;
    f.Open(CString("C:\Downloads\steg_1.bmp"), CFile::modeReadWrite|CFile::typeBinary);
    UINT bytesRead = f.Read(buf, 20000);
    f.Close();
  • C_ProC_Pro Posts: 5Member
    I use VS 2008. This is how I proced:

    char unsigned buf[20000];
    CFile f;
    f.Open(CString("C:\Downloads\steg_1.bmp"), CFile::modeReadWrite|CFile::typeBinary);
    UINT bytesRead = f.Read(buf, 20000);
    f.Close();
  • C_ProC_Pro Posts: 5Member
    I use VS 2008. This is how I proced:

    char unsigned buf[20000];
    CFile f;
    f.Open(CString("C:\Downloads\steg_1.bmp"), CFile::modeReadWrite|CFile::typeBinary);
    UINT bytesRead = f.Read(buf, 20000);
    f.Close();
Sign In or Register to comment.