【求】带窗体的dll的创建和调用的完整实例。。。。。。。
本人试图将程序模块化,只要一个主界面,其它子窗体都封装在不同的DLL里,但是我没有做过不知道怎样写一个带窗体的dll,并在主窗口去调用这个dll。所以希望高手们提供一个完整的实例学习一下,谢谢。。。
mailaddress: chenxzh517@yahoo.com
问题点数:50、回复次数:9Top
1 楼chenxzh88(小破孩)回复于 2004-09-01 10:53:20 得分 0
【更正】mailaddress: chenxzh517@yahoo.com.cnTop
2 楼luke5678()回复于 2004-09-01 10:56:51 得分 25
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};
{$R *.RES}
function Returnstr:string;stdcall;
begin
with TForm1.Create(nil) do
try
showmodal;
Result := trim(edit1.text);
finally
free;
end;
end;
exports
Returnstr;
begin
end.
这是dll的代码。
procedure TForm1.Button1Click(Sender: TObject);
var
DllHandle : THandle=0;
Rd : function : String; stdcall;
begin
DllHandle := LoadLibrary('mydll.dll');
if DllHandle > 0 then
@Rd := GetProcAddress(DllHandle,'ShowMainForm')
else
begin
DllHandle := 0;
@Rd := nil;
end;
if (DllHandle > 0) and (@Rd <> nil) then
edit1.text := Rd
else
edit1.text := '';
end;
这是调用的代码。Top
3 楼luke5678()回复于 2004-09-01 11:03:16 得分 0
不好意识,上面的代码有错
更正以后再帖Top
4 楼chenxzh88(小破孩)回复于 2004-09-01 11:13:05 得分 0
你加我的QQ吧,我不懂的地方可以请教请教。QQ:348296115Top
5 楼luke5678()回复于 2004-09-01 11:14:19 得分 0
//你要引用的窗体
unit unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ApplicationName: String;
procedure LoadForm(Handle: THandle; AppName: ShortString); export;
implementation
{$R *.dfm}
procedure LoadForm(Handle: THandle; AppName: ShortString);
begin
Application.Handle := Handle;
ApplicationName := AppName;
Form1 := TForm1.Create(Application);
try
Form1.ShowModal;
finally
Form1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
self.close;
end;
end.
//Dll代码
library usedll;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
LoadForm index 1;
begin
end.
//建立一个工程调用DLL
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
procedure LoadForm; external 'usedll.dll' index 1;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
LoadForm;
end;
end.
Top
6 楼chenxzh88(小破孩)回复于 2004-09-01 11:38:11 得分 0
为什么我在调试的时候出现内存错误?
还有就是这三部分都是是独立的吗?还是所有代码都写到一个工程里面啊?Top
7 楼luke5678()回复于 2004-09-01 11:45:23 得分 0
能不能把具体抱什么错贴一下Top
8 楼zdq801104(【☆这个杀手不太冷☆】)回复于 2004-09-01 14:19:31 得分 25
我发原码给你了,记得给分哦Top
9 楼chenxzh88(小破孩)回复于 2004-09-01 14:31:24 得分 0
Error:
Project Project2.exe raised exception class EOSError with message 'System Error.Code:1400.无效的窗口句柄。',Process stopped.Use Step or Run to continue.
只要我有收获一定给分。Top




