User Guide

DLL Component
Also, for most of the types you should always check that pIn[x] or pOut[x] are zero before attempting to extract values using the above casts
so the macros incorporate this check too which reduces crashing.
The macros are shown below:
#define GETFLOAT(p) *((float*)&p)
#define GETBOOL(p) *((bool*)&p)
#define GETINT(p) p
#define GETSTRING(p) *((char**)&p)
#define GETFLOATARRAY(p) p ? ((float*)p+1) : 0
#define GETINTARRAY(p) p ? ((int*)p+1) : 0
#define GETSTRINGARRAY(p) p ? ((char**)p+1) : 0
#define GETARRAYSIZE(p) p ? *((int*)p) : 0
#define GETFRAME(p) p ? ((float*)p+1) : 0
#define GETFRAMESIZE(p) p ? *((int*)p) : 0
#define GETBITMAPWIDTH(p) p ? *((int*)p) : 0
#define GETBITMAPHEIGHT(p) p ? *((int*)p+1) : 0
#define GETBITMAPCHANNELS(p) p ? *((int*)p+2) : 0
#define GETBITMAPDATA(p) p ? ((BYTE*)p+12) : 0
#define GETBITMAPBYTES(p) p ? *((int*)p) * *((int*)p+1) * *((int*)p+2) : 0
#define NEWINTARRAY(p,n) if(n>0) { *((int**)&p)=new int[n+1]; ((int*)p)[0]=n; }
#define NEWFLOATARRAY(p,n) if(n>0) { *((float**)&p)=new float[n+1]; ((int*)p)[0]=n; }
#define NEWSTRINGARRAY(p,n) if(n>0) { *((char***)&p)=new char*[n+1]; ((int*)p)[0]=n; }
#define DELETESTRING(p) if(p) { delete *((char**)&p); p=0; }
#define DELETEINTARRAY(p) if(p) { delete *((int**)&p); p=0; }
#define DELETEFLOATARRAY(p) if(p) { delete *((float**)&p); p=0; }
#define DELETESTRINGARRAY(p) if(p) { for( int j=0; j<*((int*)p); j++ ) { if( ((char**)p+1)[j] ) delete ((char**)p+1)[j]; } delete *((char***)&p);
p=0; }
To illustrate how these macros can help the code below shows how the code for resetting the output value for an Int Array, would reduce
down to just two lines:
// Delete previous array and reset pOut entry
DELETEINTARRAY(pOut[x])
// Create new array (assume we have declared 'length' – add 1 for size at front)
NEWINTARRAY(pOut[x],length)
If you want to use the macros, simply copy and paste them in at the top of your dll source file.
Example 1 – Float Add
This is a really simple example which simply adds two floats together and outputs the result. Whilst it is basic it shows you how all the things
we've talked about come together.
extern "C" __declspec(dllexport) void addFloats( int nParams, int* pIn, int* pOut )
{
if( pIn && pOut && nParams >= 2 )
{
float f0 = GETFLOAT(pIn[0]);
float f1 = GETFLOAT(pIn[1]);
GETFLOAT(pOut[0]) = f0+f1;
}
}
193 of 212