呼叫dll的問題 |
尚未結案
|
alick
一般會員 發表:2 回覆:12 積分:2 註冊:2003-11-24 發送簡訊給我 |
|
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
|
aquarius
資深會員 發表:3 回覆:347 積分:330 註冊:2003-05-21 發送簡訊給我 |
引言: 我寫了一個簡單的dll 在呼叫時出現error message 'access violation at 0x77fac687: write of adress 0x00030cb4' 請問是那裡出錯?? 我看書上的範例開dll類型時只有dll 我的delphi 是dll wizard 有差嗎?? 謝謝把 SOURCE CODE 放上來或還有可以幫你看出原因在那兒. 你只寫這樣, 很難看出問題是出在那個地方. ...Aquarius
------
水瓶男的blog: http://791909.blogspot.com |
fishxyz
一般會員 發表:5 回覆:6 積分:2 註冊:2003-01-27 發送簡訊給我 |
我用VC寫了一個 DLL 給 DELPHI 呼叫
也會發生這樣的錯誤!
但是把 參數i 改成 void , 也就是不傳參數進去就OK 這該怎麼辦阿???????????????? =======================================================
DLL的 source code
========================================================
extern "C" _declspec(dllexport) int test_function(int i);
extern "C" __declspec(dllexport) int test_function(int i)
{
i ;
return i;
} ===========================================================
DELPHI source
===========================================================
interface
function test_function(i : integer):Integer; stdcall; implementation
function test_function;external 'vc_dll.DLL' name 'test_function'; procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin i:=0;
test_function(i);
self.Caption := IntToStr(i);
end;
|
fishxyz
一般會員 發表:5 回覆:6 積分:2 註冊:2003-01-27 發送簡訊給我 |
|
alick
一般會員 發表:2 回覆:12 積分:2 註冊:2003-11-24 發送簡訊給我 |
function test2(x:String):String; stdcall; implementation function test2(X:String):String;
begin
ShowMessage(X ' (for test2)');
end;
==========================================
function test(X:string) : string stdcall; external 'test_dll2.dll'; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
begin
test('call dll b1');
end; procedure TForm1.Button2Click(Sender: TObject);
begin
test('call dll b2');
end; procedure TForm1.Button3Click(Sender: TObject);
begin
test('call dll b3');
end;
=========================================
這是我的程式碼..
每次run...就會出現第一篇的問題
如果我利用書附贈光碟裡的程式碼run..
就沒問題...
程式碼可說是一模一樣的..
|
aquarius
資深會員 發表:3 回覆:347 積分:330 註冊:2003-05-21 發送簡訊給我 |
改成紅色字的部份應該就要可以用了!!
引言: 我用VC寫了一個 DLL 給 DELPHI 呼叫 也會發生這樣的錯誤! 但是把 參數i 改成 void , 也就是不傳參數進去就OK 這該怎麼辦阿???????????????? ======================================================= DLL的 source code ======================================================== extern "C" _declspec(dllexport) int test_function(int i); extern "C" __declspec(dllexport) int test_function(int i) { i ; return i; } =========================================================== DELPHI source =========================================================== interface function test_function(i : integer):Integer; cdecl ; implementation function test_function;external 'vc_dll.DLL' name 'test_function'; procedure TForm1.Button1Click(Sender: TObject); var i : integer; begin i:=0; test_function(i); self.Caption := IntToStr(i); end;...Aquarius
------
水瓶男的blog: http://791909.blogspot.com |
aquarius
資深會員 發表:3 回覆:347 積分:330 註冊:2003-05-21 發送簡訊給我 |
引言: // 這邊應該是 DLL 的部份吧!!, 用 string 型態要在 Uses 加上 ShareMem, 而且還一定要放在第一個. function test2(x:String):String; stdcall; implementation function test2(X:String):String; begin ShowMessage(X ' (for test2)'); end; ========================================== var Form1: TForm1; implementation {$R *.dfm} ////function test(X:string) : string stdcall; external 'test_dll2.dll'; function test2(X:string) : string ; stdcall; external 'test_dll2.dll'; procedure TForm1.Button1Click(Sender: TObject); begin test2('call dll b1'); end; procedure TForm1.Button2Click(Sender: TObject); begin test2('call dll b2'); end; procedure TForm1.Button3Click(Sender: TObject); begin test2('call dll b3'); end; ========================================= 這是我的程式碼.. 每次run...就會出現第一篇的問題 如果我利用書附贈光碟裡的程式碼run.. 就沒問題... 程式碼可說是一模一樣的.....Aquarius
------
水瓶男的blog: http://791909.blogspot.com |
alick
一般會員 發表:2 回覆:12 積分:2 註冊:2003-11-24 發送簡訊給我 |
|
aquarius
資深會員 發表:3 回覆:347 積分:330 註冊:2003-05-21 發送簡訊給我 |
傳入值或值回值使用 string 型態問題會比較多.
我試了一下, 只要用 stdcall ; 就一定會錯, 換DELPHI 預設的 register 就沒問題了.
// DLL 的部份 library test_dll2; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses ShareMem, dialogs, SysUtils, Classes; {$R *.RES} function test2(X:String):String; export ; begin Result:=x ' (for test2)' ; ShowMessage(result); end; exports test2 ; begin end. // Appliaction 的部份 unit Unit1; interface uses sharemem,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function test2(X:string) : string ; external 'test_dll2.dll'; procedure TForm1.Button1Click(Sender: TObject); begin test2('call dll b1'); end; procedure TForm1.Button2Click(Sender: TObject); begin test2('call dll b2'); end; procedure TForm1.Button3Click(Sender: TObject); begin test2('call dll b3'); end; end....Aquarius
------
水瓶男的blog: http://791909.blogspot.com |
alick
一般會員 發表:2 回覆:12 積分:2 註冊:2003-11-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |