全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1264
推到 Plurk!
推到 Facebook!

呼叫dll的問題

尚未結案
alick
一般會員


發表:2
回覆:12
積分:2
註冊:2003-11-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-12 10:10:32 IP:61.63.xxx.xxx 未訂閱
我寫了一個簡單的dll 在呼叫時出現error message 'access violation at 0x77fac687: write of adress 0x00030cb4' 請問是那裡出錯?? 我看書上的範例開dll類型時只有dll 我的delphi 是dll wizard 有差嗎?? 謝謝
ko
資深會員


發表:28
回覆:785
積分:444
註冊:2002-08-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-12 10:56:55 IP:61.221.xxx.xxx 未訂閱
alick 你好: 基本上是一樣的 你的錯誤是指在引用時發生的錯誤,大概是傳入參數的錯誤,不能解決請上傳 到會員求助區,那裡有 >
------
======================
昏睡~
不昏睡~
不由昏睡~
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-12 11:40:31 IP:211.23.xxx.xxx 未訂閱
引言: 我寫了一個簡單的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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-12 23:57:08 IP:218.163.xxx.xxx 未訂閱
我用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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-12-13 23:40:14 IP:218.163.xxx.xxx 未訂閱
目前可以傳參數進去了, 也可以回傳return 值了 但是傳近去參數的數值, DLL中收到 似乎錯了>"< 怎麼辦@@"
alick
一般會員


發表:2
回覆:12
積分:2
註冊:2003-11-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-12-15 08:34:48 IP:61.63.xxx.xxx 未訂閱
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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-12-15 11:16:28 IP:211.23.xxx.xxx 未訂閱
    改成紅色字的部份應該就要可以用了!!    
引言: 我用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

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-12-15 11:24:56 IP:211.23.xxx.xxx 未訂閱
引言: // 這邊應該是 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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-12-15 11:35:36 IP:61.63.xxx.xxx 未訂閱
thanks to aquarius but.. sorry...還是一樣
aquarius
資深會員


發表:3
回覆:347
積分:330
註冊:2003-05-21

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-12-15 15:27:41 IP:211.23.xxx.xxx 未訂閱
傳入值或值回值使用 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

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-12-16 08:57:03 IP:61.63.xxx.xxx 未訂閱
謝謝各位的幫忙.. dll已解決了...^^... 各位大大如有興趣者... 請再幫忙這個問題 【Delphi】【問題】如何取得顯示器的字型大小比例???請賜招,謝謝!! http://delphi.ktop.com.tw/link.asp?TOPIC_ID=41925
系統時間:2024-06-27 3:17:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!