Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 15 Extending DAQFactory > 15.1 Calling an External DLL

15.1.3 The function prototype

Scroll Prev Top Next More

The second parameter of the extern function is the function prototype of the function you wish to import from a DLL.  As you can see by this example, the function prototype looks a bit like a C function prototype:

 

long ListAll(long, long, long[1], long[128],long[128],double[128])

First there is the return type, then the name of the function, then the arguments provided in parenthesis.  Although the data types may look familiar, they require a little explaining.  The following are valid data types:

ubyte or uchar - an 8 bit unsigned integer

byte or char - an 8 bit signed integer

uword or ushort or unsigned short - a 16 bit unsigned integer

word or short - a 16 bit signed integer

ulong or unsigned long - a 32 bit unsigned integer

long or dword - a 32 bit signed integer

float - a 32 bit floating point value

double - a 64 bit floating point value

string - a string of characters

void - used only as a return value, indicates nothing is returned.

They are not case sensitive.  In addition, there are pointer versions of each, except void.  To specify a pointer in the prototype, use array notation:

long[12]  - a pointer to an array of 12 long integer.

For a simple pointer, use [1]:

long[1] - a pointer to a long integer.

A string carries through to a string value in DAQFactory.  If you simply specify string, then you are specifying a constant string which cannot be changed by the external function.  This is the same as the C const char *.  If you specify a string array, string[x], then you are specifying a pointer to a buffer of characters of x length.  Make sure to include a byte for the NULL at the end of the string.  A NULL will automatically be placed at the last space of the buffer no matter what your external function does.  So:

string - a pointer to a const null terminated string (const char *)

string[10] - a pointer to a buffer of 10 bytes that will be translated to a string by DAQFactory on completion (char *).

string[x] and byte[x] are essential the same thing as far as your external DLL is concerned as both pass a pointer to a buffer of characters.  The difference is how they are treated by DAQFactory.  A string[x] is converted into a single string on completion, while byte[x] is converted into an array of numbers:

 

extern("labjackud.dll","void ErrorToString(long, string[256])","ErrToString","stdcall")

global strError

ErrToString(1001,@strError)

strError now contains a single string with the error.

 

extern("labjackud.dll","void ErrorToString(long, byte[256])","ErrToString","stdcall")

global Error

ErrToString(1001,@Error)

Error now contains an array of 256 values.  So if in the first example, strError was "ABC", Error would be {65,66,67}.

Note: DAQFactory has a general 20 argument limit which applies to external DLL functions as well.

Note: If you call extern with the same DLL and the same prototype function name but with different arguments, the old prototype is removed from the system and replaced by your new prototype.