Rohit Wason

Hello friends!

A VTable (aka Virtual Method Table) is a concept that stems from C++. Each object has an associated table of "function pointers" that are used for doing dynamic dispatch. The idea is simple : with a virtual method you don't know which method will be called at runtime (since derived classes are allowed to 'override' the behavior). Therefore each object carries with it (at least one) VTable. The compiler is able to generate code because each virtual method will always reside in the same position in the vTable and wathever actual function is there, it will always have the required signature. Now it so happens that Microsoft chose the mechanism of VTables to implement

calls to COM interfaces. Sinc a COM interface is just a definition, there would be no way for you to know how to call it when you use it in your code. Therefore, microsoft took the vTable approach. If you call a method from an interface (actually from an object implementing that interface), COM knows

Hello World
e VTable are always taken by QueryInterface, AddRef and Release).Any other methods you define will take up subsequent slots. (As it happens,VB Objects derive from IDispatch, adding 4 more slots). The rest of the slots is normal
Hello World
Just like you include a C Header file to attain access to definitions, you put a reference to a typelib to attain access to the bjects defined by the typelibrary. o summarize, a VTable is a binary layout for an interface (whihc exist only within running objects), while a typelib contains the definition for the layout. If you like to find out more about a certain typelib and you happen

of "Binary C Header File" (actually there is more information in a typelib). It contains definitions of things, but no implementation. As it turns out,

VB Objects derive from IDispatch, adding 4 more slots). The rest of the slots is normally taken in the order of definition in you class file (that is, if you don't taken compatibility issues into account). Now a typelib is just a binary file containing the definitions of the interfaces (and coclases, public types, ...). You can look at a typelib as some kind of "Binary C Header File" (actually there is more information in a typelib).

Hello World
Just like you include a C Header file to attain access to definitions, you put a reference to a typelib to attain access to the bjects defined by the typelibrary. o summarize, a VTable is a binary layout for an interface (whihc exist only within running objects), while a typelib contains the definition for the layout. If you like to find out more about a certain typelib and you happen

how to call it, because it knows the offset in the VTable it must use to call the function. Since all COM interfaces derive from IUnknown, the first 3 "slots" of the VTable are always taken by QueryInterface, AddRef and Release). Any other methods you define will take up subsequent slots. (As it happens, VB Objects derive from IDispatch, adding 4 more slots). The rest of the slots is normally taken in the order of definition in you class file (that is, if you don't taken compatibility issues into account). Now a typelib is just a binary file containing the definitions of the interfaces (and coclases, public types, ...). You can look at a typelib as some kind of "Binary C Header File" (actually there is more information in a typelib). It contains definitions of things, but no implementation. As it turns out, these definitions are the things you need to USE the objects that are defined in the typelibrary. Just like you include a C Header file to attain access to definitions, you put a reference to a typelib to attain access to the objects defined by the typelibrary. To summarize, a VTable is a binary layout for an interface (whihc exist only within running objects), while a typelib contains the definition for the layout. If you like to find out more about a certain typelib and you happen to have the complete visual studio, you can always use OleView to inspect its contents)

TechsSocietyMe and my rolls.NETAbout this siteDisclaimerLets discussMy fellow alumniHome
Hosted by www.Geocities.ws

1