First of all, this works in zorro script alone (zorro 1.54.5):

Code:
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:

Code:
#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:

Code:
#include <windows.h>
void WINAPI hellozorro(char*);
API(hellozorro,hellozorro)


Finally, my zorro script looks like this:

Code:
#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?


Attached Files before.PNGafter.PNG
hellozorro4.c (68 downloads)
zorro script
hellozorro.zip (54 downloads)
dll file
Last edited by AndrewAMD; 04/10/17 00:23.