Getting the index of a function into a virtual table

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting the index of a function into a virtual table

Jeff M.
So, I'm wrapping up a COM object, and looking through some of the ones
in the community image as examples. And, typically I see a definition
like this:

<virtual stdcall: sdword 4 IUnknown* GUID* IUnknown**>

Now, I assume that the '4' is the index into the virtual function table
where this function is located. However, in the documentation I can
find no reference to how this is gotten.

Any pointers? No pun intended. :-)

Jeff M.


Reply | Threaded
Open this post in threaded view
|

Re: Getting the index of a function into a virtual table

Blair McGlashan-4
"Jeff M." <[hidden email]> wrote in message
news:[hidden email]...

> So, I'm wrapping up a COM object, and looking through some of the ones
> in the community image as examples. And, typically I see a definition
> like this:
>
> <virtual stdcall: sdword 4 IUnknown* GUID* IUnknown**>
>
> Now, I assume that the '4' is the index into the virtual function table
> where this function is located. However, in the documentation I can
> find no reference to how this is gotten.
>
> Any pointers? No pun intended. :-)
>

Usually it is extracted automatically from a type-library by the type
library analyzer (which is used the the AX Component Wizard to generate
wrapper classes). If you don't have a type-library, then you can build one
from IDL. If you don't have IDL, then you can construct it pretty easily (in
most cases) from the C/C++ .h file.  This will work even for custom
(non-automation) interfaces, although there is some loss of fidelity in the
tlb representation that can lose some of the nuances in the original IDL.
Usually this is not a significant issue, however.

If you don't want to go down the automatic generation route (and there are a
lot of advantages to doing so, not least avoiding the need to do tedious and
error prone translation), then you will need to work out the vtbl indices
yourself.  This is pretty easy though - just count the methods all the way
up the inheritance hierarchy, including IUnknown.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Getting the index of a function into a virtual table

Jeff M.
Blair McGlashan wrote:
> If you don't want to go down the automatic generation route (and there are a
> lot of advantages to doing so, not least avoiding the need to do tedious and
> error prone translation), then you will need to work out the vtbl indices
> yourself.  This is pretty easy though - just count the methods all the way
> up the inheritance hierarchy, including IUnknown.

Yeah, I finally got down into counting and it works. Took me a few
tries to realize that Dolphin expects the counting to start at 1,
though. :-)

Thanks!

Jeff M.