Re: fread choking on binary file
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Mon, 24 Apr 2006 17:24:28 -0400
Fran D <FranD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Are you sure you mean &Image.Print.pData (the ampersand in front)
rather than Image.Print.pData (without ampersand) ? If pData is a
pointer, you probably want to read into the buffer pointed to by
pData, rather than into the memory address occupied by pData
variable itself.
If that's not it, show how the memory for Image.Print.pData is
allocated.
Yes, both of you are correct. The ampersand in front of
Image.Print.pData was incorrect.
I removed it and now the pointer to the buffer is assigned to
0x00000000, which I guess is OK...I've just never seen it assigned to
0 before.
Are you saying Image.Print.pData is NULL? If this is the case, I'm not
sure how you expect the call to work. You are supposed to allocate some
memory for the data, store the pointer to this memory in
Image.Print.pData (at which point it certainly stops being NULL), then
pass the pointer to fread.
If I understood your last question correctly, I allocate the memory
for the whole Image.Print structure with:
memset(&Image.Print, 0, sizeof(Image.Print));
memset does not allocate any memory, it just fills existing memory.
Image is probably a stack (automatic) variable, so the memory for the
structure itself is allocated when you declare it. But the structure
only contains a pointer to the actual memory buffer, and memset
helpfully sets this pointer to NULL.
With all due respect, I suggest you go back to basics and review your
favorite C 101 textbook.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Re: fread choking on binary file
- From: Igor Tandetnik
- Re: fread choking on binary file
- From: Igor Tandetnik
- Re: fread choking on binary file
- Prev by Date: Re: fread choking on binary file
- Next by Date: Re: Problems linking using std:basic_string
- Previous by thread: Re: fread choking on binary file
- Next by thread: KB831875
- Index(es):
Relevant Pages
|