http://www.tutorialspoint.com/dll/dll_quick_guide.htm

browseui.dll  时间:2021-05-24  阅读:()
Copyrighttutorialspoint.
comDLL-QUICKGUIDEDLL-QUICKGUIDEDLL-INTRODUCTIONDLL-INTRODUCTIONDynamiclinkingisamechanismthatlinksapplicationstolibrariesatruntime.
Thelibrariesremainintheirownfilesandarenotcopiedintotheexecutablefilesoftheapplications.
DLLslinktoanapplicationwhentheapplicationisrun,ratherthanwhenitiscreated.
DLLsmaycontainlinkstootherDLLs.
Manytimes,DLLsareplacedinfileswithdifferentextensionssuchas.
EXE,.
DRVor.
DLL.
AdvantagesofDLLGivenbelowareafewadvantagesofhavingDLLfiles.
UsesfewerresourcesDLLfilesdon'tgetloadedintotheRAMtogetherwiththemainprogram;theydon'toccupyspaceunlessrequired.
WhenaDLLfileisneeded,itisloadedandrun.
Forexample,aslongasauserofMicrosoftWordiseditingadocument,theprinterDLLfileisnotrequiredinRAM.
Iftheuserdecidestoprintthedocument,thentheWordapplicationcausestheprinterDLLfiletobeloadedandrun.
PromotesmodulararchitectureADLLhelpspromotedevelopingmodularprograms.
Ithelpsyoudeveloplargeprogramsthatrequiremultiplelanguageversionsoraprogramthatrequiresmodulararchitecture.
Anexampleofamodularprogramisanaccountingprogramhavingmanymodulesthatcanbedynamicallyloadedatrun-time.
AideasydeploymentandinstallationWhenafunctionwithinaDLLneedsanupdateorafix,thedeploymentandinstallationoftheDLLdoesnotrequiretheprogramtoberelinkedwiththeDLL.
Additionally,ifmultipleprogramsusethesameDLL,thenallofthemgetbenefitedfromtheupdateorthefix.
Thisissuemayoccurmorefrequentlywhenyouuseathird-partyDLLthatisregularlyupdatedorfixed.
ApplicationsandDLLscanlinktootherDLLsautomatically,iftheDLLlinkageisspecifiedintheIMPORTSsectionofthemoduledefinitionfileasapartofthecompile.
Else,youcanexplicitlyloadthemusingtheWindowsLoadLibraryfunction.
ImportantDLLFilesCOMDLG32.
DLL-Controlsthedialogboxes.
GDI32.
DLL-Containsnumerousfunctionsfordrawinggraphics,displayingtext,andmanagingfonts.
KERNEL32.
DLL-Containshundredsoffunctionsforthemanagementofmemoryandvariousprocesses.
USER32.
DLL-Containsnumeroususerinterfacefunctions.
Involvedinthecreationofprogramwindowsandtheirinteractionswitheachother.
DLL-HOWTOWRITEDLL-HOWTOWRITEFirst,wewilldiscusstheissuesandtherequirementsthatyoushouldconsiderwhiledevelopingyourownDLLs.
TypesofDLLsWhenyouloadaDLLinanapplication,twomethodsoflinkingletyoucalltheexportedDLLfunctions.
Thetwomethodsoflinkingare:load-timedynamiclinking,andrun-timedynamiclinking.
Load-timedynamiclinkingInload-timedynamiclinking,anapplicationmakesexplicitcallstotheexportedDLLfunctionslikelocalfunctions.
Touseload-timedynamiclinking,provideaheader.
hfileandanimportlibrary.
libfile,whenyoucompileandlinktheapplication.
Whenyoudothis,thelinkerwillprovidethesystemwiththeinformationthatisrequiredtoloadtheDLLandresolvetheexportedDLLfunctionlocationsatloadtime.
RuntimedynamiclinkingInruntimedynamiclinking,anapplicationcallseithertheLoadLibraryfunctionortheLoadLibraryExfunctiontoloadtheDLLatruntime.
AftertheDLLissuccessfullyloaded,youusetheGetProcAddressfunction,toobtaintheaddressoftheexportedDLLfunctionthatyouwanttocall.
Whenyouuseruntimedynamiclinking,youdonotneedanimportlibraryfile.
Thefollowinglistdescribestheapplicationcriteriaforchoosingbetweenload-timedynamiclinkingandruntimedynamiclinking:Startupperformance:Iftheinitialstartupperformanceoftheapplicationisimportant,youshoulduserun-timedynamiclinking.
Easeofuse:Inload-timedynamiclinking,theexportedDLLfunctionsarelikelocalfunctions.
Ithelpsyoucallthesefunctionseasily.
Applicationlogic:Inruntimedynamiclinking,anapplicationcanbranchtoloaddifferentmodulesasrequired.
Thisisimportantwhenyoudevelopmultiple-languageversions.
TheDLLEntryPointWhenyoucreateaDLL,youcanoptionallyspecifyanentrypointfunction.
TheentrypointfunctioniscalledwhenprocessesorthreadsattachthemselvestotheDLLordetachthemselvesfromtheDLL.
YoucanusetheentrypointfunctiontoinitializeordestroydatastructuresasrequiredbytheDLL.
Additionally,iftheapplicationismultithreaded,youcanusethreadlocalstorageTLStoallocatememorythatisprivatetoeachthreadintheentrypointfunction.
ThefollowingcodeisanexampleoftheDLLentrypointfunction.
BOOLAPIENTRYDllMain(HANDLEhModule,//HandletoDLLmoduleDWORDul_reason_for_call,LPVOIDlpReserved)//Reserved{switch(ul_reason_for_call){caseDLL_PROCESS_ATTACHED://AprocessisloadingtheDLL.
break;caseDLL_THREAD_ATTACHED://Aprocessiscreatinganewthread.
break;caseDLL_THREAD_DETACH://Athreadexitsnormally.
break;caseDLL_PROCESS_DETACH://AprocessunloadstheDLL.
break;}returnTRUE;}WhentheentrypointfunctionreturnsaFALSEvalue,theapplicationwillnotstartifyouareusingload-timedynamiclinking.
Ifyouareusingruntimedynamiclinking,onlytheindividualDLLwillnotload.
TheentrypointfunctionshouldonlyperformsimpleinitializationtasksandshouldnotcallanyotherDLLloadingorterminationfunctions.
Forexample,intheentrypointfunction,youshouldnotdirectlyorindirectlycalltheLoadLibraryfunctionortheLoadLibraryExfunction.
Additionally,youshouldnotcalltheFreeLibraryfunctionwhentheprocessisterminating.
WARNING:Inmultithreadedapplications,makesurethataccesstotheDLLglobaldataissynchronizedthreadsafetoavoidpossibledatacorruption.
Todothis,useTLStoprovideuniquedataforeachthread.
ExportingDLLFunctionsToexportDLLfunctions,youcaneitheraddafunctionkeywordtotheexportedDLLfunctionsorcreateamoduledefinition.
deffilethatliststheexportedDLLfunctions.
Touseafunctionkeyword,youmustdeclareeachfunctionthatyouwanttoexportwiththefollowingkeyword:__declspec(dllexport)TouseexportedDLLfunctionsintheapplication,youmustdeclareeachfunctionthatyouwanttoimportwiththefollowingkeyword:__declspec(dllimport)Typically,youwoulduseoneheaderfilehavingdefinestatementandanifdefstatementtoseparatetheexportstatementandtheimportstatement.
YoucanalsouseamoduledefinitionfiletodeclareexportedDLLfunctions.
Whenyouuseamoduledefinitionfile,youdonothavetoaddthefunctionkeywordtotheexportedDLLfunctions.
Inthemoduledefinitionfile,youdeclaretheLIBRARYstatementandtheEXPORTSstatementfortheDLL.
Thefollowingcodeisanexampleofadefinitionfile.
//SampleDLL.
def//LIBRARY"sampleDLL"EXPORTSHelloWorldWriteaSampleDLLInMicrosoftVisualC++6.
0,youcancreateaDLLbyselectingeithertheWin32Dynamic-LinkLibraryprojecttypeortheMFCAppWizarddllprojecttype.
ThefollowingcodeisanexampleofaDLLthatwascreatedinVisualC++byusingtheWin32Dynamic-LinkLibraryprojecttype.
//SampleDLL.
cpp#include"stdafx.
h"#defineEXPORTING_DLL#include"sampleDLL.
h"BOOLAPIENTRYDllMain(HANDLEhModule,DWORDul_reason_for_call,LPVOIDlpReserved){returnTRUE;}voidHelloWorld(){MessageBox(NULL,TEXT("HelloWorld"),TEXT("InaDLL"),MB_OK);}//File:SampleDLL.
h//#ifndefINDLL_H#defineINDLL_H#ifdefEXPORTING_DLLextern__declspec(dllexport)voidHelloWorld();#elseextern__declspec(dllimport)voidHelloWorld();#endif#endifCallingaSampleDLLThefollowingcodeisanexampleofaWin32ApplicationprojectthatcallstheexportedDLLfunctionintheSampleDLLDLL.
//SampleApp.
cpp#include"stdafx.
h"#include"sampleDLL.
h"intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){HelloWorld();return0;}NOTE:Inload-timedynamiclinking,youmustlinktheSampleDLL.
libimportlibrarythatiscreatedwhenyoubuildtheSampleDLLproject.
Inruntimedynamiclinking,youusecodethatissimilartothefollowingcodetocalltheSampleDLL.
dllexportedDLLfunction.
.
.
.
typedefVOID(*DLLPROC)(LPTSTR);.
.
.
HINSTANCEhinstDLL;DLLPROCHelloWorld;BOOLfFreeDLL;hinstDLL=LoadLibrary("sampleDLL.
dll");if(hinstDLL!
=NULL){HelloWorld=(DLLPROC)GetProcAddress(hinstDLL,"HelloWorld");if(HelloWorld!
=NULL)(HelloWorld);fFreeDLL=FreeLibrary(hinstDLL);}.
.
.
WhenyoucompileandlinktheSampleDLLapplication,theWindowsoperatingsystemsearchesfortheSampleDLLDLLinthefollowinglocationsinthisorder:TheapplicationfolderThecurrentfolderTheWindowssystemfolder(TheGetSystemDirectoryfunctionreturnsthepathoftheWindowssystemfolder).
TheWindowsfolder(TheGetWindowsDirectoryfunctionreturnsthepathoftheWindowsfolder).
DLL-REGISTRATIONDLL-REGISTRATIONInordertouseaDLL,ithastoberegisteredbyhavingappropriatereferencesenteredintheRegistry.
ItsometimeshappensthataRegistryreferencegetscorruptedandthefunctionsoftheDLLcannotbeusedanymore.
TheDLLcanbere-registeredbyopeningStart-Runandenteringthefollowingcommand:regsvr32somefile.
dllThiscommandassumesthatsomefile.
dllisinadirectoryorfolderthatisinthePATH.
Otherwise,thefullpathfortheDLLmustbeused.
ADLLfilecanalsobeunregisteredbyusingtheswitch"/u"asshownbelow.
regsvr32/usomefile.
dllThiscanbeusedtotoggleaserviceonandoff.
DLL-TOOLSDLL-TOOLSSeveraltoolsareavailabletohelpyoutroubleshootDLLproblems.
Someofthemarediscussedbelow.
DependencyWalkerTheDependencyWalkertool(depends.
exe)canrecursivelyscanforallthedependentDLLsthatareusedbyaprogram.
WhenyouopenaprograminDependencyWalker,theDependencyWalkerperformsthefollowingchecks:ChecksformissingDLLs.
ChecksforprogramfilesorDLLsthatarenotvalid.
Checksthatimportfunctionsandexportfunctionsmatch.
Checksforcirculardependencyerrors.
Checksformodulesthatarenotvalidbecausethemodulesareforadifferentoperatingsystem.
ByusingDependencyWalker,youcandocumentalltheDLLsthataprogramuses.
ItmayhelppreventandcorrectDLLproblemsthatmayoccurinthefuture.
DependencyWalkerislocatedinthefollowingdirectorywhenyouinstallMicrosoftVisualStudio6.
0:drive\ProgramFiles\MicrosoftVisualStudio\Common\ToolsDLLUniversalProblemSolverTheDLLUniversalProblemSolverDUPStoolisusedtoaudit,compare,document,anddisplayDLLinformation.
ThefollowinglistdescribestheutilitiesthatmakeuptheDUPStool:Dlister.
exe-ThisutilityenumeratesalltheDLLsonthecomputerandlogstheinformationtoatextfileortoadatabasefile.
Dcomp.
exe-ThisutilitycomparestheDLLsthatarelistedintwotextfilesandproducesathirdtextfilethatcontainsthedifferences.
Dtxt2DB.
exe-ThisutilityloadsthetextfilesthatarecreatedbyusingtheDlister.
exeutilityandtheDcomp.
exeutilityintothedllHelldatabase.
DlgDtxt2DB.
exe-ThisutilityprovidesagraphicaluserinterfaceGUIversionoftheDtxt2DB.
exeutility.
DLL-TIPSDLL-TIPSKeepthefollowingtipsinmindwhilewritingaDLL:UsepropercallingconventionCorstdcall.
Beawareofthecorrectorderofargumentspassedtothefunction.
NEVERresizearraysorconcatenatestringsusingtheargumentspasseddirectlytoafunction.
Remember,theparametersyoupassareLabVIEWdata.
ChangingarrayorstringsizesmayresultinacrashbyoverwritingotherdatastoredinLabVIEWmemory.
YouMAYresizearraysorconcatenatestringsifyoupassaLabVIEWArrayHandleorLabVIEWStringHandleandareusingtheVisualC++compilerorSymanteccompilertocompileyourDLL.
Whilepassingstringstoafunction,selectthecorrecttypeofstringtopass.
CorPascalorLabVIEWstringHandle.
Pascalstringsarelimitedto255charactersinlength.
CstringsareNULLterminated.
IfyourDLLfunctionreturnsnumericdatainabinarystringformatforexample,viaGPIBortheserialport,itmayreturnNULLvaluesasapartofthedatastring.
Insuchcases,passingarraysofshort8bitintegersismostreliable.
Ifyouareworkingwitharraysorstringsofdata,ALWAYSpassabufferorarraythatislargeenoughtoholdanyresultsplacedinthebufferbythefunctionunlessyouarepassingthemasLabVIEWhandles,inwhichcaseyoucanresizethemusingCINfunctionsunderVisualC++orSymanteccompiler.
ListDLLfunctionsintheEXPORTSsectionofthemoduledefinitionfileifyouareusing_stdcall.
ListDLLfunctionsthatotherapplicationscallinthemoduledefinitionfileEXPORTSsectionortoincludethe_declspecdllexportkeywordinthefunctiondeclaration.
IfyouuseaC++compiler,exportfunctionswiththeextern.
C.
{}statementinyourheaderfileinordertopreventnamemangling.
IfyouarewritingyourownDLL,youshouldnotrecompileaDLLwhiletheDLLisloadedintothememorybyanotherapplication.
BeforerecompilingaDLL,ensurethatallapplicationsusingthatparticularDLLareunloadedfromthememory.
ItensuresthattheDLLitselfisnotloadedintothememory.
Youmayfailtorebuildcorrectlyifyouforgetthisandyourcompilerdoesnotwarnyou.
TestyourDLLswithanotherprogramtoensurethatthefunctionandtheDLLbehavecorrectly.
TestingitwiththedebuggerofyourcompilerorasimpleCprograminwhichyoucancallafunctioninaDLLwillhelpyouidentifywhetherpossibledifficultiesareinherenttotheDLLorLabVIEWrelated.
DLL-EXAMPLESDLL-EXAMPLESWehaveseenhowtowriteaDLLandhowtocreatea"HelloWorld"program.
ThatexamplemusthavegivenyouanideaaboutthebasicconceptofcreatingaDLL.
Here,wewillgiveadescriptionofcreatingDLLsusingDelphi,BorlandC++,andagainVC++.
Letustaketheseexamplesonebyone.
HowtowriteandcallDLL'swithinDelphiMakingDLL'sfromtheBorlandC++BuilderIDEMakingDLL'sinMicrosoftVisualC++6.
0Loading[MathJax]/jax/output/HTML-CSS/jax.
js

