dll的傳值問題的應用 |
尚未結案
|
snoopyet0909
一般會員 發表:2 回覆:6 積分:1 註冊:2005-06-09 發送簡訊給我 |
以下是程式部份: unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, 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; function test(i:string):string; stdcall; var
Fa:TForm1; implementation {$R *.dfm} function test(i:string):string;
begin
Fa:=TForm1.Create(Application);
Fa.ShowModal;
result:=test(i);
end; procedure TForm1.Button1Click(Sender: TObject);
var a:integer;
begin
a:=strtoint(edit1.Text); end;
end. ------------------------------------------------------------- unit Unit2; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; function test():string;
stdcall; external'project2.dll'; var
Form1: TForm1;
implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=test(); end; end.
------------------------------------------------------------- library Project2; { 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
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1}; {$R *.res} exports
test;
begin
end. -------------------------------------------------------------
問題
1.以上三個程式,可不可以麻煩妳們告訴我哪一個是主程式?
因為我怎麼看都看不出來!
2.上面的程式是屬於不完整的程式
因為執行結果是這樣
按下按鈕後會出現一個表單
然後輸入數值
接下來所輸入的數值會傳回原本的表單
而那個突然跑出來的表單會不見
可是呀
我不管怎麼寫
都不會出來
所以想麻煩大家幫幫我的忙!! 先在這邊向各位說聲謝謝.....!!
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
|
snoopyet0909
一般會員 發表:2 回覆:6 積分:1 註冊:2005-06-09 發送簡訊給我 |
|
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
引言: 以下是程式部份: unit Unit1; //<-- 單元名稱:Unit1 interface uses Windows, Messages, SysUtils, Variants, 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; function test(i:string):string; stdcall; var Fa:TForm1; implementation {$R *.dfm} function test(i:string):string; begin Fa:=TForm1.Create(Application); //<--創建後,沒釋放 Fa.ShowModal; result:=test(i); //<--怎一直呼叫自己的函數呢 end; procedure TForm1.Button1Click(Sender: TObject); //<--完全不懂這是做什麼用的 var a:integer; begin a:=strtoint(edit1.Text); end; end. ------------------------------------------------------------- unit Unit2;//<-- 單元名稱:Unit1,這是主程式的單元檔案 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; function test():string; stdcall; external'project2.dll'; //<--導入Project2.dll檔的test函數 var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin label1.Caption:=test(); end; end. ------------------------------------------------------------- library Project2; //<--DLL專案程式 { 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 SysUtils, Classes, Unit1 in 'Unit1.pas' {Form1}; //<--包函了某個單元 {$R *.res} exports test; //<--輸出的DLL函數 begin end. ------------------------------------------------------------- 問題 1.以上三個程式,可不可以麻煩妳們告訴我哪一個是主程式? 因為我怎麼看都看不出來! 2.上面的程式是屬於不完整的程式 因為執行結果是這樣 按下按鈕後會出現一個表單 然後輸入數值 接下來所輸入的數值會傳回原本的表單 而那個突然跑出來的表單會不見 可是呀 我不管怎麼寫 都不會出來 所以想麻煩大家幫幫我的忙!! 先在這邊向各位說聲謝謝.....!!發表人 - jest0024 於 2005/06/10 00:20:45 |
snoopyet0909
一般會員 發表:2 回覆:6 積分:1 註冊:2005-06-09 發送簡訊給我 |
|
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
Dll Function function Test:PChar;stdcall; var Form:TForm1; S :PChar; begin Form:=TForm1.Create(nil); if Form.ShowModal=mrOk then S:=PChar(Form.Edit1.Text) else S:=''; Form.Free; Result:=S; end; Exe Function function test:PChar;stdcall; external'project2.dll'; |
snoopyet0909
一般會員 發表:2 回覆:6 積分:1 註冊:2005-06-09 發送簡訊給我 |
|
jest0024
高階會員 發表:11 回覆:310 積分:224 註冊:2002-11-24 發送簡訊給我 |
|
snoopyet0909
一般會員 發表:2 回覆:6 積分:1 註冊:2005-06-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |