![]() |
struct gaining 2 bytes ?
Hi, I'm having the problem when trying to read in the data to the following struct.
:
struct BMPFileHeadernow, this struct should only be 14 bytes, but when doing a sizeof of this header, i find that it is giving 16 bytes instead, causing some trouble when reading data. I remember reading why this happens a while back. but I was wondering, is there any work around ? I would like to keep the struct if possible for ease of coding, but I can read em in individually if need be.... sigh. I can't change the order of which I declare these either. |
iirc, your compiler will generally pad your structures to an 8-byte boundry, i.e. it'll pad it 'up to' 16.
When I manipulated the PE header, the general way I did it was just make a pointer to the structure and just point it at the start of your file map; pointer arithmetic should take care of it from there (the code to manipulate/read PE files I wrote I still have, you can see it here if you want a reference.) I don't quite know how you're trying this, though. Have you tried it with the existing structure? If so, providing there were issues, it'd be nice to see some example code. |
I think most compilers these days including vc++ comes with the #pragma pack preprocessor directive.
sample reference: http://publib.boulder.ibm.com/infoce...f/rnpgpack.htm Set it to 1 to solve all your problems. Think there is also the "UNALIGNED" type modifier supported by some compilers |
If you're working with Windows, I'd recommend you skip the packing and use their predefined stuff for bitmap handling. The bitmap file header, for instance, is
:
typedef struct tagBITMAPFILEHEADER { |
cheers for the response. I decided to read each part of the struct in seperately as it is only 5 parts in size. Am working with windows, but really wanted to use my own code.... I know its reinventing the wheel.
I currently have both the file and info header reading in ok, but I am now finding difficulty reading in the actual image data. But alas, I believe I should leave that for another thread. |
You're aware that the data may either contain the pixel values or be an index into a color table?
|
| All times are GMT -5. The time now is 2:24 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC