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幾個經典版本簡介?
?
Delphi從1995年的 1.0版本,發展到現在的最新的XE3版本,歷經N多版本,但最為經典的幾個版本個人覺得應屬 7.0、2007和 2010。
?????? Delphi 7.0應該是Delphi用戶最多的版本。
?
Delphi 2007是功能就不多說了,歸根結底一句話,它是 AnsiString的最后一個版本,在Delphi 2007中,string類型映射為AnsiString ,char類型映射為AnsiChar,Pchar類型映射為PAnsiChar。所以DELPHI低版本的程序可以較輕松地遷移到DELPHI 2007版本。Delphi 2007也是Delphi程序員很容易上手的晚期版本。
?
從Delphi2009開始起,到現在的Delphi XE3為止,都是 unicode版本。String類型映射為 UnicodeString而不是 AnsiString,Char類型映射為 WideChar,PChar類型映射為 PWideChar。
由于Delphi 7.0、2007和 2010在界面上乃至功能上的一些變化,所以在動態鏈接庫DLL斷點調試上,有較大的變化。在今后幾天的時間中,筆者會以三篇文章來分別詳細地介紹Delphi 7、2007和 2010這三個版本中的DLL斷點調試技術。
?????? 本篇文章來詳細地介紹 Delphi 7中的動態鏈接庫DLL斷點調試技術。
?
?
?
?
2????DELPHI 7的DLL斷點設置與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窗口對應的文本框中,輸入 1和2后,然后點擊按鈕“=”,即進入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程序代碼-----
?
轉載于:https://www.cnblogs.com/wuyida/archive/2013/02/26/6300782.html
總結
以上是生活随笔為你收集整理的DELPHI 7 动态链接库DLL断点调试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 文件大小ll和du不一致问题
- 下一篇: NSDate与NSDateFormatt