一个很简单的自编DLL,就输出一个字符串,静态调用正常,动态出错。(100)

3

336764

Unregistered / Unconfirmed
GUEST, unregistred user!
一个很简单的自编DLL,就输出一个字符串,静态调用正常,动态调用出错。请问,错在哪里了??出错时,程序直接关闭退出,没有任何提示。
Code:
unit loaddllUnit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Edit1: TEdit;    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.dfm}// function TESTDLL:string; stdcall; external 'DLL/dll1.dll';procedure TForm1.Button1Click(Sender: TObject);var  dll: Cardinal; // THandle;  Getppx: function: string;begin  dll := LoadLibrary(PChar('DLL/dll1.dll'));  if dll > 32 then  begin    @Getppx := GetProcAddress(dll, 'TESTDLL');    if Assigned(@Getppx) then    begin      Edit1.Text := Getppx;    end;    FreeLibrary(dll);  end;  // Edit1.Text:= TESTDLL;end;end.
======================================dll:
Code:
library dll1;uses  SysUtils,  Classes;{$R *.res}function TESTDLL:string;stdcall;begin  Result:='test.';end;exportsTESTDLL;beginend.
 
3

336764

Unregistered / Unconfirmed
GUEST, unregistred user!
到底错在哪儿了???????????
 
3

336764

Unregistered / Unconfirmed
GUEST, unregistred user!
事实证明,就是string换成pchar的问题。。。
 
3

336764

Unregistered / Unconfirmed
GUEST, unregistred user!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=4001692杯具。。。。。
 
D

dorry

Unregistered / Unconfirmed
GUEST, unregistred user!
改成如下即可library dll1;uses ShareMem,//必须第一个 SysUtils, Classes;{$R *.res}function TESTDLL:string;stdcall;begin Result:='test.';end;exportsTESTDLL;beginend.同时发布程序时徐发布BORLNDMM.DLL.
 
A

aikede

Unregistered / Unconfirmed
GUEST, unregistred user!
dll中如返回String,ShareMem,//必须第一个
 
K

kk2000

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);var dll: Cardinal; // THandle; Getppx: function: string;stdcall; //这句加上就可以了
 
Top Bottom