0% found this document useful (0 votes)
249 views8 pages

Component Object Model

The document discusses the Component Object Model (COM) which is a binary interface standard introduced by Microsoft in 1993 that allows software components to communicate between processes and enables dynamic object creation in different programming languages. COM became the basis for technologies like OLE, ActiveX, COM+ and DCOM and is still used in Windows components like the shell and DirectX. It provides language-neutral reusable software components through well-defined interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
249 views8 pages

Component Object Model

The document discusses the Component Object Model (COM) which is a binary interface standard introduced by Microsoft in 1993 that allows software components to communicate between processes and enables dynamic object creation in different programming languages. COM became the basis for technologies like OLE, ActiveX, COM+ and DCOM and is still used in Windows components like the shell and DirectX. It provides language-neutral reusable software components through well-defined interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

ComponentObjectModel
FromWikipedia,thefreeencyclopedia

NottobeconfusedwithCOMfile.
ComponentObjectModel(COM)[Link]
[Link]
Microsofttechnologiesandframeworks,includingOLE,OLEAutomation,ActiveX,COM+,DCOM,theWindowsshell,DirectX,UMDFand
WindowsRuntime.

Contents
1Overview
2History
3Relatedtechnologies
3.1COM+andDCOM
[Link]
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,[Link],COMallowsreuseofobjectswithnoknowledgeoftheirinternal
implementation,[Link]
differentallocationsemanticsoflanguagesareaccommodatedbymakingobjectsresponsiblefortheirowncreationanddestructionthrough
[Link]
inheritancewithinCOMisthecreationofsubobjectstowhichmethodcallsaredelegated.
COMisaninterfacetechnologydefinedandimplementedasstandardonlyonMicrosoftWindowsandApple'sCoreFoundation1.3andlater
pluginAPI,[1]thatinanycaseimplementonlyasubsetofthewholeCOMinterface.[2]Forsomeapplications,COMhasbeenreplacedatleastto
[Link],andsupportforWebServicesthroughtheWindowsCommunicationFoundation(WCF).
However,[Link],
[Link],such
asCORBAandJavaBeans,althougheachhasitsownstrengthsandweaknesses.
UnlikeC++,COMprovidesastableABIthatdoesnotchangebetweencompilerreleases.[3]ThismakesCOMinterfacesattractiveforobject
orientedC++librariesthataretobeusedbyclientscompiledusingdifferentcompilerversions.

History
OneofthefirstmethodsofinterprocesscommunicationinWindowswasDynamicDataExchange(DDE),firstintroducedin1987,thatallowed
sendingandreceivingmessagesinsocalled"conversations"betweenapplications.
[Link]

1/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

