COM / OLE / ActiveX / IDispatch confusion

2020-05-27 15:12发布

问题:

I can't wrap my head around the differences among these terms.

Are COM and ActiveX synonyms?

Is ActiveX object just a COM object that exposes IDispatch?

Lots of older MSDN pages mention IDispatch without any COM context. Does it have a separate history, and was just introduced under the COM 'umbrella' later in its lifecycle?

Where does OLE fit in? Is its (considerable) presence in MFC naming and MSDN in general - all just legacy?

Wikipedia gives some insight, but not much. I couldn't find a more in depth reference.

回答1:

Found some quotes from COM Programming by Example:

Another thing you'll quickly find with COM is that marketing had a field trip day with the terminology. Rather then helping to promote understanding, you'll find in most cases it promotes mystery. ... OLE, ActiveX, Remotable Objects - which one means what this week? ...

COM evolved out of the solution to a specific problem - how to allow a word processor to edit the spreadsheet in a letter without the user having to exit the word processor to do it. This solution was called OLE. ... However, with the second release of OLE (OLE2), its creators modified OLE32.DLL to expose more of the basic functionality of OLE so that its API could be used to allow any application to acess the functionality of another. This API, which hasn't changed much since 1993, is what is considered to be the COM API. ...

Once the COM API was exposed, Microsoft used it to create what were then called OLE controls to allow sophisticated controls (e.g., buttons that spiral, list boxes that play music) written in Visual C++ to be accessible to Visual Basic applications. Eventually this same technology was used to allow a control to be downloaded and used by your web browser. At this point, the name changed to ActiveX controls or just plain ActiveX purely for marketing reasons. Although you can package any functionality in an ActiveX Control, its requrirements have been specialized for supporting a user interface control.

I'm still curious about the very last sentence - must a COM object satisfy some additional requirements to qualify as an ActiveX control? - but its enough to let it go.

Thanks for your answers!



回答2:

ActiveX is marketing-ese for COM, although ActiveX is usually used in the context of "ActiveX controls" which are GUI objects.

IDispatch is an interface implemented by COM objects so that client programs can call its methods dynamically at run-time (late-binding), as opposed to at compile time where all the methods and argument types need to be known ahead of time.

OLE is the earlier version of COM.



回答3:

Regarding OLE: COM has its roots in OLE. But today, OLE may be considered to be built on top of COM and is mostly used for what its name suggests -- document linking and embedding. While COM itself defines only a couple of interfaces itself (IUnknown, IClassFactory, IMalloc etc), OLE adds a whole bunch of additional interfaces like IMoniker, IOleItemComtainer, etc.

To sum up: COM is the foundation, ActiveX and OLE are layers on top of COM.