Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Use a function from an external DLL #447039
11/13/14 19:12
11/13/14 19:12
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
I am trying the simple example :

I created a dll containing the following code

#include "test_Z.h"

int basic_test(int a, int b)
{
return(a*b);
}


where the header contains :

#ifndef test_Z_H__
#define test_Z_H__

int basic_test(int a, int b);

#endif

I placed the dll into the Zorro folder and the header into the include folder of Zorro
I tested with the following code :

int __stdcall basic_test(int a, int b);
API(basic_test,test_Z)

function main()
{
int c = basic_test(5, 2);

printf("Result = %d", c);
}

It returns me the good result 10 but an error message then appears :

Error 111 : Crash in script

I am using Zorro 1.26 under windows 7 64x and the dll has been created using minGW, could you please tell me why do I get this error message ?

Re: Use a function from an external DLL [Re: byakuren81] #447043
11/13/14 19:22
11/13/14 19:22
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
ok I realise I do not need to include the header as we use the line :
int __stdcall basic_test(int a, int b);

I have cancelled the line #include "test_Z.h" but I still get the same error message...

Re: Use a function from an external DLL [Re: byakuren81] #447072
11/14/14 18:05
11/14/14 18:05
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
I have changed the variable type and it's getting worse, for example if my function is now :

double basic_test(double a, double b)
{
return(a*b);
}

and my zorro code :

double __stdcall basic_test(double a, double b);
API(foo,bar)

function main()
{
double c = basic_test(5.25, 5.25);

printf("Result = %f", c);
}

I get :

Result = 27.562500
Result = 27.562500

It appears twice !!! with the same error message than before :

Error111: Crash in script

Pleeeeeease could someone help me ?

Last edited by byakuren81; 11/14/14 18:05.
Re: Use a function from an external DLL [Re: byakuren81] #447074
11/14/14 18:51
11/14/14 18:51
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
OK I have read in details the manual (script conversion) and programmed my function the same way :

#include "stdlib.h"

__declspec(dllexport) void basic_test (double a, double b, double *c)
{
double *out;

out = c;

*out = a + b;
}

I created the dll and placed it in the zorro folder, my zorro script is :

int __stdcall basic_test(double a, double b, double *c);
API(basic_test,bar)

function main()
{
double c;

basic_test(5.25, 5.25, &c);

printf("\nResult = %f", c);
}

when compiling I got the correct answer :

Result = 10.500000

but once again the same error message !!!!

Error111: Crash in script

this is driving me mad I cannot believe no one never encountered the same issue !

Re: Use a function from an external DLL [Re: byakuren81] #447075
11/14/14 21:46
11/14/14 21:46
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Stop using stdcall in your typedef. The lite-c compiler may not know any other callingconventions then cdecl so stack is cleaned up 2 times (by caller and callee) and will crash you.
Try cdecl.
EDIT: Im also not sure if lite-c can handle double o.o Try float sicne double is 8byte

Last edited by Ch40zzC0d3r; 11/14/14 21:49.
Re: Use a function from an external DLL [Re: Ch40zzC0d3r] #447078
11/14/14 23:25
11/14/14 23:25
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
stdcall was indeed the issue, it works fine with cdecl instead ! many thanks to you !

Re: Use a function from an external DLL [Re: byakuren81] #447082
11/15/14 11:01
11/15/14 11:01
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
No problem - your welcome laugh

Last edited by Ch40zzC0d3r; 11/15/14 11:01.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1