资源描述:
《怎么在DLL使用类》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、IntroductionIhaveseenquitealotofcodeexplaininghowtouseclassesexportedfromaDLLinanapplication.However,allthesedescribetheusageoftheexportedclassesbylinkingimplicitlytotheDLL.RefreshingourDLLconcepts,therearetwowaysforanapplicationtouseafunctionwritteninaDLL.Thefirstwayistohaveyourapplication'ssour
2、cecodesimplyreferencesymbolscontainedintheDLL.Thiscausestheloadertoimplicitlyload(andlink)therequiredDLLwhentheapplicationisinvoked.Thisisknownasimplicitlinking.ThesecondwayisfortheapplicationtoexplicitlyloadtherequiredDLL(usingaLoadLibrary()call)andexplicitlylinktothedesiredexportedsymbolwhileth
3、eapplicationisrunning.Inotherwords,iftheapplicationdecidesthatitwantstocallafunctioninaDLL,itcanexplicitlyloadtheDLLintotheprocess'addressspace,getthevirtualmemoryaddressofthefunctioncontainedwithintheDLL,andthencallthefunctionusingthismemoryaddress.Thebeautyofthistechniqueisthateverythingisdonew
4、hiletheapplicationisrunningandtheapplicationcanunloadtheDLLfromitsprocessaddressspacewhenithasfinisheditsworkwiththeDLL.Asyoumighthaveguessed,thistechniqueisknownasexplicitlinking.BackgroundSofar,Ispokeofusingfunctions,buthey,whataboutusingclassesexportedfromaDLL?Well,inthecaseofimplicitlylinkedD
5、LLs,thereisnodifferenceatall.ButwhataboutloadingDLLsexplicitlyandusingtheexportedclasses?Well,undernormalcircumstances,itcannotbedone,butIwrotethisarticlenottoexplaintoyouwhyitcannotbedone,buttogiveyouanideaastohowyoucandoit.That'sright!!UsingexportedclassesbyloadingaDLLusingaLoadLibrary()call.Bu
6、tbeforeproceedingfurther,Iwarnyouthatthemethodgivenbelowissortofahack,andifforanyreasonyouplantouseitinyourproject,pleasetakethepriorapprovalofyourboss...(ifbyanychanceyoudomanagetogethis/herapprovalonthistechnique!!).However,thiscolumnisbasicallyforyourunderstandingandalsoforextremecaseswhenyouj
7、ustcantdowithoutthishack.UsingthecodeIfyoulookatthesamplecode,youcanseethatIhavecreatedaCalculatorDLLcalledCalc.DLLandIamusingthecalculatingpowerspresentintheDLLinmyconsoleapplicationcalledUserOfCalc(Icouldn'tthinkofab