DLL封装Interface(接口)(D2007+win764位)
相关资料:
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驱动 ...
随机推荐
- openstack网络基础
一.概述 网络虚拟化是云计算的最重要部分,本文详细讲述 Linux 抽象出来的各种网络设备的原理.用法.数据流向.您通过此文,能够知道如何使用 Linux 的基础网络设备进行配置以达到特定的目的,分析 ...
- Python学习笔记009—函数
1. 空函数 如果想定义一个什么事也不做的空函数,可以用pass语句: def nop(): pass pass语句什么都不做,那有什么用?实际上pass可以用来作为占位符,比如现在还没想好怎么写函数 ...
- android 4.4 支持透明状态栏和透明导航栏
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceSt ...
- MongoDB学习笔记(10)-- 排序
MongoDB sort() 方法 在 MongoDB 中使用 sort() 方法对数据进行排序,sort() 方法可以通过参数指定排序的字段,并使用 1 和 -1 来指定排序的方式,其中 1 为升序 ...
- Python读文本文件
file_object = open('thefile.txt') try: all_the_text = file_object.read() finally: file_object.close( ...
- Android RoboGuice开源框架、Butter Knife开源框架浅析
Google Guice on Android(RoboGuice) 今天介绍一下Google的这个开源框架RoboGuice, 它的作用跟之前讲过的Dagger框架差点儿是一样的,仅仅是Dagger ...
- SqlExcel使用文档及源码
昨天帮朋友做了个小工具,以完成多表连接处理一些数据.今天下班后又做了份使用文档,不知友能看懂否?现将使用文档及源码发布如下,以供有同样需求的朋友下载. 使用文档 一.增.改.查.删 1.增(向shee ...
- Proxy源代码分析——谈谈如何学习Linux网络编程
Linux是一个可靠性非常高的操作系统,但是所有用过Linux的朋友都会感觉到, Linux和Windows这样的"傻瓜"操作系统(这里丝毫没有贬低Windows的意思,相反这应该 ...
- 最全PyCharm教程
最全PyCharm教程--for python PyCharm简介: PyCharm是由JetBrains打造的一款Python IDE,VS2010的重构插件Resharper就是出自JetBrai ...
- python3 如何给装饰器传递参数
[引子] 之前写过一篇文章用来讲解装饰器(https://www.cnblogs.com/JiangLe/p/9309330.html) .那篇文章的定位是入门级的 所以也就没有讲过多的高级主题,决定 ...