AntonyWilliams,oneofthemostnotablethinkersinvolvedinthecreationoftheCOMarchitecture,laterdistributedtwointernalpapersin
Microsoftthatembracedtheconceptofsoftwarecomponents:ObjectArchitecture:DealingWiththeUnknownorTypeSafetyina
DynamicallyExtensibleClassLibraryin1988andOnInheritance:[Link]
manyoftheideasbehindCOM.
ObjectLinkingandEmbedding(OLE),Microsoft'sfirstobjectbasedframework,wasbuiltontopofDDEanddesignedspecificallyfor
compounddocuments.ItwasintroducedwithWordforWindowsandExcelin1991,andwaslaterincludedwithWindows,startingwithversion
3.1in1992.
AnexampleofacompounddocumentisaspreadsheetembeddedinaWordforWindowsdocument:aschangesaremadetothespreadsheet
withinExcel,theyappearautomaticallyinsidetheWorddocument.
In1991,MicrosoftintroducedVisualBasicExtensions(VBX)[Link]
linklibrary(DLL)[Link]
forusebyotherlanguagessuchasVisualC++.
In1992,whenversion3.1ofWindowswasreleased,[Link]
interface(ABI)wasthesameastheMAPIABI,whichwasreleasedin1992.WhileOLE1wasfocusedoncompounddocuments,COMand
[Link]
enoughtoallowsharingapplicationfeaturesinarobustandextensibleway,soCOMwascreatedasanewfoundation,andOLEchangedto
OLE2.
In1994OLEcustomcontrols(OCXs)[Link],MicrosoftstatedthatOLE2would
justbeknownas"OLE",andthatOLEwasnolongeranacronym,butanameforallofthecompany'scomponenttechnologies.
Inearly1996,MicrosoftfoundanewuseforOLECustomControls,expandingtheirWebbrowser'scapabilitytopresentcontent,renamedsome
partsofOLErelatingtotheInternet"ActiveX",andgraduallyrenamedallOLEtechnologiestoActiveX,exceptthecompounddocument
[Link],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,[Link]
COM+serviceswerehandledmoredirectlybytheaddedlayerofCOM+,[Link]
releaseofMTS,interceptionwastackedoninstallinganMTScomponentwouldmodifytheWindowsRegistrytocalltheMTSsoftware,and
notthecomponentdirectly.
Windows2000alsorevisedtheComponentServicescontrolpanelapplicationusedtoconfigureCOM+components.
AnadvantageofCOM+wasthatitcouldberunin"componentfarms".Instancesofacomponent,ifcodedproperly,couldbepooledandreused
[Link](calledfromanothermachine).
COM+andMicrosoftVisualStudioprovidedtoolstomakeiteasytogenerateclientsideproxies,soalthoughDCOMwasusedtomakethe
remotecall,itwaseasytodofordevelopers.
COM+alsointroducedasubscriber/publishereventmechanismcalledCOM+Events,andprovidedanewwayofleveragingMSMQ(inter
applicationasynchronousmessaging)[Link]+eventsextendtheCOM+programmingmodelto
supportlatebound(seeLatebinding)eventsormethodcallsbetweenthepublisherorsubscriberandtheeventsystem.

.NET
Mainarticle:.NETFramework
[Link],andtointeractwithCOM+(viaCOMinteropassemblies).NET
[Link]
development.

[Link]

2/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

.NETcanleverageCOM+[Link],andseveraloftheservicesthatCOM+provideshavebeenduplicated
[Link],[Link],whichprovides
transactionmanagementwithoutresortingtoCOM+.Similarly,queuedcomponentscanbereplacedbyWindowsCommunicationFoundation
withanMSMQtransport.(MSMQisanativeCOMcomponent,however.)
[Link]
(RCW).[4]NETobjectsthatconformtocertaininterfacerestrictionsmaybeusedinCOMobjectsbycallingaCOMcallablewrapper(CCW).[5]
[Link],[Link].
WCF(WindowsCommunicationFoundation)easesanumberofCOM'[Link],itallowsobjectstobe
transparentlymarshalledbyvalueacrossprocessormachineboundariesmoreeasily.

WindowsRuntime
Mainarticle:WindowsRuntime
Microsoft'snewWindowsRuntime(orWinRT,nottobeconfusedwithWindowsRT)programmingandapplicationmodelisessentiallya
COMbasedAPI,[Link],WindowsRuntimeallowsrelativelyeasyinterfacing
frommultiplelanguages,justasCOMdoes,butitisessentiallyanunmanaged,[Link],however,storedin".winmd"
files,whichareencodedinECMA335metadataformat,[Link]
formatallowsforsignificantlylessoverheadthanP/[Link],anditssyntaxismuchsimpler.

Security
COMandActiveXcomponentsarerunasnativecodeontheuser'smachine,[Link]
[Link]
malwareinfections.MicrosoftrecognizedtheproblemwithActiveXasfarbackas1996whenCharlesFitzgeraldsaid,"Wenevermadethe
claimupfrontthatActiveXisintrinsicallysecure".[6]
RecentversionsofInternetExplorerprompttheuserbeforeinstallingActiveXcontrols,enablingtheusertodisallowinstallationofcontrols
[Link]
disableActiveXcontrolsaltogether,ortoallowonlyaselectedfew.
[Link]
[Link]
affectingtheintegrityoftheotherprocesses,[Link],onlytheaffectedsubsystem
[Link],wherearoguepointerinone
subsystemcanrandomlycorruptothersubsystems.

