DLL Base Address VTABLEs and COM

F

first10

Hello,

Apologies for being slightly off topic - but this group seems the best
fit for the question.

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?

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?

I am trying to write a COM client "manually" without using windows api
or vc++ compiler features as a learning exercise - I think I am missing
a bit of pointer arithmetic to get the last step to work.

All the best,

John
 
R

red floyd

Hello,

Apologies for being slightly off topic - but this group seems the best
fit for the question.

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?

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?

I am trying to write a COM client "manually" without using windows api
or vc++ compiler features as a learning exercise - I think I am missing
a bit of pointer arithmetic to get the last step to work.

All the best,

John

It's not the best fit. Try microsoft.public.vc.language
 
R

Richard Herring

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top