Lets say I have a linked list with a struct defined like this.
struct LList *NextList;
When I allocate memory for a new entry to the list, and then put the pointer at correct spot in the previous entry, it unfortunately points to the start of the next structure. How, to I get it to instead point the the SAME spot in the next structure? Like it will be such that each entry in the list, will have its pointer pointing to the pointer item (the one called *NextList) in the next entry in the linked list?
Yes, I can simply add 4 to that pointer so it points 4 bytes ahead into the next structure, but then when ACCESSING it, in another part of the code, it will be treating the pointer as if it were pointing to the start of the next entry, when instead it's pointing 4 bytes ahead of that. How do I make it be a pointer with a true 4-byte offset into the next entry in the list, that will be correctly handled when reading back from that list?
the order of a struct is the order provided... if you want the pointer to be the zero offset, put it first.
however, the question, no offense, implies you don't understand something or are trying to do something really weird or getting to far down in the raw bytes.
the thing that is accessing the list should NOT have to know this level of detail about the memory alignment. It is either accessing it in a bad way, or you are not understanding something.
typical linked lists are just a chain of struct -> struct-> struct and the things inside the struct do not matter at all as far as alignment or ordering.
accessing it is just current->field ... regardless of where field lies in the block of memory.
The pointers in the field called "LIST_ENTRY InMemoryOrderLinks;" do NOT point to the start of the next struct. If it did, it would point to the field "PVOID Reserved1;" in the next struct. What it does instead is it points to the field "LIST_ENTRY InMemoryOrderLinks;" in the next struct (that's 8 bytes into the struct, not the start of the struct). I can verify this by using a debugger to analyze any running EXE file and then looking at the correct block of system memory (where this struct resides).
I'm trying to do something similar with the struct that I'll be using as a linked-list in for my own C program.