http://blog.sina.com.cn/s/blog_62c46c3701010q7h.html

一、编写dll

library TestDllByD2007;

uses
  SysUtils,
  Classes;
  function test(const astr:PChar):Boolean;stdcall;
  begin
    Result:=True;
  end;
{$R *.res}
  exports test;
begin
end.

注意:1.不能使用string类型,否则涉及到资源释放的问题,使用Pchar代替string。

2.Dll中不能直接返回string,除非引用ShareMem单元,发布程序时需要包含BORLNDMM.DLL

二、编写测试窗体,就一个button.在button的代码中,实现dll的动态加载和释放。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TFTest=function (const astr:PChar):Boolean;
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
  sdll:string;
  tfTTT:TFTest;
  handle:THandle;
  sstr:string;//声明该变量,目的是避免发生异常。
begin
  sdll:='TestDllByD2007.dll';
  Caption:='';
  handle:=LoadLibrary(PAnsiChar(sdll));
  if Handle <> 0 then
  begin
    @tfTTT := GetProcAddress(Handle, 'test');
    if @tfTTT <> nil then
    begin
      sstr:='testsss';
      if tfTTT(PChar(sstr))=True then
      begin
        Caption:='true';
      end
      else
      begin
        Caption:='false';
      end;
    end
    else
    begin
      Caption:='can not find the test function';
    end;
    FreeLibrary(Handle);
  end
  else
  begin
    Caption:='can not load library '+ sdll;
  end;
end;

end.

Delphi Dll 动态调用例子(1)的更多相关文章

  1. Delphi Dll 动态调用例子(3)-仔细看一下

    http://blog.163.com/bxf_0011/blog/static/35420330200952075114318/ Delphi 动态链接库的动态和静态调用 为了让人能快速的理解 静态 ...

  2. Delphi Dll 动态调用例子(2)

    http://zhidao.baidu.com/question/157196792.html delphi动态调用DLL 写了个1.dll内容如下 library Project2; uses Sy ...

  3. Delphi 类库(DLL)动态调用与静态调用示例讲解

    在Delphi或者其它程序中我们经常需要调用别人写好的DLL类库,下面直接上示例代码演示如何进行动态和静态的调用方法: { ************************************** ...

  4. 托管非托管Dll动态调用

    原文:托管非托管Dll动态调用 最近经常看到有人问托管非托管Dll调用的问题.对于动态库的调用其实很简单.网上很多代码都实现了Dll的静态调用方法.我主要谈论下动态库的动态加载. 对于托管动态库,实现 ...

  5. Delphi中动态调用TXMLDocument的经历

    var  vXMLDocument: TXMLDocument;begin  vXMLDocument := TXMLDocument.Create('c:/temp/temp.xml');  Cap ...

  6. 在Delphi中静态调用DLL

    在Delphi中静态调用DLL top 调用一个DLL比写一个DLL要容易一些.首先给大家介绍的是静态调用方法,稍后将介绍动态调用方法,并就两种方法做一个比较.同样的,我们先举一个静态调用的例子. u ...

  7. delphi dll调用问题

    dll传递string实现方法 delphi中dll传递string的实现方法: dll项目uses第一个引用sharemem单元; 调用的项目uses第一个引用sharemem单元; 调用的单元us ...

  8. delphi dll创建及调用

    第一章 DLL简单介绍由于在目前的学习工作中,需要用到DLL文件,就学习了下,在这里作个总结.首先装简单介绍下DLL:1,减小可执行文件的大小DLL技术的产生有很大一部分原因是为了减小可执行文件的大小 ...

  9. C++调用DLL有两种方法——静态调用和动态调用

    C++调用DLL有两种方法——静态调用和动态调用 标签: dllc++winapinullc 2011-09-09 09:49 11609人阅读 评论(0) 收藏 举报  分类: cpp(30)  [ ...

随机推荐

  1. ingress 密码验证

    traefik ingress 上面的方式需要引入haprox或者nginx,多引入了一个代理转发层,其实ingress本身就提供了basic auth的支持,在ingress规则中添加额外的认证an ...

  2. IIS中的MIME类型设置

    https://www.cnblogs.com/David-Young/p/5323949.html

  3. cf451C-Predict Outcome of the Game

    http://codeforces.com/problemset/problem/451/C A - Predict Outcome of the Game Time Limit:2000MS     ...

  4. fieldOfView

    fieldOfView 属性 fieldOfView:Number 语言版本:  ActionScript 3.0 运行时版本:  Flash Player 10, AIR 1.5 为三维视野指定一个 ...

  5. 跳跃游戏 12 · Jump Game 12

    跳跃游戏 1 [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: 由于要用itera ...

  6. error: In function ‘void* opencv_showimg(void*)’:

    今天这个问题折磨了我一下午,终于知道是为什么了,心酸历程.....赶紧来记录一下 错误: /home/wj/workspace/Loitor_VI_Sensor_SDK_V1./SDK/src/cam ...

  7. win下php5.4安装ffmpeg-php扩展

    1.ffmpeg的官网没有提供ffmpeg-php dll的扩展下载. http://ffmpeg-php.sourceforge.net/ 虽然在http://sourceforge.net/上提供 ...

  8. 【转】Hadoop HDFS分布式环境搭建

    原文地址  http://blog.sina.com.cn/s/blog_7060fb5a0101cson.html Hadoop HDFS分布式环境搭建 最近选择给大家介绍Hadoop HDFS系统 ...

  9. struts框架中OGNL表达式的使用之jsp页面获取action中的属性值

    在jsp页面中获取action中的值: 1.写一个action类OgnlAction类: 需要注意的地方: 如果在aciton中直接使用ognl表达式,将值存储的值栈中,是不能通过跳转将值传到jsp页 ...

  10. WebApi是轻量级的,WCF是重量级的,可以Api调用WCF,更灵活

    WCF.WebAPI.WCFREST.WebService之间的区别 注明:转载 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在 ...