DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試.doc_第1頁
DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試.doc_第2頁
DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試.doc_第3頁
DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試.doc_第4頁
DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試.doc_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

DELPHI 2010 動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試馬根峰 ( 廣東聯(lián)合電子服務(wù)股份有限公司, 廣州 510300)摘要:本文詳細(xì)介紹了Delphi 2010中的動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試技術(shù)關(guān)鍵詞: DELPHI 2010;Dll斷點(diǎn)調(diào)試;1 Delphi 幾個(gè)經(jīng)典版本簡介 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)鏈接庫DLL斷點(diǎn)調(diào)試上,有較大的變化。在今后幾天的時(shí)間中,筆者會(huì)以三篇文章來分別詳細(xì)地介紹Delphi 7.0、2007和 2010這三個(gè)版本中的DLL斷點(diǎn)調(diào)試技術(shù)。本篇文章來詳細(xì)地介紹 Delphi 2010中的動(dòng)態(tài)鏈接庫DLL斷點(diǎn)調(diào)試技術(shù)。2 DELPHI 2010的DLL斷點(diǎn)設(shè)置與DLL調(diào)試在DELPHI 7.0以及以前的版本中,動(dòng)態(tài)鏈接庫的調(diào)試方法如下:點(diǎn)擊菜單Run-Parameters.打開Run Parameters窗口,如圖1所示。 圖1 點(diǎn)擊菜單Run-Parameters.打開Run Parameters窗口設(shè)置圖中斷點(diǎn),然后點(diǎn)擊F9或者RunRun來運(yùn)行宿主程序Delphi2007_Dll_Debug.exe,但發(fā)現(xiàn)斷點(diǎn)無效,如圖2所示:圖2 設(shè)置斷點(diǎn)后,運(yùn)行宿主程序 Delphi2007_Dll_Debug.exe,斷點(diǎn)無效 點(diǎn)擊Project-Options.,在Project Options窗口中,在Delphi CompilerCompiling屬性頁中將Debug information設(shè)置為True,如圖3所示:圖3 在Delphi CompilerCompiling屬性頁中將Debug information設(shè)置為True點(diǎn)擊Project-Options.,在Project Options窗口中,在Delphi CompilerLinking屬性頁中將Debug information和Include remote debug symbols兩項(xiàng)設(shè)置為True,如圖4所示:圖4 將Debug information和Include remote debug symbols兩項(xiàng)設(shè)置為True運(yùn)行宿主程序Delphi2007_Dll_Debug.exe,斷點(diǎn)還是無效,如圖5所示:圖5 運(yùn)行宿主程序 Delphi2007_Dll_Debug.exe,發(fā)現(xiàn)斷點(diǎn)還是無效切換到Delphi的DLL工程文件上,點(diǎn)擊ctrl+alt+M,跳出一個(gè)名叫Modules的窗體來。左上角顯示了宿主程序本身及其它所調(diào)用的資源。找到動(dòng)態(tài)鏈接庫 Magenf_Detail.dll項(xiàng),發(fā)現(xiàn)目錄沒有指向當(dāng)前DLL所在的目錄。點(diǎn)擊鼠標(biāo)右鍵,選中菜單項(xiàng)“Reload Symbol Table”如圖6所示:圖6 打開Modules屬性頁,找到Magenf_Detail.dll項(xiàng),點(diǎn)擊鼠標(biāo)右鍵,Reload Symbol Table重新設(shè)置動(dòng)態(tài)鏈接庫Magenf_Detail.dll 的位置,選中當(dāng)前DLL工程Magenf_Detail所在目錄的動(dòng)態(tài)鏈接庫Magenf_Detail.dll文件,如圖7所示:圖7 打開Modules屬性頁,找到Magenf_Detail.dll項(xiàng),點(diǎn)擊鼠標(biāo)右鍵,Reload Symbol Table,重新設(shè)置它的位置 然后切換到Delphi的屬性頁Magenf_Detail,發(fā)現(xiàn)斷點(diǎn)生效,如圖8所示:圖8 點(diǎn)擊屬性頁Magenf_Detail,發(fā)現(xiàn)斷點(diǎn)生效在Delphi2007_Dll_Debug.exe,輸入 1和2 后點(diǎn)擊銨鈕“=”,如圖9所示:圖9 在Delphi2007_Dll_Debug.exe,輸入 1和2 后點(diǎn)擊銨鈕“=” 進(jìn)入DLL斷點(diǎn)調(diào)試,如圖10所示:圖10 進(jìn)入DLL的斷點(diǎn)調(diào)試3 例子中的宿主程序及DLL程序代碼-宿主程序代碼-unit UDllDebug;interfaceuses 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 hinst0 then begin FDll_Add:=getprocaddress(hinst,pchar(Dll_Add); if FDll_Addnil 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 librarys USES clause AND your projects (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 *.RESfunction Dll_Add(int_1,int_2:integer):integer;stdcall;var intS

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論