1 / 9

Implicit Linking 與 Explicit Linking

Implicit Linking 與 Explicit Linking. 4.17 王俊富. Implicit Linking( 隱式聯結 ).

Télécharger la présentation

Implicit Linking 與 Explicit Linking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Implicit Linking與Explicit Linking 4.17 王俊富

  2. Implicit Linking(隱式聯結) • Implicitly Link(隱式聯結)又稱靜態載入,所謂靜態載入是指程式在聯結時期即與DLLs所對應的import libraries做靜態鏈結,於是可執行檔中便對所有的DLL函式都有一份重定位表格(relocation table)和待修正記錄(fixup record)。當程式被Windows 載入器載入記憶體中,載入器會自動修正所有的fixup records,而這個fixup records 就是記錄由DLL中所有輸出資源的正確位址,經過這樣的程序動態聯結便順利產生。也就是說,程式開始執行時,會用靜態載入方式所使用的DLLs都載入到行程的記憶體裡。

  3. 靜態載入方式的優點 • 1、靜態載入方式所使用到的這個DLL會在應用程式執行時載入,然後就可以呼叫出所有由DLL中匯出的函式,就好像是包含在程式中一般。 • 2、動作較為簡單,載入的方法由編譯器負責處理,不須動腦筋。

  4. 靜態載入方式的缺點 • 1、當這個程式靜態載入方式所使用到的這個DLL不存在時,這個程式在開始時就出現無法找到DLL的訊息而導致應用程式無法執行。 • 2、編譯時需要加入額外的import library。 • 3、若是要載入的DLLs一多,載入應用程式的速度會變慢。 • 4、若遇到不同品牌的C++編譯器時,靜態載入可就沒這麼簡單處理了,因為當函式經過Calling Conventions的處理後,若要使用其他品牌編譯器所製造出的DLL須得大動干戈才行。

  5. Explicit Linking • 所謂Explicitly link(顯式聯結)又稱動態載入,使用 DLL 的可執行檔必須製作動態載入和卸載 DLL 的函式呼叫 (Function Call),並且存取 DLL 的匯出函式。用戶端可執行檔必須經由函式指標呼叫匯出函式。 • 可執行檔可以使用具任何一種連結方式的相同 DLL。再者,這些機制之間並不會互相排斥,因此當一個可執行檔隱式地連結至 DLL 時,另一個可執行檔可以顯式地連結至它。

  6. 動態載入方式的優缺點 • 1、DLL只有需要時才會載入到記憶體中,可以更有效的使用記憶體。 • 2、應用程式載入的速度較使用隱式鏈結時快,因為當程式開始載入時並不需要把DLL給載入到行程中。 • 3、編譯時不須額外的import library檔。 • 4、讓我們可以更清楚DLL的載入流程。 • 缺點就是必須寫多一點程式碼。

  7. 動態載入基本流程 • 必須使用LoadLibrary這個Windows API來手動載入DLL,並使用GetProcessAddress 來取得所要使用的函式的函式指標,最後不需要用到此DLL時使用FreeLibrary將DLL 釋放。所以,在學會動態載入DLL時,必須先知道函式指標的用法。

  8. 動態載入範例 • http://www2.borland.com.tw/tw/td001018.html

  9. 參考資料 • 探訪動態連結函式庫 http://www2.borland.com.tw/tw/td001018.html • dll小小紀錄 http://kevin.iecs.us/2006/11/08/ • DLL應用 http://sun.cis.scu.edu.tw/~nms9115/articles/delphi/PluginDLL/PluginDLL.htm • 使用DLL的優點 http://msdn2.microsoft.com/zh-tw/library/dtba4t8b(VS.80).aspx

More Related