ISystemDebugEventFire Example (Visual J++)

   

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.

// Import required class libraries.
import vaiea.*;
import com.ms.com.Variant;
import com.ms.com.SafeArray;

// Declare an event creator object.
static ISystemDebugEventFireAuto m_IEA = null;

// Now define GUIDs for the component that will generate VSA events, as
// well as a user-defined event,and a parameter that can hold a GUID if
// you wanted to pass a GUID as a parameter to FireEvent.

static String SAMPLE_SOURCE_GUID = "{E736B2E0-652D-11d1-A06D-00AA006BBFAD}";
static String SAMPLE_EVENT_GUID = "{E736B2E2-652D-11d1-A06D-00AA006BBFAD}";
static String SAMPLE_GUID_PARAMETER = "{E736B2E5-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 creator object.
private static void SampleCreateIEA()
   {
      m_IEA = new MSVSAAutomatableInprocEventCreator();
   }

// Begin a session with the component.
// SAMPLE_SOURCE_GUID identifies the component.
// Specify a name (Sample Session Name) to uniquely identify the session
// to Visual Studio Analyzer. The session name must be unique for each
// time, each component, and each run of the component.
private static void SampleBeginSession()
   {
      m_IEA.BeginSession( SAMPLE_SOURCE_GUID, "Sample Session Name" );
   }

// Verify that the event creator object is ready to generate events.
private static boolean SampleIsActive()
   {
      boolean registered[] = { false, false };
      
      m_IEA.IsActive( registered );
      return( registered[ 0 ] );
   }

// Prepare to generate an event.
// Declare an array to hold event parameters.
private static final int MAXPARAMS = 2;

// Event data is passed in arrays of parameter names (keys) and values.
private static void SampleFireEvent()
   {
      SafeArray saKeys = new SafeArray( Variant.VariantString, MAXPARAMS
);
      saKeys.setString( 0, "CorrelationID" );         // Stock parameter
      saKeys.setString( 1, "This is a custom parameter" );
      Variant rgKeys = new Variant( saKeys, false );
      
      SafeArray saValues = new SafeArray( Variant.VariantString,
MAXPARAMS );
      saValues.setString( 0, "String parameter" );
      saValues.setString( 1, "Another string parameter" );
      Variant rgValues = new Variant( saValues, false );
      
      // Generate the event.
      // SAMPLE_EVENT_GUID is the GUID of the registered event to
      // generate.
      m_IEA.FireEvent( SAMPLE_EVENT_GUID, rgKeys, rgValues, MAXPARAMS, 
         eVSAEventFlags.cVSAEventDefaultSource |
         eVSAEventFlags.cVSAEventDefaultTarget );
   }

// End the session when you are finished generating events.
private static void SampleEndSession()
   {
      m_IEA.EndSession();
   }

// Destroy the event creator object.
private static void SampleDestroyIEA()
   {
      m_IEA = null;
   }