Component Object Model
Component Object Model
ComponentObjectModelWikipedia,thefreeencyclopedia
ComponentObjectModel
FromWikipedia,thefreeencyclopedia
NottobeconfusedwithCOMfile.
ComponentObjectModel(COM)isabinaryinterfacestandardforsoftwarecomponentsintroducedbyMicrosoftin1993.Itisusedtoenable
interprocesscommunicationanddynamicobjectcreationinalargerangeofprogramminglanguages.COMisthebasisforseveralother
Microsofttechnologiesandframeworks,includingOLE,OLEAutomation,ActiveX,COM+,DCOM,theWindowsshell,DirectX,UMDFand
WindowsRuntime.
Contents
1Overview
2History
3Relatedtechnologies
3.1COM+andDCOM
3.2.NET
3.3WindowsRuntime
4Security
5Technicaldetails
5.1Interfaces
5.2Classes
5.3InterfaceDefinitionLanguageandtypelibraries
5.4COMasanobjectframework
5.5Referencecounting
5.6Programming
5.7Registryusage
5.8RegistrationfreeCOM
5.9Processandnetworktransparency
5.10Threading
6Criticisms
6.1Messagepumping
6.2Referencecounting
6.3DLLHell
7Seealso
8References
9Externallinks
Overview
TheessenceofCOMisalanguageneutralwayofimplementingobjectsthatcanbeusedinenvironmentsdifferentfromtheoneinwhichthey
werecreated,evenacrossmachineboundaries.Forwellauthoredcomponents,COMallowsreuseofobjectswithnoknowledgeoftheirinternal
implementation,asitforcescomponentimplementerstoprovidewelldefinedinterfacesthatareseparatedfromtheimplementation.The
differentallocationsemanticsoflanguagesareaccommodatedbymakingobjectsresponsiblefortheirowncreationanddestructionthrough
referencecounting.CastingbetweendifferentinterfacesofanobjectisachievedthroughtheQueryInterfacemethod.Thepreferredmethodof
inheritancewithinCOMisthecreationofsubobjectstowhichmethodcallsaredelegated.
COMisaninterfacetechnologydefinedandimplementedasstandardonlyonMicrosoftWindowsandApple'sCoreFoundation1.3andlater
pluginAPI,[1]thatinanycaseimplementonlyasubsetofthewholeCOMinterface.[2]Forsomeapplications,COMhasbeenreplacedatleastto
someextentbytheMicrosoft.NETframework,andsupportforWebServicesthroughtheWindowsCommunicationFoundation(WCF).
However,COMobjectscanbeusedwithall.NETlanguagesthrough.NETCOMInterop.NetworkedDCOMusesbinaryproprietaryformats,
whileWCFencouragestheuseofXMLbasedSOAPmessaging.COMisverysimilartoothercomponentsoftwareinterfacetechnologies,such
asCORBAandJavaBeans,althougheachhasitsownstrengthsandweaknesses.
UnlikeC++,COMprovidesastableABIthatdoesnotchangebetweencompilerreleases.[3]ThismakesCOMinterfacesattractiveforobject
orientedC++librariesthataretobeusedbyclientscompiledusingdifferentcompilerversions.
History
OneofthefirstmethodsofinterprocesscommunicationinWindowswasDynamicDataExchange(DDE),firstintroducedin1987,thatallowed
sendingandreceivingmessagesinsocalled"conversations"betweenapplications.
https://en.wikipedia.org/wiki/Component_Object_Model
1/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
AntonyWilliams,oneofthemostnotablethinkersinvolvedinthecreationoftheCOMarchitecture,laterdistributedtwointernalpapersin
Microsoftthatembracedtheconceptofsoftwarecomponents:ObjectArchitecture:DealingWiththeUnknownorTypeSafetyina
DynamicallyExtensibleClassLibraryin1988andOnInheritance:WhatItMeansandHowToUseItin1990.Theseprovidedthefoundationof
manyoftheideasbehindCOM.
ObjectLinkingandEmbedding(OLE),Microsoft'sfirstobjectbasedframework,wasbuiltontopofDDEanddesignedspecificallyfor
compounddocuments.ItwasintroducedwithWordforWindowsandExcelin1991,andwaslaterincludedwithWindows,startingwithversion
3.1in1992.
AnexampleofacompounddocumentisaspreadsheetembeddedinaWordforWindowsdocument:aschangesaremadetothespreadsheet
withinExcel,theyappearautomaticallyinsidetheWorddocument.
In1991,MicrosoftintroducedVisualBasicExtensions(VBX)withVisualBasic1.0.AVBXisapackagedextensionintheformofadynamic
linklibrary(DLL)thatallowsobjectstobegraphicallyplacedinaformandmanipulatedbypropertiesandmethods.Thesewerelateradapted
forusebyotherlanguagessuchasVisualC++.
In1992,whenversion3.1ofWindowswasreleased,MicrosoftreleasedOLE2withitsunderlyingobjectmodel.TheCOMApplicationbinary
interface(ABI)wasthesameastheMAPIABI,whichwasreleasedin1992.WhileOLE1wasfocusedoncompounddocuments,COMand
OLE2weredesignedtoaddresssoftwarecomponentsingeneral.TextconversationsandWindowsmessageshadprovednottobeflexible
enoughtoallowsharingapplicationfeaturesinarobustandextensibleway,soCOMwascreatedasanewfoundation,andOLEchangedto
OLE2.
In1994OLEcustomcontrols(OCXs)wereintroducedasthesuccessortoVBXcontrols.Atthesametime,MicrosoftstatedthatOLE2would
justbeknownas"OLE",andthatOLEwasnolongeranacronym,butanameforallofthecompany'scomponenttechnologies.
Inearly1996,MicrosoftfoundanewuseforOLECustomControls,expandingtheirWebbrowser'scapabilitytopresentcontent,renamedsome
partsofOLErelatingtotheInternet"ActiveX",andgraduallyrenamedallOLEtechnologiestoActiveX,exceptthecompounddocument
technologythatwasusedinMicrosoftOffice.Laterthatyear,DCOMwasintroducedasananswertoCORBA.
Relatedtechnologies
COMwasthemajorsoftwaredevelopmentplatformforWindowsand,assuch,influenceddevelopmentofanumberofsupportingtechnologies.
COM+andDCOM
InorderforMicrosofttoprovidedeveloperswithsupportfordistributedtransactions,resourcepooling,disconnectedapplications,event
publicationandsubscription,bettermemoryandprocessor(thread)management,aswellastopositionWindowsasanalternativetoother
enterpriseleveloperatingsystems,MicrosoftintroducedatechnologycalledMicrosoftTransactionServer(MTS)onWindowsNT4.
WithWindows2000,thatsignificantextensiontoCOMwasincorporatedintotheoperatingsystem(asopposedtotheseriesofexternaltools
providedbyMTS)andrenamedCOM+.Atthesametime,MicrosoftdeemphasizedDCOMasaseparateentity.Componentsthatmadeuseof
COM+serviceswerehandledmoredirectlybytheaddedlayerofCOM+,inparticularbyoperatingsystemsupportforinterception.Inthefirst
releaseofMTS,interceptionwastackedoninstallinganMTScomponentwouldmodifytheWindowsRegistrytocalltheMTSsoftware,and
notthecomponentdirectly.
Windows2000alsorevisedtheComponentServicescontrolpanelapplicationusedtoconfigureCOM+components.
AnadvantageofCOM+wasthatitcouldberunin"componentfarms".Instancesofacomponent,ifcodedproperly,couldbepooledandreused
bynewcallstoitsinitializingroutinewithoutunloadingitfrommemory.Componentscouldalsobedistributed(calledfromanothermachine).
COM+andMicrosoftVisualStudioprovidedtoolstomakeiteasytogenerateclientsideproxies,soalthoughDCOMwasusedtomakethe
remotecall,itwaseasytodofordevelopers.
COM+alsointroducedasubscriber/publishereventmechanismcalledCOM+Events,andprovidedanewwayofleveragingMSMQ(inter
applicationasynchronousmessaging)withcomponentscalledQueuedComponents.COM+eventsextendtheCOM+programmingmodelto
supportlatebound(seeLatebinding)eventsormethodcallsbetweenthepublisherorsubscriberandtheeventsystem.
.NET
Mainarticle:.NETFramework
Microsoft.NETprovidesmeansbothtoprovidecomponenttechnology,andtointeractwithCOM+(viaCOMinteropassemblies).NET
provideswrapperstomostofthecommonlyusedCOMcontrols.Microsoft.NEThidesmostdetailfromcomponentcreationandthereforeeases
development.
https://en.wikipedia.org/wiki/Component_Object_Model
2/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
.NETcanleverageCOM+viatheSystem.EnterpriseServicesnamespace,andseveraloftheservicesthatCOM+provideshavebeenduplicated
inrecentreleasesof.NET.Forexample,theSystem.Transactionsnamespacein.NETprovidestheTransactionScopeclass,whichprovides
transactionmanagementwithoutresortingtoCOM+.Similarly,queuedcomponentscanbereplacedbyWindowsCommunicationFoundation
withanMSMQtransport.(MSMQisanativeCOMcomponent,however.)
Thereislimitedsupportforbackwardcompatibility.ACOMobjectmaybeusedin.NETbyimplementingaRuntimeCallableWrapper
(RCW).[4]NETobjectsthatconformtocertaininterfacerestrictionsmaybeusedinCOMobjectsbycallingaCOMcallablewrapper(CCW).[5]
FromboththeCOMand.NETsides,objectsusingtheothertechnologyappearasnativeobjects.SeeCOMInterop.
WCF(WindowsCommunicationFoundation)easesanumberofCOM'sremoteexecutionchallenges.Forinstance,itallowsobjectstobe
transparentlymarshalledbyvalueacrossprocessormachineboundariesmoreeasily.
WindowsRuntime
Mainarticle:WindowsRuntime
Microsoft'snewWindowsRuntime(orWinRT,nottobeconfusedwithWindowsRT)programmingandapplicationmodelisessentiallya
COMbasedAPI,althoughitreliesonanenhancedCOM.BecauseofitsCOMlikebasis,WindowsRuntimeallowsrelativelyeasyinterfacing
frommultiplelanguages,justasCOMdoes,butitisessentiallyanunmanaged,nativeAPI.TheAPIdefinitionsare,however,storedin".winmd"
files,whichareencodedinECMA335metadataformat,thesameformatthat.NETuseswithafewmodifications.Thiscommonmetadata
formatallowsforsignificantlylessoverheadthanP/InvokewhenWinRTisinvokedfrom.NETapplications,anditssyntaxismuchsimpler.
Security
COMandActiveXcomponentsarerunasnativecodeontheuser'smachine,withnosandboxing.Therearethereforefewrestrictionsonwhat
thecodecando.ThepriorpracticeofembeddingActiveXcomponentsonwebpageswithInternetExplorerdidthereforeleadtoproblemswith
malwareinfections.MicrosoftrecognizedtheproblemwithActiveXasfarbackas1996whenCharlesFitzgeraldsaid,"Wenevermadethe
claimupfrontthatActiveXisintrinsicallysecure".[6]
RecentversionsofInternetExplorerprompttheuserbeforeinstallingActiveXcontrols,enablingtheusertodisallowinstallationofcontrols
fromsitesthattheuserdoesnottrust.TheActiveXcontrolsaresignedwithdigitalsignaturestoguaranteetheirauthenticity.Itisalsopossibleto
disableActiveXcontrolsaltogether,ortoallowonlyaselectedfew.
ThetransparentsupportforoutofprocessCOMserversstillpromotessoftwaresafetyintermsofprocessisolation.Thiscanbeusefulfor
decouplingsubsystemsoflargeapplicationintoseparateprocesses.Processisolationlimitsstatecorruptioninoneprocessfromnegatively
affectingtheintegrityoftheotherprocesses,sincetheyonlycommunicatethroughstrictlydefinedinterfaces.Thus,onlytheaffectedsubsystem
needstoberestartedinordertoregainvalidstate.Thisisnotthecaseforsubsystemswithinthesameprocess,wherearoguepointerinone
subsystemcanrandomlycorruptothersubsystems.
Technicaldetails
COMprogrammersbuildtheirsoftwareusingCOMawarecomponents.DifferentcomponenttypesareidentifiedbyclassIDs(CLSIDs),which
areGloballyUniqueIdentifiers(GUIDs).EachCOMcomponentexposesitsfunctionalitythroughoneormoreinterfaces.Thedifferent
interfacessupportedbyacomponentaredistinguishedfromeachotherusinginterfaceIDs(IIDs),whichareGUIDstoo.
COMinterfaceshavebindingsinseverallanguages,suchasC,C++,VisualBasic,Delphi,Python[7][8]andseveralofthescriptinglanguages
implementedontheWindowsplatform.Allaccesstocomponentsisdonethroughthemethodsoftheinterfaces.Thisallowstechniquessuchas
interprocess,orevenintercomputerprogramming(thelatterusingthesupportofDCOM).
Interfaces
AllCOMcomponentsimplementtheIUnknown(custom)interface,whichexposesmethodsforreferencecountingandtypeconversion
(casting).
AcustomIUnknowninterfaceconsistsofapointertoavirtualmethodtablethatcontainsalistofpointerstothefunctionsthatimplementthe
functionsdeclaredintheinterface,inthesameorderthattheyaredeclaredintheinterface.Theinprocessinvocationoverheadistherefore
comparabletovirtualmethodcallsinC++.
Inadditiontocustominterfaces,COMalsosupportsdispatchinterfacesinheritingfromIDispatch.Dispatchinterfacessupportlatebindingfor
OLEAutomation.Thisallowsdispatchinterfacestobenativelyaccessedfromawiderrangeofprogramminglanguagesthancustominterfaces.
Classes
https://en.wikipedia.org/wiki/Component_Object_Model
3/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
ACOMclass(coclass)isaconcreteimplementationofoneormoreinterfaces,andcloselyresemblesclassesinobjectorientedprogramming
languages.ClassesarecreatedbasedontheirclassID(CLSID)orbasedontheirprogrammaticidentifierstring(progid).
Likemanyobjectorientedlanguages,COMprovidesaseparationofinterfacefromimplementation.Thisdistinctionisespeciallystrongin
COM,whereobjectscannotbeaccesseddirectly,butonlythroughtheirinterfaces.COMalsohassupportformultipleimplementationsofthe
sameinterface,sothatclientsatruntimecanchoosewhichimplementationofaninterfacetoinstantiate.
InterfaceDefinitionLanguageandtypelibraries
TypelibrariescontainmetadatatorepresentCOMtypes.ThesetypesaredescribedusingMicrosoftInterfaceDefinitionLanguage
(MSIDL/IDL).
IDLfilesdefineobjectorientedclasses,interfaces,structures,enumerationsandotheruserdefinedtypesinalanguageindependentmanner.IDL
issimilarinappearancetoC++declarationswithsomeadditionalkeywordssuchas"interface"and"library"fordefininginterfacesand
collectionsofclasses.IDLalsosupportstheuseofbracketedattributesbeforedeclarationstoprovideadditionalinformation,suchasinterface
GUIDsandtherelationshipsbetweenpointerparametersandlengthfields.
IDLfilesarecompiledbytheMIDLcompiler.ForC/C++,theMIDLcompilergeneratesacompilerindependentheaderfilecontainingstruct
definitionstomatchthevtblsofthedeclaredinterfacesandaCfilecontainingdeclarationsoftheinterfaceGUIDs.C++sourcecodeforaproxy
modulecanalsobegeneratedbytheMIDLcompiler.ThisproxycontainsmethodstubsforconvertingCOMcallsintoremoteprocedurecallsto
enableDCOMforoutofprocesscommunication.
IDLfilescanalsobecompiledbytheMIDLcompilerintoatypelibrary(TLB).TLBfilescontainbinarymetadatathatcanbeprocessedby
differentlanguagecompilersandruntimeenvironments(e.g.VB,Delphi,.NETetc.)togeneratelanguagespecificconstructstorepresentthe
COMtypesdefinedintheTLB.ForC++,thiswillconverttheTLBbacktoitsIDLrepresentation.
COMasanobjectframework
BecauseCOMisaruntimeframework,typeshavetobeindividuallyidentifiableandspecifiableatruntime.Toachievethis,globallyunique
identifiers(GUIDs)areused.EachCOMtypeisdesignateditsownGUIDforidentificationatruntime.
InorderforinformationonCOMtypestobeaccessibleatbothcompiletimeandruntime,COMusestypelibraries.Itisthroughtheeffectiveuse
oftypelibrariesthatCOMachievesitscapabilitiesasadynamicframeworkfortheinteractionofobjects.
ConsiderthefollowingexamplecoclassdefinitioninanIDL:
coclassSomeClass{
[default]interfaceISomeInterface;
};
TheabovecodefragmentdeclaresaCOMclassnamedSomeClasswhichimplementsaninterfacenamedISomeInterface.
ThisisconceptuallyequivalenttodefiningthefollowingC++class:
classSomeClass:publicISomeInterface{
...
...
};
whereISomeInterfaceisaC++purevirtualclass.
TheIDLfilescontainingCOMinterfacesandclassesarecompiledintotypelibraries(TLB)files,whichcanlaterbeparsedbyclientsatruntime
todeterminewhichinterfacesanobjectsupports,andinvokeanobject'sinterfacemethods.
InC++,COMobjectsareinstantiatedwiththeCoCreateInstancefunctionthattakestheclassID(CLSID)andinterfaceID(IID)asarguments.
InstantiationofSomeClasscanbeimplementedasfollows:
ISomeInterface*interface_ptr=NULL
HRESULThr=CoCreateInstance(CLSID_SomeClass,NULL,CLSCTX_ALL,
IID_ISomeInterface,(void**)&interface_ptr);
Inthisexample,theCOMsubsystemisusedtoobtainapointertoanobjectthatimplementsISomeInterfaceinterface,andcoclass
CLSID_SomeClass'sparticularimplementationofthisinterfaceisrequired.
Referencecounting
https://en.wikipedia.org/wiki/Component_Object_Model
4/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
AllCOMobjectsutilizereferencecountingtomanageobjectlifetimes.ThereferencecountsarecontrolledbytheclientsthroughtheAddRefand
ReleasemethodsinthemandatoryIUnknowninterfacethatallCOMobjectsimplement.COMobjectsarethenresponsibleforfreeingtheirown
memorywhenthereferencecountdropstozero.
Certainlanguages(e.g.VisualBasic)provideautomaticreferencecountingsothatCOMobjectdevelopersneednotexplicitlymaintainany
internalreferencecounterintheirsourcecodes.InC++,acodermayeitherperformexplicitreferencecountingorusesmartpointersto
automaticallymanagethereferencecounts.
ThefollowingareguidelinesforwhentocallAddRefandReleaseonCOMobjects:
Functionsandmethodsthatreturninterfacereferences(viareturnvalueorvia"out"parameter)shallincrementthereferencecountofthe
returnedobjectbeforereturning.
Releasemustbecalledonaninterfacepointerbeforethepointerisoverwrittenorgoesoutofscope.
Ifacopyismadeonaninterfacereferencepointer,AddRefshouldbecalledonthatpointer.
AddRefandReleasemustbecalledonthespecificinterfacewhichisbeingreferencedsinceanobjectmayimplementperinterface
referencecountsinordertoallocateinternalresourcesonlyfortheinterfaceswhicharebeingreferenced.
Allreferencecountcallsarenotsentouttoremoteobjectsoverthewireaproxykeepsonlyonereferenceontheremoteobjectandmaintainsits
ownlocalreferencecount.
TosimplifyCOMdevelopment,MicrosoftintroducedATL(ActiveTemplateLibrary)forC++developers.ATLprovidesforahigherlevel
COMdevelopmentparadigm.ItalsoshieldsCOMclientapplicationdevelopersfromtheneedtodirectlymaintainreferencecounting,by
providingsmartpointerobjects.
OtherlibrariesandlanguagesthatareCOMawareincludetheMicrosoftFoundationClasses,theVCCompilerCOMSupport,[9]VBScript,
VisualBasic,ECMAScript(JavaScript)andBorlandDelphi.
Programming
COMisalanguageagnosticbinarystandardthatcanbedevelopedinanyprogramminglanguagecapableofunderstandingandimplementingits
binarydefineddatatypesandinterfaces.
COMimplementationsareresponsibleforenteringandleavingtheCOMenvironment,instantiatingandreferencecountingCOMobjects,
queryingobjectsforsupportedinterfaces,aswellashandlingerrors.
TheMicrosoftVisualC++compilersupportsextensionstotheC++languagereferredtoasC++Attributes.[10]Theseextensionsaredesignedto
simplifyCOMdevelopmentandremovemuchoftheplumbingcoderequiredtoimplementCOMserversinC++.[11]
Registryusage
InWindows,COMclasses,interfacesandtypelibrariesarelistedbyGUIDsintheregistry,underHKEY_CLASSES_ROOT\CLSIDforclasses
andHKEY_CLASSES_ROOT\Interfaceforinterfaces.COMlibrariesusetheregistrytolocateeitherthecorrectlocallibrariesforeachCOM
objectorthenetworklocationforaremoteservice.
RegistrationfreeCOM
RegistrationFreeCOM(RegFreeCOM)isatechnologyintroducedwithWindowsXPthatallowsComponentObjectModel(COM)
componentstostoreactivationmetadataandCLSID(ClassID)forthecomponentwithoutusingtheregistry.Instead,themetadataandCLSIDs
oftheclassesimplementedinthecomponentaredeclaredinanassemblymanifest(describedusingXML),storedeitherasaresourceinthe
executableorasaseparatefileinstalledwiththecomponent.[12]Thisallowsmultipleversionsofthesamecomponenttobeinstalledindifferent
directories,describedbytheirownmanifests,aswellasXCOPYdeployment.[13]ThistechniquehaslimitedsupportforEXECOMservers[14]
andcannotbeusedforsystemwidecomponentssuchasMDAC,MSXML,DirectXorInternetExplorer.
Duringapplicationloading,theWindowsloadersearchesforthemanifest.[15]Ifitispresent,theloaderaddsinformationfromittotheactivation
context[13]WhentheCOMclassfactorytriestoinstantiateaclass,theactivationcontextisfirstcheckedtoseeifanimplementationforthe
CLSIDcanbefound.Onlyifthelookupfailsistheregistryscanned.[13]
Processandnetworktransparency
COMobjectscanbetransparentlyinstantiatedandreferencedfromwithinthesameprocess(inprocess),acrossprocessboundaries(outof
process),orremotelyoverthenetwork(DCOM).Outofprocessandremoteobjectsusemarshallingtoserializemethodcallsandreturnvalues
overprocessornetworkboundaries.Thismarshallingisinvisiblefortheclient,whoaccessestheobjectasifitwerealocalinprocessobject.
Threading
https://en.wikipedia.org/wiki/Component_Object_Model
5/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
InCOM,threadingisaddressedthroughaconceptknownasapartments.[16]AllCOMobjectsliveinexactlyoneapartment,whichmighteither
besinglethreadedormultithreaded.TherearethreetypesofapartmentsinCOM:SingleThreadedApartment(STA),MultiThreaded
Apartment(MTA),andThreadNeutralApartment(NA).Eachapartmentrepresentsonemechanismwherebyanobject'sinternalstatemaybe
synchronizedacrossmultiplethreads.AprocesscanconsistofmultipleCOMobjects,someofwhichmayuseSTAandothersofwhichmayuse
MTA.AllthreadsaccessingCOMobjectssimilarlyliveinoneapartment.ThechoiceofapartmentforCOMobjectsandthreadsaredetermined
atruntime,andcannotbechanged.
Apartmenttype
Description
Asinglethreadisdedicatedtoexecutethemethodsoftheobject.Insuchanarrangement,methodcallsfrom
SingleThreaded
threadsoutsideoftheapartmentaremarshalledandautomaticallyqueuedbythesystem(viaastandard
Windowsmessagequeue).Thus,theCOMruntimeprovidesautomaticsynchronizationtoensurethateach
Apartment[17](STA),
(ThreadingModel=Apartment) methodcallofanobjectisalwaysexecutedtocompletionbeforeanotherisinvoked.Thedevelopertherefore
doesnotneedtoworryaboutthreadlockingorraceconditions.
MultiThreaded
Apartment[18](MTA),
(ThreadingModel=Free)
TheCOMruntimeprovidesnosynchronization,andmultiplethreadsareallowedtocallCOMobjects
simultaneously.COMobjectsthereforeneedtoperformtheirownsynchronizationtopreventsimultaneous
accessfrommultiplethreadsfromcausingaracecondition.CallstoanMTAobjectfromathreadinanSTAare
alsomarshalled.
Dynamicallydetermined
apartment
(ThreadingModel=Both)
IntheBothapartmentmode,theserverautoselectsSTAorMTAatobjectcreationtomatchtheapartmenttype
ofthecallingthread.[19]ThiscanbeusefultoavoidmarshalingoverheadwhenMTAserversareaccessedbya
STAthread.
Aspecialapartmentwithoutanyassignedthreads.WhenaSTAorMTAthreadcallsaNAobjectinthesame
ThreadNeutralApartment process,thenthecallingthreadtemporarilyleavesitsapartmentandexecutescodedirectlyintheNAwithout
(NA),
anythreadswitching.[20]Therefore,onecanthinkofNAasanoptimizationforefficientinterapartmentmethod
(ThreadingModel=Neutral)
calls.
Threadsandobjectswhichbelongtothesameapartmentfollowthesamethreadaccessrules.Methodcallswhicharemadeinsidethesame
apartmentarethereforeperformeddirectlywithoutanyassistancefromCOM.Methodcallsmadeacrossapartmentsareachievedvia
marshalling.Thisrequirestheuseofproxiesandstubs.
Criticisms
SinceCOMhasafairlycompleximplementation,programmerscanbedistractedbysomeofthe"plumbing"issues.
Messagepumping
WhenanSTAisinitializeditcreatesahiddenwindowthatisusedforinterapartmentandinterprocessmessagerouting.Thiswindowmust
haveitsmessagequeueregularlypumped.Thisconstructisknownasamessagepump.OnearlierversionsofWindows,failuretodosocould
causesystemwidedeadlocks.ThisproblemiscomplicatedbysomeWindowsAPIsthatinitializeCOMaspartoftheirimplementation,which
causesaleakofimplementationdetails.
Referencecounting
ReferencecountingwithinCOMmaycauseproblemsiftwoormoreobjectsarecircularlyreferenced.Thedesignofanapplicationmusttake
thisintoaccountsothatobjectsarenotleftorphaned.
ObjectsmayalsobeleftwithactivereferencecountsiftheCOM"eventsink"modelisused.Sincetheobjectthatfirestheeventneedsa
referencetotheobjectreactingtotheevent,theobject'sreferencecountwillneverreachzero.
Referencecyclesaretypicallybrokenusingeitheroutofbandterminationorsplitidentities.Intheoutofbandterminationtechnique,anobject
exposesamethodwhich,whencalled,forcesittodropitsreferencestootherobjects,therebybreakingthecycle.Inthesplitidentitytechnique,a
singleimplementationexposestwoseparateCOMobjects(alsoknownasidentities).ThiscreatesaweakreferencebetweentheCOMobjects,
preventingareferencecycle.
DLLHell
BecauseinprocessCOMcomponentsareimplementedinDLLfilesandregistrationonlyallowsforasingleversionofaDLLperCLSIDthey
mightinsomesituationsbesubjecttothe"DLLHell"effect.RegistrationfreeCOMcapabilityeliminatesthisproblem.
Seealso
Portableobject(computing)crosslanguagecrossplatformObjectModeldefinition
DistributedComponentObjectModel(DCOM),extensionmakingCOMabletoworkinnetworks
https://en.wikipedia.org/wiki/Component_Object_Model
6/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
CommonLanguageInfrastructurecurrent.NETcrosslanguagecrossplatformObjectModel
WindowsRuntime,anapplicationmodel,evolvedversionofCOMtargetingWindows8
CORBACommonObjectRequestBrokerArchitecture,opencrosslanguagecrossplatformobjectmodel
DBusopencrosslanguagecrossplatformObjectModel
KDEKPartKDEcomponentframework
SOMIBMSystemObjectModel,featurerichalternativetoCOM
XPCOMMozillaapplicationscrossPlatformComponentObjectModel
JavaBeans
JavaRemoteMethodInvocation
InternetCommunicationsEngine
Languagebinding
Foreignfunctioninterface
Callingconvention
Namemangling
ApplicationprogramminginterfaceAPI
ApplicationBinaryInterfaceABI
SWIGopensourceautomaticinterfacesbindingsgeneratorfrommanylanguagestootherlanguages
References
1. http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFPlugIns/Concepts/conceptual.html%23//apple_ref/doc/uid/20001160
102910BAJFDFFC
2. "PluginsandMicrosoft'sCOM"
(http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFPlugIns/Concepts/com.html#//apple_ref/doc/uid/20001158
CJBEJBHH).AppleInc.Retrieved20101005.
3. Microsoftforum:BinarycompatibilityacrossVisualC++versions(http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/86eda6a74d904e19
a9d46cbe22b661f4)
4. RuntimeCallableWrapperMSDNLibrary(http://msdn.microsoft.com/enus/library/8bwh56xe.aspx)
5. COMcallablewrapperMSDNLibrary(http://msdn.microsoft.com/f07c8z1c.aspx)
6. http://replay.waybackmachine.org/20060810235058/http://www.javaworld.com/javaworld/jw031997/jw03component.web97.html
7. http://docs.activestate.com/activepython/2.4/pywin32/html/com/win32com/HTML/docindex.html
8. http://www.boddie.org.uk/python/COM.html
9. "CompilerCOMSupport"(http://msdn.microsoft.com/enus/library/h31ekh7e.aspx).MSDN.Microsoft.
10. MicrosoftMSDN:C++AttributesReference(http://msdn.microsoft.com/enUS/library/f520z3b3.aspx)
11. MSDNMagazine:C++Attributes:MakeCOMProgrammingaBreezewithNewFeatureinVisualStudio.NET(http://msdn.microsoft.com/en
us/magazine/cc301337.aspx)
12. "AssemblyManifests"(http://msdn.microsoft.com/enus/library/aa374219(VS.85).aspx).MSDN.Retrieved20091105.
13. DaveTemplin."SimplifyAppDeploymentwithClickOnceandRegistrationFreeCOM"(http://msdn.microsoft.com/enus/magazine/cc188708.aspx).
MSDNMagazine.Retrieved20080422.
14. "HowtouseanoutofprocessCOMserverwithoutitstlbfile"(http://stackoverflow.com/questions/2369181/howtouseanoutofprocesscomserver
withoutitstlbfile).Retrieved20110416.
15. "ConceptsofIsolatedApplicationsandSidebysideAssemblies"(http://msdn.microsoft.com/enus/library/ms235531(VS.80).aspx).MSDN.Retrieved
20091105.
16. MicrosoftMSDN:Processes,Threads,andApartments(http://msdn.microsoft.com/enus/library/windows/desktop/ms693344.aspx)
17. MicrosoftMSDN:SingleThreadedApartments(http://msdn.microsoft.com/enus/library/windows/desktop/ms680112.aspx)
18. MicrosoftMSDN:MultithreadedApartments(http://msdn.microsoft.com/enus/library/windows/desktop/ms693421.aspx)
19. MicrosoftMSDN:UnderstandingandUsingCOMThreadingModels(http://msdn.microsoft.com/enus/library/ms809971.aspx)
20. Codeguru:UnderstandingCOMApartments(http://www.codeguru.com/cpp/comtech/activex/apts/article.php/c5529/UnderstandingCOMApartmentsPart
I.htm)
"COM:ABriefIntroduction(powerpoint)"(http://www.cs.ucr.edu/~dberger/Documents/Presentations/comintro.ppt).RetrievedMarch7,
2006.
Box,Don(1998).EssentialCOM.AddisonWesley.ISBN0201634465.
Chappell,David(1996).UnderstandingActiveXandOLE.MicrosoftPress.ISBN9781572312166.
"IntegrationandMigrationofCOM+servicestoWCF"(http://msdn.microsoft.com/enus/library/bb978523.aspx).RetrievedApril15,
2010.
Externallinks
MicrosoftCOMTechnologies(http://www.microsoft.com/com/)
InterviewwithTonyWilliams,CoInventorofCOM(http://channel9.msdn.com/ShowPost.aspx?PostID=224935)(VideoWebcast,August
2006)
Info:DifferenceBetweenOLEControlsandActiveXControls(http://support.microsoft.com/kb/159621/enus)fromMicrosoft
TypeLibDataFormatSpecification(unofficial)(http://theircorp.byethost11.com/index.php?vw=TypeLib)withopensourcedumperutility.
TheCOM/DCOMGlossary(http://www.innovatia.com/software/papers/com.htm)
Retrievedfrom"https://en.wikipedia.org/w/index.php?title=Component_Object_Model&oldid=681265882"
https://en.wikipedia.org/wiki/Component_Object_Model
7/8
9/22/2015
ComponentObjectModelWikipedia,thefreeencyclopedia
https://en.wikipedia.org/wiki/Component_Object_Model
8/8