User Guide
DLL Component
{
delete *((char**)&pOut[x]);
pOut[x] = 0;
}
// Create new string (assume we have declared 'length' – add 1 for null terminator)
char* s = new char[length+1];
// {initialise the string here}
// Don't forget to null terminate
s[length] = 0;
// Assign to correct entry in the output array
*((char**)&pOut[x]) = s;
If you're using the same length string each time then you could create it once and save having to delete and make a new one each time. If
you're working with strings of a maximum length then you could also stick with one string and move the null terminator each time. It's up to
you.
Float Arrays
These are represented as a C array of floats but with an extra entry at the start which provides 4 bytes to store the number of array
elements. So we have two casts to make, one for the array size and one for the array itself:
int size = *((int*)pIn[x]);
float* array = (float*)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. This is a similar process as for Strings. Once again 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 *((float**)&pOut[x]);
pOut[x] = 0;
}
// Create new array (assume we have declared 'length' – add 1 for size at front)
float* array = new float[length+1];
// Set the size
*((int*)array) = length;
// {initialise the array here}
// Assign to correct entry in the output array
*((float**)&pOut[x]) = array;
This will create a new array each time the function is called. Again, you could create a single array if you're working with fixed sizes or adjust
the array only if you need more storage space.
Int Arrays
Int arrays are handled in an identical way to Float arrays. The only difference is the base type, a C int in this case. Again, there's an extra
entry at the start which provides 4 bytes to store the number of array elements. So we have two casts to make, one for the array size and
one for the array itself:
189 of 212