调用Dll里面的窗体
用Delphi生成DLL并封装窗体的示例
调用Dll里面的窗体

DLL文件
library Project2;
{ 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,
Unit2
in 'Unit2.pas'
{Form1};
{$R
*.res}
exports
Dll_Showform,
Dll_CreateForm,
DLL_GetValue,
DLL_SetTitle;
begin
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
Buttons;
type
TForm1
= class(TForm)
Memo1:
TMemo;
BitBtn1: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1:
TForm1;
//Ready for DLl Export
list
procedure
Dll_Showform();stdcall;
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;
function DLL_GetValue():string;stdcall;
procedure DLL_SetTitle(text:string); stdcall;
implementation
{$R
*.dfm}
//无参数
procedure Dll_Showform();stdcall;
var frm:TForm1;
begin
frm:=TForm1.Create(Application);
frm.Position:=poMainFormCenter;
frm.ShowModal;
end;
//带参数
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;
var frm:TForm1;
begin
frm:=TForm1.Create(Application);
frm.Left:=Left;
frm.Top:=Top;
frm.Width:=Width;
frm.Height:=Height;
frm.BorderStyle:=bsNone;
frm.ShowModal;
end;
//获得返回值
function
DLL_GetValue():string;stdcall;
var
frm:TForm1;
begin
Result:='';
frm:=TForm1.Create(Application);
frm.Position:=poMainFormCenter;
if frm.ShowModal = mrok
then
Result:=frm.Memo1.Lines.Text;
end;
//回调
procedure DLL_SetTitle(text:string); stdcall;
var frm:TForm1;
begin
frm:=TForm1.Create(Application);
frm.Position:=poMainFormCenter;
frm.Caption:=text;
frm.ShowModal;
end;
end.
调用Dll
unit Unit1;
interface
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
//-------------------------------------------------------------------------------
procedure Dll_Showform();stdcall;external 'project2.dll'; //1无参数
直接调用
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;external 'project2.dll';//2带参数了
function DLL_GetValue():string;stdcall;external 'project2.dll';//3获得返回值
//-------------------------------------------------------------------------------
type
TfrmMain1 = class(TForm)
Button1:
TButton;
Button2:
TButton;
Button3:
TButton;
Memo1:
TMemo;
Button4:
TButton;
procedure
Button1Click(Sender: TObject);
procedure Button2Click(Sender:
TObject);
procedure
Button3Click(Sender: TObject);
procedure Button4Click(Sender:
TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain1: TfrmMain1;
implementation
{$R
*.dfm}
//------------------------------------------------------------------------------
procedure TfrmMain1.Button1Click(Sender:
TObject);
begin
Dll_Showform;
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button2Click(Sender:
TObject);
var
x,y:Integer;
begin
x:=frmMain1.left+Button2.left+8; //Left
y:=frmMain1.Top+Button2.Top +Button2.Height+28; //Top
Dll_Createform(x,y,400,400);
// Dll_Createform(0,0,100,200);
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button3Click(Sender:
TObject);
begin
Memo1.Text:=DLL_GetValue;
end;
//------------------------------------------------------------------------------
type
TSetCaption = procedure(text:string); stdcall;//4回调
procedure
TfrmMain1.Button4Click(Sender: TObject);
var
pSetTitle:
TSetCaption;
h:THandle;
begin
h:=LoadLibrary(PChar('project2.dll'));
pSetTitle
:= TSetCaption( GetProcAddress(h, PChar('DLL_SetTitle')) );
if h = 0 then
Exit;
if
Assigned(pSetTitle) then
pSetTitle('Hello
World!');
FreeLibrary(h);
end;
end.

调用Dll里面的窗体的更多相关文章
- Delphi程序调用C#.Net编译的DLL并打开窗体(详解)
Delphi程序调用C#.Net编译的DLL并打开窗体(详解)最近用C#.Net写了一个公用模块, 本以为仅提供给.Net程序使用, 但是领导要求把这些功能提供给旧系统使用, 天啦, 几套旧系统全是D ...
- 学习反射例子,调用DLL窗体及方法
创建类库,并添加新窗体,加入以下方法 public static string setText(string str) { return str; } 编译后把生成的DLL文件放入新项目的bin目录, ...
- 【转】C#调用DLL
C#中如何调用动态链接库DLL(转) 每种编程语言调用DLL的方法都不尽相同,在此只对用C#调用DLL的方法进行介绍.首先,您需要了解什么是托管,什么是非托管.一般可以认为:非托管代码主要是基 ...
- C#程序实现动态调用DLL的研究(转)
摘 要:在<csdn开发高手>2004年第03期中的<化功大法——将DLL嵌入EXE>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...
- C#:控制台程序调用中间库创建窗体
1.类库项目引用System.Windows.Forms并添加引用后,才可创建窗体. 2.控制台应用程序调用中间库(DLL)中的方法创建窗体:中间类库使用反射下的Assembly加载包含窗体的类库及创 ...
- delphi 基础之三 编写和调用dll文件
delphi 编写和调用dll文件 Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...
- 【VB技巧】VB静态调用与动态调用dll详解
本文“[VB技巧]VB静态调用与动态调用dll详解”,来自:Nuclear'Atk 网络安全研究中心,本文地址:http://lcx.cc/?i=489,转载请注明作者及出处! [[请注意]]:在以下 ...
- C#程序实现动态调用DLL的研究[转]
摘 要: 在< csdn 开发高手> 2004 年第 03 期中的<化功大法——将 DLL 嵌入 EXE >一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在 ...
- C#程序实现动态调用DLL的研究
摘 要:在<csdn开发高手>2004年第03期中的<化功大法——将DLL嵌入EXE>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...
随机推荐
- [转] ArcEngine 产生专题图
小生原文 ArcEngine 产生专题图 ArcEngine提供多个着色对象用于产生专题图,可以使用标准着色方案,也可以自定义着色方案,ArcEngine提供8中标准着色方案. 一.SimpleRen ...
- 开启Ubuntu Linux下VirtualBox访问USB功能
解决方法如下: 1.增加用户组usbfs sudo groupadd usbfs 2.查看usbfs用户组的gid cat /etc/group | grep usbfs usbfs:x:1002: ...
- spring中的BeanFactory与ApplicationContext的作用和区别?
BeanFactory类关系继承图 1. BeanFactory类结构体系: BeanFactory接口及其子类定义了Spring IoC容器体系结构,由于BeanFactory体系非常的庞大和复杂, ...
- C++11笔记
__func__宏 __func__返回当前的函数名,也可以返回class和struct名. /*返回函数名hello*/ const char* hello() { return __func__; ...
- Andriod中绘(画)图----Canvas的使用详解
http://blog.csdn.net/qinjuning/article/details/6936783
- 七中滤波方法测试matlab实现
http://blog.163.com/xiaheng0804@126/blog/static/1205282120132129471816/ 创建两个混合信号,便于更好测试滤波器效果.同时用七中滤波 ...
- redis集群的搭建
1.首先下载好软件包 #cd /opt/tzr/ #wget http://redis.googlecode.com/files/redis-2.6.11.tar.gz #mkdir /opt/tzr ...
- 瞬间从IT屌丝变大神——HTML规范
HTML规范包含以下内容: DTD统一用<!DOCTYPE HTML PUBLIC "_//W3C//DTD XHTML 1.0 Transitional//EN"" ...
- 【转】你真的了解iOS代理设计模式吗?
转自:http://www.cocoachina.com/ios/20160317/15696.html 在项目中我们经常会用到代理的设计模式,这是iOS中一种消息传递的方式,也可以通过这种方式来传递 ...
- C 语言中包含的标准头文件(24个)
<assert.h><complex.h><ctype.h><errno.h><fenv.h><float.h><intt ...