Me again.. this time: how does C/C++ store struct/class info in a file anyway??
Hi, I'm back again, I haven't been away from lack of coding, I've just been quite busy and haven't run into any interesting problems lately ;)
Anyway, I did a little while ago, but then got busy enough I never had a chance to ask it, so here goes.
How does c/c++ store classes in binary format in a file anyway?
The main reason I ask this is because I want to load a bitmap into a DOS-based app. I know, SDL is better, etc; don't worry, I'll get to that, but first I want to try doing it myself. It has always been easier for me to learn things from the ground up, even if it seems a tad unneccessarry(I am sure I spelled that wrong but it's late..)
So the big thing is this. I tried loading up a bitmap into this working graphics shell I (finally) managed to hack together from various sites using the old code from those graphics tutorials by.. uhmm.. whatsisname.. that were done (originally) in pascal.
The compiler I'm using is DJGPP(which I don't normally use)
I put in the code from this website, under the faq, entry about "how do i load a bitmap into my dos program?" I modified it *very* slightly to fit my graphics shell.
I created a test graphic in Windows Paint, and attempted loading it. It gave me the error "this is not a valid bitmap".
After a bit of poking, I found that the bfType was loading in properly (value is 19778), but everything after that seems to be screwed up.
The big question is - what order are the bytes in a class or struct's member variables stored on a file?
Is djgpp somehow loading them in a different order than they were saved in?
And if so, how can I fix it?
Also, as extra info, I don't remember exactly what I did since it's actually been a couple months since I was messing around with it, but if I remember I also did the following:
loaded the values of the BITMAP struct with various values and saved it to a file, then loaded it back, with both djgpp and MSVC++ 6.0: both times it worked fine.
(also used fstream.read and fstream.write to write a class which was the same as the struct for bitmap, and had the exact same results)
Also compiled code to load a bitmap in MSVC++, and had the same results as in DJGPP (i.e. everything after the BM is screwed)
I also tried using Paint Shop Pro and Photoshop to create bitmaps, both with the same results as Windows Paint
it *seems* like somehow the code I write is loading the values, but somehow switching the order of the bytes(or nibbles) in the values it loads;
I've also read from *quite* a few different sources on how to load bitmaps, and they all have the same code as is in the FAQ here at cprogramming.
I'm totally stumped on this one.. and I don't really want to write some fancy translation code to un-screw-up all the values I load, since I'm probably just missing something simple.. I hope ^.^
Any help will be greatly appreciated.. especially if I learn something real good from it :D