WMI

G

Guest

Hi all, sorry for my bad englisch . How I enumerate classes in the scope ?
thanx
marek g.
 
A

Anushi

Hi Marek,

The following is a piece of code that enumerates all the classes defined in
a type library..

' Return a collection with all creatable classes of
' the type library specified in TypeLibFile.
'
' Set IncludeNotCreatableClasses = True to include not creatable classes
' (that is, those with Instancing property set to PublicNotCreatable) too.

' Be sure that "TypeLib Information" type library (TlbInf32.tlb)
' is referenced in your VB project.

Function GetClasses(ByVal TypeLibFile As String, _
Optional ByVal IncludeNotCreatableClasses As Boolean) As Collection
Dim TLI As New TLIApplication
Dim TypeLibrary As TypeLibInfo
Dim Class As CoClassInfo

' raises an error if unable to open the type library
' (e.g. file not found or not a TLB)
Set TypeLibrary = TLI.TypeLibInfoFromFile(TypeLibFile)

' prepare the result
Set GetClasses = New Collection

' fill the return collection with class names
For Each Class In TypeLibrary.CoClasses
' exclude not creatable classes if necessary
If IncludeNotCreatableClasses Or (Class.AttributeMask And _
TYPEFLAG_FCANCREATE) Then
' the class is creatable or we don't care
' about the creatable attribute
GetClasses.Add Class.Name, Class.Name
End If
Next
End Function

However, it has been written in VB. There's another article that describes
enumerating your leaf classes through MFC (applicable to VC++.NET 2002,
2003) :

http://www.codeproject.com/cpp/enumleafclasses.asp

HTH,
Anushi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top