SnmpMgrTrapListen function (mgmtapi.h)

[SNMP is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use Windows Remote Management, which is the Microsoft implementation of WS-Man.]

The SnmpMgrTrapListen function registers the ability of an SNMP manager application to receive SNMP traps from the SNMP Trap Service. This function is an element of the SNMP Management API.


  [out] HANDLE *phTrapAvailable


[out] phTrapAvailable

Pointer to an event handle to receive an indication that there are traps available, and that the application should call the SnmpMgrGetTrap function.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError, which may return any of the following error codes.

Return code Description
Indicates a memory allocation error.
Indicates that this function has already been called.
Indicates one or more errors occurred; traps are not accessible. The application can attempt to call the function again.

This function may return other system errors as well.


It is important to note that for users who are not administrators, the SnmpMgrTrapListen function succeeds only if the SNMP trap service has been started.

The application must always call the SnmpMgrTrapListen function before calling the SnmpMgrGetTrap function. This is because the event handle pointed to by the phTrapAvailable parameter enables the event-driven acquisition of SNMP traps. The SNMP Management API signals an application's event when the SNMP Trap Service delivers a trap.

The application can also poll the SnmpMgrGetTrap function for traps at regular intervals. In this case, the application should repeatedly call SnmpMgrGetTrap until the function returns zero.

Windows Server 2003:  SNMP manager applications can call SnmpMgrClose with a NULLsession parameter to clean up resources associated with a successful call to the SnmpMgrTrapListen function. Note, however, that if your application is a DLL, it should not call SnmpMgrClose from its DllMain entry-point function.


Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header mgmtapi.h
Library Mgmtapi.lib
DLL Mgmtapi.dll

See also

SNMP Functions

Simple Network Management Protocol (SNMP) Overview