COM 教程 计算机 英文.docx
《COM 教程 计算机 英文.docx》由会员分享,可在线阅读,更多相关《COM 教程 计算机 英文.docx(52页珍藏版)》请在课桌文档上搜索。
1、IntroductionFormanypeople,learningCOMandDCOMistough.YouknowthatlearningCOMistherightthingtodo-youhearconstanthypeandyouknowthatmanyofMicrosoft,sproductsandprogrammertoolsarebasedonCOM,soitisobviouslysomethingthatisimportant.ButyoualsoknowthatCOMisreallyhard.YoumayhavealreadytriedtolearnCOMonce,ormay
2、beevenseveraltimes.Youmayhaveslidthroughacoupleofbooks,playedwithsomewizards,etc.Butitjustdoesn,tmakeanysense.Everythingseemsextremelycomplicatedandmuchharderthanitneedstobe.There,salsothevocabulary:marshalling,apartmentthreads”,z,singletonobjects“andsoon.Whatisthis?Thepurposeofthissetoftutorialsist
3、ohelpyoutoquicklyunderstandwhatisgoingonintheworldofDCOMsothatyoucancreateCOMclientsandserverseasily.Wedothatstartingatthebeginningandlayingthingsoutforyousimplyandintherightorder.BythetimeyoufinishthesetutorialsyouwillunderstandallofthebasicconceptsdrivingDCOMandyouwillbeabletoproceedquicklytolearn
4、therest.YouwillbeamazedathoweasyDCOMcanbeonceyougetagoodstart. TheBaSiCSOfCOM-thebestplacetostartisatthebeginning. SimDIeCoMCIientS-COMclientsareeasy SimPIeCOMSerVerS-usingtheAT1.wizardtobuildaserverTheBasicsofCOMUnderstandinghowCOMworkscanbeintimidatingatfirst.Onereasonforthisintimidationisthefactt
5、hatCOMusesitsownvocabulary.AsecondreasonisthatCOMcontainsanumberofnewconcepts.OneoftheeasiestwaystomasterthevocabularyandconceptsistocompareCOMobjectstonormalC+objectstoidentifythesimilaritiesanddifferences.YoucanalsomapunfamiliarconceptsfromCOMintothestandardC+modelthatyoualreadyunderstand.Thiswill
6、giveyouacomfortablestartingpoint,fromwhichwelllookatCOMsfundamentalconcepts.Oncewehavedonethis,theexamplepresentedinthefollowingsectionswillbeextremelyeasytounderstand.ClassesandObjectsImaginethatyouhavecreatedasimpleclassinC+calledxxx.Ithasseveralmemberfunctions,namedMethodA,MethodB,andMethodC.Each
7、memberfunctionacceptsparametersandreturnsaresult.Theclassdeclarationisshownhere:classxxxpublic:intMethodA(inta);intMethodB(floatb);floatMethodC(floatc);;Theclassdeclarationitselfdescribestheclass.Whenyouneedtousetheclass,youmustcreateaninstanceoftheobject.Instantiationsaretheactualobjects;classesare
8、justthedefinitions.Eachobjectiscreatedeitherasavariable(localorglobal)oritiscreateddynamicallyusingthenewstatement.Thenewstatementdynamicallycreatesthevariableontheheapandreturnsapointertoit.Whenyoucallmemberfunctions,youdosobydereferencingthepointer.Forexample:xxx*px;/px=newxxx;/p-MethodA(l);/delet
9、epx;/pointertoxxxclasscreateobjectonheapcallmethodfreeobjectItisimportantforyoutounderstandandrecognizethatCOMfollowsthissameobjectedorientedmodel.COMhasclasses,memberfunctionsandinstantiationsjustlikeC+objectsdo.AlthoughyounevercallnewonaCOMobject,youmuststillcreateitinmemory.YouaccessCOMobjectswit
10、hpointers,andyoumustde-allocatethemwhenyouarefinished.WhenwewriteCOMcode,wewontbeusingnewanddelete.Althoughwe,regoingtouseC+asourlanguage,wellhaveawholenewsyntax.COMisimplementedbycallstotheCOMAPI,whichprovidesfunctionsthatcreateanddestroyCOMobjects.HeresanexampleCOMprogramwritteninpsedo-COMcode.ixx
11、*pi/CoCreateInstance(,&pi)/pi-MethodA();/pi-Release();/pointertoxxxCOMinterfacecreateinterfacecallmethodfreeinterfaceInthisexample,wellcallclassixxaninterface.Thevariablepiisapointertotheinterface.ThemethodCoCreateInstancecreatesaninstanceoftypeixx.Thisinterfacepointerisusedtomakemethodcalls.Release
12、deletestheinterface.vepurposelyomittedtheparameterstoCoCreateInstance.Ididthissoasnottoobscurethebasicsimplicityoftheprogram.CoCreateInstancetakesanumberofarguments,allofwhichneedsomemoredetailedcoverage.Fornow,letstakeastepbackandlookatthebiggerissueswithCOM.HowCOMIsDifferentCOMisnotC+,andforgoodre
13、ason.COMobjectsaresomewhatmorecomplicatedthentheirC+brethren.Mostofthiscomplicationisnecessarybecauseofnetworkconsiderations.TherearefourbasicfactorsdictatingthedesignofCOM:C+objectsalwaysruninthesameprocessspace.COMobjectscanrunacrossprocessesoracrosscomputers. COMmethodscanbecalledacrossanetwork.C
14、+methodnamesmustbeuniqueinagivenprocessspace.COMobjectnamesmustbeuniquethroughouttheworld. COMserversmaybewritteninavarietyofdifferentlanguagesandonentirelydifferentoperatingsystems,whileC+objectsarealwayswritteninC+.1.etslookatwhatthesedifferencesbetweenCOMandC+meantoyouasaprogrammer.COMcanrunacros
15、sprocessesInCOM,youastheprogrammerareallowedtocreateobjectsinotherprocesses,andonanymachineonthenetwork.ThatdoesnotmeanthatyouW川alwaysdoit(inmanycasesyouwont).However,thepossibilitymeansthatyoucantcreateaCOMobjectusingthenormalC+newstatement,andcallingitsmethodswithlocalprocedurecallswontsuffice.Toc
16、reateaCOMobject,someexecutingentity(anEXEoraService)willhavetoperformremotememoryallocationandobjectcreation.Thisisaverycomplextask.Byremote,wemeaninanotherprocessoronanotherprocess.ThisproblemissolvedbycreatingaconceptcalledaCOMserver.ThisotherentityW川havetomaintaintightcommunicationwiththeclient.C
17、OMmethodscanbecalledacrossanetworkIfyouhaveaccesstoamachineonthenetwork,andifaCOMserverfortheobjectyouwanttousehasbeeninstalledonthatmachine,thenyoucancreatetheCOMobjectonthatcomputer.Ofcourse,youmusttheproperprivileges,andeverythinghastobeset-upcorrectlyontheothercomputer.SinceyourCOMobjectwillnotn
18、ecessarilybeonthelocalmachine,youneedagoodwaytopointtoit,eventhoughitsmemoryissomewhereelse.Technically,thereisnowaytodothis.Inpractice,itcanbesimulatedbyintroducingawholenewlevelofobjects.OneofthewaysCOMdoesthisiswithaconceptcalledaproxystb.Welldiscussproxy/stubsinsomedetaillater.Anotherimportantis
19、sueispassingdatabetweentheCOMclientanditsCOMserver.Whendataispassedbetweenprocesses,threads,oroveranetwork,itiscalledMarshalling.Again,theproxystbtakescareofthemarshallingforyou.COMcanalsomarshaldataforcertaintypesofinterfaceusingType1.ibrariesandtheAutomationmarshaller.TheAutomationmarshallerdoesno
20、tneedtobespecificallybuiltforeachCOMserver.COMobjectsmustbeuniquethroughouttheworldThewholeworld?Comeon!Thismayseemlikeanexaggerationatfirst,butconsidertheInternettobeaworldwidenetwork.Evenifyoureworkingonasinglecomputer,COMmusthandlethepossibility.Uniquenessistheissue.InC+allclassesarehandledunequi
21、vocallybythecompiler.Thecompilercanseetheclassdefinitionforeveryclassusedinaprogramandmatchupallreferencestoittomakesuretheyconformtotheclassexactly.Thecompilercanalsoguaranteethatthereisonlyoneclassofagivenname.InCOMtheremustbeagoodwaytogetasimilarlyunequivocalmatch.COMmustguaranteethatthereW川OnIyb
22、eoneobjectofagivennameeventhoughthenumberofobjectsavailableonaworldwidenetworkishuge.ThisproblemissolvedbycreatingaconceptcalledaGUID.COMislanguageindpendentCOMserversmaybewrittenwithadifferentlanguageandanentirelydifferentoperatingsystem.COMobjectshavethecapabilityofbeingremotelyaccessible.Thatmean
23、stheymaybeinadifferentthread,process,orevenonadifferentcomputer.Theothercomputermayevenberunningunderadifferentoperatingsystem.Thereneedstobeagoodwaytotransmitparametersoverthenetworktoobjectsonothermachines.Thisproblemissolvedbycreatinganewwaytocarefullyspecifytheinterfacebetweentheclientandserver.
24、ThereisalsoanewcompilercalledMID1.(Microsoft?lnterfaceDefinition1.anguage).Thiscompilermakesitpossibletogenericallyspecifytheinterfacebetweentheserverandclient.MID1.definesCOMobjects,interfaces,methodsandparameters.COMVocabularyOneoftheproblemswe,regoingtohaveiskeepingtrackoftwosetsofterminology.You
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- COM 教程 计算机 英文
链接地址:https://www.desk33.com/p-1407251.html