欢迎来到课桌文档! | 帮助中心 课桌文档-建筑工程资料库
课桌文档
全部分类
  • 党建之窗>
  • 感悟体会>
  • 百家争鸣>
  • 教育整顿>
  • 文笔提升>
  • 热门分类>
  • 计划总结>
  • 致辞演讲>
  • 在线阅读>
  • ImageVerifierCode 换一换
    首页 课桌文档 > 资源分类 > DOCX文档下载  

    COM 教程 计算机 英文.docx

    • 资源ID:1407251       资源大小:129.68KB        全文页数:52页
    • 资源格式: DOCX        下载积分:5金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要5金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    COM 教程 计算机 英文.docx

    IntroductionFormanypeople,learningCOMandDCOMistough.YouknowthatlearningCOMistherightthingtodo-youhearconstanthypeandyouknowthatmanyofMicrosoft,sproductsandprogrammertoolsarebasedonCOM,soitisobviouslysomethingthatisimportant.ButyoualsoknowthatCOMisreallyhard.YoumayhavealreadytriedtolearnCOMonce,ormaybeevenseveraltimes.Youmayhaveslidthroughacoupleofbooks,playedwithsomewizards,etc.Butitjustdoesn,tmakeanysense.Everythingseemsextremelycomplicatedandmuchharderthanitneedstobe.There,salsothevocabulary:"marshalling","apartmentthreads”,z,singletonobjects“andsoon.Whatisthis?ThepurposeofthissetoftutorialsistohelpyoutoquicklyunderstandwhatisgoingonintheworldofDCOMsothatyoucancreateCOMclientsandserverseasily.Wedothatstartingatthebeginningandlayingthingsoutforyousimplyandintherightorder.BythetimeyoufinishthesetutorialsyouwillunderstandallofthebasicconceptsdrivingDCOMandyouwillbeabletoproceedquicklytolearntherest.YouwillbeamazedathoweasyDCOMcanbeonceyougetagoodstart. TheBaSiCSOfCOM-thebestplacetostartisatthebeginning. SimDIeCoMCIientS-COMclientsareeasy SimPIeCOMSerVerS-usingtheAT1.wizardtobuildaserverTheBasicsofCOMUnderstandinghowCOMworkscanbeintimidatingatfirst.OnereasonforthisintimidationisthefactthatCOMusesitsownvocabulary.AsecondreasonisthatCOMcontainsanumberofnewconcepts.OneoftheeasiestwaystomasterthevocabularyandconceptsistocompareCOMobjectstonormalC+objectstoidentifythesimilaritiesanddifferences.YoucanalsomapunfamiliarconceptsfromCOMintothestandardC+modelthatyoualreadyunderstand.Thiswillgiveyouacomfortablestartingpoint,fromwhichwelllookatCOM'sfundamentalconcepts.Oncewehavedonethis,theexamplepresentedinthefollowingsectionswillbeextremelyeasytounderstand.ClassesandObjectsImaginethatyouhavecreatedasimpleclassinC+calledxxx.Ithasseveralmemberfunctions,namedMethodA,MethodB,andMethodC.Eachmemberfunctionacceptsparametersandreturnsaresult.Theclassdeclarationisshownhere:classxxxpublic:intMethodA(inta);intMethodB(floatb);floatMethodC(floatc);;Theclassdeclarationitselfdescribestheclass.Whenyouneedtousetheclass,youmustcreateaninstanceoftheobject.Instantiationsaretheactualobjects;classesarejustthedefinitions.Eachobjectiscreatedeitherasavariable(localorglobal)oritiscreateddynamicallyusingthenewstatement.Thenewstatementdynamicallycreatesthevariableontheheapandreturnsapointertoit.Whenyoucallmemberfunctions,youdosobydereferencingthepointer.Forexample:xxx*px;/px=newxxx;/p->MethodA(l);/deletepx;/pointertoxxxclasscreateobjectonheapcallmethodfreeobjectItisimportantforyoutounderstandandrecognizethatCOMfollowsthissameobjectedorientedmodel.COMhasclasses,memberfunctionsandinstantiationsjustlikeC+objectsdo.AlthoughyounevercallnewonaCOMobject,youmuststillcreateitinmemory.YouaccessCOMobjectswithpointers,andyoumustde-allocatethemwhenyouarefinished.WhenwewriteCOMcode,wewon'tbeusingnewanddelete.Althoughwe,regoingtouseC+asourlanguage,we'llhaveawholenewsyntax.COMisimplementedbycallstotheCOMAPI,whichprovidesfunctionsthatcreateanddestroyCOMobjects.Here'sanexampleCOMprogramwritteninpsedo-COMcode.ixx*pi/CoCreateInstance(,&pi)/pi->MethodA();/pi->Release();/pointertoxxxCOMinterfacecreateinterfacecallmethodfreeinterfaceInthisexample,we'llcallclassixxan"interface".Thevariablepiisapointertotheinterface.ThemethodCoCreateInstancecreatesaninstanceoftypeixx.Thisinterfacepointerisusedtomakemethodcalls.Releasedeletestheinterface.vepurposelyomittedtheparameterstoCoCreateInstance.Ididthissoasnottoobscurethebasicsimplicityoftheprogram.CoCreateInstancetakesanumberofarguments,allofwhichneedsomemoredetailedcoverage.Fornow,let'stakeastepbackandlookatthebiggerissueswithCOM.HowCOMIsDifferentCOMisnotC+,andforgoodreason.COMobjectsaresomewhatmorecomplicatedthentheirC+brethren.Mostofthiscomplicationisnecessarybecauseofnetworkconsiderations.TherearefourbasicfactorsdictatingthedesignofCOM:C+objectsalwaysruninthesameprocessspace.COMobjectscanrunacrossprocessesoracrosscomputers. COMmethodscanbecalledacrossanetwork.C+methodnamesmustbeuniqueinagivenprocessspace.COMobjectnamesmustbeuniquethroughouttheworld. COMserversmaybewritteninavarietyofdifferentlanguagesandonentirelydifferentoperatingsystems,whileC÷+objectsarealwayswritteninC+.1.et'slookatwhatthesedifferencesbetweenCOMandC+meantoyouasaprogrammer.COMcanrunacrossprocessesInCOM,youastheprogrammerareallowedtocreateobjectsinotherprocesses,andonanymachineonthenetwork.ThatdoesnotmeanthatyouW川alwaysdoit(inmanycasesyouwon't).However,thepossibilitymeansthatyoucan'tcreateaCOMobjectusingthenormalC+newstatement,andcallingitsmethodswithlocalprocedurecallswon'tsuffice.TocreateaCOMobject,someexecutingentity(anEXEoraService)willhavetoperformremotememoryallocationandobjectcreation.Thisisaverycomplextask.Byremote,wemeaninanotherprocessoronanotherprocess.ThisproblemissolvedbycreatingaconceptcalledaCOMserver.ThisotherentityW川havetomaintaintightcommunicationwiththeclient.COMmethodscanbecalledacrossanetworkIfyouhaveaccesstoamachineonthenetwork,andifaCOMserverfortheobjectyouwanttousehasbeeninstalledonthatmachine,thenyoucancreatetheCOMobjectonthatcomputer.Ofcourse,youmusttheproperprivileges,andeverythinghastobeset-upcorrectlyontheothercomputer.SinceyourCOMobjectwillnotnecessarilybeonthelocalmachine,youneedagoodwayto"pointto"it,eventhoughitsmemoryissomewhereelse.Technically,thereisnowaytodothis.Inpractice,itcanbesimulatedbyintroducingawholenewlevelofobjects.OneofthewaysCOMdoesthisiswithaconceptcalledaproxystb.Welldiscussproxy/stubsinsomedetaillater.AnotherimportantissueispassingdatabetweentheCOMclientandit'sCOMserver.Whendataispassedbetweenprocesses,threads,oroveranetwork,itiscalled"Marshalling".Again,theproxystbtakescareofthemarshallingforyou.COMcanalsomarshaldataforcertaintypesofinterfaceusingType1.ibrariesandtheAutomationmarshaller.TheAutomationmarshallerdoesnotneedtobespecificallybuiltforeachCOMserver.COMobjectsmustbeuniquethroughouttheworldThewholeworld?Comeon!Thismayseemlikeanexaggerationatfirst,butconsidertheInternettobeaworldwidenetwork.Evenifyou'reworkingonasinglecomputer,COMmusthandlethepossibility.Uniquenessistheissue.InC+allclassesarehandledunequivocallybythecompiler.Thecompilercanseetheclassdefinitionforeveryclassusedinaprogramandmatchupallreferencestoittomakesuretheyconformtotheclassexactly.Thecompilercanalsoguaranteethatthereisonlyoneclassofagivenname.InCOMtheremustbeagoodwaytogetasimilarlyunequivocalmatch.COMmustguaranteethatthereW川OnIybeoneobjectofagivennameeventhoughthenumberofobjectsavailableonaworldwidenetworkishuge.ThisproblemissolvedbycreatingaconceptcalledaGUID.COMislanguageindpendentCOMserversmaybewrittenwithadifferentlanguageandanentirelydifferentoperatingsystem.COMobjectshavethecapabilityofbeingremotelyaccessible.Thatmeanstheymaybeinadifferentthread,process,orevenonadifferentcomputer.Theothercomputermayevenberunningunderadifferentoperatingsystem.Thereneedstobeagoodwaytotransmitparametersoverthenetworktoobjectsonothermachines.Thisproblemissolvedbycreatinganewwaytocarefullyspecifytheinterfacebetweentheclientandserver.ThereisalsoanewcompilercalledMID1.(Microsoft?lnterfaceDefinition1.anguage).Thiscompilermakesitpossibletogenericallyspecifytheinterfacebetweentheserverandclient.MID1.definesCOMobjects,interfaces,methodsandparameters.COMVocabularyOneoftheproblemswe,regoingtohaveiskeepingtrackoftwosetsofterminology.You'reprobablyalreadyfamiliarwithC+andsomeObjectOrientedterminology.ThistableprovidesaroughequivalencybetweenCOMandconventionalterminology.ConceptConventional(C+OOP)COMClientAprogramthatrequestservicesfromaserver.AprogramthatcallsCOMmethods.ServerAprogramthat"serves"otherprograms.AprogramthatmakesCOMobjectsavailabletoaCOMclient.InterfaceNone.ApointertoagroupoffunctionsthatarecalledthroughCOM.ClassAdatatype.Definesagroupofmethodsanddatathatareusedtogether.ThedefinitionofanobjectthatimplementsoneormoreCOMinterfaces.Also,"coclass".ObjectAninstanceofaclass.Theinstanceofacoclass.MarshallingNone.Movingdatabetweenclientandserver.You'llnoticetheconceptsofInterfaceandMarshallingdon'ttranslatewellintotheC+model.TheclosestthingtoaninterfaceinC+istheexportdefinitionsofaD1.1.D1.1.'sdomanyofthesamethingsasCOMwhendealingwithatightlycoupled(in-process)COMserver.MarshallinginC+isalmostentirelymanual.Ifyou'retryingtocopydatabetweenprocessesandcomputers,you'llhavetowritethecodeusingsomesortofinter-processcommunication.Youhaveseveralchoices,includingsockets,theclipboard,andmailslots.TheInterfaceThusfar,we,vebeenusingtheword"interface"prettyloosely.Mydictionary(1947AmericanCollegeDictionary)definesaninterfaceasfollows:"Interface,n.asurfaceregardedasthecommonboundaryoftwobodiesorsurfaces"That'sactuallyausefulgeneraldescription.InCOM"interface"hasaveryspecificmeaning.COMinterfacesareacompletelynewconcept,notavailableinC+.Theconceptofaninterfaceisinitiallyhardtounderstandformanypeople.Aninterfaceisaghostlikeentitythatneverhasaconcreteexistence.It'ssortoflikeanabstractclass-butnotexactly.Atitssimplest,aninterfaceisnothingbutanamedcollectionoffunctions.InC+,aclass(usingthisterminology)isallowedonlyoneinterface.Thememberfunctionsofthatinterfaceareallthepublicmemberfunctionsoftheclass.Inotherwords,theinterfaceisthepubliclyvisiblepartoftheclass.InC+thereisalmostnodistinctionbetweenaninterfaceandaclass.Here'sanexampleC+class:classyyypublic:intDoThisO;private:voidHelperl();intcount;intx,y,z;);Whensomeonetriestousethisclass,theyonlyhaveaccesstothepublicmembers.(Forthemomentwe,reignoringprotectedmembersandinheritance.)Theycan'tcallHelperl,oruseanyoftheprivatevariables.Totheconsumerofthisclass,thedefinitionlookslikethis:classyyyintDoThisO;;Thispublicsubsetoftheclassisthe'interface'totheoutsideworld.Essentiallytheinterfacehidesthegutsoftheclassfromtheconsumer.ThisC+analogyonlygoessofar.ACOMinterfaceisnotaC+class.COMinterfacesandclasseshavetheirownspecialsetofrulesandconventions.COMallowsacoclass(COMclass)tohavemultipleinterfaces,eachinterfacehavingitsownnameanditsowncollectionoffunctions.Thereasonforthisfeatureistoallowformorecomplexandfunctionalobjects.ThisisanotherconceptthatisalientoC+.(Perhapsmultipleinterfacescouldbeenvisionedasaunionoftwoclassdefinitions-somethingthatisn'tallowedinC÷+.)InterfacesisolatetheclientfromtheserverOneofthecardinalrulesofCOMisthatyoucanonlyaccessaCOMobjectthroughaninterface.Theclientprogramiscompletelyisolatedfromtheserver'simplementationthroughinterfaces.Thisisanextremelyimportantpoint.TheclientprogramknowsnothingabouttheCOMobjectorC+classthatimplementstheCOMobject.Allitcanseeistheinterface.TheinterfaceislikewindowintotheCOMobject.Theinterfacedesignerallowstheclienttoseeonlythosepartsoftheobjectthatheorshewishestoexpose.Figure2-1illustrateshowallclientaccesstotheCOMobjectisfeledthroughtheinterface.FigUreThenotationusedhere,asmallcircleconnectedbyastick,istheconventionalwaytodrawaCOMinterface.Therearemanyimportantrulesassociatedwithinterfaces.WhilecriticalforunderstandingthedetailshowCOMworks,wecanleavethemuntillater.Fornow,wellconcentrateonthebroadconceptsofinterfaces.ImaginingaCOMInterfaceHere'sanotherwaytovisualizeaninterface.Inthissectionwe,llpresentaCOMinterfacewithoutanyoftheC+baggage.Welltrytolookataninterfaceinitsabstractform.Imaginea"car"object.All"car"objectsthatyouarefamiliarwithintherealworldhavea"driving"interfacethatallowsyoutodirectthecarleftandrightandalsotospeedthecarupandslowitdown.Thememberfunctionsforthedrivinginterfacemightbe"left","right","faster","slower","forward"and"reverse".Manycarsalsohappentohavea"radio"interfaceaswell,iftheyhavearadioinstalled.Thefunctionsfortheradiointerfacemightbe"on","off","louder","softer","nextstation"and"previousstation".DrivingRadio1.eft()On()Right()otf()Slower()1.ouder()Faster()Softer()ForwardQNextStationOReverse()PrevStationOTherearemanykindsofcars,butnotallofthemhaveradios.Therefore,theydonotimplementtheradiointerface,althoughtheydosupportthedrivinginterface.Inallcarsthatdohaveradiosthecapabilitiesoftheradioarethesame.Apersondrivingacarwithoutaradiocanstilldrive,butcannothearmusic.Inacarthatdoeshavearadio,theradiointerfaceisavailable.COMsupportsthissamesortofmodelforCOMclasses.ACOMobjectcansupportacollectionofinterfaces,eachofwhichhasaname.ForCOMobjectsthatyoucreateyourself,youwilloftendefineandusejustasingleCOMinterface.ButmanyexistingCOMobjectssupportmultipleCOMinterfacesdependingonthefeaturestheysupport.Anotherimportantdistinctionisthatthedrivinginterfaceisnotthecar.Thedrivinginterfacedoesn'ttellyouanythingaboutthebrakes,orthewheels,ortheengineofthecar.Youdon'tdrivetheengineforexample,youusethefasterandslowermethods(acceleratorandbrakes)ofthedrivinginterface.Youdon'treallycarehowtheslower(brake)methodisimplemented,aslongasthecarslowsdown.Whetherthecarhashydraulicorairbrakesisn'timportant.ImagineacomponentWhenyou'rebuildingaCOMobject,youareveryconcernedabouthowtheinterfaceworks.Theuseroftheinterfacehowever,shouldn'tbeconcernedaboutitsimplementation.1.ikethebrakesonacar,theusercaresonlythattheinterfaceworks,notaboutthedetailsbehindtheinterface.ThisisolationofinterfaceandimplementationiscrucialforCOM.Byisolatingtheinterfacefromit'simplementation,wecanbuildcomponents.Componentscanbereplacedandre-used.Thisbothsimplifiesandmultipliestheusefulnessoftheobject.What'sinaname?OneimportantfacttorecognizeisthatanamedCOMinterfaceisunique.Thatis,aprogrammerisallowedtomakeanassumptioninCOMthatifheaccessesaninterfaceofaspecificname,thememberfunctionsandparametersofthatinterfaceW川beexactlythesameinallCOMobjectsthatimplementtheinterface.So,followingourexample,theinterfacesnamed"driving"and"radio"willhaveexactlythesamememberfunctionsignatureinanyCOMobjectthatimplementsthem.Ifyouwanttochangethememberfunctionsofaninterfaceinanywaytyouhavetocreateanewinterfacewithanewname.Thesourceofallinterfaces-IUnknownTraditionalexplanationsofCOMstartoutwithathoroughdescriptionofthe(Unknowninterface.!UnknownisthefundamentalbasisforallCOMinterfaces.Despiteitsimportance,youdon'tneedtoknowabout!Unknowntounderstandtheinterfaceconcept.Theimplementationof!Unknownishiddenbythehigherlevelabstractionswe'llbeusingtobuildourCOMobjects.Actually,payingtoomuchattentionto!Unknowncanbeconfusing.1.et'sdealwithitatahighlevelheresoyouunderstandtheconcepts.(UnknownislikeanabstractbaseclassinC+.AllCOMinterfacesmustinheritfromIUnknown.!Unknownhandlesthecreationandmanagementoftheinterface.Themethodsof!Unknownareusedtocreate,referencecount,andreleaseaCOMobject.AllCOMinterfacesimplementthese3methodsandtheyareusedinternallybyCOMtomanageinterfaces.Youwilllikelynevercallthese3methodsyourself.AtypicalCOMobjectNowlet'sputallofthesenewconceptstogetheranddescribeatypicalCOMobjectandaprogramthatwantstoaccessit.Inthenextsectionandthefollowingchapterswewillmakethisrealbyimplementingtheactualcodefortheobject.ImaginethatyouwanttocreatethesimplestpossibleCOMobject.Thisobjectwillsupportasingleinterface,andthatinterfacewillcontainasin

    注意事项

    本文(COM 教程 计算机 英文.docx)为本站会员(夺命阿水)主动上传,课桌文档仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知课桌文档(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-1

    经营许可证:宁B2-20210002

    宁公网安备 64010402000986号

    课桌文档
    收起
    展开