3
336764
Unregistered / Unconfirmed
GUEST, unregistred user!
一个很简单的自编DLL,就输出一个字符串,静态调用正常,动态调用出错。请问,错在哪里了??出错时,程序直接关闭退出,没有任何提示。
======================================dll:
代码:
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.
代码:
library dll1;uses SysUtils, Classes;{$R *.res}function TESTDLL:string;stdcall;begin Result:='test.';end;exportsTESTDLL;beginend.