用 DELPHI 寫一 DLL 問題? |
答題得分者是:wameng
|
y2485967
一般會員 發表:9 回覆:0 積分:1 註冊:2002-10-21 發送簡訊給我 |
小弟用DELPHI 寫DLL小程式 library TestDLL; function IsTest(PassWord:string):string;
var i:integer;
PassWordState:string;
begin
PassWordState:='';
For i:=0 to 5 do PassWordState:=PassWordState 'A';
Result:=PassWordState;
end; exports
IsTest index 1; begin
end. 編輯此程式無誤 用語呼叫程式 unit CallDLLU; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.DFM} function IsTest(PasswORD:string):string;
external 'TestDLL.DLL'; procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=IsTest('1234'); end; end. 執行時卻出現
Invalid pointer operation 錯誤訊息
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
christie
資深會員 發表:30 回覆:299 積分:475 註冊:2005-03-25 發送簡訊給我 |
方法二:uses sharemem例
[code delphi] = = = = = AP: = = = = = = = = = = program Project1; uses ShareMem, Forms, CallDLLu in 'CallDLLu.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. - - - - - - - - - - - - - - - - - unit CallDLLU; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function IsTest(PasswORD:string):string; stdcall; external 'TestDLL.DLL'; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text:=IsTest('1234'); end; end. =====TestDLL.dpr===== library TestDLL; uses ShareMem; function IsTest(PassWord:string):string; stdcall; var i:integer; PassWordState:string; begin PassWordState:=''; For i:=0 to 5 do PassWordState:=PassWordState 'B'; Result:=PassWordState; end; exports IsTest; begin end. [/code] ===================引 用 wameng 文 章=================== 1. String 改為 PCHAR 。 2. 或 Uses sharemem 單元 另外在DLL 使用請加上 StdCall function IsTest(PassWord:string):string;stdcall; 發表人 - wameng 於 2004/10/25 20:43:17
------
What do we live for if not to make life less difficult for each other? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |