• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphi2010动态链接库DLL断点调试

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

           马根峰 

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

 

 

摘要:本文详细介绍了Delphi 2010中的动态链接库DLL断点调试技术

关键词DELPHI 2010Dll断点调试;

 

 

 

1      Delphi几个经典版本简介 

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

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.02007 2010在界面上乃至功能上的一些变化,所以在动态链接库DLL断点调试上,有较大的变化。在今后几天的时间中,笔者会以三篇文章来分别详细地介绍Delphi 7.02007 2010这三个版本中的DLL断点调试技术。

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

 

 

 

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

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

点击菜单Run-->Parameters.打开Run Parameters窗口,如图1所示。 

      图1 点击菜单Run-->Parameters.打开Run Parameters窗口

 

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

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

 

点击Project-->Options..,在Project Options窗口中,在Delphi Compiler—Compiling属性页中将Debug information设置为True,如图3所示: 

      3 Delphi Compiler—Compiling属性页中将Debug information设置为True

 

点击Project-->Options..,在Project Options窗口中,在Delphi Compiler—Linking属性页中将Debug informationInclude remote debug symbols两项设置为True,如图4所示:  
       
4 Debug informationInclude remote debug symbols两项设置为True

 

运行宿主程序Delphi2007_Dll_Debug.exe,断点还是无效,如图5所示:
 

      5 运行宿主程序Delphi2007_Dll_Debug.exe,发现断点还是无效

 

切换到DelphiDLL工程文件上,点击ctrl+alt+M,跳出一个名叫Modules的窗体来。左上角显示了宿主程序本身及其它所调用的资源。

找到动态链接库 Magenf_Detail.dll项,发现目录没有指向当前DLL所在的目录。点击鼠标右键,选中菜单项“Reload Symbol Table…”如图6所示:
 
 

      6 打开Modules属性页,找到Magenf_Detail.dll项,点击鼠标右键,Reload Symbol Table…

 

重新设置动态链接库Magenf_Detail.dll的位置,选中当前DLL工程Magenf_Detail所在目录的动态链接库Magenf_Detail.dll文件,如图7所示:
 
 

      7 打开Modules属性页,找到Magenf_Detail.dll项,点击鼠标右键,Reload Symbol Table…,重新设置它的位置

 

然后切换到Delphi的属性页Magenf_Detail,发现断点生效,如图8所示:
 

      8 点击属性页Magenf_Detail,发现断点生效

 

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

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

 

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



      
10 进入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(&apos;Fatal error! Function not be found!&apos;,mtWarning, [mbYes], 0) ;

         end

         else

             messagedlg(&apos;Fatal error! Magenf_Detail.dll not be found!&apos;,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程序代码-----


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB安装后出现“License Manager Error -8?”,如何解决?发布时间:2022-07-18
下一篇:
bp神经网络及matlab实现发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap