I have program compiled with FoxPro that calls d1.dll functions. d1.dll was developed with Delphi 2007. I need to develop d1.dll that will replace existing one using c++. After several tests FoxPro application crashes in random places with random messages like:
Fatal error: Exception code=C0000005 @ 2012.12.12 11:33. Error log file: C:\Program Files\Common Files\Microsoft Shared\VFP\vfp9rerr.log
or
No enaugh memory execute some_function
I have removed all code from c++ dll and left just some test values that original dll usually returns. But this does't helps. Probably something is wrong with declaration and variable usage.
I have build Fox Pro small test program according to manner of declaring d1.dll function in main Fox Pro program. Unfortunately it doesn't crash. I run it from IDE while mine program runs from executable, but I don't think this is reason. Probably there is som issuersregarding variable usage.
What might be problem?
Function declaration in Delphi and C++:
C++
extern "C" int _stdcall f1(unsigned char *aError)
extern "C" int_stdcall f2(char *txt,unsigned char *aError)
extern "C" int _stdcall f3(unsigned char *aError, char *aAnswer)
extern "C" int _stdcall f4(unsigned char *aError)
extern "C" int _stdcall f5( char* descriptor, char x, double pr, char aError, double qtity, char kd, char* pd ) extern "C" int _stdcall f6(char *acomment_string, unsigned char* aError)
extern "C" int _stdcall f7(unsigned char tender_number, double amount, unsigned char *aError)
extern "C" int _stdcall f8(unsigned char *aError)
DELPHI 2007
function f1(var aError: byte):bool; stdcall; function f2(txt: pchar; var aError: byte):bool; stdcall;
function f3(var aError: byte; adata: pchar):bool; stdcall;
function f4(var aError: byte):bool; stdcall;
function f5(descriptor: pchar;x: byte; pr: double; var aError: byte ; qtity: double; kd : pchar ; pd: pchar ):bool; stdcall;
function f6(non_fiscal_string: pchar; var aError: byte):bool; stdcall;
function f7(tender_number:byte; amount:double; var aError: byte):bool; stdcall;
function f8 (var aError: byte):bool; stdcall;
FoxPro test program
FoxPro FoxPro
declare integer f1 in c:\d1.dll string err
declare integer f2 in c:\d1.dll string txt,string err
declare integer f3 in c:\d1.dll string err, string rec_nr
declare integer f4 in c:\d1.dll string err
declare integer f5 in c:\d1.dll string descr, integer x, double pr ,string err, double qty, string kd, string pd
declare integer f6 in c:\d1.dll string non_fiscal_string,string err
declare integer f7 in c:\d1.dll integer tender, double amount ,string err
declare integer f8 in c:\d1.dll string err
aLength=2048
aCardinal=4
ff_log=space(aLength)
rec_nr=SPACE(aCardinal)
fiscal_rec_nr=SPACE(aCardinal)
serial_nr = SPACE(aLength)
status_bytes=SPACE(aCardinal)
descr = "descr"
x =1 pr = 123 t=0 t= f2(descr,@kl)
t= f1(@kl)
Thisform.text1.Value=ff_log
t= f2(descr,@kl)
t= f4(@kl)
t=f3(@kl,@ff_log) t=GetStatus(@kl,rec_nr,fiscal_rec_nr,serial_nr,status_bytes)
t= f5(descr,x,pr,@kl, 1, "","")
t= f2(descr,@kl)
t= f2(descr,@kl)
t=f6(descr,@kl)
t=f8(@kl)
t=f7(1,100,@kl)