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
上次部落分享过VirMach提供的End of Life Plans系列的VPS主机,最近他们又发布了DEDICATED MIGRATION SPECIALS产品,并提供6.5-7.5折优惠码,优惠后最低每月27.3美元起。同样的这些机器现在订购,将在2021年9月30日至2022年4月30日之间迁移,目前这些等待迁移机器可以在洛杉矶、达拉斯、亚特兰大、纽约、芝加哥等5个地区机房开设,未来迁移的时...
95idc是一家香港公司,主要产品香港GIA线路沙田CN2线路独服,美国CERA高防服务器,日本CN2直连服务器,即日起,购买香港/日本云主机,在今年3月份,95IDC推出来一款香港物理机/香港多ip站群服务器,BGP+CN2线路终身7折,月付350元起。不过今天,推荐一个价格更美的香港物理机,5个ip,BGP+CN2线路,月付299元起,有需要的,可以关注一下。95idc优惠码:优惠码:596J...
HostMem近日发布了最新的优惠消息,全场云服务器产品一律75折优惠,美国洛杉矶QuadraNet机房,基于KVM虚拟架构,2核心2G内存240G SSD固态硬盘100Mbps带宽4TB流量,27美元/年,线路方面电信CN2 GT,联通CU移动CM,有需要美国大硬盘VPS云服务器的朋友可以关注一下。HostMem怎么样?HostMem服务器好不好?HostMem值不值得购买?HostMem是一家...
browseui.dll为你推荐
人才ipad联通iphone4联通iphone4怎么样,好不好用?联通iphone4联通iphone4合约迅雷快鸟迅雷快鸟这种强盗软件不违规吗?win7关闭135端口请问如何关闭135端口?chromeframe无法安装chrome frame,求助迅雷雷鸟迅雷会员每日免费抽奖,抽中迅雷的雷鸟披肩了,要钱吗win7还原系统win7如何一键还原电脑系统怎么操作google搜图google自定义搜索是什么?怎么用google搜图google搜索的网址是什么?
vps虚拟服务器 google镜像 edgecast 香港主机 免备案cdn mediafire下载 sockscap evssl证书 美国php空间 panel1 gg广告 支付宝扫码领红包 太原联通测速 游戏服务器出租 atom处理器 lamp的音标 空间服务器 免费个人网页 小夜博客 数据湾 更多