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. How to iterate vtable of COM coclass?

How to iterate vtable of COM coclass?

Scheduled Pinned Locked Moved COM
comtutorialquestion
14 Posts 7 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.
  • G Offline
    G Offline
    glitteringsound
    wrote on last edited by
    #1

    Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil

    K S 2 Replies Last reply
    0
    • G glitteringsound

      Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil

      K Offline
      K Offline
      KingsGambit
      wrote on last edited by
      #2

      Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?

      G C F 3 Replies Last reply
      0
      • K KingsGambit

        Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?

        G Offline
        G Offline
        glitteringsound
        wrote on last edited by
        #3

        I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?

        L R K 3 Replies Last reply
        0
        • G glitteringsound

          I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Take a look at this article[^] which explains the basics of the COM vtable and pointers, it should help you understand how to get what you want.

          txtspeak is the realm of 9 year old children, not developers. Christian Graus

          1 Reply Last reply
          0
          • K KingsGambit

            Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?

            C Offline
            C Offline
            Cool_Dev
            wrote on last edited by
            #5

            a coclass will always have pointers to virtual tables (of all interfaces it implements) as its instance data. In CreateObject() function, coclass is instantiated, type casted to the interface ptr which we demands through CoCreaInstance and returned. so the returned ptr will be pointing to the virtual table of that interface. This virtual table ptr is used later in function calls to locate the correct implemented functions. Pls correct me if iam wrong..

            G 1 Reply Last reply
            0
            • C Cool_Dev

              a coclass will always have pointers to virtual tables (of all interfaces it implements) as its instance data. In CreateObject() function, coclass is instantiated, type casted to the interface ptr which we demands through CoCreaInstance and returned. so the returned ptr will be pointing to the virtual table of that interface. This virtual table ptr is used later in function calls to locate the correct implemented functions. Pls correct me if iam wrong..

              G Offline
              G Offline
              glitteringsound
              wrote on last edited by
              #6

              Can we then be able to take its size as well? I mean how many no of entries(addresses) that vtable would then have?

              C 1 Reply Last reply
              0
              • G glitteringsound

                I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?

                R Offline
                R Offline
                R jeev K R
                wrote on last edited by
                #7

                Checkout the following articles... It may helpful for your needs.... Writing An Extensible COM Application[^] Pluggable Components using Component Categories Part I[^]

                1 Reply Last reply
                0
                • G glitteringsound

                  Can we then be able to take its size as well? I mean how many no of entries(addresses) that vtable would then have?

                  C Offline
                  C Offline
                  Cool_Dev
                  wrote on last edited by
                  #8

                  size of the returned interface ptr will be size of a pointer (4 bytes as any pointer). so in order to call the functions using that ptr, u need to have their declarations. Also for all com interfaces, first few entries in vtable will point to the implementation of functions from the base interfaces, such as QueryInterface, AddRef ... of IUnknown. So think whether ur plan is going to work our or not..

                  1 Reply Last reply
                  0
                  • G glitteringsound

                    Hello, How to iterate (infact access) the vtable of COM coclass(that will implement the methods of its exposed interfaces).? Only I need to access vtable where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum" Regards Muhammad Usman Khalil

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    You're going about things the wrong way. Getting the v-table's address is no problem. Doing something useful with it will be. All it is an array of function pointers. The pointers have no type information associated with them. It sounds like you should look into type libraries (see the ITypeLib[^] interface) or automation[^].

                    Steve

                    G 1 Reply Last reply
                    0
                    • S Stephen Hewitt

                      You're going about things the wrong way. Getting the v-table's address is no problem. Doing something useful with it will be. All it is an array of function pointers. The pointers have no type information associated with them. It sounds like you should look into type libraries (see the ITypeLib[^] interface) or automation[^].

                      Steve

                      G Offline
                      G Offline
                      glitteringsound
                      wrote on last edited by
                      #10

                      I have got the addresses of functions from vtable but in little wiered manner. like typedef void (*FN)(void) FN pFn=0 int* dwPtr= (int*)pSomeInterface; pFn=(FN)*((int*)*(&dwPtr[Count])+1);//will give the address of QueryInterface pFn=(FN)*((int*)*(&dwPtr[Count])+2);//will give the address of AddRef pFn=(FN)*((int*)*(&dwPtr[Count])+3);say release pFn=(FN)*((int*)*(&dwPtr[Count])+6);//and finally my method Sum but this is all hardcoded stuff and little wiered. I in a search of some generic usefull method to lookup their addresses and then I NEED their NAME as well so that which ever at runtime I give the name as function my app should traverse and call only that method

                      C 1 Reply Last reply
                      0
                      • G glitteringsound

                        I have got the addresses of functions from vtable but in little wiered manner. like typedef void (*FN)(void) FN pFn=0 int* dwPtr= (int*)pSomeInterface; pFn=(FN)*((int*)*(&dwPtr[Count])+1);//will give the address of QueryInterface pFn=(FN)*((int*)*(&dwPtr[Count])+2);//will give the address of AddRef pFn=(FN)*((int*)*(&dwPtr[Count])+3);say release pFn=(FN)*((int*)*(&dwPtr[Count])+6);//and finally my method Sum but this is all hardcoded stuff and little wiered. I in a search of some generic usefull method to lookup their addresses and then I NEED their NAME as well so that which ever at runtime I give the name as function my app should traverse and call only that method

                        C Offline
                        C Offline
                        Cool_Dev
                        wrote on last edited by
                        #11

                        typedef void (*FN)(void)

                        using FN, how are you going to call those methods like QueryInterface, AddRef.. as they take various number of arguments? u may be able to call without errors, bt result will be unexpected. without having specific info about the functions in interface, u won't be able to proceed..

                        G 1 Reply Last reply
                        0
                        • C Cool_Dev

                          typedef void (*FN)(void)

                          using FN, how are you going to call those methods like QueryInterface, AddRef.. as they take various number of arguments? u may be able to call without errors, bt result will be unexpected. without having specific info about the functions in interface, u won't be able to proceed..

                          G Offline
                          G Offline
                          glitteringsound
                          wrote on last edited by
                          #12

                          Yeah true.!! but _asm patch helped me out in this regard. _asm { push argument_1 push argument_2 call proc ;function address } Here suppose i have given all info (parameters or arguments) at run time for NOW(Which I have passed it on runtime console). For future(might be later) I will load every thing from TLB's. e.g (How to know that QueryInterface taking 3 params of different type? This is ITypeLibe which provides information from TLB of that Component which I can query from registry to load specific TLB and give me specific function signature and types). Hence I got all params and function names as well(Which I can decipher from signature working with RE's(regular expression)). But Now I need to call the function, which would have specific address(NOT KNOWN) arguments(parameters) which I have collected from TLB, and name as well. How that address corresponds to that function name to which I am going to call. For this I need to traverse vtable which is holding functional addresses, LASTLY need to correspond function address with NAME of that function. This is I dont know. How? More over one function with the same name may appear in vtable(Overloading case). In that case we need to distinguish function names w.r.t their addresses. How to tackle ?

                          1 Reply Last reply
                          0
                          • G glitteringsound

                            I need to call all the functions of COM Interface exposed methods at runtime. For this I need to access vtable of COM coclass where all addresses of exposed methods of its interfaces are stored. e.g Say Math is COM object and its exposed interface is "Operations" and "Sum" is the method of this interface. I need the address of "Sum", so that I can call it on run time. Just like you use loadlibrary for DLL and adter passing functional address, using GetProcAddress we can call function at runtime. Here in COM same I need to do. But here no LoadLibrary , and no GetProcAddress. Just we need to iterate vtable and one by one we'll get the addresses of methods and we'll call these methods on run time. Any Suggestions?

                            K Offline
                            K Offline
                            KingsGambit
                            wrote on last edited by
                            #13

                            Even if you get the function pointers this way, how to get the function signature (arguments and types)? You may have to use type library to get more details about the interface functions and supported interfaces.

                            1 Reply Last reply
                            0
                            • K KingsGambit

                              Checking the first 4 bytes of the location pointed to by the interface pointer returned by CoCreateInstance() function might give you the address of vtable (I have not tried it). But why do you want to do this?

                              F Offline
                              F Offline
                              Frederick J Harris
                              wrote on last edited by
                              #14

                              Here is a link to very extensive work & code concerning this, that is, dumping VTables and VPtrs... http://www.jose.it-berater.org/smfforum/index.php?board=362.0

                              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