Solved

how can i enumerate the interfaces supported by an IDispatch?

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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