Archived

This topic is now archived and is closed to further replies.

clrscr

What is this (very strange)

Recommended Posts

Once again I was browsing around in the quake II Source code when I notcied this some interface->lpVtbl->some function, now the question is whats an lpVtbl, why couldent they just go interface->function As a note it only seems to be used in the Direct Sound portation of the code. Its not knowing the path but walking it.

Share this post


Link to post
Share on other sites
They''re using the C compiler, so they use the interface->lpVtbl->function(interface,...) notation. It''s just a difference between C++ and C, C++ does the vtable stuff automatically through virtual functions, whereas in C it is done with function pointers.

Share this post


Link to post
Share on other sites
you must understand that you are looking at C code (not C++) ... so the interface for dealing with COM interfaces and components (which DirectX is based on) is really ugly.

The DirectX components are written in C++, and the interface->lpVTbl->SomeFunc is the way microsoft has made the C++ vtable available from C ... the lpVTbl is a "long pointer to the V Table" ... so:

in C++, this line:

result = interface->SomeVirtualFunction();

becomes this line of C:

result = interface->lpVTbl->SomeVirtualFunction();

... it''s really pretty simple once you realize that the vtable is nothing more than a pointer at the first address of your c++ object, which pointers to a table of function pointers somewhere in the program. The book "Inside COM" expains this type stuff REALLY REALLY WELL.

Good Luck

Share this post


Link to post
Share on other sites