Using 1D string arrays in extension command DLLs

Questions and coding techniques using PiXCL 10
Post Reply
StewD
Posts: 9
Joined: Mon Jul 13, 2015 2:31 pm

Using 1D string arrays in extension command DLLs

Post by StewD » Fri Oct 04, 2019 8:00 am

When creating a set of extension commands in a DLL, it's unclear how arrays, and in particular string arrays, are defined and used. The command arg list data types (i.e. the command syntax) are declared in the DLL RegisterExtLibCmdSet(...) function. Suppose we define a command set with functions starting with "abc...". A simple command is

lpCmd[nCommands++] = (LPSTR)"\",\"abcDeleteSensor\", Res, P_NUMBER, P_NUM_VARIABLE)";

where P_NUMBER is the integer sensor identifier, and P_NUM_VARIABLE is the function mandatory return variable. In app code, this might be called as
abcDeleteSensor(11, Result) or abcDeleteSensor(sensorID, Result)

In the arg pointer list, these are
anArgBuffer[0] == sensorID integer
anArgBuffer[1] == return variable pointer (Result)

If we define a new command that uses an integer array, we have
lpCmd[nCommands++] = (LPSTR)"\",\"abcDeleteAllSensors\", Res, P_VARIANT_ARRAY,
P_SQ_BRACKET_LEFT, P_NUMBER, P_SQ_BRACKET_RIGHT, P_NUM_VARIABLE)";


In app code, this becomes
abcDeleteAllSensors(SensorSet[0], Result)

In the arg pointer list, these are
anArgBuffer[0] == SensorSet array pointer
anArgBuffer[1] == array start index
anArgBuffer[2] == return variable (Result)

If we want to use a string or string array, the commands might be

lpCmd[nCommands++] = (LPSTR)"\",\"abcDeleteNamedSensor\", Res, P_STRING, P_NUM_VARIABLE)";

In app code, this becomes
abcDeleteNamedSensor(SensorID$, Result)

In the arg pointer list, these are
anArgBuffer[0,1] == sensorIDname$ pointer, string length
anArgBuffer[2] == return variable pointer (Result)

and
lpCmd[nCommands++] = (LPSTR)"\",\"abcDeleteAllNamedSensors\", Res, P_VARIANT_ARRAY,
P_SQ_BRACKET_LEFT, P_NUMBER, P_SQ_BRACKET_RIGHT, P_NUM_VARIABLE)";


In app code, this becomes
abcDeleteAllNamedSensor(SensorIDs$[0], Result)

In the arg pointer list, these are
anArgBuffer[0,1] == code offset pointer (not used), SensorIDSetName$ array pointer
anArgBuffer[2] == array start index
anArgBuffer[3] == return variable (Result)

Note the difference how the string and string array pointers are handled by the anArgBuffer list.

If you have more questions on arrays, please comment or contact Tech Support.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest