The following code shows the use of all methods in ISystemDebugEventInstall. 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.
Use ISystemDebugEventInstall to register the component that will generate events and the events that component will generate. After you finish the registration process, you can generate events. ISystemDebugEventFire provides methods for generating events.
Option Explicit
' Code examples for methods in ISystemDebugEventInstall.
' Declare the installer object like this; note that
' this particular variable is module-level.
Private mESI As MSVSAAutomatableEventSourceInstaller
' Instantiate an installer object.
Private Sub Sample_InstantiateESI()
Set mESI = New MSVSAAutomatableEventSourceInstaller
End Sub
' Check to see whether a normal component is registered.
Private Sub Sample_IsSourceRegistered(ByVal sSourceGUID As String)
Dim bIsRegistered As Boolean
' sSourceGUID is the GUID for the component.
' bIsRegistered is passed by reference and gets the answer.
' Run the method.
mESI.IsSourceRegistered sSourceGUID, bIsRegistered
If bIsRegistered Then MsgBox "Registered" Else MsgBox "Not Registered"
End Sub
'Check to see whether a dynamic component is registered.
Private Sub Sample_IsDynamicSourceRegistered(ByVal sSourceGUID As String)
Dim bIsRegistered As Boolean
' sSourceGUID is the GUID for the component.
' bIsRegistered is passed by reference and gets the answer.
' Run the method.
mESI.IsDynamicSourceRegistered sSourceGUID, bIsRegistered
If bIsRegistered Then MsgBox "Registered" Else MsgBox "Not Registered"
End Sub
' Register a normal component with Visual Studio Analyzer.
Private Sub Sample_RegisterEventSource()
Dim sSourceGUID As String
Dim sSourceName As String
' You need a unique GUID to assign to the component;
' substitute your own in the following line.
sSourceGUID = "{B3303262-5C87-11d1-A2AD-00AA003B23FF}"
' Assign a name to the component.
sSourceName = "MyEventSource1"
' Run the method.
mESI.RegisterSource sSourceGUID, sSourceName
End Sub
' Register a dynamic component with Visual Studio Analyzer.
Private Sub Sample_RegisterDynamicSource()
Dim sDynamicSourceGUID As String
Dim sDynamicSourceName As String
Dim sDynamicSourceDescr As String
Dim sCLSID As String
Dim lInProc As Long
' You need a unique GUID to assign to the component;
' substitute your own in the following line.
sDynamicSourceGUID = "{B3303260-5C87-11d1-A2AD-00AA003B23FF}"
' Assign a name and description to the component.
sDynamicSourceName = "MyDynamicEventSource1"
sDynamicSourceDescr = "MyDynamicEventSource1 Description"
' If the dynamic component is a COM object that you want
' VSA to start automatically, you need to provide its CLSID.
' Substitute the correct CLSID in the following line.
sCLSID = "{B3303261-5C87-11d1-A2AD-00AA003B23FF}"
' Specify whether your COM object should be started in process;
' use nonzero for true, zero for false.
lInProc = 1
' Run the method.
mESI.RegisterDynamicSource _
sDynamicSourceGUID, _
sDynamicSourceName, _
sDynamicSourceDescr, _
sCLSID, _
lInProc
End Sub
' Register a system-defined (stock) event.
Private Sub Sample_RegisterStockEvents(ByVal sSourceGUID As String)
' sSourceGUID is the component for which to
' register this stock event.
' Run the method.
' This registers the stock event DEBUG_EVENT_CALL.
mESI.RegisterStockEvent sSourceGUID, DEBUG_EVENT_CALL
End Sub
' Register a user-defined (custom) event.
Private Sub Sample_RegisterCustomEvent(ByVal sSourceGUID As String)
Dim sCustomEventGUID As String
Dim sCustomEventName As String
Dim sCustomEventDescr As String
Dim sIconFile As String, lIcon As Long
' sSourceGUID is the component for which to register
' this custom event.
' You need to create a unique GUID for the event; substitute your own
' in the following line.
sCustomEventGUID = "{A84C4E72-1FD7-11D1-A573-00C04FD5B402}"
' Assign a name and description to the event.
sCustomEventName = "MyCustomDebugEvent1"
sCustomEventDescr = "MyCustomDebugEvent1 Description"
' Pass the next two parameters empty.
sIconFile = "": lIcon = 0
' Run the method.
' This call assigns the defaults for event type and category.
mESI.RegisterCustomEvent _
sSourceGUID, _
sCustomEventGUID, _
sCustomEventName, _
sCustomEventDescr, _
DEBUG_EVENT_TYPE_DEFAULT, DEBUG_EVENT_CATEGORY_ALL, _
sIconFile, _
lIcon
End Sub
' Register a custom event category.
Private Sub Sample_RegisterEventCategory(ByVal sSourceGUID As String)
Dim sEventCategoryGUID As String
Dim sParentGUID As String
Dim sEventCategoryName As String
Dim sEventCategoryDescr As String
Dim sIconFile As String, lIcon As Long
' sSourceGUID is the component for which to register
' this custom event category.
' Create a unique GUID for the custom event category;
' substitute your own in the following line.
sEventCategoryGUID = "{B3303263-5C87-11d1-A2AD-00AA003B23FF}"
' If you want to specify a position in a hierarchy, specify a
' parent, such as All Events; leaving this empty will place
' your custom category at the top level
' in the Filter Editor.
sParentGUID = ""
' Specify a name and description for the event category.
sEventCategoryName = "MyCustomEventCategory1"
sEventCategoryDescr = "MyCustomEventCategory1 Description"
' Pass the next two parameters empty.
sIconFile = "": lIcon = 0
' Run the method.
mESI.RegisterEventCategory sSourceGUID, _
sEventCategoryGUID, _
sParentGUID, _
sEventCategoryName, _
sEventCategoryDescr, _
sIconFile, _
lIcon
End Sub
' Unregister a dynamic component.
Private Sub Sample_UnregisterDynamicSource(ByVal sSourceGUID As String)
' sSourceGUID is the GUID for the component
mESI.UnRegisterDynamicSource sSourceGUID
End Sub
' Unregister a normal component.
Private Sub Sample_UnregisterEventSource(ByVal sSourceGUID As String)
' sSourceGUID is the GUID for the component
mESI.UnRegisterSource sSourceGUID
End Sub
' Destroy the installer object.
Private Sub Sample_DestroyESI()
Set mESI = Nothing
End Sub