User Guide

DLL Component
int size = *((int*)pIn[x]);
int* array = (int*)pIn[x]+1;
You can see that we interpret the first entry as an int giving us the array length. The array itself then begins at the second entry, hence the
'+1'.
To set the output value we need to create a new array. The management of memory is up to you. Here's one way of doing it:
// Delete previous array and reset pOut entry
if( pOut[x] )
{
delete *((int**)&pOut[x]);
pOut[x] = 0;
}
// Create new array (assume we have declared 'length' – add 1 for size at front)
int* array = new int[length+1];
// Set the size
*((int*)array) = length;
// {initialise the array here}
// Assign to correct entry in the output array
*((int**)&pOut[x]) = array;
This will create a new array each time the function is called. You could create a single array if you're working with fixed sizes or adjust the
array only if you need more storage space.
String Arrays
String arrays are probably the most complicated of all the data types to work with. You not only have to manage the array but you also have
to manage each String in the array.
A string array is represented by a C array of char*. As with the other arrays, there is an additional element at the front which is used to store
the size of the array.
Accessing the array is similar to Float and Int arrays in that there are two casts to make, one for the array size and one for the array itself:
int size = *((int*)pIn[x]);
char** array = (char**)pIn[x]+1;
You can see that we interpret the first entry as an int giving us the array length. The array itself then begins at the second entry, hence the
'+1'.
To set the output value we need to create a new array and each string that goes in it. Here is one way of doing this:
// Delete previous array (and contents) and reset pOut entry
if( pOut[x] )
{
int size = *((int*)pOut[x]);
char** array = (char**)pOut[x]+1;
for( int i=0; i<size; i++ )
{
if( array[i] )
delete array[i];
}
delete (char**)pOut[x];
pOut[x] = 0;
}
190 of 212