C++ MFC

Moderators: Lundin
Number of threads: 3337
Number of posts: 9005

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need Help Reading a Binary File Posted by licensed2kill on 21 Sept 2002 at 12:23 PM
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.

Report
Re: Need Help Reading a Binary File Posted by grahamoj on 22 Sept 2002 at 3:07 AM
: 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.

Report
Re: Need Help Reading a Binary File Posted by licensed2kill on 22 Sept 2002 at 4:28 PM
: : 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

Report
Re: Need Help Reading a Binary File Posted by C_Pro on 12 Mar 2012 at 8:24 PM
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();
Report
Re: Need Help Reading a Binary File Posted by C_Pro on 12 Mar 2012 at 8:27 PM
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();
Report
Re: Need Help Reading a Binary File Posted by C_Pro on 12 Mar 2012 at 8:29 PM
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();
Report
Re: Need Help Reading a Binary File Posted by C_Pro on 13 Mar 2012 at 5:17 PM
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();
Report
Re: Need Help Reading a Binary File Posted by C_Pro on 13 Mar 2012 at 5:19 PM
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();



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.