调用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>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...
随机推荐
- Oracle存储过程实现返回多个结果集 在构造函数方法中使用 dataset
原文 Oracle存储过程实现返回多个结果集 在构造函数方法中使用 dataset DataSet相当你用的数据库: DataTable相当于你的表.一个 DataSet 可以包含多个 DataTab ...
- [Papers]MHD, $\pi$, Lorentz space [Suzuki, DCDSA, 2011]
$$\bex \sen{\pi}_{L^{s,\infty}(0,T;L^{q,\infty}(\bbR^3))} +\sen{{\bf b}}_{L^{\gamma,\infty}(0,T;L^{\ ...
- [Everyday Mathematics]20150116
设 $\al_n\geq 0$ 且 $\dps{\vlm{n}\al_n=0}$, 试求 $$\bex \vlm{n}\frac{1}{n}\sum_{k=1}^n \ln\sex{\frac{k}{ ...
- [Everyday Mathematics]20150110
试证: $$\bex \vlm{n}\frac{\ln^2n}{n}\sum_{k=2}^{n-2}\frac{1}{\ln k\cdot \ln(n-k)}=1. \eex$$
- Android之APK文件签名——keytool和jarsigner
一.生成密钥库将位置定位在jdk的bin文件中,输入以下命名行:keytool -genkey -alias ChangeBackgroundWidget.keystore -keyalg RSA - ...
- PICT实现组合测试用例(一)
最近阅读了史亮老师的<软件测试实战:微软技术专家经验总结>一书,其中“测试建模”一章让我受益匪浅.想想以前的测试有多久没有花过心思放在测试用例的设计上了,一直强调“测试思想”的培养也都只是 ...
- 深入学习Android有关网络连接的内容
基于实际项目中碰到的些许问题,开始重新深入学习Android网络连接有关知识. Android的4.1.2版本的AndroidHttpClient模块setSoTimeout之后实际超时时间和设置的时 ...
- cocos2d-x 详解之 CCTexture2D(纹理图片)和 CCTextureCache(纹理缓存)
精灵和动画都涉及到纹理图片的使用,所以在研究精灵与动画之前,我们先来了解一下纹理图片类CCTexture2D和纹理缓存CCTextureCache的原理: 当一张图片被加载到内存后,它是以纹理的形式存 ...
- Rust 中的继承与代码复用
在学习Rust过程中突然想到怎么实现继承,特别是用于代码复用的继承,于是在网上查了查,发现不是那么简单的. C++的继承 首先看看c++中是如何做的. 例如要做一个场景结点的Node类和一个Sprit ...
- 关于CodeBlocks中stdc++-6.dll缺失的小问题
前一阵子在用CodeBlocks刷OJ(也并不是什么很难的算法,背包问题而已)时,遇到了个小麻烦,按下F9编译运行(有的人习惯用鼠标去点那个小button,多麻烦啊)后,Windows给我跳出个小窗说 ...