Solved

how can i enumerate the interfaces supported by an IDispatch?

Posted on 2004-10-06
4
431 Views
Last Modified: 2010-04-05
it sure would be nice to be able to get an enumeration of all the interfaces supported by an IDispatch descendant.  any ideas?  i ask because i am not sure what type(s) are being returned.  i want to not need to know the GUID.

thanks!
mp
0
Comment
Question by:mikepj
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 125 total points
ID: 12244262
Interesting. I never knew this was possible to do. Actually, I don't think this is possible. Or if it's possible, it must have been implemented in some way by the development tool since there's no logic build-in into Delphi or COM to do this.
0
 
LVL 2

Author Comment

by:mikepj
ID: 12244392
i'm not saying it's possible but i am assuming it's possible.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12247137
IDispatch is just an interface type that allows the use of dispatch interfaces. Basically, a dispatch interface is just a list of method indexes that also provide the correct syntax for the method. With the dispatch interface you can call the methods through the IDispatch interface of the object. This is done through the Invoke method of IDispatch that wants the dispatch ID of the method and some additional parameters and stuff.

IDispatch just lacks the information to provide information about the object itself. There are no methods in this interface that will help you enumerate all interfaces.

There is a way, though. This is a pure Delphi solution though, since other tools might have solved it differently. The TObject class has a class method called GetInterfaceTable that points to the table of interfaces that Delphi stores internally. Definitions:

type
  PInterfaceEntry = ^TInterfaceEntry;
  TInterfaceEntry = packed record
    IID: TGUID;
    VTable: Pointer;
    IOffset: Integer;
    ImplGetter: Integer;
  end;
  PInterfaceTable = ^TInterfaceTable;
  TInterfaceTable = packed record
    EntryCount: Integer;
    Entries: array[0..9999] of TInterfaceEntry;
  end;

If you have access to this interface table then you could enumerate all GUID's that this type supports. However, this only works for Delphi components and even worse, it's version-specific! It could even change when you patch your Delphi version. And you can only access it if you know the class type instead of the interface type.

So what if your IDispatch object was written in another language? Or in an unknown Delphi version? Well, then you just can't enumerate the interfaces, since all you have are the methods provided by the IDispatch interface.
0
 
LVL 2

Author Comment

by:mikepj
ID: 12253390
thank you for your response!

the trouble is that i get an IDispatch type returned and the only way i can find out anything is to try "as" for a "shopping list" of possible interfaces.

i'll leave this up for a bit and see if anyone comes up with anything more.

thanks,
mp
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now