Technicaldetails
[Link](CLSIDs),which
areGloballyUniqueIdentifiers(GUIDs).[Link]
interfacessupportedbyacomponentaredistinguishedfromeachotherusinginterfaceIDs(IIDs),whichareGUIDstoo.
COMinterfaceshavebindingsinseverallanguages,suchasC,C++,VisualBasic,Delphi,Python[7][8]andseveralofthescriptinglanguages
[Link]
interprocess,orevenintercomputerprogramming(thelatterusingthesupportofDCOM).

Interfaces
AllCOMcomponentsimplementtheIUnknown(custom)interface,whichexposesmethodsforreferencecountingandtypeconversion
(casting).
AcustomIUnknowninterfaceconsistsofapointertoavirtualmethodtablethatcontainsalistofpointerstothefunctionsthatimplementthe
functionsdeclaredintheinterface,[Link]
comparabletovirtualmethodcallsinC++.
Inadditiontocustominterfaces,[Link]
[Link].

Classes

[Link]

3/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

ACOMclass(coclass)isaconcreteimplementationofoneormoreinterfaces,andcloselyresemblesclassesinobjectorientedprogramming
[Link](CLSID)orbasedontheirprogrammaticidentifierstring(progid).
Likemanyobjectorientedlanguages,[Link]
COM,whereobjectscannotbeaccesseddirectly,[Link]
sameinterface,sothatclientsatruntimecanchoosewhichimplementationofaninterfacetoinstantiate.

InterfaceDefinitionLanguageandtypelibraries
[Link]
(MSIDL/IDL).
IDLfilesdefineobjectorientedclasses,interfaces,structures,[Link]
issimilarinappearancetoC++declarationswithsomeadditionalkeywordssuchas"interface"and"library"fordefininginterfacesand
[Link],suchasinterface
GUIDsandtherelationshipsbetweenpointerparametersandlengthfields.
[Link]/C++,theMIDLcompilergeneratesacompilerindependentheaderfilecontainingstruct
definitionstomatchthevtblsofthedeclaredinterfacesandaCfilecontainingdeclarationsoftheinterfaceGUIDs.C++sourcecodeforaproxy
[Link]
enableDCOMforoutofprocesscommunication.
IDLfilescanalsobecompiledbytheMIDLcompilerintoatypelibrary(TLB).TLBfilescontainbinarymetadatathatcanbeprocessedby
differentlanguagecompilersandruntimeenvironments([Link],Delphi,.NETetc.)togeneratelanguagespecificconstructstorepresentthe
[Link]++,thiswillconverttheTLBbacktoitsIDLrepresentation.

COMasanobjectframework
BecauseCOMisaruntimeframework,[Link],globallyunique
identifiers(GUIDs)[Link].
InorderforinformationonCOMtypestobeaccessibleatbothcompiletimeandruntime,[Link]
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
[Link]

4/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

[Link]
[Link]
memorywhenthereferencecountdropstozero.
Certainlanguages([Link])provideautomaticreferencecountingsothatCOMobjectdevelopersneednotexplicitlymaintainany
[Link]++,acodermayeitherperformexplicitreferencecountingorusesmartpointersto
automaticallymanagethereferencecounts.
ThefollowingareguidelinesforwhentocallAddRefandReleaseonCOMobjects:
Functionsandmethodsthatreturninterfacereferences(viareturnvalueorvia"out"parameter)shallincrementthereferencecountofthe
returnedobjectbeforereturning.
Releasemustbecalledonaninterfacepointerbeforethepointerisoverwrittenorgoesoutofscope.
Ifacopyismadeonaninterfacereferencepointer,AddRefshouldbecalledonthatpointer.
AddRefandReleasemustbecalledonthespecificinterfacewhichisbeingreferencedsinceanobjectmayimplementperinterface
referencecountsinordertoallocateinternalresourcesonlyfortheinterfaceswhicharebeingreferenced.
Allreferencecountcallsarenotsentouttoremoteobjectsoverthewireaproxykeepsonlyonereferenceontheremoteobjectandmaintainsits
ownlocalreferencecount.
TosimplifyCOMdevelopment,MicrosoftintroducedATL(ActiveTemplateLibrary)forC++[Link]
[Link],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\[Link]
objectorthenetworklocationforaremoteservice.

