Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I have a code like this:

C++
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)
	{
//Loging to the file
		CallbackError("TrapCaptureThread",buf.GetBuffer());
		CallbackError("TrapCaptureThread","SnmpMgrTrapListen error!");
	}
				
	return Thread_ErrSNMPListenReport_ExitCode; 
} 
// Start a loop to get traps


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
Posted
Comments
Sandeep Mewara 28-Oct-12 3:45am    
SnmpMgrTrapListen return 0 (which means some error) - sure? Debugged?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900