调用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>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...
随机推荐
- information_schema中的三个关于锁的表
在5.5中,information_schema 库中增加了三个关于锁的表(MEMORY引擎):innodb_trx ## 当前运行的所有事务innodb_locks ## ...
- HDU 4609 3-idiots FFT+容斥
一点吐槽:我看网上很多分析,都是在分析这个题的时候,讲了半天的FFT,其实我感觉更多的把FFT当工具用就好了 分析:这个题如果数据小,统计两个相加为 x 的个数这一步骤(这个步骤其实就是求卷积啊),完 ...
- lightoj 1023
题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...
- acdream 1056 (黑白染色)
题意:给你一些关系,每个关系是两只马的名字,表示这两个马不能在一个分组里,问你能否将这些马分成两组. 黑白染色,相邻的点染不同颜色.bfs搞即可,水题. /* * this code is made ...
- HDU-3001 Travelling
http://acm.hdu.edu.cn/showproblem.php?pid=3001 从任何一个点出发,去到达所有的点,但每个点只能到达2次,使用的经费最小.三进制 Travelling Ti ...
- duilib中控件拖拽功能的实现方法(附源码)
转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41144283 duilib库中原本没有显示的对控件增加拖拽的功能,而实际 ...
- DataGrid的打印预览和打印
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System. ...
- JavaScript中的事件冒泡机制
事件冒泡机制 事件冒泡发生的条件:当为多个嵌套的元素设置了相同的事件处理程序,它们将触发事件冒泡机制.在事件冒泡中,最内部的元素将首先触发其事件,然后是栈内的下一个元素触发该事件,以此类推,直到到达最 ...
- CSS快速制作图片轮播的焦点
来源:http://www.ido321.com/858.html 效果图: 演示地址:http://jsfiddle.net/Web_Code/q5qfd8aL/embedded/result/ 代 ...
- Designing Evolvable Web API with ASP.NET 随便读,随便记 “The Internet,the World Wide Web,and HTTP”——HTTP
HTTP 我们将只聚焦在于与创建 Web APIs有关的部分. HTTP 是信息系统中的一个应用层协议,是Web的支柱. 其原先由 Berners-Lee, Roy Fielding 和 Henrik ...