Microsoft DirectX 8.1 (C++)

Custom Guide Store Objects (Visual Basic)

The Guide Store is fully extensible. Applications can create their own objects and store these in the repository.

Because Visual Basic does not support aggregation, custom objects must be generic objects that do not have unique methods or data. To create a collection of such objects, first retrieve a top-level collection of objects by using the GuideStore.Objects property. You can now add objects to this collection by using Objects.AddNew.

A generic object is not useful until you attach data to it, which is done by adding metaproperties. To associate metaproperties with an object, retrieve the metaproperties of the generic object by using GuideStore.MetaPropertiesOf. Add an existing MetaProperty object to this collection by using MetaProperties.Add, or create a new, initialized MetaProperty by using MetaProperties.AddNew.

The following sample code creates a generic object to represent a writer, and assigns the writer's name as a metaproperty. For simplicity, error-checking is omitted.

Private Sub MakeNewWriter(varName As Variant)
     
  ' Create or retrieve the MetaPropertyType.
 
  Dim MPType As MetaPropertyType
  Dim MPSets As IMetaPropertySets
  Set MPSets = g_gs.MetaPropertySets
  Set MPType = MPSets.Lookup("Writer.Name")
 
  ' Create a MetaProperty of that type.
 
  Dim MP As MetaProperty
  Set MP = MPType.New(0, varName)
 
  ' Get the collection of all objects.
 
  Dim AllObjects As Objects
  Set AllObjects = g_gs.Objects

  ' See if the object with the metaproperty already exists.

  Dim MatchingObjects As Objects
  Set MatchingObjects = AllObjects.ItemsWithMetaProperty(MP)
  
  ' If it doesn't, create it and give it the metaproperty.
  
  If MatchingObjects.count = 0 Then

      ' Create a generic object.
 
      Dim UnkWriter As IUnknown
      Set UnkWriter = AllObjects.AddNew
 
      ' Get a collection of the metaproperties of the new object.
      ' This is an empty collection.
    
      Dim MPs As MetaProperties
      Set MPs = g_gs.MetaPropertiesOf(UnkWriter)
 
      ' Add the writer's name to the object's collection
      ' of metaproperties.
 
      MPs.Add MP
 
   End If
      
End Sub