Calling API Functions

All LayGO API function names and argument sequences are identical to those documented in the C language API. For instance, the code to open a CID which might be written in C as:

LCid    cid;

cid = lgo_Open("PHYS0");

if (cid < 0)

translates directly into the following Visual Basic code:

Dim cid As Integer

cid = lgo_Open("PHYS0")

If cid < 0 Then
    PostOpenError cid
    ConnectCid cid
End If

For functions which take C pointer types such as LDataBuffer or LCtlBuffer, substitute the first element of an array of Byte. The C code to read data:

unsigned char    buffer[1024];
LResult          result;

result = lgo_Read(cid, buffer, 1024);

if (result > 0)
    ProcessData(buffer, result);
else if (result == lgo_ERROR_EVENT_WAITING)

becomes the Visual Basic code:

Dim buffer(1024) As Byte
Dim result As Integer

result = lgo_Read(cid, buffer(0), 1024)

If result > 0 Then
    ProcessData buffer, result
ElseIf result = ERROR_EVENT_WAITING Then
End If

The 2nd parameter of lgo_Read() is declared as "pass by reference". So an argument of buffer(0) means that Visual Basic will pass the address of the first element of the array, which is what the C language function expects.

Where a NULL pointer would be used in C, substitute the manifest constant vbNullString:

LResult    result;

result = lgo_ConnectRequest(cid, NULL, 0);


Dim result As Integer

result = lgo_ConnectRequest(cid, vbNullString, 0)

All the other C integral types which are used as function arguments or return values are mapped to the Visual Basic Integer type, with the exception of LUserId which is mapped to type Long.