Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how can i enumerate the interfaces supported by an IDispatch?

Posted on 2004-10-06
4
447 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 45
Wincontrol not (correctly) drawn 15 40
Delphi: barcode reading on android platform 1 51
DBCtrlGrid, Delphi, Scroll 7 26
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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