Determine virtual function table size
-
Hi all, I am wondering if it is possible to determine the size (or number of valid function entries) of a virtual function table using the queried interface pointer. Say I obtained an interface pointer
pIMy
via QueryInterface:pIBase->QueryInterface(&IID_MYINTERFACE, (void**)&pIMy, hr);
I was able to cast the
pIMy
to vtable pointer pVTable and access each each function's address value with pVTable[0], pVTable[1]..etc. And obviouslysizeof(pVTable)
returns 4 instead of size of the vtable. Any ideas how it is possible to determine the size virtual function table? Thanks in advance, J.B. -
Hi all, I am wondering if it is possible to determine the size (or number of valid function entries) of a virtual function table using the queried interface pointer. Say I obtained an interface pointer
pIMy
via QueryInterface:pIBase->QueryInterface(&IID_MYINTERFACE, (void**)&pIMy, hr);
I was able to cast the
pIMy
to vtable pointer pVTable and access each each function's address value with pVTable[0], pVTable[1]..etc. And obviouslysizeof(pVTable)
returns 4 instead of size of the vtable. Any ideas how it is possible to determine the size virtual function table? Thanks in advance, J.B.Perhaps there's a trick that I'm not aware of, but I don't think you can get the size of the vtable in runtime. If you create an interface that inherits from IUnknown, the first 12 bytes of the vtable will be the addresses of QueryInterface(), AddRef() and Release(). The next four bytes will contain the address of the first method for the new (child) interface and so on until the vtable is complete. The bytes following the vtable will contain data for the member variables, there's no "padding" or "termination" of the vtable, hence I don't think you can tell the size of it in runtime. Perhaps there's a trick when building for 'Debug', but I don't think so. On the other hand: why do you want to know the size of the vtable? :confused: Perhaps there's another solution for your problem. -- Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998
"...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above