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.
// Import required class libraries.
import vaesa.*;
import com.ms.com.Variant;
import com.ms.com.SafeArray;
// Declare an event installer object.
static ISystemDebugEventInstallAuto m_ESA = null;
// Now generate GUIDs for the component that will generate VSA events, as
// well as a custom event category, a user-defined event, a dynamic
// component, and the CLSID of a COM component that implements the
// dynamic event interface. The CLSID is used when you want Visual Studio
// Analyzer to start the dynamic component automatically.
static String SAMPLE_SOURCE_GUID = "{E736B2E0-652D-11d1-A06D-00AA006BBFAD}";
static String SAMPLE_CATEGORY_GUID = "{E736B2E1-652D-11d1-A06D-00AA006BBFAD}";
static String SAMPLE_EVENT_GUID = "{E736B2E2-652D-11d1-A06D-00AA006BBFAD}";
static String SAMPLE_DYNAMIC_SOURCE_GUID = "{E736B2E3-652D-11d1-A06D-00AA006BBFAD}";
static String CLSID_SAMPLE_DYNAMIC_SOURCE = "{E736B2E4-652D-11d1-A06D-00AA006BBFAD}";
// Define constants for a system-defined event and category
static String DEBUG_EVENT_CALL = "{6c736d61-BCBF-11D0-8A23-00AA00B58E10}";
static String DEBUG_EVENT_CATEGORY_ALL = "{6c736d85-BCBF-11D0-8A23-00AA00B58E10}";
// Declare variables for event type and for a standard event parameter
static final int DEBUG_EVENT_TYPE_GENERIC = 2;
static final int cVSAStandardParameterCorrelationID = 0x4005;
// Create an event installer object.
private static void SampleCreateESA()
{
m_ESA = new MSVSAAutomatableEventSourceInstaller();
}
// Check to see whether a component is already registered.
// SAMPLE_SOURCE_GUID is the GUID for the component (defined in
// preceding code); substitute the GUID for your component.
private static boolean SampleIsSourceRegistered()
{
boolean registered[] = { false, false };
m_ESA.IsSourceRegistered( SAMPLE_SOURCE_GUID, registered );
return( registered[ 0 ] );
}
// Register the component we checked for in preceding code.
// SAMPLE_SOURCE_GUID is defined in preceding code; substitute the
// GUID for your component.
private static void SampleRegisterSource()
{
m_ESA.RegisterSource( "Sample Event Source", SAMPLE_SOURCE_GUID );
}
// Check to see whether a dynamic component is already registered.
// SAMPLE_DYNAMIC_SOURCE_GUID is the GUID for the dynamic component
// (defined in preceding code); substitute the GUID for your dynamic
// component.
private static boolean SampleIsDynamicSourceRegistered()
{
boolean registered[] = { false, false };
m_ESA.IsDynamicSourceRegistered( SAMPLE_DYNAMIC_SOURCE_GUID,
registered );
return( registered[ 0 ] );
}
// Register the dynamic component we checked for in preceding code.
// SAMPLE_DYNAMIC_SOURCE_GUID is defined in preceding code; substitute
// the GUID for your dynamic component.
// If the dynamic component is a COM object that you want VSA to start
// automatically, provide its CLSID (CLSID_SAMPLE_DYNAMIC_SOURCE).
// Also specify whether the COM object should be started in process (true
// or false). Note that dynamic components should usually be created
// out-of-process so that if they crash, Visual Studio Analyzer will not
// be affected.
private static void SampleRegisterDynamicSource()
{
m_ESA.RegisterDynamicSource( "Sample Dynamic Event Source",
SAMPLE_DYNAMIC_SOURCE_GUID, "A sample dynamic event source",
CLSID_SAMPLE_DYNAMIC_SOURCE, 1 );
}
// Register a system-defined event for the component to generate.
// SAMPLE_SOURCE_GUID is the component that will generate the event
// being registered; DEBUG_EVENT_CALL is the event.
private static void SampleRegisterStockEvent()
{
m_ESA.RegisterStockEvent( SAMPLE_SOURCE_GUID, DEBUG_EVENT_CALL );
}
// Register a custom event category for the component.
// SAMPLE_SOURCE_GUID is the component for the category being registered.
// SAMPLE_CATEGORY_GUID is a unique GUID for the category (defined
// in preceding code); substitute the GUID for your component.
// If you want the category to appear in a hierarchy, specify a parent
// (DEBUG_EVENT_CATEGORY_ALL will be the parent of this category).
// If you do not specify a parent, your category will appear at the top
// level in the Filter Editor.
private static void SampleRegisterCategory()
{
m_ESA.RegisterEventCategory( SAMPLE_SOURCE_GUID, SAMPLE_CATEGORY_GUID,
DEBUG_EVENT_CATEGORY_ALL, "Sample Event Category",
"Category for all sample events", null, 0 );
}
// Register a user-defined event for the component to generate.
// SAMPLE_SOURCE_GUID is the component that will generate the event
// being registered.
// SAMPLE_EVENT_GUID is a unique GUID for the event (defined in
// preceding code); substitute the GUID for your component.
private static void SampleRegisterCustomEvent()
{
m_ESA.RegisterCustomEvent( SAMPLE_SOURCE_GUID, SAMPLE_EVENT_GUID,
"Sample Event", "Event fired by the sample event source",
DEBUG_EVENT_TYPE_GENERIC, SAMPLE_CATEGORY_GUID, null, 0 );
}
// Destroy the event installer object.
private static void SampleDestroyESA()
{
m_ESA = null;
}
// Normally, you would unregister your components only during uninstall.
// The following code would be placed in your component's uninstall
// code.
// Unregister the component.
private static void SampleUnRegisterSource()
{
m_ESA.UnRegisterSource( SAMPLE_SOURCE_GUID );
}
// Unregister the dynamic component.
private static void SampleUnRegisterDynamicSource()
{
m_ESA.UnRegisterDynamicSource( SAMPLE_DYNAMIC_SOURCE_GUID );
}