Results 1 to 4 of 4

Thread: Get the Interfaces implemented by a given Class

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Oz
    Posts
    4

    Wink Get the Interfaces implemented by a given Class

    Howdi,

    Does anybody know if/how could I find out if a class implements a certain interface?
    I know the InProcServer file name, class name and CLSID for the class.
    I searched through the registry for some clues, but I couldn't find anything there. I hoped I would find an API call to hep me, but no luck there too.
    I'm sure somebody out there knows something I don't about this issue. Could you please help?

    Cheers

  2. #2
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    If TypeOf CMyClass Is IMyInterface then
    'CMyClass Implements IMyInterface
    End if

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Oz
    Posts
    4

    Thumbs down

    Yes, but it only works after I get a reference to the class in my project. I might have not been very clear, but what I want to do is something like this.
    The user browse to a registered ActiveX dll file, opens it and gets a list of classes defined in that dll. Next he/she selects a class in the list and gets the CLSID. This is not very complicated, but I want to refine the classes list so it will contain only the classes that implement a certain interface. If I could instanciate the selected class at run-time, the Is TypeOf would work, but how can I do this?


  4. #4
    Junior Member
    Join Date
    Aug 2001
    Location
    UK
    Posts
    16

    Lightbulb Determining if a class is the implementation of an interface

    You will need to examine the appropriate DLL file with the OLE/COM object viewer. Assuming (I know I shouldn't) that your DLL is a normal COM DLL, you can find it in the "Type Libraries Heirarchy" of the OLE/COM Viewer. Once you have found it, click on the Binoculars with the yellow key-like logo on the toolbar. This will bring up the TypeLib Viewer (a new window) for that DLL. In the right hand pane you will see the IDL (Interface Definition Language) data which details the classes and methods contained. In the left pane will be a tree heirarcht for coclasses, interfaces and structure and usually other C type objects/structures.

    You can read the IDL (if you can do C++ this shouldn't be too difficult because it's quite similar). The interface definitions are like code blocks with "interface ISomeInterface" syntax - so you can look through the IDL and find them if you really want to get your brain cells into the mechanics. Otherwise, just use the left pane and click on the silver-key looking icons (interface icon) - these nodes expand to display the contained methods. You can click on each method to see how it is defined. The methods won't be in VB, they be in C, so read some C/C++ basics and you should be able to figure out the VB equivalent.

    If you can find these Interfaces, you can use them although typically you will not be able to see them using VBs object browser and in some cases even when you choose the option "Display Hidden Members". This is because DLL's written in C/C++ require the developer to write the IDL (unless they're using a wizard). The IDL can be created in such a way that classes can be seen in the Object Browser but appear to have no methods of any kind - this is a developer trick usually used to prevent reverse engineering of COM software. Don't ask me exactly how this is done, I'm still learning that bit ;-)

    $CCF$

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width