2012-12-12 18 views
0

我有用FoxPro編譯的程序調用d1.dll函數。 d1.dll是使用Delphi 2007開發的。我需要開發d1.dll,它將使用C++替換現有的d1.dll。後在任意地方多次測試FoxPro應用程序崩潰,就像是隨機的消息:FoxPro的C++ dll

Fatal error: Exception code=C0000005 @ 2012.12.12 11:33. Error log file: C:\Program Files\Common Files\Microsoft Shared\VFP\vfp9rerr.log

No enaugh memory execute some_function

我已刪除了所有的代碼從C++ DLL,離開只是原始的dll文件通常會返回一些測試值。但這沒有幫助。聲明和變量的使用可能有些問題。

我具有根據在主福克斯Pro程序聲明d1.dll功能的方式建立福克斯臨小測試程序。不幸的是它不會崩潰。我從IDE運行它,而我的程序從可執行文件運行,但我不認爲這是理由。可能有一些問題可能會使用變量。

什麼可能是問題?在Delphi和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的測試程序

的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)

+1

引用錯誤消息時,始終粘貼文本文本,不要從內存中重寫。你永遠不知道你可能會留下什麼(也可以讓你免於尷尬的錯別字。) –

+0

-1您必須修復格式。使用代碼塊而不是引號。請注意目前問題中的斜體。那些不是你想要的,我確定。另外,你如何期待我們調試呢?我們看不到任何代碼! –

回答

1

1)編輯的問題 - 與你的Delphi版本添加標記。它不僅禮貌,而且在這裏可能很關鍵。

2)你看到FoxPro代碼「串」的引用 - 這可能意味着你的char*聽到的是C-字符串(又名ASCIIZ串,又名零結尾的字符串)

他們需要有點特殊處理。嘗試將它們作爲PAnsiChar - 像 - function f1(const aError: PAnsiChar):bool; stdcall;

閱讀幫助德爾福PChar類型類型 - 但總是在固定的DLL API使用PAnsiChar:PChar類型是不同的Delphi版本曖昧 - 映射到PAnsiChar或PWideChar

3)回報正確的數據類型。不bool。

聲明整數F2在C:\ d1.dll串TXT,串犯錯
的extern 「C」 INT _stdcall F2(字符* TXT,無符號字符* AERROR)
功能F2 (const txt,aError:PAnsiChar):integer; STDCALL;

+0

有沒有必要改變在Delphi代碼中的東西。崩潰DLL與Visual c + + – vico

+0

完成,然後做反向轉換! 'var x:byte'將代表by-ref'unsigned char & x'; Bool是一些windows布爾類型 - 在docwiki.embarcadero.com上搜索並使用正確的窗口類型。而你的FoxPro代碼似乎與Delphi代碼不一致 - Delphi代碼中沒有它們的字符串。只有PChar aka PAnsiChar是字符串。 not char&type –

+0

你還應該配置VC++來創建非Unicode庫,所以它會有1個字節的字符,而不是2個字節的字符 –