大
大花鸡
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟在学DLL中显示模式窗体时有个问题,下面是DLL的代码。
library ShowFormLib;
uses
ShareMem,
SysUtils,
Classes,
EditForm in 'EditForm.pas' {Form1};
{$R *.res}
exports
ShowEditForms;
begin
end.
下面是DLL中的窗体:
unit EditForm;
interface
uses
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;
function ShowEditForms(AHandle:THandle;ACaption:String):String;StdCall;
implementation
{$R *.dfm}
function ShowEditForms(AHandle:THandle;ACaption:String):String;StdCall;
var
Form1: TForm1;
begin
Application.Handle:=AHandle;
Form1:=TForm1.Create(application);
try
Form1.Caption:=ACaption;
Form1.ShowModal;
Result:=Form1.Edit1.Text;
finally
Form1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
end.
最后是主程序:
unit frmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TShowEditForms=function (AHandle:THandle;ACaption:String):String;StdCall;
EDLLLoadError = class(Exception);
TMform = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Mform: TMform;
implementation
{$R *.dfm}
procedure TMform.Button1Click(Sender: TObject);
var
LibHandle:THandle;
ShowEditForms:TShowEditForms;
begin
LibHandle:=LoadLibrary('ShowFormLib.dll');
try
if LibHandle=0 then
raise EDLLLoadError.Create('Unabled to Find the DLL file');
@ShowEditForms:=GetProcAddress(LibHandle,'ShowEditForms');
if not (@ShowEditForms=nil) then
label1.Caption:=ShowEditForms(Application.Handle,caption)
else
RaiseLastWin32Error;
finally
FreeLibrary(Libhandle);
end;
end;
end.
总是出现错误说找不到程序,为什么?代码是:
System Error.Code:127.
找不到指定程序。
library ShowFormLib;
uses
ShareMem,
SysUtils,
Classes,
EditForm in 'EditForm.pas' {Form1};
{$R *.res}
exports
ShowEditForms;
begin
end.
下面是DLL中的窗体:
unit EditForm;
interface
uses
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;
function ShowEditForms(AHandle:THandle;ACaption:String):String;StdCall;
implementation
{$R *.dfm}
function ShowEditForms(AHandle:THandle;ACaption:String):String;StdCall;
var
Form1: TForm1;
begin
Application.Handle:=AHandle;
Form1:=TForm1.Create(application);
try
Form1.Caption:=ACaption;
Form1.ShowModal;
Result:=Form1.Edit1.Text;
finally
Form1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
end.
最后是主程序:
unit frmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TShowEditForms=function (AHandle:THandle;ACaption:String):String;StdCall;
EDLLLoadError = class(Exception);
TMform = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Mform: TMform;
implementation
{$R *.dfm}
procedure TMform.Button1Click(Sender: TObject);
var
LibHandle:THandle;
ShowEditForms:TShowEditForms;
begin
LibHandle:=LoadLibrary('ShowFormLib.dll');
try
if LibHandle=0 then
raise EDLLLoadError.Create('Unabled to Find the DLL file');
@ShowEditForms:=GetProcAddress(LibHandle,'ShowEditForms');
if not (@ShowEditForms=nil) then
label1.Caption:=ShowEditForms(Application.Handle,caption)
else
RaiseLastWin32Error;
finally
FreeLibrary(Libhandle);
end;
end;
end.
总是出现错误说找不到程序,为什么?代码是:
System Error.Code:127.
找不到指定程序。