Platform SDK: Network Management |
The WinSNMP SnmpGetLastError function returns the calling application's last-error code value. The value indicates the reason why the last function call executed by the WinSNMP application failed.
SNMPAPI_STATUS SnmpGetLastError( HSNMP_SESSION session // handle to the WinSNMP session );
In certain cases, when a function call fails you can pass a NULL session value to the SnmpGetLastError function to retrieve the last-error code value. This is true for function calls that do not involve a session parameter, and cases in which the session parameter value is invalid. These cases are noted in the Return Values section on the function's reference page.
A single-thread application can pass a NULL session value to SnmpGetLastError to retrieve last-error information for the entire application.
For more information, see the following Remarks and Return Values sections.
If the session parameter is a valid WinSNMP session handle, the SnmpGetLastError function returns the last WinSNMP error that occurred for the indicated session.
If the session parameter is NULL — for example, if the SnmpStartup function fails, SnmpGetLastError returns the last WinSNMP error that occurred.
A WinSNMP application must call SnmpGetLastError immediately after a function fails, to retrieve the last-error code. If another function fails, it overwrites the last-error code set by the most recently failed function. For more information, see WinSNMP Error Codes.
Although the session parameter accommodates both multithread and single-thread Windows operating environments, the potential still exists for the last-error code from one thread to overwrite the last-error code from another thread.
Note that SnmpGetLastError must be able to return the last-error code to a WinSNMP application under the following conditions:
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Winsnmp.h.
Library: Use Wsnmp32.lib.
WinSNMP API Overview, WinSNMP Functions, SnmpStartup, SnmpCreateSession, SnmpClose, SnmpCleanup