Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Determine virtual function table size

Determine virtual function table size

Scheduled Pinned Locked Moved COM
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    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 pIMyvia 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 obviously sizeof(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.

    R 1 Reply Last reply
    0
    • J J B 0

      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 pIMyvia 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 obviously sizeof(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.

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups