I just started with WinSNMP (in Visual Studio 2005), and have written the following code. (This is a snippet.)
m_Status = SnmpStartup(&m_MajorVersion, &m_MinorVersion, &m_Level, &m_TranslateMode, &m_RetransmissionMode);
ASSERT(m_Status != SNMPAPI_FAILURE);
m_SnmpSession = SnmpCreateSession(GetSafeHwnd(), WM_SNMP_TEST, &CallBackFunction, NULL);
ASSERT(m_SnmpSession != SNMPAPI_FAILURE);
SnmpStrToOid("1.3.6.1.2.1.1.3.0", m_pIOD);
m_Status = SnmpRegister(&m_SnmpSession, m_pSrcEntity, m_pDstEntity, m_pContext, m_pIOD, SNMPAPI_ON);
SNMPAPI_STATUS temp = SnmpGetLastError(m_SnmpSession);
ASSERT(m_Status != SNMPAPI_FAILURE);
CallBackFunction is defined as:
SNMPAPI_STATUS CALLBACK CallBackFunction
(HSNMP_SESSION hSession=0, HWND hWnd=0, UINT wMsg=0,
WPARAM wParam=0, LPARAM lParam=0, LPVOID lpClientData=0)
{
return (SNMPAPI_SUCCESS);
}
m_pSrcEntity, m_pDstEntity, m_pContext are NULL in the example. WM_SNMP_TEST has been registed by me as a Windows Message.
The first ASSERT succeeds. m_SnmpSession gets the value 0x00000001 when the SnmpCreateSession() is called, so second ASSERT also succeeds. Is that normal? I mean can the session have the mentioned value? Then the SnmpRegister() fails and SnmpGetLastError() returns 1. My Windows SNMP and SNMP Trap services are running. What am I doing wrong?