event tracing for windows example, windows 7 home
代码
// EventLogging.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <evntprov.h> // ETW Publishing header
#include <winevt.h> // 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 event Error = %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;
}
//
#include "stdafx.h"
#include <windows.h>
#include <evntprov.h> // ETW Publishing header
#include <winevt.h> // 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 event Error = %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;
}