
Problem with SNMP API call in VB - please help!
I am working on a VB module that uses the SNMP API.
I am having problems now in translating the C declaration of an SNMP API
function.
The original C code:
--------------------
#define RECVBUFSIZE 4096
//Type definitions
typedef SOCKET SockDesc; // Socket is u_int in winsock.h, thats
long in VB
typedef struct _SNMP_MGR_SESSION {
SockDesc fd;
struct sockaddr destAddr; // sockaddr is from winsock.h
LPSTR community;
INT timeout;
INT retries;
AsnInteger requestId; // is defined as LONG in C
char recvBuf[RECVBUFSIZE];
Quote:
} SNMP_MGR_SESSION, *LPSNMP_MGR_SESSION;
// function prototype
LPSNMP_MGR_SESSION
SNMP_FUNC_TYPE
SnmpMgrOpen(
IN LPSTR lpAgentAddress,
IN LPSTR lpAgentCommunity,
IN INT nTimeOut,
IN INT nRetries
);
In a C sample program from the Platform SDK, the function is called like
this:
LPSNMP_MGR_SESSION session;
session = SnmpMgrOpen(agent, community, timeout, retries)
That is my translation in VB:
----------------------------
Type sockaddr ' Taken from winsock.h
sa_family As Integer '/* address family */
sa_data(14) As Byte '/* up to 14 bytes of direct address */
End Type
Public Type Type_SNMP_MGR_SESSION
fd As Long ' Socket descriptor,
u_int in C
destAddr As sockaddr
community As String
timeout As Long
retries As Long
requestId As Long
recvBuf As String * 4096
End Type
'*************************************************
'**SNMP API Management Funktionen (MGMTAPI.DLL) **
'*************************************************
Declare Function SnmpMgrOpen Lib "mgmtapi.dll" _
(ByVal lpAgentAddress As String, _
ByVal lpAgentCommunity As String, _
ByVal nTimeout As Long, _
ByVal nRetries As Long) As
Type_SNMP_MGR_SESSION
My function call in VB:
-----------------------
Dim session As Type_SNMP_MGR_SESSION
Dim agent as String
Dim community as String
Dim timeout as Long
Dim retries as Long
session = SnmpMgrOpen(agent, community, timeout, retries)
This function call fails (wrong calling conventions). What is wrong with
my declaration?
Please help! I need it very urgently!
Andre
---------------------------
Andre Schneickert
ESCS, Germany