For people that are using the Visual Studio compiler for the Windows platform. Here is how to create a DLL containing a function that can be called from a ZScript:
1) Create a solution.
2) Create a Win32 DLL project.
3) Create a new C++ file containing the entry point function that is going to be called from the ZScript. It should have the following declaration:
#define DLLEXPORT __declspec(dllexport)
extern "C" int DLLEXPORT FunctionName(unsigned char* message, double number, void* memblock, void* memblock2)
{
// function body
}
The calling ZScript has the following FileExecute command. “MemBlock” refers to a memory block handle created earlier in the ZScript.
[FileExecute, "DllName.dll", "FunctionName", "StringArgument", [MemGetSize, "MemBlock"], "MemBlock",]
For example, to read the first integer written into the memory block, you could just write the following code in the FunctionName body:
int mbSize = (int)number; // the second argument have to be a double
// Read from the memory block via a strstream
std:small_orange_diamond:strstream mbStream((char*)memblock, mbSize);
// Read the first integer written into the memory block by the ZScript
int val = 0;
mbStream.read((char*)&val, 4);