📄 snmptrlg.cpp
字号:
case (SNMPELEA_ERROR) :
return(EVENTLOG_ERROR_TYPE); // error message
default:
return(EVENTLOG_INFORMATION_TYPE); // default to informational
}
}
VOID
WriteLog(
IN NTSTATUS nMsgNumber
)
/*++
Routine Description:
WriteLog is called to write message text to the system event log. This is
a C++ overloaded function. In case a log record cannot be written
to the system event log, TraceWrite is called to write the appropriate
message text to the trace file.
Arguments:
nMsgNumber - This is the message number in SNMPELMG.H in NTSTATUS format
that is to be written to the event log.
Return Value:
None
--*/
{
static USHORT wLogType; // to hold event log type
static BOOL fReportEvent; // return flag from report event
if (hWriteEvent != NULL) // if we have previous log access ability
{
wLogType = MessageType(nMsgNumber); // get message type
fReportEvent = ReportEvent( // write message
hWriteEvent, // handle to log file
wLogType, // message type
0, // message category
nMsgNumber, // message number
NULL, // user sid
0, // number of strings
0, // data length
0, // pointer to string array
(PVOID) NULL); // data address
if ( !fReportEvent ) // did the event log okay?
{ // not if we get here.....
TraceWrite(TRUE, TRUE, // show error in trace file
"WriteLog: Error writing to system event log is %lu\n",
GetLastError() );
FormatTrace(nMsgNumber, NULL); // format trace information
}
}
else // if we can't write to event log
{
TraceWrite(FALSE, TRUE, // show error in trace file
"WriteLog: Unable to write to system event log; handle is null\n");
FormatTrace(nMsgNumber, NULL); // format trace information
}
return; // exit the function
}
VOID
WriteLog(
IN NTSTATUS nMsgNumber, // message number to log
IN DWORD dwCode // code to pass to message
)
/*++
Routine Description:
WriteLog is called to write message text to the system event log. This is
a C++ overloaded function. In case a log record cannot be written
to the system event log, TraceWrite is called to write the appropriate
message text to the trace file.
Arguments:
nMsgNumber - This is the message number in SNMPELMG.H in NTSTATUS format
that is to be written to the event log.
dwCode - This is a double word code that is to be converted to a
string and substituted appropriately in the message text.
Return Value:
None
--*/
{
static USHORT wLogType; // to hold event log type
static TCHAR *lpszEventString[1]; // array of strings to pass to event logger
static BOOL fReportEvent; // return flag from report event
lpszEventString[0] = new TCHAR[34]; // allocate space for string conversion
if (hWriteEvent != NULL) // if we have previous log access ability
{
if ( lpszEventString[0] != (TCHAR *) NULL ) // if storage allocated
{
wLogType = MessageType(nMsgNumber); // get message type
_ultoa(dwCode, lpszEventString[0], 10); // convert to string
fReportEvent = ReportEvent( // write message
hWriteEvent, // handle to log file
wLogType, // message type
0, // message category
nMsgNumber, // message number
NULL, // user sid
1, // number of strings
0, // data length
(const char **) lpszEventString, // pointer to string array
NULL); // data address
if ( !fReportEvent ) // did the event log okay?
{ // not if we get here.....
TraceWrite(TRUE, TRUE, // write trace file record
"WriteLog: Error writing to system event log is %lu\n",
GetLastError() );
FormatTrace(nMsgNumber, lpszEventString); // format trace information
}
}
else // if we can't allocate memory
{
TraceWrite(FALSE, TRUE, // write trace file record
"WriteLog: Error allocating memory for system event log write\n");
FormatTrace(nMsgNumber, NULL); // format trace information
}
}
else // if we can't write to system log
{
TraceWrite(FALSE, TRUE, // write trace file record
"WriteLog: Unable to write to system event log; handle is null\n");
if ( lpszEventString[0] != (TCHAR *) NULL ) // if storage allocated
{
_ultoa(dwCode, lpszEventString[0], 10); // convert to string
FormatTrace(nMsgNumber, lpszEventString); // format trace information
}
else // if we can't allocate memory
{
TraceWrite(FALSE, TRUE, // write trace file record
"WriteLog: Error allocating memory for system event log write\n");
FormatTrace(nMsgNumber, NULL); // format trace information
}
}
delete lpszEventString[0]; // free storage
return; // exit function
}
VOID
WriteLog(
IN NTSTATUS nMsgNumber,
IN DWORD dwCode1,
IN DWORD dwCode2
)
/*++
Routine Description:
WriteLog is called to write message text to the system event log. This is
a C++ overloaded function. In case a log record cannot be written
to the system event log, TraceWrite is called to write the appropriate
message text to the trace file.
Arguments:
nMsgNumber - This is the message number in SNMPELMG.H in NTSTATUS format
that is to be written to the event log.
dwCode1 - This is a double word code that is to be converted to a
string and substituted appropriately in the message text.
dwCode2 - This is a double word code that is to be converted to a
string and substituted appropriately in the message text.
Return Value:
None
--*/
{
static USHORT wLogType; // to hold event log type
static TCHAR *lpszEventString[2]; // array of strings to pass to event logger
static BOOL fReportEvent; // return flag from report event
lpszEventString[0] = new TCHAR[34]; // allocate space for string conversion
lpszEventString[1] = new TCHAR[34]; // allocate space for string conversion
if (hWriteEvent != NULL) // if we have previous log access ability
{
if ( (lpszEventString[0] != (TCHAR *) NULL) &&
(lpszEventString[1] != (TCHAR *) NULL) ) // if storage allocated
{
wLogType = MessageType(nMsgNumber); // get message type
_ultoa(dwCode1, lpszEventString[0], 10); // convert to string
_ultoa(dwCode2, lpszEventString[1], 10); // convert to string
fReportEvent = ReportEvent( // write message
hWriteEvent, // handle to log file
wLogType, // message type
0, // message category
nMsgNumber, // message number
NULL, // user sid
2, // number of strings
0, // data length
(const char **) lpszEventString, // pointer to string array
NULL); // data address
if ( !fReportEvent ) // did the event log okay?
{ // not if we get here.....
TraceWrite(TRUE, TRUE, // write a trace file entry
"WriteLog: Error writing to system event log is %lu\n",
GetLastError() );
FormatTrace(nMsgNumber, lpszEventString); // format trace information
}
}
else // if we can't allocate memory
{
TraceWrite(FALSE, TRUE, // write trace file record
"WriteLog: Error allocating memory for system event log write\n");
FormatTrace(nMsgNumber, NULL); // format trace information
}
}
else // if we can't write to system log
{
TraceWrite(FALSE, TRUE, // write trace file entry
"WriteLog: Unable to write to system event log; handle is null\n");
if ( (lpszEventString[0] != (TCHAR *) NULL) &&
(lpszEventString[1] != (TCHAR *) NULL) ) // if storage allocated
{
_ultoa(dwCode1, lpszEventString[0], 10); // convert to string
_ultoa(dwCode2, lpszEventString[1], 10); // convert to string
FormatTrace(nMsgNumber, lpszEventString); // format trace information
}
else // if we can't allocate memory
{
TraceWrite(FALSE, TRUE, // write trace file record
"WriteLog: Error allocating memory for system event log write\n");
FormatTrace(nMsgNumber, NULL); // format trace information
}
}
delete lpszEventString[0]; // free storage
delete lpszEventString[1]; // free storage
return; // exit function
}
VOID
WriteLog(
IN NTSTATUS nMsgNumber,
IN DWORD dwCode1,
IN LPTSTR lpszText1,
IN LPTSTR lpszText2,
IN DWORD dwCode2
)
/*++
Routine Description:
WriteLog is called to write message text to the system event log. This is
a C++ overloaded function. In case a log record cannot be written
to the system event log, TraceWrite is called to write the appropriate
message text to the trace file.
Arguments:
nMsgNumber - This is the message number in SNMPELMG.H in NTSTATUS format
that is to be written to the event log.
dwCode1 - This is a double word code that is to be converted to a
string and substituted appropriately in the message text.
lpszText1 - This contains a string parameter that is to be substituted
into the message text.
lpszText2 - This contains a string parameter that is to be substituted
into the message text.
dwCode2 - This is a double word code that is to be converted to a
string and substituted appropriately in the message text.
Return Value:
None
--*/
{
static USHORT wLogType; // to hold event log type
static TCHAR *lpszEventString[4]; // array of strings to pass to event logger
static BOOL fReportEvent; // return flag from report event
lpszEventString[0] = new TCHAR[34]; // allocate space for string conversion
lpszEventString[1] = new TCHAR[MAX_PATH+1]; // allocate space for string conversion
lpszEventString[2] = new TCHAR[MAX_PATH+1]; // allocate space for string conversion
lpszEventString[3] = new TCHAR[34]; // allocate space for string conversion
if (hWriteEvent != NULL) // if we have previous log access ability
{
if ( (lpszEventString[0] != (TCHAR *) NULL) &&
(lpszEventString[1] != (TCHAR *) NULL) &&
(lpszEventString[2] != (TCHAR *) NULL) &&
(lpszEventString[3] != (TCHAR *) NULL) ) // if storage allocated
{
wLogType = MessageType(nMsgNumber); // get message type
_ultoa(dwCode1, lpszEventString[0], 10); // convert to string
strcpy(lpszEventString[1],lpszText1); // copy the string
strcpy(lpszEventString[2],lpszText2); // copy the string
_ultoa(dwCode2, lpszEventString[3], 10); // convert to string
fReportEvent = ReportEvent( // write message
hWriteEvent, // handle to log file
wLogType, // message type
0, // message category
nMsgNumber, // message number
NULL, // user sid
4, // number of strings
0, // data length
(const char **) lpszEventString, // pointer to string array
NULL); // data address
if ( !fReportEvent ) // did the event log okay?
{ // not if we get here.....
TraceWrite(TRUE, TRUE, // write trace file record
"WriteLog: Error writing to system event log is %lu\n",
GetLastError() );
FormatTrace(nMsgNumber, lpszEventString); // format trace information
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -