Hi Guys,
I have a code like this:
if(!(dwResult = SnmpMgrTrapListen(&m_hNewTrapsEvent)))
{
LPVOID lpMsgBuf;
CString buf;
dwResult = GetLastError();
switch (dwResult)
{
case SNMP_MEM_ALLOC_ERROR:
buf="memory allocation error";
break;
case SNMP_MGMTAPI_TRAP_DUPINIT:
buf="this function has already been called";
break;
case SNMP_MGMTAPI_TRAP_ERRORS:
buf="one or more errors occurred; traps are not accessible. The application can attempt to call the function again";
break;
default:
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM|
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwResult,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,0,NULL);
buf.Append((LPTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
if (buf.GetLength() == 0)
{
CString bufConst("Err No: ");
bufConst.AppendFormat("%u", dwResult);
buf = bufConst;
}
break;
}
if (CallbackError)
{
CallbackError("TrapCaptureThread",buf.GetBuffer());
CallbackError("TrapCaptureThread","SnmpMgrTrapListen error!");
}
return Thread_ErrSNMPListenReport_ExitCode;
}
In the code, I call SnmpMgrTrapListen, if this call is OK, then I start a loop and start getting traps otherwise I will write the error happend to the log and return.
I have a very weird problem, sometimes when I stop/start my service, SnmpMgrTrapListen return 0 (which means some error), but the error message (from the FormatMessage function) is: "The operation completed successfully.--" !!!! So if an error has occured whay I am getting successfull message!
any Idea?
Thank you,
Aidin