Solved

how can i enumerate the interfaces supported by an IDispatch?

Posted on 2004-10-06
4
453 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
[X]
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
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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