DELPHI 7 动态链接库DLL断点调试
?DELPHI 7 動(dòng)態(tài)鏈接庫(kù)DLL斷點(diǎn)調(diào)試
???????? ?馬根峰
???????? ?(廣東聯(lián)合電子服務(wù)股份有限公司, 廣州 510300)
?
作者博客:
CSDN博客:http://blog.csdn.net/magenfeng
新浪博客:?http://blog.sina.com.cn/magenfeng
QQ空間:?http://user.qzone.qq.com/630414817
?
?
?
?
1??Delphi幾個(gè)經(jīng)典版本簡(jiǎn)介?
?
Delphi從1995年的 1.0版本,發(fā)展到現(xiàn)在的最新的XE3版本,歷經(jīng)N多版本,但最為經(jīng)典的幾個(gè)版本個(gè)人覺得應(yīng)屬 7.0、2007和 2010。
?????? Delphi 7.0應(yīng)該是Delphi用戶最多的版本。
?
Delphi 2007是功能就不多說了,歸根結(jié)底一句話,它是 AnsiString的最后一個(gè)版本,在Delphi 2007中,string類型映射為AnsiString ,char類型映射為AnsiChar,Pchar類型映射為PAnsiChar。所以DELPHI低版本的程序可以較輕松地遷移到DELPHI 2007版本。Delphi 2007也是Delphi程序員很容易上手的晚期版本。
?
從Delphi2009開始起,到現(xiàn)在的Delphi XE3為止,都是 unicode版本。String類型映射為 UnicodeString而不是 AnsiString,Char類型映射為 WideChar,PChar類型映射為 PWideChar。
由于Delphi 7.0、2007和 2010在界面上乃至功能上的一些變化,所以在動(dòng)態(tài)鏈接庫(kù)DLL斷點(diǎn)調(diào)試上,有較大的變化。在今后幾天的時(shí)間中,筆者會(huì)以三篇文章來分別詳細(xì)地介紹Delphi 7、2007和 2010這三個(gè)版本中的DLL斷點(diǎn)調(diào)試技術(shù)。
?????? 本篇文章來詳細(xì)地介紹 Delphi 7中的動(dòng)態(tài)鏈接庫(kù)DLL斷點(diǎn)調(diào)試技術(shù)。
?
?
?
?
2????DELPHI 7的DLL斷點(diǎn)設(shè)置與DLL調(diào)試
?
在DELPHI 7.0以及以前的版本中,動(dòng)態(tài)鏈接庫(kù)的調(diào)試方法如下:
?
點(diǎn)擊菜單Run-->Parameters.打開Run Parameters窗口,如圖1所示。
?
圖1?點(diǎn)擊菜單Run-->Parameters.打開Run Parameters窗口
?
?
在Run Parameters窗口中,在Host Application中填入宿主程序的完整路徑然后選擇,如圖2所示。
??
圖2?在Run Parameters窗口中,點(diǎn)擊Browse選中宿主程序G:\Delphi_Dll_Debug\70\Magenf_Master\Delphi2007_Dll_Debug.exe
?
?
設(shè)置斷點(diǎn)后,輸入F9或者點(diǎn)擊Run-->Run來運(yùn)行宿主程序Delphi2007_Dll_Debug.exe,如圖3所示
?
?
???圖3?設(shè)置斷點(diǎn)后,輸入F9或者點(diǎn)擊Run-->Run來運(yùn)行宿主程序Delphi2007_Dll_Debug.exe
?
?
在主程序Delphi2007_Dll_Debug.exe窗口對(duì)應(yīng)的文本框中,輸入 1和2后,然后點(diǎn)擊按鈕“=”,即進(jìn)入DLL的斷點(diǎn)調(diào)試,如圖4所示。
?
??????????????????? 圖4?進(jìn)入DLL的斷點(diǎn)調(diào)試
?
?
?
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程序代碼-----
?
轉(zhuǎn)載于:https://www.cnblogs.com/wuyida/archive/2013/02/26/6300782.html
總結(jié)
以上是生活随笔為你收集整理的DELPHI 7 动态链接库DLL断点调试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 文件大小ll和du不一致问题
- 下一篇: NSDate与NSDateFormatt