First of all, this works in zorro script alone (zorro 1.54.5):
void hellozorro (char* message)
{
strcpy(message, "Hello, Zorro!");
return;
}
void nl()
{
printf("\n");
return;
}
void dothis()
{
char message[101];
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test1"); printf("%s",message); nl();
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test2"); printf("%s",message); nl();
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test3"); printf("%s",message); nl();
return;
}
int main()
{
dothis();
printf("We made it to the end!"); nl();
return(0);
}
My objective is to replace the first function with a DLL (as a learning exercise).
I built a dll in VC++2017 with this in the main file:
#include "stdafx.h"
#include <string>
#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT void hellozorro(char* output)
{
strcpy(output, "Hello, Zorro!");
return;
}
In zorro, I made hellozorro.h:
#include <windows.h>
void WINAPI hellozorro(char*);
API(hellozorro,hellozorro)
Finally, my zorro script looks like this:
#include <hellozorro.h>
void nl()
{
printf("\n");
return;
}
void dothis()
{
char message[101];
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test1"); printf("%s",message); nl();
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test2"); printf("%s",message); nl();
hellozorro(message);printf("%s",message); nl();
strcpy(message,"test3"); printf("%s",message); nl();
return;
}
int main()
{
dothis();
printf("We made it to the end!"); nl();
return(0);
}
Outputs attached. I get an "Error 111: Crash in script". If I'm lucky, I'll even crash Zorro too at random!
Here's what I tried, to no avail:
- Switch between /MD and /MT build modes
- Rebuild solution in VC++2013.
What am I doing wrong? Also, how am I supposed to diagnose this?