DLL_full.zip

  • Rahul4455
    了解作者
  • Delphi
    开发工具
  • 19KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2020-06-13 21:53
    上传日期
DLL about how to create dll
DLL_full.zip
  • DLL_full.doc
    73.5KB
内容介绍
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta name="generator" content="pdf2htmlEX"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css"> <link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css"> <link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/6268cfa04f8811599e1890df/raw.css"> <script src="https://static.pudn.com/base/js/compatibility.min.js"></script> <script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script> <script> try{ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({}); }catch(e){} </script> <title></title> </head> <body> <div id="sidebar" style="display: none"> <div id="outline"> </div> </div> <div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/6268cfa04f8811599e1890df/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">DLL<span class="fs1">(Dynamic Link Library)</span></div><div class="t m0 x2 h4 y3 ff2 fs1 fc0 sc0 ls0 ws0">A <span class="fc1">DLL</span> or a dynamic link library acts as a shared library of function, that can be<span class="_ _0"></span> called by</div><div class="t m0 x2 h4 y4 ff2 fs1 fc0 sc0 ls0 ws0">applications and by other DLLs.</div><div class="t m0 x2 h4 y5 ff2 fs1 fc0 sc0 ls0 ws0">When you want to call a function exported by a DLL, one question comes up: <span class="_ _0"></span><span class="ff1">should </span></div><div class="t m0 x2 h5 y6 ff1 fs1 fc0 sc0 ls0 ws0">you use static or dynamic DLL loading?</div><div class="t m0 x2 h4 y7 ff2 fs1 fc0 sc0 ls0 ws0">Before you can call routines defined in DLL, you must import them.</div><div class="t m0 x2 h4 y8 ff2 fs1 fc0 sc0 ls0 ws0">Functions exported from a DLL can be imported in two ways: by declaring an external<span class="_ _0"></span> </div><div class="t m0 x2 h4 y9 ff2 fs1 fc0 sc0 ls0 ws0">procedure or function (static), or by direct calls to DLL specific API functions (dynamic).</div><div class="t m0 x2 h5 ya ff1 fs1 fc0 sc0 ls0 ws0">Loading DLLs</div><div class="t m0 x2 h4 yb ff2 fs1 fc0 sc0 ls0 ws0">Before you use a function or procedure in a DLL, you first have to load the DLL into </div><div class="t m0 x2 h4 yc ff2 fs1 fc0 sc0 ls0 ws0">memory. Loading DLLs at runtime can be accomplished in two ways, as follows:</div><div class="t m0 x3 h4 yd ff3 fs2 fc0 sc0 ls0 ws0">&#61623;<span class="_ _1"> </span><span class="ff2 fs1">Static loading </span></div><div class="t m0 x3 h4 ye ff3 fs2 fc0 sc0 ls0 ws0">&#61623;<span class="_ _1"> </span><span class="ff2 fs1">Dynamic loading </span></div><div class="t m0 x2 h4 yf ff2 fs1 fc0 sc0 ls0 ws0">Both methods have their advantages and disadvantages. I'll explain the differences<span class="_ _0"></span> </div><div class="t m0 x2 h4 y10 ff2 fs1 fc0 sc0 ls0 ws0">between static loading and dynamic loading next.</div><div class="t m0 x2 h5 y11 ff1 fs1 fc0 sc0 ls0 ws0">Static Loading<span class="_ _2"></span> <span class="_ _3"> </span> </div><div class="t m0 x2 h4 y12 ff4 fs1 fc0 sc0 ls0 ws0">Static loading<span class="ff2"> means that your DLL is automatically loaded w<span class="_ _0"></span>hen the application that </span></div><div class="t m0 x2 h4 y13 ff2 fs1 fc0 sc0 ls0 ws0">calls the DLL is executed. To use static loading, you declare a function or procedure<span class="_ _0"></span> that </div><div class="t m0 x2 h4 y14 ff2 fs1 fc0 sc0 ls0 ws0">resides in the DLL with the external keyword (more on that in the section "Calling Using </div><div class="t m0 x2 h4 y15 ff2 fs1 fc0 sc0 ls0 ws0">Static Loading"). The DLL is automatically loaded when the application<span class="_ _0"></span> loads, and you </div><div class="t m0 x2 h4 y16 ff2 fs1 fc0 sc0 ls0 ws0">call any functions or procedures exported from the DLL just as you would any other </div><div class="t m0 x2 h4 y17 ff2 fs1 fc0 sc0 ls0 ws0">function or procedure. This is by far the easiest way to use code contained in a<span class="_ _0"></span> DLL. The </div><div class="t m0 x2 h4 y18 ff2 fs1 fc0 sc0 ls0 ws0">disadvantage to this approach is that if a DLL that the program references<span class="_ _0"></span> is missing, the </div><div class="t m0 x2 h4 y19 ff2 fs1 fc0 sc0 ls0 ws0">program will refuse to load.</div><div class="t m0 x2 h5 y1a ff1 fs1 fc0 sc0 ls0 ws0">Dynamic Loading<span class="_ _4"></span> <span class="_ _5"> </span> </div><div class="t m0 x2 h4 y1b ff4 fs1 fc0 sc0 ls0 ws0">Dynamic loading<span class="ff2"> means that you specifically load the D<span class="_ _0"></span>LL when needed and unload it </span></div><div class="t m0 x2 h4 y1c ff2 fs1 fc0 sc0 ls0 ws0">when you are done with it. This type of DLL loading has its advantages and </div><div class="t m0 x2 h4 y1d ff2 fs1 fc0 sc0 ls0 ws0">disadvantages, too. One advantage is that the DLL is in memory only as long as you need</div><div class="t m0 x2 h4 y1e ff2 fs1 fc0 sc0 ls0 ws0">it, so you are making more efficient use of memory. Another advantage is that your </div><div class="t m0 x2 h4 y1f ff2 fs1 fc0 sc0 ls0 ws0">application will load more quickly when using dynamic loading because not all the<span class="_ _0"></span> code </div><div class="t m0 x2 h4 y20 ff2 fs1 fc0 sc0 ls0 ws0">needed to run the program is loaded when the application initially loads.</div><div class="t m0 x2 h4 y21 ff2 fs1 fc0 sc0 ls0 ws0">The primary disadvantage to using the dynamic loading approach is that it is a bit more </div><div class="t m0 x2 h4 y22 ff2 fs1 fc0 sc0 ls0 ws0">work for you. First, you need to load the DLL with the Windows API function </div><div class="t m0 x2 h4 y23 ff2 fs1 fc0 sc0 ls0 ws0">LoadLibrary. Then, when you are done with the DLL, you unload it with FreeLibrary. </div><div class="t m0 x2 h4 y24 ff2 fs1 fc0 sc0 ls0 ws0">Further (and this is where the work comes in), you need to use the GetProcAddress </div><div class="t m0 x2 h4 y25 ff2 fs1 fc0 sc0 ls0 ws0">function to obtain a pointer to the function or procedure you want to call. To say that this </div><div class="t m0 x2 h4 y26 ff2 fs1 fc0 sc0 ls0 ws0">approach can be a tad confusing would be an understatement. The following s<span class="_ _0"></span>ection </div><div class="t m0 x2 h4 y27 ff2 fs1 fc0 sc0 ls0 ws0">describes how to call procedures and functions in DLLs using both static and dynamic </div><div class="t m0 x2 h4 y28 ff2 fs1 fc0 sc0 ls0 ws0">loading.</div></div><a class="l" rel='nofollow' onclick='return false;'><div class="d m1"></div></a></div><div class="pi" data-data='{"ctm":[1.568627,0.000000,0.000000,1.568627,0.000000,0.000000]}'></div></div> </body> </html>
评论
    相关推荐