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. js json转对象

    使用eval() 读取 for (var i=0;i< response.length; i++) { //alert(response[i].username) html=html+" ...

  2. Zookeeper 注册中心

    一.Zookeeper的介绍 Zookeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用 ...

  3. 可能空字符串转换为浮点型或者整数型:java.lang.NumberFormatException: For input string: " "

    Integer.valueOf(str.equals("")?"0":str)

  4. xpath定位--绝对与相对的定位

    xpath定位--绝对与相对的定位: xpath定位即为xml路径语言,它是一种用来确定xml文档中某部分位置的语言,xpath基于xml的树状结构,提供在数据结构中找寻节点的能力 xpath的相对定 ...

  5. Appium学习路-安装篇

    比较好的文章:http://www.15yan.com/story/4GbuTwXQKDU/ 官网资料:http://appium.io/slate/cn/v1.2.0/?python#appium ...

  6. webpack 构建同时适用于手机和电脑的调试服务器

    plugins plugins: [ new HtmlWebpackPlugin({ // 使用模板同时生成 pc.html和mobile.html title: 'pc', filename: 'p ...

  7. JAVA——遍历

    关于遍历,发现了个坑. 详见如下: package com.fxl.test; import java.util.ArrayList; import java.util.Iterator; impor ...

  8. input限制数字输入

    onkeyup="this.value=this.value.replace(/\D/g,'')"

  9. 第六章 图(a)概述

  10. [leetcode]163. Missing Ranges缺失范围

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, up ...