Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ SNMP
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)
	{
//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 26-Oct-12 14:54pm
Comments
Sandeep Mewara at 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)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100