devxlogo

GetClassesByInterface – Retrieve all the classes that implement a given interface

GetClassesByInterface – Retrieve all the classes that implement a given interface

' Return all classes of the type library specified in' TypeLibFile parameter that support a certain interface.' the interface can be specified as an Object or through its IID' Be sure that "TypeLib Information" type library (TlbInf32.tlb)' is referenced in your VB project.Function GetClassesByInterface(ByVal TypeLibFile As String, _    ObjectOrInterfaceIID As Variant) As Collection    Dim TLI As New TLIApplication    Dim TypeLibrary As TypeLibInfo    Dim Class As CoClassInfo    Dim Interface As InterfaceInfo    Dim IID_objInterface As String        ' prepare the result    Set GetClassesByInterface = New Collection        ' raises an error if unable to open the type library    ' (e.g. file not found or not a TLB)    Set TypeLibrary = TLI.TypeLibInfoFromFile(TypeLibFile)        ' get the IID of requested interface    If VarType(ObjectOrInterfaceIID) = vbString Then        IID_objInterface = ObjectOrInterfaceIID    Else        IID_objInterface = TLI.InterfaceInfoFromObject(ObjectOrInterfaceIID) _            .Guid    End If        ' fill the return collection with names of    ' classes that implement the interface    For Each Class In TypeLibrary.CoClasses        For Each Interface In Class.Interfaces            ' compare GUIDs            If StrComp(Interface.Guid, IID_objInterface, vbTextCompare) = 0 Then                ' ok, this class implements the interface                GetClassesByInterface.Add Class.Name, Class.Name                Exit For            End If        Next    Next    End Function

See also  Comparing different methods of testing your Infrastructure-as-Code
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist