DELPHI 2007 动态链接库DLL断点调试

 

  DELPHI 2007动态链接库DLL断点调试         

                          马根峰

( 广东联合电子服务股份有限公司, 广州510300) 

作者博客:

CSDN博客:http://blog.csdn.net/magenfeng

新浪博客: http://blog.sina.com.cn/magenfeng

QQ空间: http://user.qzone.qq.com/630414817

  

1      Delphi几个经典版本简介  

          Delphi1995年的1.0版本,发展到现在的最新的XE3版本,历经N多版本,但最为经典的几个版本个人觉得应属7.020072010 

Delphi 7.0应该是Delphi用户最多的版本。 

Delphi 2007是功能就不多说了,归根结底一句话,它是AnsiString的最后一个版本,在Delphi 2007中,string类型映射为AnsiStringchar类型映射为AnsiCharPchar类型映射为PAnsiChar。所以DELPHI低版本的程序可以较轻松地迁移到DELPHI 2007版本。Delphi 2007也是Delphi程序员很容易上手的晚期版本。

Delphi2009开始起,到现在的Delphi XE3为止,都是unicode版本。String类型映射为UnicodeString而不是AnsiStringChar类型映射为WideCharPChar类型映射为PWideChar

由于Delphi 7.020072010在界面上乃至功能上的一些变化,所以在动态链接库DLL断点调试上,有较大的变化。在今后几天的时间中,笔者会以三篇文章来分别详细地介绍Delphi 7.020072010这三个版本中的DLL断点调试技术。 

本篇文章来详细地介绍Delphi 2007中的动态链接库DLL断点调试技术。

 

2        DELPHI 2007 DLL断点设置与DLL调试

      DELPHI 7.0以及以前的版本中,动态链接库的调试方法如下:

点击菜单Run-->Parameters.打开Run Parameters窗口,在Host application中选中宿主程序,如图1所示。
 
 

        打开Run Parameters窗口,在Host application中选中宿主程序

 

设置图中断点,然后点击F9或者Run—Run来运行宿主程序Delphi2007_Dll_Debug.exe,但发现断点无效,如图2所示:

 
           设置断点后,运行宿主程序Delphi2007_Dll_Debug.exe,断点无效

 

点击Project-->Options..,在Project Options窗口中,点击Compiler,选中Debug information,如图3所示:


  Project Options窗口中,点击Compiler,选中Debug information 

点击Project-->Options..,在Project Options窗口中,点击Linker可以看到Include TD32 debug InfoInclude remote debug symbols两项为非选中状态,如图4所示:  

       Include TD32 debug InfoInclude remote debug symbols两项为非选中状态。

 

选中Include TD32 debug InfoInclude remote debug symbols,如图5所示:
  

选中Include TD32 debug InfoInclude remote debug symbols
 

然后点击F9或者Run—Run来运行宿主程序Delphi2007_Dll_Debug.exe,但发现断点生效,如图6所示:
  

      图运行宿主程序,发现断点生效

 

Delphi2007_Dll_Debug.exe,输入12后点击铵钮“=”,如图7所示:

  
Delphi2007_Dll_Debug.exe,输入12后点击铵钮“=

 

进入DLL断点调试,如图8所示:
  

    图进入DLL的断点调试

    

3        例子中的宿主程序及DLL程序代码

-------宿主程序代码-----

unit UDllDebug;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, Buttons,  Contnrs ,   ActiveX, StrUtils ;

 

type

 

  

 

    

  TDll_Add=function(int_1,int_2:integer):integer;stdcall;

  TfrmDllDebug = class(TForm)

    Edit1: TEdit;

    Edit2: TEdit;

    Label1: TLabel;

    Edit3: TEdit;

    BtnAdd: TButton;

    procedure FormCreate(Sender: TObject);

    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure BtnAddClick(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

 

    HInst:Thandle;                                    

    FDll_Add:TFarProc;

    functionDll_Add:TDll_Add;

 

    //aForeThread:MuliThread;

  end;

 

var

  frmDllDebug: TfrmDllDebug;

 

implementation

 

{$R *.dfm}

 

 

 

               

  

procedure TfrmDllDebug.FormCreate(Sender: TObject);

begin

       hinst:=loadlibrary('Magenf_Detail.dll'); 

       if hinst>0 then

       begin

              FDll_Add:=getprocaddress(hinst,pchar('Dll_Add'));

 

              if FDll_Add<>nil then

                 functionDll_Add:=TDll_Add(FDll_Add)

              else

                 messagedlg('Fatal error! Function not be found!',mtWarning, [mbYes], 0) ;

         end

         else

              messagedlg('Fatal error!  Magenf_Detail.dll not be found!',mtWarning, [mbYes], 0) ;

 

end;

 

procedure TfrmDllDebug.FormClose(Sender: TObject;

  var Action: TCloseAction);

begin

    try

        freelibrary(hinst);

    except

    end;

 

end;

        

 

 

 

 

procedure TfrmDllDebug.BtnAddClick(Sender: TObject);

var

    int1,int2,int_return:integer;

begin

 

    int1:=strToInt(edit1.Text);

    int2:=strToInt(edit2.Text);

    int_return:=functionDll_Add(int1,int2);

    edit3.Text :=intToStr(int_return);

 

end;

 

end.

-------宿主程序代码-----

 

--------------DLL程序代码------------

library Magenf_Detail;

 

uses

  SysUtils,Classes;

 

{$R *.RES}

 

 

function    Dll_Add(int_1,int_2:integer):integer;stdcall;

var

     intSum:integer;

begin

    intSum:=int_1+int_2;

    result:=intSum;

end;

 

 

exports

    Dll_Add;

 

end.

 

--------------DLL程序代码------------

 

 

 

备注:

Delphi 2007中调试动态链接库DLL的时候,在宿主程序所在目录中,如果含有要调试的动态链接库DLL生成文件(扩展名为dll),为避免引起不必要的麻烦,请将其删除,然后再进行以上的调试过程。

 

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值