ISystemDebugEventFire Example (Visual Basic)

See Also   Applies To

The following code shows the use of all methods in ISystemDebugEventFire. In order to modify this code for your own use, you need to add error handling. Each method can raise errors, which you should make sure to trap. You can use the Windows® application Guidgen.exe to generate globally unique IDs (GUIDs) where required.

Before you can generate events from a component, you must register the component and the events you want it to generate with Visual Studio Analyzer. ISystemDebugEventInstall provides methods for accomplishing this registration.

' Declare an event creator object like this; 
' this variable is module-level.
Private mIEC As MSVSAAutomatableInprocEventCreator

' Instantiate the event creator object.
Private Sub Sample_InstantiateIEC()
   Set mIEC = New MSVSAAutomatableEventSourceInstaller
End Sub

' Begin a session with the event creator object.
Private Sub Sample_BeginSession(ByVal sSourceGUID As String)
   Dim sSessionName As String
   ' sSourceGUID identifies the component that will be monitored
   ' sSessionName uniquely identifies the session to 
   ' Visual Studio Analyzer.
   sSessionName = "MyEventSourceFiringSession1"
   ' Begin the session.
   mIEC.BeginSession sSourceGUID, sSessionName
End Sub

' Verify that the event creator object is ready to generate events.
Private Sub Sample_IsActive()
   Dim bIsActive As Boolean
   ' bIsActive is passed by reference and gets the answer.
   ' Run method.
   mIEC.IsActive bIsActive
End Sub

' Generate an event.
Private Sub Sample_FireEvent(ByVal sEventGUID As String)
   Dim Keys(1 To 3) As Variant, Values(1 To 3) As Variant
   Dim lCount As Long
   Dim lFlags As Long
   ' The event creator object must be active (as indicated 
   ' by IsActive method). sEventGUID is the GUID of the event 
   ' to generate and should be the GUID of a registered event.
   
   ' The FireEvent method takes an array of parameter 
   ' names and their values.
   ' These parameters contain descriptive information about the event.
   ' The parameter names are strings.
   ' The parameter values can be strings or numerical.
   ' See VSAStandardParameter for a complete list of the system-defined
   ' event parameter names and descriptions.
   ' Create arrays of keys and values for passing the event parameters.
   ' Fixed-count arrays of variants are used here, but you can also use
   ' dynamic arrays and arrays of strings.
   Keys(1) = PARAM_CausalityID   ' A system-defined parameter
   Values(1) = "SomeIDString"
   Keys(2) = "MyCustomParam1"      ' A custom parameter (text)
   Values(2) = "SomeString"
   Keys(3) = "MyCustomParam2"      ' A custom parameter (number)
   Values(3) = 7
   ' lCount is the total count of event parameters in the array
   lCount = 3
   ' lFlags can contain zero or more Visual Studio Analyzer constants,
   ' which you can combine with a logical OR. See VSAEventFlags for a
   ' complete list of the constants you can use.
   lFlags = cVSAEventStandard
   Generate the event
   mIEC.FireEvent sEventGUID, Keys, Values, lCount, lFlags
End Sub

' End the session with the event creator object when you are
' finished generating events.
Private Sub Sample_EndSession()
   mIEC.EndSession
End Sub

' Destroy the event creator object.
Private Sub Sample_DestroyIEC()
   Set mIEC = Nothing
End Sub