Re: Interface Question
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 23:37:23 -0500
Hans-Peter Diettrich wrote:
Rob Kennedy wrote:
http://www.cs.wisc.edu/~rkennedy/interface-object
A fine article :-)
I only disagree with the last paragraph(s), about how to retrieve object references. In the case of a Delphi class, the offset of the interface pointer is stored in the interface description, no need to look into the stubs (hint: the compiler obtains the offset just from that place).
How can it be stored in the interface description? Consider the record I use to describe TInterfacedObject:
type
TInterfacedObjectLayout = record
VMT: Pointer;
FRefCount: Integer;
FIUnknown: PIUnknownMT;
end;
In that class, the offset is 8, corresponding to SizeOf(VMT) + Sizeof(FRefCount). Now consider the layout of a class that implements IUnknown without reference counting:
type
TInterfacedObjectNoRefLayout = record
VMT: Pointer;
FIUnknown: PIUnknownMT;
end;
The offset in this case is only 4. The classes implement the same interface in both cases, but the offset is different. The IUnknown definition doesn't say anything about 4 or 8.
Looking into the stub code is a bit safer, because that code may be less version dependent, than the info in the classtype structure.
But there is no class type yet. All we have is an interface reference, and we're trying to get to the object. We don't know what class we'll get until after we get it.
--
Rob
.
- Follow-Ups:
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- References:
- Interface Question
- From: alanglloyd@xxxxxxx
- Re: Interface Question
- From: Rob Kennedy
- Re: Interface Question
- From: Hans-Peter Diettrich
- Interface Question
- Prev by Date: Re: Interface Question
- Next by Date: Re: Interface Question
- Previous by thread: Re: Interface Question
- Next by thread: Re: Interface Question
- Index(es):
Relevant Pages
|