i'm struggling with Structures and I just don't know how to implement them :(

Here's what I want to achieve:
I want to open a .rar file and read the first 7 bytes from it (the main header), and put them into a structure.

Here's what the structure looks like:


I know how to open/close a file, read/write from/to a file, read/write to memory etc .. but how can I read the first 7 bytes from the file INTO the structure?
Do I need to make a pointer to my structure?

Can someone please provide me with a small example? I've searched LOTS of websites, source codes, etc .. without succes so far :(

I hope someone can enlighten me on this subject.

Thanx in advance!

PS: Don't mind my crappy english :)
Posted on 2005-01-23 16:26:58 by dev0wn
If you know how to read from a file, then just do what you usually do. I assume that you're not trying to read into the structure itself, which is impossible because it only exists in your head, but rather into memory locations that you are going to refer to by means of field names in the structure.
Posted on 2005-01-23 16:53:37 by Sephiroth3
first you need to initialize the structure:

rar_hdr MARK_HEAD <>

than you could write to it i.e
invoke ReadFile, file_handle, ADDR rar_hdr, sizeof rar_hdr, ADDR sometemp, 0

later you can access the data like this for example
mov  ebx, offset rar_hdr

mov eax, word ptr [ebx.MARK_HEAD.HEAD_SIZE]
Posted on 2005-01-23 17:00:37 by arafel
Wow, thats exacly what I needed! Thanx arafel. :-D
You guys really helped me out here!
Posted on 2005-01-23 17:05:57 by dev0wn
It is not only for making code readable, but it also allows you to quickly change the order of the fields without changing many places in your code.

You can't define a label called MARK_HEAD when you also have a structure definition called MARK_HEAD. You must use a different name.
The structure can be copied from one location to another using the following sequence of instructions:

mov esi,pMemory
mov edi,offset Destination

For long transfers, use rep movsb in place of lodsb, stosb and loop to avoid wasting space and time. Loading an immediate value into a 32-bit register where bits 7-31 are all the same can be carried out with push and pop instructions to save 2 bytes.

Edit: Ah, I see that you changed your mind while I was writing this
Posted on 2005-01-23 17:32:41 by Sephiroth3
Edit: Ah, I see that you changed your mind while I was writing this

Yes, but I'll definitly keep your solution in mind as well!

Thanx alot!
Posted on 2005-01-23 18:01:54 by dev0wn