|
Guys, I've problem reading binary files using the following code. It works text/wri. Can you guys spot an error in this? Specifically, the pBuf in the code loads 0 or null after a certain number of loops even though the file huge.
void MyClass::Read(CString sFilename)
{
BYTE *pBuf = new BYTE[4096];
CFile pFile (sFilename, CFile::modeRead); //tried
//CFile::typeBinary too
int iReadSize = 0;
while(true){
iReadSize = pFile.Read(pBuf, 4096);
if(iReadSize == 0)
break;
else{
//my processing goes here
}
}
pFile.Close();
}
Any ideas?
Thanks.
JJ
|
|
|
|
|
the pBuf in the code loads 0 or null after a certain number of loops
Binary data can have null characters
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
So, Papa, how do I make sure the end of file has been reached? Still from the number of bytes returned from reading, right? But, my problem is that my buffer reads and loads "" into it..more likely, it loads nothing in the buffer.
void MyClass::Read(CString sFilename)
{
BYTE *pBuf = new BYTE[4096];
CFile pFile (sFilename, CFile::modeRead); //tried
//CFile::typeBinary too
int iReadSize = 0;
while(true){
iReadSize = pFile.Read(pBuf, 4096);
if(iReadSize == 0)
break;
else{
//my processing goes here
}
}
pFile.Close();
}
Thanks,
JJ
|
|
|
|
|
it does read, and fill the right values, but the prob is if u try to output it using a messagebox for instance it wont show cos the chars ur trying to print aint printable !
U can see an ascii table for more info
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Merc wrote:
Guys, I've problem reading binary files using the following code. It works text/wri. Can you guys spot an error in this? Specifically, the pBuf in the code loads 0 or null after a certain number of loops even though the file huge.
What sort of file are you reading. If it is an exe, dll etc. then it is highly likely you'll find lot's of 0's in the file. Or are you saying that iReadSize coming back with 0 before the end of the file?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Hi,
You're right. The number of bytes returned from reading is ZERO before end of file has been reached.
When I check the pBuf, it has loaded "" into it..more likely, it loads nothing in the buffer. That's why it returns ZERO bytes. But this works for text/wri files though.
void MyClass::Read(CString sFilename)
{
BYTE *pBuf = new BYTE[4096];
CFile pFile (sFilename, CFile::modeRead); //tried
//CFile::typeBinary too
int iReadSize = 0;
while(true){
iReadSize = pFile.Read(pBuf, 4096);
if(iReadSize == 0)
break;
else{
//my processing goes here
}
}
pFile.Close();
}
Your thoughts on this will be very appreciated.
JJ
|
|
|
|
|
Merc wrote:
You're right. The number of bytes returned from reading is ZERO before end of file has been reached.
When I check the pBuf, it has loaded "" into it..more likely, it loads nothing in the buffer. That's why it returns ZERO bytes. But this works for text/wri files though.
Is this happening if you specify: CFile::typeBinary, because it shouldn't. Have you wrapped the Read in a try/catch block to see if an exception is being raised. This is what the VC++ docs suggest you do.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Hmmm, I'll try the try/catch thing and keep you posted. Yes, I did specify typeBinary. I'll check the MSDN website where I hog 24/7 for info. You're the only one who understood the problem right, you know.
Thanks for the input...catch you soon.
JJ
|
|
|
|
|
I believe your process code is setting pBuf = 0 at some point. That's why you get the ASSERT.
Todd Smith
|
|
|
|
|
Hi Todd,
That's not the case though. The number of bytes returned from Read(pbuf, 4095) is zero after couple of loops. Just this is only a problem for txt/wri files.
Thanks if you can help.
jj
|
|
|
|
|
I know that this is probably a very obvious solution but I'm just not getting anywhere with it. I tried setting the m_pszHelpFilePath to point to my chm file but I then get a blah.chm is not a windows help file or file is corupted error message. If I double click on the .chm file, it opens without any problems.
Does anyone know what I'm doing wrong?
well hell doesn't want you
and heaven is full.
Tom Waits
|
|
|
|
|
The online help in MFC uses WinHelp format (.hlp) files. Using the HTML help (.chm) requires more coding - you need to replace cals to WinHelp API with calls to HTMLHelp API.
You can find an example here[^].
Pavel
Sonork 100.15206
|
|
|
|
|
Thank you!!
well hell doesn't want you
and heaven is full.
Tom Waits
|
|
|
|
|
I downloaded the sample at the link you gave, and its missing
#include "htmlhelp.h"
No such file exists. I thought maybe its a windows file, but I dont have one on my machine. Any ideas?
Thanks,
ns
|
|
|
|
|
|
You need to install HTMLHelp Workshop (free MS download).
Pavel
Sonork 100.15206
|
|
|
|
|
That makes sense!
Thanks,
ns
|
|
|
|
|
CFileDialog is used to get a filename. But I need to get a folder where I will copy file to, what should I do? Thank you.
|
|
|
|
|
you can use the SHBrowseForFolder function.
lookup it in MSDN for detail.
|
|
|
|
|
|
Hi All,
I need to enable the Password meets required complexity option within the password policy of windows 2000 programmatically. Is there any API available to do this programmatically.I also want to change the default configuration provided by the Windows 2000 to suite my needs.For that I have developed a password filter dll but am unable to use it correctly.Can anybody guide me in how the settings are to be made.
Kindly help me if anybody knows this.
Thanks
Abhishek.
Learning is a never ending process of Life.
|
|
|
|
|
Help, I'm a bit lost creating my very own static library.
I've created a .lib with one header file and one source file. It contains only one function (for testing). The header file includes windows.h and stdio.h , mainly for things like LPCTSTR which I want to add later on.
The header file has the #if !defined ... #define declared so redefinition is out of the question.
Now, when I want to use this library in another application, I've got to include the library's header file. The library itself is added through add to project -> files... in the project menu of vc++. So far, so good.
Trying to compile the testapp, results in these linker errors. Why?
Linking...
LIBCD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCD.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBCD.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/DownloadTest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
|
|
|
|
|
You need to have either anything as debug or anything as release. Same is for multithreaded and singlethreaded.
Check your application project settings: the 'Debug' configuration HAS TO link against a 'Debug'-version of your lib, and the 'Release' HAS TOuse a 'Release'-lib.
Likewise for 'singlethreaded' vs. 'multithreaded'. So you may end up with 4 differing configurations for your project.
|
|
|
|
|
Everything is debug.
And for the single-multithread, I've never messed with them so it's not very likely going to be that...
I've left this out of the library source file, cause it didn't compile otherwise.
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
But then, if we compile both as release, the errors are still there.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
|
|
|
|
|
Oops...
Forgot to mention that the app is mfc. Now I've selected mcf-dynamicaly instead of no mfc in the library config, although the library itself does NOT use mfc.
it works
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
|
|
|
|