SnmpOpen

[This is preliminary documentation and subject to change.]

The SnmpOpen function requests the Microsoft WinSNMP implementation to open a session for the WinSNMP manager application. This WinSNMP function enables the implementation to allocate and initialize memory, resources, data structures, and communications mechanisms. The SnmpOpen function returns a handle to the new WinSNMP session.

HSNMP_SESSION SnmpOpen(
  HWND hWnd,      // handle to the notification window 
  UINT wMsg       // window notification message number 
);
 

Parameters

hWnd
Handle to a window of the WinSNMP manager application to notify when an asynchronous request completes, or when trap notification occurs.
wMsg
Specifies an unsigned integer that identifies the notification message to send to the WinSNMP manager application window.

Return Values

If the function succeeds, the return value is a handle that identifies the WinSNMP session that the implementation opens for the calling manager application.

If the function fails, the return value is SNMPAPI_FAILURE. To get extended error information, call SnmpGetLastError. The SnmpGetLastError function can return one of the following errors.

Error Code Description
SNMPAPI_NOT_INITIALIZED The SnmpStartup function did not complete successfully.
SNMPAPI_ALLOC_ERROR An error occurred during memory allocation.
SNMPAPI_HWND_INVALID The hWnd parameter is not a valid window handle.
SNMPAPI_OTHER_ERROR An unknown or undefined error occurred.

Remarks

The SnmpOpen function returns a unique handle to each open WinSNMP session within the calling WinSNMP manager application. The application must use the session handle that SnmpOpen returns in other WinSNMP function calls to facilitate allocation and deallocation of resources by the implementation. When the implementation allocates resources to an individual session, it performs an orderly release of resources in response to a call to SnmpClose for the session.

The SnmpOpen function passes to the implementation the handle to an application window and a notification message identifier. If the wParam component of the notification message specified by the wMsg parameter is equal to zero, the WinSNMP manager application must retrieve the incoming protocol data unit (PDU). The application does this by calling the SnmpRecvMsg function with the session handle returned by SnmpOpen. If the wParam parameter of the notification message is not equal to zero, it represents a WinSNMP error code. The error code applies to the PDU identified by the request identifier in the lParam parameter of the notification message.

One WinSNMP manager application can open multiple WinSNMP sessions. If an application opens multiple sessions using the same window handle, it is recommended that the WinSNMP manager application specify a unique wMsg parameter for each session.

It is recommended that a WinSNMP manager application call the SnmpClose function once for each session that the implementation opens as a result of a call to the SnmpOpen function. If a WinSNMP manager application terminates unexpectedly, it must call SnmpCleanup before it terminates to enable the implementation to deallocate all resources. The implementation treats one SnmpCleanup call as if it were a series of SnmpClose calls, one call for each session the implementation opens as a result of a call to SnmpOpen.

For additional information, see WinSNMP Sessions.

QuickInfo

  Windows NT: Requires version 5.0 or later. Available as a redistributable for Windows NT 4.0.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winsnmp.h.
  Import Library: Use wsnmp32.lib.

See Also

WinSNMP Manager API Overview, WinSNMP Functions, SnmpClose, SnmpCleanup, SnmpRecvMsg