線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1627
推到 Plurk!
推到 Facebook!

請問dll檔如果要return一個值回去該怎麼寫

尚未結案
kochen
一般會員


發表:8
回覆:5
積分:2
註冊:2004-09-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-22 23:44:43 IP:61.56.xxx.xxx 未訂閱
library Project1; { 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 classes9. 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'; exports PCopyFile; var i:integer; begin i := 1; result:=i; //這行一直說錯...在bcb裡面最後會可以寫 return 1 ;就回回傳1這個值回去.只是我這樣寫一直沒辦法過..能否幫忙指點一下 end.
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-23 00:04:34 IP:203.204.xxx.xxx 未訂閱
您好: 不曉得是甚麼錯誤訊息,我寫了一各範例您看看    建立dll
library makedll;    uses
  SysUtils,
  Classes,
  Dialogs,
  main1 in 'main1.pas';    function a():string;export; {宣告一個函數}
begin
ShowMessage('you success use dll');
result:='result';
end;    exports a;
{$R *.RES}    begin
end.
存取dll函數,秀出一段訊息,並傳回result的傳回值
unit main;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,main1;    type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    function a():string; far;external 'makedll.dll'; //設定要呼叫的函數名稱    implementation    {$R *.DFM}    procedure TForm1.Button1Click(Sender: TObject);
var
 LibH:THandle;                       {宣告一個讓dll使用的Handle}
 s:String;
begin
LibH:=LoadLibrary('makedll.dll');    {載入dll檔案}
if Libh=0 then ShowMessage('error'); {如果載入失敗時會傳回0}
s:=a();
showmessage(s);                      {使用Dll中的函數}
FreeLibrary(LibH);                   {釋放dll的Handle}
end;    end.
發表人 - supman 於 2005/04/23 00:06:52
kochen
一般會員


發表:8
回覆:5
積分:2
註冊:2004-09-05

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-23 07:22:28 IP:61.56.xxx.xxx 未訂閱
感謝您.我等會試試看能不能解決我滴問題...真是謝謝您了
系統時間:2024-05-17 12:51:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!