618云上Go:腾讯云秒杀云服务器95元/年起,1C2G5M三年仅288元起

进入6月,各大网络平台都开启了618促销,腾讯云目前也正在开展618云上Go活动,上海/北京/广州/成都/香港/新加坡/硅谷等多个地区云服务器及轻量服务器秒杀,最低年付95元起,参与活动的产品还包括短信包、CDN流量包、MySQL数据库、云存储(标准存储)、直播/点播流量包等等,本轮秒杀活动每天5场,一直持续到7月中旬,感兴趣的朋友可以关注本页。活动页面:https://cloud.tencent...

Cloudxtiny:£1.5/月,KVM-512MB/100GB/英国机房

Cloudxtiny是一家来自英国的主机商,提供VPS和独立服务器租用,在英国肯特自营数据中心,自己的硬件和网络(AS207059)。商家VPS主机基于KVM架构,开设在英国肯特机房,为了庆祝2021年欧洲杯决赛英格兰对意大利,商家为全场VPS主机提供50%的折扣直到7月31日,优惠后最低套餐每月1.5英镑起。我们对这场比赛有点偏见,但希望这是一场史诗般的决赛!下面列出几款主机套餐配置信息。CPU...

incogne$2.5/月t芬兰VPS,AMD Ryzen、1Gbps带宽

