A
Axel
Hiho,
I want to read the content of a binary file into a string. It works, but
only the first 4 chars are left after the reading and the stringsize is,
of course, 4 bytes.
I got this method from a tutorial and though it works...what's wrong? Is
the buffersize for the String 'FileContent' not ok? Before fread the
size of 'FileContent' is correct, but after the operation its truncated
to 4.
The Codepart
--------------------------------------
int fsize;
CString FileContent;
LPTSTR pStr;
FILE *fl = fopen(ff,"rb");
if(!fl)
{
//Error Message
}
else
{
fseek(fl, 0, SEEK_END);
fsize = ftell(fl);
pStr = FileContent.GetBufferSetLength((int)fsize + 1);
fseek(fl, 0, SEEK_SET);
c_edit1.SetWindowText(itoa(fsize, buf, 100));
fsize = fread(pStr, 1, fsize, fl);
*(pStr + fsize) = '\0';
FileContent.ReleaseBuffer(-1);
}
fclose(fl);
I want to read the content of a binary file into a string. It works, but
only the first 4 chars are left after the reading and the stringsize is,
of course, 4 bytes.
I got this method from a tutorial and though it works...what's wrong? Is
the buffersize for the String 'FileContent' not ok? Before fread the
size of 'FileContent' is correct, but after the operation its truncated
to 4.
The Codepart
--------------------------------------
int fsize;
CString FileContent;
LPTSTR pStr;
FILE *fl = fopen(ff,"rb");
if(!fl)
{
//Error Message
}
else
{
fseek(fl, 0, SEEK_END);
fsize = ftell(fl);
pStr = FileContent.GetBufferSetLength((int)fsize + 1);
fseek(fl, 0, SEEK_SET);
c_edit1.SetWindowText(itoa(fsize, buf, 100));
fsize = fread(pStr, 1, fsize, fl);
*(pStr + fsize) = '\0';
FileContent.ReleaseBuffer(-1);
}
fclose(fl);