#include
//
// FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
//
// PURPOSE: Allows any thread to log an error message
//
// PARAMETERS:
// lpszMsg - text for message
// type - 1 Error 0 Info
// RETURN VALUE:
// none
//
// COMMENTS:
//
#define SZSERVICENAME "Your_Application"
void AddToMessageLog(LPTSTR lpszMsg, int type)
{
TCHAR szMsg[256];
HANDLE hEventSource;
LPTSTR lpszStrings[2];
DWORD dwErr = GetLastError();
// Use event logging to log the error.
//
hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
_stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
lpszStrings[0] = szMsg;
lpszStrings[1] = lpszMsg;
if (hEventSource != NULL) {
if(type)
ReportEvent(hEventSource, // handle of event source
EVENTLOG_ERROR_TYPE, // event type
0, // event category
0, // event ID
NULL, // current user's SID
2, // strings in lpszStrings
0, // no bytes of raw data
(const char **)lpszStrings, // array of error strings
NULL); // no raw data
else
ReportEvent(hEventSource, // handle of event source
EVENTLOG_INFORMATION_TYPE, // event type
0, // event category
1000, // event ID
NULL, // current user's SID
2, // strings in lpszStrings
0, // no bytes of raw data
(const char **)lpszStrings, // array of error strings
NULL); // no raw data
(void) DeregisterEventSource(hEventSource);
}
}
int main(int argc, char* argv[])
{
AddToMessageLog( "dir", 0 );
return 0;
}