DLL封装Interface(接口)(D2007+win764位)
.jpg)
相关资料:
http://blog.csdn.net/liangpei2008/article/details/5394911
结果注意:
1.函数的传参方向必须一至。
DLL实例代码:
ZJQInterface.pas
unit ZJQInterface; interface type
IInterface1 = interface
function Func1: Integer;
function Func2: Integer;
end; IInterface2 = interface
procedure Proc1;
procedure Proc2;
end; implementation end.
ZJQInterfaceDll.dpr
//************************************************************//
// DLL封装接口
//************************************************************//
library ZJQInterfaceDll; { 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
Dialogs,
SysUtils,
Classes,
ZJQInterface in 'ZJQInterface.pas'; type
TClass1 = class(TInterfacedObject, IInterface1, IInterface2)//可以继承一下接口
public
procedure Proc1;
procedure Proc2;
function Func1: Integer;
function Func2: Integer;
end; {$R *.res}
{ TClass1 } function TClass1.Func1: Integer;
begin
ShowMessage('IInterface1.Func1');
Result := ;
end; function TClass1.Func2: Integer;
begin
ShowMessage('IInterface1.Func2');
Result := ;
end; procedure TClass1.Proc1;
begin
ShowMessage('IInterface2.Proc1');
end; procedure TClass1.Proc2;
begin
ShowMessage('IInterface2.Proc2');
end; function CreateInterface: IInterface1; stdcall;//stdcall关键字必须有,因为UNIT1中也用到了这个,必须一至。
begin
Result := TClass1.Create;
end; exports
CreateInterface; begin
end.
EXE实例代码:
Unit1.pas
//************************************************************//
//EXE调用DLL的接口实例
//程序运行不了,请生成新的DLL放在EXE的同目录里。
//************************************************************//
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
ZJQInterface, jpeg, ExtCtrls;//引入接口单元 type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//静态调用
function CreateInterface: IInterface1; stdcall; external 'ZJQInterfaceDll.dll';//stdcall需要与DLL中的一至 var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
i1: IInterface1;
begin
i1 := CreateInterface;
i1.Func1;
//i1 := nil;//全局的接口要写这行,局部的可以不写。
end; end.
ZJQInterfaceExe.dpr
program ZJQInterfaceExe; uses
Forms,
Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin
Application.Initialize;
ReportMemoryLeaksOnShutdown := True;//打开内存溢出提示
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
DLL封装Interface(接口)(D2007+win764位)的更多相关文章
- APSC4xSeries_Ver32.exe在win764位提示缺少DLL错误解决办法
APSC4xSeries_Ver32.exe在win764位提示缺少DLL错误解决办法 从网上下载oatime_epson-me1清零软件,Stylus4xProgram_Ver32的 解决办法:还是 ...
- 64位进程调用32位dll的解决方法 / 程序64位化带来的问题和思考
最近做在Windows XP X64,VS2005环境下做32位程序编译为64位程序的工作,遇到了一些64位编程中可能遇到的问题:如内联汇编(解决方法改为C/C++代码),long类型的变化,最关键的 ...
- Delphi 中的DLL 封装和调用对象技术(刘艺,有截图)
Delphi 中的DLL 封装和调用对象技术本文刊登2003 年10 月份出版的Dr.Dobb's 软件研发第3 期刘 艺摘 要DLL 是一种应用最为广泛的动态链接技术但是由于在DLL 中封装和调用对 ...
- Java基础04 封装与接口
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 总结之前的内容,对象(object)指代某一事物,类(class)指代象的类型.对 ...
- golang面向对象和interface接口
一. golang面向对象介绍 1.golang也支持面向对象编程,但是和传统的面向对象编程有区别,并不是纯粹的面向对象语言.2.golang没有类(class),golang语言的结合体(struc ...
- C++中模块(Dll)对外暴露接口的方式
总结下C++中模块(Dll)对外暴露接口的方式: (1)导出API函数的方式这种方式是Windows中调用DLL接口的最基本方式,GDI32.dll, User32.dll都是用这种方式对外暴露系统A ...
- Java基础04 封装与接口(转载)
数据成员和方法都是同时开放给内部和外部的.在对象内部,我们利用this来调用对象的数据成员和方法.在对象外部,比如当我们在另一个类中调用对象的时,可以使用 对象.数据成员 和 对象.方法() 来调用对 ...
- java Vamei快速教程04 封装和接口
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 总结之前的内容,对象(object)指代某一事物,类(class)指代象的类型.对 ...
- WIN764位主机的虚拟机安装的xp系统串口添加
WIN764位主机的虚拟机安装的xp系统串口添加 我的电脑安装的是64位的WIN7系统,今天为了验证一个问题,需要用到6410开发板,但在安装USB驱动时无法成功安装,估计是S3C6410的USB驱动 ...
随机推荐
- C 简单1
#include <stdio.h> #define Height 10 int main(){ int width; int clong; int result; printf(&quo ...
- 【MySQL】mysql中any,in,some,all的区别
子查询就是指在一个select语句中嵌套另一个select语句. any,in,some,all分别是子查询关键词之一, any 可以与=.>.>=.<.<=.<> ...
- Easyui中 messager出现的位置
$.messager.alert 弹出框的位置随页面的长度越大越靠下. $.messager.alert('消息','只能对单个客户进行清款!','info'); 弹出的位置 太靠下方.修改为: $. ...
- SimpleAdapter真不简单!
作为一名编程初学者,我总是认为自己什么都不会,什么都不行,就算实现了文档指定的功能,我永远都是觉得自己写过的代码实在是太烂了,它只是恰巧能够运行而已!它只是在运行的时候恰巧没有发现错误而已!!一直都是 ...
- Cassandra 2.x 提示“错误: 代理抛出异常错误: java.lang.NullPointerException”
这个问题多半是由于运行了多个Cassandra实例造成的错误,看cassandra的启动脚本中可发现这样的语句: # see CASSANDRA-7254 "$JAVA" -cp ...
- Android 线程 thread 两种实现方法
原文链接: http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thr ...
- dig 命令
dig命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法 dig(选项)(参数) 选项 @<服务器地址>:指定进行域名解析的域名服务器: -b<ip地址>:当主 ...
- JetBrains PyCharm专业版激活
PyCharm最新2018激活码 激活时选择License server 填入 http://idea.imsxm.com 然后点击Active即可 PS:在线激活有一个过期时间,这个时间一过就必须再 ...
- java时区转化相关工具方法
import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java. ...
- 转:zTree树控件入门之checkbox:如何动态设置节点的checkbox选择框启用与禁用状态(chkDisabled)
当一棵树的部分节点根据登入用户角色不同而决定是否启用节点前的checkbox选择框的时候,我们应该如何做呢?也或者如何在页面加载的时候动态根据当前登入用户角色动态切换节点前的checkbox的禁用状态 ...