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
Hostodo在九月份又发布了两款特别套餐,开设在美国拉斯维加斯、迈阿密和斯波坎机房,基于KVM架构,采用NVMe SSD高性能磁盘,最低1.5GB内存8TB月流量套餐年付34.99美元起。Hostodo是一家成立于2014年的国外VPS主机商,主打低价VPS套餐且年付为主,基于OpenVZ和KVM架构,美国三个地区机房,支持支付宝或者PayPal、加密货币等付款。下面列出这两款主机配置信息。CP...
GreencloudVPS此次在四个机房都上线10Gbps大带宽VPS,并且全部采用AMD处理器,其中美国芝加哥机房采用Ryzen 3950x处理器,新加坡、荷兰阿姆斯特丹、美国杰克逊维尔机房采用Ryzen 3960x处理器,全部都是RAID-1 NVMe硬盘、DDR4 2666Mhz内存,GreenCloudVPS本次促销的便宜VPS最低仅需20美元/年,支持支付宝、银联和paypal。Gree...
近日CloudCone发布了最新的补货消息,针对此前新年闪购年付便宜VPS云服务器计划方案进行了少量补货,KVM虚拟架构,美国洛杉矶CN2 GT线路,1Gbps带宽,最低3TB流量,仅需14美元/年,有需要国外便宜美国洛杉矶VPS云服务器的朋友可以尝试一下。CloudCone怎么样?CloudCone服务器好不好?CloudCone值不值得购买?CloudCone是一家成立于2017年的美国服务器...
browseui.dll为你推荐
三星itunesrealgooglepreloadedbaiduspeakingphpFDCphp支持ipad支持ipad您的iphonewin7关闭445端口win7系统怎么关闭445和135这两个端口重庆宽带测速重庆市电信网速测试是哪个网站或ip
韩国vps俄罗斯美女 动态域名解析软件 国外服务器 isatap 腾讯云数据库 新站长网 申请个人网页 dux 已备案删除域名 佛山高防服务器 qq云端 免费智能解析 789电视剧 ca187 空间登录首页 便宜空间 免费php空间 杭州电信宽带 睿云 japanese50m咸熟 更多