#pragma warning(push)
#pragma warning(disable : 4793)
void __cdecl WriteToEventLog(WORD eventLogType, DWORD eventId, LPCTSTR sourceName, LPCTSTR pszFormat, ...) throw()
{
const int LOG_EVENT_MSG_SIZE = 256;
TCHAR chMsg[LOG_EVENT_MSG_SIZE];
HANDLE hEventSource;
LPTSTR lpszStrings[1];
va_list pArg;
va_start(pArg, pszFormat);
_vsntprintf_s(chMsg, LOG_EVENT_MSG_SIZE, LOG_EVENT_MSG_SIZE-1, pszFormat, pArg);
va_end(pArg);
chMsg[LOG_EVENT_MSG_SIZE - 1] = 0;
lpszStrings[0] = chMsg;
/* Get a handle to use with ReportEvent(). */
hEventSource = RegisterEventSource(NULL, sourceName);
if (hEventSource != NULL)
{
/* Write to event log. */
ReportEvent(hEventSource, eventLogType, 0, eventId, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
DeregisterEventSource(hEventSource);
}
}
#pragma warning(pop)