Platform SDK: Network Management

SnmpStrToOid

The WinSNMP SnmpStrToOid function converts the dotted numeric string format of an SNMP object identifier, for example, "1.2.3.4.5.6", to its internal binary representation.

SNMPAPI_STATUS SnmpStrToOid(
  LPCSTR string,      // string object identifier to convert 
  smiLPOID dstOID     // object identifier internal representation 
);

Parameters

string
[in] Pointer to a null-terminated object identifier string to convert.
dstOID
[out] Pointer to an smiOID structure that receives the converted value.

Return Values

If the function succeeds, the return value is the number of subidentifiers in the converted object identifier. This number is also the value of the len member of the smiOID structure pointed to by the dstOID parameter.

If the function fails, the return value is SNMPAPI_FAILURE. To get extended error information, call SnmpGetLastError specifying a NULL value in its session parameter. 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_OID_INVALID The string parameter is invalid. For additional information, see the following Remarks section.
SNMPAPI_OTHER_ERROR An unknown or undefined error occurred.

Remarks

The WinSNMP application must call the SnmpFreeDescriptor function to free resources allocated for the ptr member of the smiOID structure pointed to by the dstOID parameter. On input, SnmpFreeDescriptor ignores the members of this smiOID structure. The Microsoft WinSNMP implementation overwrites the smiOID members if the function completes successfully.

The SnmpStrToOid function fails and returns the SNMPAPI_OID_INVALID error code if the string parameter meets one of the following conditions:

For additional information, see WinSNMP Data Management Concepts and Freeing WinSNMP Descriptors.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Winsnmp.h.
  Library: Use Wsnmp32.lib.

See Also

WinSNMP API Overview, WinSNMP Functions, SnmpFreeDescriptor, smiOID