Re: DLL Base Address VTABLEs and COM
In message <1146240916.761370.314810@g10g2000cwb.googlegroups.com>,
first10@btinternet.com writes
Hello,
Apologies for being slightly off topic - but this group seems the best
fit for the question.
Something (highly) platform-specific would be better... but there are
generic answers:
How does the compiler handle the problem of not knowing which address a
DLL will be loaded at when it tries to resolve calls to virtual
functions via the vtable?
The same way it handles the problem of not knowing which address the
functions within any executable program will be loaded at, and the same
way it handles function pointers. Somewhere within the object code it
generates there will be information about pointers that need to be
adjusted when the executable code is loaded. How this is done is
platform-specific.
Does the vtable hold pointers relative to itself or to the dll in which
it resides?
If the compiler places absolute memory addresses in the vtable there is
no guarantee these will be correct when the dll is loaded at a
different address than expected?
There is no "expected" address. The program-loading mechanism provided
by the OS, in conjunction with the data output by the compiler, ensures
that by the time the program starts running, all its addresses have been
adjusted to contain the correct values.
I am trying to write a COM client "manually" without using windows api
or vc++ compiler features as a learning exercise
In platform-neutral terms, you have an array of pointers to functions.
So long as the compiler is aware of that, all the necessary adjustments
should happen automatically.
- I think I am missing
a bit of pointer arithmetic to get the last step to work.
--
Richard Herring