相关资料:

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位)的更多相关文章

  1. APSC4xSeries_Ver32.exe在win764位提示缺少DLL错误解决办法

    APSC4xSeries_Ver32.exe在win764位提示缺少DLL错误解决办法 从网上下载oatime_epson-me1清零软件,Stylus4xProgram_Ver32的 解决办法:还是 ...

  2. 64位进程调用32位dll的解决方法 / 程序64位化带来的问题和思考

    最近做在Windows XP X64,VS2005环境下做32位程序编译为64位程序的工作,遇到了一些64位编程中可能遇到的问题:如内联汇编(解决方法改为C/C++代码),long类型的变化,最关键的 ...

  3. Delphi 中的DLL 封装和调用对象技术(刘艺,有截图)

    Delphi 中的DLL 封装和调用对象技术本文刊登2003 年10 月份出版的Dr.Dobb's 软件研发第3 期刘 艺摘 要DLL 是一种应用最为广泛的动态链接技术但是由于在DLL 中封装和调用对 ...

  4. Java基础04 封装与接口

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 总结之前的内容,对象(object)指代某一事物,类(class)指代象的类型.对 ...

  5. golang面向对象和interface接口

    一. golang面向对象介绍 1.golang也支持面向对象编程,但是和传统的面向对象编程有区别,并不是纯粹的面向对象语言.2.golang没有类(class),golang语言的结合体(struc ...

  6. C++中模块(Dll)对外暴露接口的方式

    总结下C++中模块(Dll)对外暴露接口的方式: (1)导出API函数的方式这种方式是Windows中调用DLL接口的最基本方式,GDI32.dll, User32.dll都是用这种方式对外暴露系统A ...

  7. Java基础04 封装与接口(转载)

    数据成员和方法都是同时开放给内部和外部的.在对象内部,我们利用this来调用对象的数据成员和方法.在对象外部,比如当我们在另一个类中调用对象的时,可以使用 对象.数据成员 和 对象.方法() 来调用对 ...

  8. java Vamei快速教程04 封装和接口

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 总结之前的内容,对象(object)指代某一事物,类(class)指代象的类型.对 ...

  9. WIN764位主机的虚拟机安装的xp系统串口添加

    WIN764位主机的虚拟机安装的xp系统串口添加 我的电脑安装的是64位的WIN7系统,今天为了验证一个问题,需要用到6410开发板,但在安装USB驱动时无法成功安装,估计是S3C6410的USB驱动 ...

随机推荐

  1. dubbo 学习(5) dubbo多协议和多注册中心

    转载 http://blog.csdn.net/songjinbin/article/details/49498431 一.配置dubbo多协议模式 1.默认协议 Dubbo缺省协议采用单一长连接和N ...

  2. Git 别名(分布式版本控制系统)

    1.Git 别名 Git 并不会在你输入部分命令时自动推断出你想要的命令.如果不想每次都输入完整的 Git 命令,可以通过 git config 文件来轻松地为每一个命令设置一个别名.这里有一些例子你 ...

  3. php非阻塞服务器

    <?php class PHPSocketServer { const ERROR = 0; const LOG = 1; const DEBUG = 2; private $aConfig = ...

  4. golang学习笔记 --switch

    switch的例子: switch coinflip() { case "heads": heads++ case "tails": tails++ defau ...

  5. org.hibernate.exception.ConstraintViolationException: could not insert:

    org.hibernate.exception.ConstraintViolationException: could not insert: 报错原由于xxx.hbm.xml文件里的主键类型设置有问 ...

  6. samba 服务器搭建

    为了能在两台机器上共享代码,方便测试不同平台性能和搭建分布式的web server,今天耗费半天时间搭建一个samba服务器共享数据,要求开放写权限,但多次实验均告失败,最终在 鸟哥 的提醒下 检查发 ...

  7. SharePoint自动化部署,利用SPSD工具包

    目录 怎样使用SPSD 配置Environment XML文件 PowerShell激活Feature  上篇博客讲了利用PowerShell导出.导入AD中的Users.这篇介绍简单介绍一下SPSD ...

  8. 第一篇:初识ASP.NET控件开发_第一节:控件类及其继承关系

    1)System.Web.UI.Control(以下简称Control) Control 类是包括自定义控件.用户控件和页在内的所有 ASP.NET 服务器控件的基类..定义由所有 ASP.NET 服 ...

  9. Java 8 Optional In Depth

    OptionalBasicExample.java package com.mkyong; import java.util.Optional; public class OptionalBasicE ...

  10. Android之四大组件、六大布局、五大存储 总结

    Android之四大组件.六大布局.五大存储 一.四大组件:Android四大组件分别为activity.service.content provider.broadcast receiver.   ...