一个如何调用dll 窗体的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 雨林18
  • 开始时间 开始时间

雨林18

Unregistered / Unconfirmed
GUEST, unregistred user!
我编译了一个DLL文件代码如下
主程序代码
library Project1;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
end.

窗体一代码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

end.

窗体二代码
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

end.

我现在用另一个exe程序掉用他,我在Button1Click事件调用代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
DLLHandle: THandle;
begin
DLLHandle:=LoadLibrary('Project1.dll');
if DLLHandle <> 0 then
begin
我想在这里调用DLL的窗体一;
end;
end;
end;

我想在TForm1.Button1Click 事件里调用窗体一,在从窗体一的Button1Click调用窗体二如何实现!请高手指教,谢谢
 
能不能给出代码,谢谢
 
在窗体里面也给调用的接口
 
to godyad
能不能就在我的代码里改,只要能能在程序里调出窗体一显示出来就可以了,谢谢
 
窗体一代码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
function test():boolean;export;
var
Form1: TForm1;

implementation

{$R *.dfm}
function test():boolean;
var
a:tform1;
begin
a:=tformq.creat(application);
//do something
a.free;
end;
end.

procedure TForm1.Button1Click(Sender: TObject);
type
TTest=function():boolean;
var
DLLHandle: THandle;
test:ttest;
a:boolean;
begin
DLLHandle:=LoadLibrary('Project1.dll');
if DLLHandle <> 0 then
begin
//我想在这里调用DLL的窗体一;
@test:=getprocaddress(dllhandle,'test');
a:=test;
freelibrary(dllhandle);
end;
end;
end;
 
to erqie
我试了一下程序出错呀!
 
哪儿出错?在library里的begin之前加一句exports test;//这个做了没?
a:=tformq.creat(application);//这句打错了应为:
a:=tform1.creat(application);
 
to erqie
做了,编译是通过了但运行时出错,麻烦再帮看看谢谢!!!
 
输出函数要加stdcall
 
调用dll的时候,你把窗体2的handle传给窗体1,窗体2通过handle调用窗体1
 
多人接受答案了。
 

Similar threads

后退
顶部