RegistrationfreeCOM
RegistrationFreeCOM(RegFreeCOM)isatechnologyintroducedwithWindowsXPthatallowsComponentObjectModel(COM)
componentstostoreactivationmetadataandCLSID(ClassID)[Link],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
[Link].[13]

Processandnetworktransparency
COMobjectscanbetransparentlyinstantiatedandreferencedfromwithinthesameprocess(inprocess),acrossprocessboundaries(outof
process),orremotelyoverthenetwork(DCOM).Outofprocessandremoteobjectsusemarshallingtoserializemethodcallsandreturnvalues
[Link],whoaccessestheobjectasifitwerealocalinprocessobject.

Threading
[Link]

5/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

InCOM,threadingisaddressedthroughaconceptknownasapartments.[16]AllCOMobjectsliveinexactlyoneapartment,whichmighteither
[Link]:SingleThreadedApartment(STA),MultiThreaded
Apartment(MTA),andThreadNeutralApartment(NA).Eachapartmentrepresentsonemechanismwherebyanobject'sinternalstatemaybe
[Link],someofwhichmayuseSTAandothersofwhichmayuse
[Link]
atruntime,andcannotbechanged.
Apartmenttype

Description

[Link],methodcallsfrom
SingleThreaded
threadsoutsideoftheapartmentaremarshalledandautomaticallyqueuedbythesystem(viaastandard
Windowsmessagequeue).Thus,theCOMruntimeprovidesautomaticsynchronizationtoensurethateach
Apartment[17](STA),
(ThreadingModel=Apartment) [Link]
doesnotneedtoworryaboutthreadlockingorraceconditions.
MultiThreaded
Apartment[18](MTA),
(ThreadingModel=Free)

TheCOMruntimeprovidesnosynchronization,andmultiplethreadsareallowedtocallCOMobjects
[Link]
[Link]
alsomarshalled.

Dynamicallydetermined
apartment
(ThreadingModel=Both)

IntheBothapartmentmode,theserverautoselectsSTAorMTAatobjectcreationtomatchtheapartmenttype
ofthecallingthread.[19]ThiscanbeusefultoavoidmarshalingoverheadwhenMTAserversareaccessedbya
STAthread.

[Link]
ThreadNeutralApartment process,thenthecallingthreadtemporarilyleavesitsapartmentandexecutescodedirectlyintheNAwithout
(NA),
anythreadswitching.[20]Therefore,onecanthinkofNAasanoptimizationforefficientinterapartmentmethod
(ThreadingModel=Neutral)
calls.
[Link]
[Link]
[Link].

Criticisms
SinceCOMhasafairlycompleximplementation,programmerscanbedistractedbysomeofthe"plumbing"issues.

Messagepumping
[Link]
[Link],failuretodosocould
[Link],which
causesaleakofimplementationdetails.

Referencecounting
[Link]
thisintoaccountsothatobjectsarenotleftorphaned.
ObjectsmayalsobeleftwithactivereferencecountsiftheCOM"eventsink"[Link]
referencetotheobjectreactingtotheevent,theobject'sreferencecountwillneverreachzero.
[Link],anobject
exposesamethodwhich,whencalled,forcesittodropitsreferencestootherobjects,[Link],a
singleimplementationexposestwoseparateCOMobjects(alsoknownasidentities).ThiscreatesaweakreferencebetweentheCOMobjects,
preventingareferencecycle.

