DLL中传递引用的问题(100分)

  • 主题发起人 主题发起人 wind1
  • 开始时间 开始时间
W

wind1

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL中如何传递引用?请举一例子!如在DLL中用引用传递返回一Pchar!
 
参数前加上 var
 
dll:
library test;
uses
ShareMem,
SysUtils,
Classes;
function test(test:Pchar):integer;export;stdcall;
begin
Strcopy(test,Pchar('123'));
test:=0;
end;
exports
test;
begin
end.

unit unit1;

interface

uses
Sharemem,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
function test(test:PChar):integer;stdcall;external 'Project2.dll';
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var s:String;
begin
setlength(s,100);
test(pchar(s));
end;
end.

不能加VAR!!
 
接受答案了.
 
后退
顶部