如何在VC中記錄系統日誌
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#define Register_Event_Error 0x00000001;
#define Report_Event_Error 0x00000002;
int main(int argc, char* argv[])
{
HANDLE EventResourceHandle;
LPCTSTR ErrorEventStr = "This My Test Text!";
LPTSTR ServiceName = "Service"; //這裡的服務名稱可以是任意的,不過建議使用已經安裝的服務名稱
EventResourceHandle = RegisterEventSource( NULL, ServiceName );
if ( EventResourceHandle != NULL ) {
if ( !ReportEvent( EventResourceHandle,
EVENTLOG_INFORMATION_TYPE,
0,
0,
NULL,
1,
0,
&ErrorEventStr,
NULL) )
{
printf("Could not report the event.");
return Report_Event_Error;
}
printf("Write Text to Log successed!");
DeregisterEventSource( EventResourceHandle );
return 0;
}
printf("Could not register the event source.");
return Register_Event_Error;
}