I’ve been working on building Chatscript as a DLL, which I’ve done now, but for information and future reference, I had to make a small change to the code.
When the DLL is loaded via a LoadLibrary() call, then the location of the code might be relocated in the processes’ address space. This was certainly true for me in the environment I was running in. What this meant was that the userFileSystem struct that contains pointers to the various file handling functions was now pointing to the wrong locations and the app crashed as soon as I tried to PerformChat().
My solution was to reinitialise the userFileSystem struct in InitSystem() to the same functions.
unsigned int InitSystem(int argc, char* argv[], char* unchangedPath, char* readablePath, char* writeablePath, USERFILESYSTEM* userfiles)
{
InitFileSystem(unchangedPath, readablePath, writeablePath);
#ifdef DLL
userFileSystem = { FopenBinaryWrite, FopenReadWritten, fclose, fread, fwrite, FileSize };
#endif
. . .
}