DLLHell
BecauseinprocessCOMcomponentsareimplementedinDLLfilesandregistrationonlyallowsforasingleversionofaDLLperCLSIDthey
mightinsomesituationsbesubjecttothe"DLLHell"[Link].

Seealso
Portableobject(computing)crosslanguagecrossplatformObjectModeldefinition
DistributedComponentObjectModel(DCOM),extensionmakingCOMabletoworkinnetworks
[Link]

6/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

[Link]
WindowsRuntime,anapplicationmodel,evolvedversionofCOMtargetingWindows8
CORBACommonObjectRequestBrokerArchitecture,opencrosslanguagecrossplatformobjectmodel
DBusopencrosslanguagecrossplatformObjectModel
KDEKPartKDEcomponentframework
SOMIBMSystemObjectModel,featurerichalternativetoCOM
XPCOMMozillaapplicationscrossPlatformComponentObjectModel
JavaBeans
JavaRemoteMethodInvocation
InternetCommunicationsEngine
Languagebinding
Foreignfunctioninterface
Callingconvention
Namemangling
ApplicationprogramminginterfaceAPI
ApplicationBinaryInterfaceABI
SWIGopensourceautomaticinterfacesbindingsgeneratorfrommanylanguagestootherlanguages

References
1. [Link]
102910BAJFDFFC
2. "PluginsandMicrosoft'sCOM"
([Link]
CJBEJBHH).AppleInc.Retrieved20101005.
3. Microsoftforum:BinarycompatibilityacrossVisualC++versions([Link]
a9d46cbe22b661f4)
4. RuntimeCallableWrapperMSDNLibrary([Link]
5. COMcallablewrapperMSDNLibrary([Link]
6. [Link]
7. [Link]
8. [Link]
9. "CompilerCOMSupport"([Link]
10. MicrosoftMSDN:C++AttributesReference([Link]
11. MSDNMagazine:C++Attributes:[Link]([Link]
us/magazine/[Link])
12. "AssemblyManifests"([Link]
13. DaveTemplin."SimplifyAppDeploymentwithClickOnceandRegistrationFreeCOM"([Link]
MSDNMagazine.Retrieved20080422.
14. "HowtouseanoutofprocessCOMserverwithoutitstlbfile"([Link]
withoutitstlbfile).Retrieved20110416.
15. "ConceptsofIsolatedApplicationsandSidebysideAssemblies"([Link]
20091105.
16. MicrosoftMSDN:Processes,Threads,andApartments([Link]
17. MicrosoftMSDN:SingleThreadedApartments([Link]
18. MicrosoftMSDN:MultithreadedApartments([Link]
19. MicrosoftMSDN:UnderstandingandUsingCOMThreadingModels([Link]
20. Codeguru:UnderstandingCOMApartments([Link]
[Link])

"COM:ABriefIntroduction(powerpoint)"([Link]
2006.
Box,Don(1998).[Link].ISBN0201634465.
Chappell,David(1996).[Link].ISBN9781572312166.
"IntegrationandMigrationofCOM+servicestoWCF"([Link]
2010.

Externallinks
MicrosoftCOMTechnologies([Link]
InterviewwithTonyWilliams,CoInventorofCOM([Link]
2006)
Info:DifferenceBetweenOLEControlsandActiveXControls([Link]
TypeLibDataFormatSpecification(unofficial)([Link]
TheCOM/DCOMGlossary([Link]
Retrievedfrom"[Link]
[Link]

7/8

9/22/2015

ComponentObjectModelWikipedia,thefreeencyclopedia

Categories: Componentbasedsoftwareengineering Interprocesscommunication Microsoftapplicationprogramminginterfaces


Objectorientedprogramming Objectmodels Objectrequestbroker
Thispagewaslastmodifiedon16September2015,at05:36.
[Link],youagreeto
[Link],Inc.,anonprofitorganization.

[Link]

8/8

You might also like