Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Aug 26, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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
        IID_objInterface = TLI.InterfaceInfoFromObject(ObjectOrInterfaceIID) _
    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
End Function
Alberto Falossi
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date