peibaishi 发表于 2015-5-14 06:43:59

event tracing for windows example, windows 7 home

代码

// EventLogging.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include            // ETW Publishing header
#include            // EventLog Header.

#include "Manifest\manifest.h"

int _tmain(int argc, _TCHAR* argv[])
{
    //first step - register the event
    REGHANDLE hPub = NULL;
    ULONG res = EventRegister(&DOTNETPERFORMANCE_TECHNICALWRITING_PUBLISHER, NULL, NULL, &hPub);   
    if (ERROR_SUCCESS != res){
      _tprintf(_T("Could not register event\n"));
    }
    else{
      _tprintf(_T("Event registered successfully\n"));
    }
    EVENT_DATA_DESCRIPTOR opEventDesc;
    PWSTR pwsOp = L"My Operational Event";
    EventDataDescCreate(&opEventDesc, pwsOp, ((ULONG)wcslen(pwsOp)+1)*sizeof(WCHAR));
    res = EventWrite(hPub, &DNP_OP_EVENT, 1, &opEventDesc);
    if (ERROR_SUCCESS != res){
      _tprintf(_T("Could not raise operational eventError = %i\n"), res);
    }
    else{
      _tprintf(_T("Operational event successfully raised\n"));
    }
    EVENT_DATA_DESCRIPTOR debugEventDesc;
    PWSTR pwsDebug = L"My Debug Event";
    EventDataDescCreate(&debugEventDesc, pwsDebug, ((ULONG)wcslen(pwsDebug)+1)*sizeof(WCHAR));

    res = EventWrite(hPub, &DNP_DEBUG_EVENT, 1, &debugEventDesc);
    if (ERROR_SUCCESS != res){
      _tprintf(_T("Could not raise debug event.Error = %i\n"), res);
    }
    else{
      _tprintf(_T("Debug event successfully raised\n"));
    }
    EventUnregister(hPub);
    return 0;
}
  
页: [1]
查看完整版本: event tracing for windows example, windows 7 home