flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > structure field offset

Author
Thread Post new topic Reply to topic
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
Hi! I have such code:

Code:
struct CDocItem CUnknown
    m_adviseSink CInterfaced
    m_clientSite CInterfaced
    m_inPlaceSite CInterfaced
ends
    


How can I determine offset of m_clientSite field relative to beginning of CDocItem structure?
Post 16 Aug 2005, 11:52
View user's profile Send private message ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
Does this code solve my problem? (I understand fasm macro langage poor)

Code:
macro interface name

common
        offsetof.#name = $
        name CInterfaced


struct CDocItem CUnknown
        interface m_advSink
        interface m_oleClientSite
        interface m_oleInPlaceSite
ends
    
Post 16 Aug 2005, 12:58
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7310
Location: Kraków, Poland
What do you mean by "the beginning of CDocItem" structure? Do you mean something different than the "CDocItem.m_clientSite" value?
Post 16 Aug 2005, 13:17
View user's profile Send private message Visit poster's website Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
For example:

struct MyStruc
field1 dd ?
field2 dd ?
field3 dd ?
m_oleClientSite CInterfaced
ends

offset of "field1" in this case is 0.
offset of "field2" is 4.
offset of "field3" is 8.
offset of m_oleClientSite is 12.

But what if I write:

struct MyStruct2 MyStruct
m_fieldNext dd ?
ends

I don't know offset of n_fieldNext until I calculate size of MyStruct.

I whant to obtain this offsets like "offsetof.MyStruct.m_oleClientSite".

For example if I whant to write table based QueryInterface implementation I can define table of offsets like this:

LABEL CMyObject_InterfaceMap
dd IID_IUnknown, offsetof.CMyObject.m_unknown
dd IID_IOleClientSite, offsetof.CMyObject.m_oleClientSite
dd IID_IOleInPlaceSite, offsetof.CMyObject.m_oleInPlaceSite
dd 0, 0

But now I have to manually calculate these offsets. And I often make mistakes, so QueryInterface returns wrong pointer ...
Post 16 Aug 2005, 13:42
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7310
Location: Kraków, Poland
The "struct" macro defines those offsets for you. They are just named like:
MyStruc.field1, MyStruc.field2, etc. (what I already mentioned in my previous post).
Post 16 Aug 2005, 13:46
View user's profile Send private message Visit poster's website Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
Thanks. I didn`t know this...
Post 16 Aug 2005, 13:53
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7310
Location: Kraków, Poland
It is documented in the section about structures here.
Post 16 Aug 2005, 14:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.