118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
/*++
|
|
|
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
|
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
|
|
PURPOSE.
|
|
|
|
Module Name:
|
|
|
|
SimpleProvider.cpp
|
|
|
|
Abstract:
|
|
|
|
Simple ETW provider sample for Windows 7 SDK.
|
|
Demonstrates how to easily create a ETW provider using the macros generated by MC (Message Compiler).
|
|
|
|
Environment:
|
|
|
|
User mode only.
|
|
|
|
--*/
|
|
|
|
#include <stdlib.h>
|
|
#include <windows.h>
|
|
#include <tchar.h>
|
|
#include <stdio.h>
|
|
|
|
//
|
|
// Include header file generated by MC (message compiler) containing support code for logging. The file is
|
|
// generated based on the event definitions in the instrumentation manifest. The file defines macros for each
|
|
// event defined in the manifest and hides calls to ETW Eventing APIs - making the developer's life way easier.
|
|
// Please refer to the ReadMe.txt to see the full script used for generating this file.
|
|
//
|
|
|
|
#include "SimpleProviderEvents.h"
|
|
|
|
int
|
|
main()
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
main() routine.
|
|
Calls the macros defined in the generated code (SimpleProviderEvents.h) to log Integers, Floats, Boolean,
|
|
UnicodeString and Guid.
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful
|
|
STATUS_UNSUCCESSFUL otherwise
|
|
|
|
--*/
|
|
|
|
{
|
|
ULONG Status = ERROR_SUCCESS;
|
|
|
|
//
|
|
// Register the provider. If registration fails then each of the successive event logging calls will fail.
|
|
//
|
|
|
|
Status = EventRegisterMicrosoft_Windows_SDKSample_SimpleProvider();
|
|
if (Status != ERROR_SUCCESS) {
|
|
wprintf(L"ERROR: EventRegisterMicrosoft_Windows_SDKSample_SimpleProvider() Failed with Status code = %d\n", Status);
|
|
exit(Status);
|
|
}
|
|
|
|
//
|
|
// Write Integer data for Event ID 101 in SimpleProvider.man.
|
|
//
|
|
|
|
EventWriteSampleEvt_INT32(3);
|
|
wprintf(L"Using Macro: EventWriteSampleEvt_INT32.\n");
|
|
|
|
//
|
|
// Write Float data for Event ID 102 in SimpleProvider.man.
|
|
//
|
|
|
|
EventWriteSampleEvt_Float(3.0);
|
|
wprintf(L"Using Macro: EventWriteSampleEvt_Float.\n");
|
|
|
|
//
|
|
// Write Boolean data for Event ID 103 in SimpleProvider.man.
|
|
//
|
|
|
|
EventWriteSampleEvt_Bool(TRUE);
|
|
wprintf(L"Using Macro: EventWriteSampleEvt_Bool.\n");
|
|
|
|
//
|
|
// Write String data for Event ID 104 in SimpleProvider.man.
|
|
//
|
|
|
|
EventWriteSampleEvt_UnicodeString(L"Sample String.");
|
|
wprintf(L"Using Macro: EventWriteSampleEvt_UnicodeString.\n");
|
|
|
|
//
|
|
// Write the provider GUID for Event ID 105 in SimpleProvider.man.
|
|
// MICROSOFT_WINDOWS_SDKSAMPLE_SIMPLEPROVIDER is declared in the generated file (SimpleProviderEvents.h).
|
|
//
|
|
|
|
EventWriteSampleEvt_Guid(&MICROSOFT_WINDOWS_SDKSAMPLE_SIMPLEPROVIDER);
|
|
wprintf(L"Using Macro: EventWriteSampleEvt_Guid.\n");
|
|
|
|
//
|
|
// Unregister provider
|
|
//
|
|
|
|
EventUnregisterMicrosoft_Windows_SDKSample_SimpleProvider();
|
|
wprintf(L"Using Macro: EventUnregisterMicrosoft_Windows_SDKSample_SimpleProvider.\n");
|
|
return Status;
|
|
}
|