如何在dll中调用窗体

ljp940531 2003-07-11 03:20:09
dll 工程中如下; 还有一个form1function showunit1(str:string):longint;stdcall;export;
begin
showmessage(str);
form1.ShowModal;
result:=0;
end;
exports
showunit1;
begin
end.
(文件名mydll.dll)


调用如下:
type
showunit=function(str:string):longint;stdcall;
var
aa:showunit;
libhandle:Thandle;
begin
libhandle:=loadlibrary('mydll');
if libhandle=0 then begin showmessage('fail');exit;end;
@aa:=GetProcAddress(libhandle,'showunit1');
if @aa=nil then begin showmessage('fail');exit;end;
aa('df');
end;
能弹出df对话框,但执行form1.showmodal 出错
...全文
50 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
up
itfly 2003-07-12
  • 打赏
  • 举报
回复
反请教两位高手。是不是可以让DLL的代码能够集合在EXE里面呢?!
fuz998 2003-07-12
  • 打赏
  • 举报
回复
dll如下:
library MinMax;
{$R *.res}

function Min(x,y:integer):integer;stdcall;//使用stdcall编译可以给其他编成语言使用
begin
if x<y then result:=x else result:=y;
end;

function Max(x,y:integer):integer;stdcall;//使用stdcall编译可以给其他编成语言使用
begin
if x<y then result:=y else result:=x;
end;

exports
Min,Max;

begin
end.
//
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function Max(x,y:ingeter); stdcall; external 'DLL的名字.dll' name 'Max';

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(max(1,2)));
end;

ljp940531 2003-07-12
  • 打赏
  • 举报
回复
to ljmanage(过客)
thanks;
李_军 2003-07-11
  • 打赏
  • 举报
回复
dll 工程中如下; 还有一个form1 (不好意思,回车)
uses
Forms;
function showunit1(str:string):longint;stdcall;export;
begin
showmessage(str);
try
Form1 := TForm1.Create(Application);
form1.ShowModal; //你的Form1没有创建
finally
FreeAndNIl(Form1);
result:=0;
end;
exports
showunit1;
begin
end.
ljp940531 2003-07-11
  • 打赏
  • 举报
回复
dll 工程中如下; 还有一个form1 (不好意思,回车)
function showunit1(str:string):longint;stdcall;export;
begin
showmessage(str);
form1.ShowModal;
result:=0;
end;
exports
showunit1;
begin
end.
(文件名mydll.dll)

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