IncogNet LLC是个由3个人运作的美国公司,主要特色是隐私保护,号称绝对保护用户的隐私安全。业务涵盖虚拟主机、VPS等,支持多种数字加密货币、PayPal付款。注册账号也很简单,输入一个姓名、一个邮箱、国家随便选,填写一个邮箱就搞定了,基本上不管资料的真假。当前促销的vps位于芬兰机房,全部都是AMD Ryzen系列的CPU,性能不会差的!5折优惠码:CRYPTOMONTH,支持:BTC,...

browseui.dll为你推荐
支持ipadIOJsios8支持ipad张女士苹果5C1:山东品牌商品馆xp如何关闭445端口请大家帮帮忙,怎样关闭135和445端口?fusionchartsfusioncharts怎么生成图片至excel迅雷快鸟迅雷快鸟这种强盗软件不违规吗?win7关闭135端口win7系统 怎么关闭135 445 端口 修改注册表 创建IP安全策略 也试过 就是关不了 还望高手指教google分析google分析里的数据包括搜索引擎爬虫的数据吗?
免费云主机 上海虚拟主机 免费网站域名注册 187邮箱 linode webhostingpad 国内永久免费云服务器 彩虹ip 好看qq空间 gg广告 vip购优汇 速度云 cn3 免费美国空间 天翼云盘 免费dns解析 宏讯 阿里云邮箱登陆 免费网络空间 电信宽带测速软件 更多