zoukankan      html  css  js  c++  java
  • DELPHI 7 动态链接库DLL断点调试


     DELPHI 7 动态链接库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.02007 2010


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

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

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

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

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

     

     

     


     

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

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

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

     

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

     

    Run Parameters窗口中,在Host Application中填入宿主程序的完整路径然后选择,如图2所示。

     
     

    2 Run Parameters窗口中,点击Browse选中宿主程序G:\Delphi_Dll_Debug\70\Magenf_Master\Delphi2007_Dll_Debug.exe

     
     

    设置断点后,输入F9或者点击Run-->Run来运行宿主程序Delphi2007_Dll_Debug.exe,如图3所示

     
     

       图3 设置断点后,输入F9或者点击Run-->Run来运行宿主程序Delphi2007_Dll_Debug.exe
     

     

    在主程序Delphi2007_Dll_Debug.exe窗口对应的文本框中,输入 12后,然后点击按钮“=”,即进入DLL的断点调试,如图4所示。


     


                        图
    4 进入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;

     

    { Important note about DLL memory management: ShareMem must be the

     first unit in your library's USES clause AND your project's (select

     Project-View Source) USES clause if your DLL exports any procedures or

     functions that pass strings as parameters or function results. This

     applies to all strings passed to and from your DLL--even those that

     are nested in records and classes. ShareMem is the interface unit to

     the BORLNDMM.DLL shared memory manager, which must be deployed along

     with your DLL. To avoid using BORLNDMM.DLL, pass string information

     using PChar or ShortString parameters. }

     

    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程序代码-----

     

     
     
     
     
  • 相关阅读:
    gulp-css-spriter 将css代码中的切片图片合并成雪碧图
    通过JS模拟select表单,达到美化效果[demo]
    jQuery拖拽 & 弹出层
    sublime text 快速编码技巧 GIT图
    原生JS不到30行,实现类似javascript MVC的功能-minTemplate
    javascript拖拽原理与简单实现方法[demo]
    滚动焦点图实现原理和实践[原创视频]
    谈一谈值类型与引用类型和装箱与拆箱
    【原创】asp.net内部原理(三) 第三个版本 (最详细的版本)
    由JS函数返回值引发的一场”血案"
  • 原文地址:https://www.cnblogs.com/wuyida/p/6300782.html
Copyright © 2011-2022 走看看