SnmpMgrTrapListen  2X9..A5 

The SnmpMgrTrapListen function registers the ability of a manager application to receive SNMP traps.

BOOL SnmpMgrTrapListen(

    HANDLE *phTrapAvailable

// event handle indicating trap(s) available

   );

 

 

Parameters

phTrapAvailable

[out] Points to an event handle that will be used to indicate that there are traps available, and that the application should call the SnmpMgrGetTrap5_2__VT function.

 

Return Values

If the function succeeds, the return value is TRUE.

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

Error Code

Description

SNMP_MEM_ALLOC_ERROR

Indicates a memory allocation error.

SNMP_MGMTAPI_TRAP_DUPINIT

Indicates that this function has already been called.

SNMP_MGMTAPI_AGAIN

Indicates an error occurred; the application can attempt to call the function again.

 

This function may return other system errors as well.

Remarks

It is important to note that the SnmpMgrTrapListen function succeeds on Windows NT 4.0 only if the SNMP Trap Service has been started. See Turning SNMP On and OffLX8SAM for additional information.

The event that the phTrapAvailable parameter points to allows event-driven acquisition of SNMP traps. If you call the SnmpMgrTrapListen function first, you can ignore the event handle and poll the SnmpMgrGetTrap5_2__VT function for traps at regular intervals instead.

Another method to acquire traps is to create a thread to wait on the event using the WaitForSingleObjectJ9IQ2G function. When the call initiates an event, the thread should clear the event using the ResetEvent1.IH1GV function. Then the thread should repeatedly call the SnmpMgrGetTrap function until it returns a value of FALSE.

Always call the SnmpMgrTrapListen function before calling SnmpMgrGetTrap to receive traps. If an SNMP manager application calls SnmpMgrGetTrap first to receive traps, it returns a value of FALSE, even if there are traps available. If the application calls GetLastError11C2VS7 before calling SnmpMgrTrapListen, GetLastError returns the error code SNMP_MGMTAPI_TRAP_ERRORS.

See Also

SnmpMgrGetTrap5_2__VT, WaitForSingleObjectJ9IQ2G, ResetEvent1.IH1GV