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.
For example, to read the first integer written into the memory block, you could just write the following code in the FunctionName body:
[FileExecute, "DllName.dll", "FunctionName", "StringArgument", [MemGetSize, "MemBlock"], "MemBlock",]
int mbSize = (int)number; // the second argument have to be a double
// Read from the memory block via a strstream
std::strstream mbStream((char*)memblock, mbSize);
// Read the first integer written into the memory block by the ZScript
int val = 0;