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. idea 打包java程序

    创建maven项目 在pom.xml中添加: <build> <plugins> <plugin> <groupId>org.apache.maven. ...

  2. Swagger与SpringMVC整合

    依赖管理   在整合之前,需要把所有使用到的依赖包全部引入.网上很多文章只是简单告诉读者引入swagger-springmvc-1.0.2.jar包,但是随后你发现这远远不够,还需要很多包,如下所示: ...

  3. Docker Dockerfile 定制镜像(转)

    转自: https://yeasy.gitbooks.io/docker_practice/ 及 https://blog.csdn.net/wo18237095579/article/details ...

  4. 第八章 高级搜索树 (b4)B-树: 插入

  5. 1.Two Sum (Array; HashTable)

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  6. 清明梦超能力者黄YY(idx数组)

    清明梦超能力者黄YY https://www.nowcoder.com/acm/contest/206/I 题目描述 黄YY是一个清明梦超能力者,同时也是一个记忆大师.他能够轻松控制自己在梦中的一切, ...

  7. Robotium原理初步--Android自动化测试学习历程

    章节:自动化基础篇——Robotium原理初步(第四讲) 主要讲解内容与笔记: 一.基于控件 1.spinner——下拉菜单 2.TabHost——左右滑动选择菜单,类似电话本 3.Gallery—— ...

  8. popupMenu-----弹出菜单

    import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android ...

  9. Spring的2.5版本中提供了一种:p名称空间的注入(了解)

    1. 步骤一:需要先引入 p 名称空间 * 在schema的名称空间中加入该行:xmlns:p="http://www.springframework.org/schema/p"( ...

  10. PAT 1062 最简分数(20)(代码+思路)

    1062 最简分数(20 分) 一个分数一般写成两个整数相除的形式:N/M,其中 M 不为0.最简分数是指分子和分母没有公约数的分数表示形式. 现给定两个不相等的正分数 N​1​​/M​1​​ 和 N ...