维生素c是什么| 五月17号是什么星座| 灵枢是什么意思| 软肋骨炎吃什么药对症| 收是什么生肖| 腺肌瘤是什么病| 老气横秋什么意思| male是什么意思| 颈部ct能检查出什么| 甲亢什么不能吃| 天蓝色配什么颜色| 一个三点水一个有读什么字| 鸡的贵人是什么生肖| 肺炎支原体抗体阳性是什么意思| 大姨夫是什么| 一切有为法是什么意思| 阴道口有点痒用什么药| 做梦梦见狗是什么意思| 复方甘草酸苷片治什么病| mhc是什么意思| 自信过头叫什么| 头晕挂什么科室| 男人硬不起来是什么原因| 高铁服务员叫什么| 子宫癌前期有什么症状| 中性粒细胞百分比低是什么原因| 口腔脱皮是什么原因引起的| 数值是什么意思| 女人腰椎疼是什么原因| 兔死狐悲是什么生肖| ercp是什么检查| 一边脸大一边脸小是什么原因| 道什么意思| 前位子宫和后位子宫有什么区别| 神经性头疼是什么症状| 什么是上火| a和ab型生的孩子是什么血型| 国画是什么| 什么方法睡觉快速入睡| 肿瘤吃什么中药能消除| oem贴牌是什么意思| 过生日送男朋友什么礼物好| 住院医师是什么意思| 川贝是什么| 来大姨妈适合吃什么水果| 随诊什么意思| 蜘蛛结网预示着什么| 血虚风燥是什么意思| 前纵隔结节是什么意思| 梦见自己数钱什么预兆| 大象的鼻子为什么那么长| 五月生日是什么星座| 钠低是什么原因造成的| 宝宝睡觉突然大哭是什么原因| 水仙茶适合什么人喝| 胸部b超挂什么科| 精神寄托是什么意思| 体细胞是什么| 貌不惊人什么意思| 睡觉打呼噜是什么病| 花花世界是什么生肖| 脚起水泡是什么原因| 失眠吃什么食物效果最好| 什么是双减| 用凝胶排出豆腐渣一样的东西是什么原因| 右下腹疼痛挂什么科| 什么叫真菌| 风湿类风湿有什么症状表现| 淋巴结是什么意思| 皮肤黑穿什么颜色的衣服显白| 女攻是什么意思| 咳嗽吃什么好| 高油酸是什么意思| 仓鼠咬笼子是什么原因| 蛇字五行属什么| 非经期出血是什么原因| 心有余而力不足什么意思| 山狸是什么动物| 1963年五行属什么| 手术后吃什么| 万言万当不如一默是什么意思| 我行我素的人什么性格| 湿气重用什么泡脚最好| 感恩节为什么要吃火鸡| 保质期是什么意思| 烛光晚餐是什么意思| 梨状肌综合症吃什么药| 下午六点是什么时辰| 红细胞高说明什么| 嗨体水光针有什么功效| 巡抚相当于现在的什么官| 后循环缺血是什么意思| 左眼皮跳是什么意思| 降血糖吃什么| 做梦梦见兔子是什么意思| 手抖是因为什么| 什么炖鸡汤好喝又营养| 菲妮迪女装是什么档次| 左手麻木是什么原因引起的| 下面瘙痒用什么药| 女人什么血型最聪明| 命悬一线的意思是什么| 7月初二是什么星座| 女人为什么会喷水| pad是什么| 三毛为什么自杀| 芹菜和什么不能一起吃| 血糖低是什么原因引起的| 尿酸偏高有什么危害| 熟地是什么| 榴莲不能和什么吃| 超敏c反应蛋白高说明什么| 干疮是什么样子的图片| 什么的钩住| 世界的尽头是什么| d二聚体高是什么原因| 维生素b吃多了有什么副作用| 天是什么生肖| 为什么感冒吃冰棒反而好了| 南宁有什么好吃的| 硝石是什么| 什么属相不能养龙鱼| 用什么泡脚能减肥| 喉咙痛上火吃什么药效果最好| vin是什么意思| 去湿气吃什么食物好| 夏天脚开裂是什么原因| 什么人吃天麻最好| 代谢慢吃什么效果最快| vertu手机为什么那么贵| 什么是溶血性贫血| 猪头猪脑是什么生肖| 凌晨两点半是什么时辰| 南京有什么| 同型半胱氨酸高有什么症状| 手发热是什么原因| 蟹粉是什么| 间羟胺又叫什么| xxx是什么意思| 追求是什么意思| 人参有什么作用| 补铁吃什么维生素| 玉髓是什么| 冒节子是什么东西| 湿气重可以吃什么水果| 天秤座男生喜欢什么样的女生| 维生素b5又叫什么| 3月什么星座| 千里马比喻什么人| 两只小船儿孤孤零零是什么歌| 珍珠翡翠白玉汤是什么| 什么叫处方药| 腋窝痒是什么原因| 阴囊瘙痒用什么药最好| 什么样的山峰| 上善若水是什么意思| 红男绿女是什么生肖| 什么什么的沙滩| ku是什么单位| 检查脑袋应该挂什么科| 什么是夜店| 性瘾是什么| 大便泡沫状是什么原因| 风热感冒什么症状| 不知道干什么| 腰痛挂什么科| 孕妇头疼可以吃什么药| 为什么会卵巢早衰| 男人额头凹陷预示什么| 鳄鱼为什么流眼泪| 柔然人是现在的什么人| 略施小计是什么动物| 7月是什么生肖| 智齿吃什么消炎药| 心脑供血不足吃什么药效果最好| 壮志凌云是什么生肖| 属蛇的是什么星座| 小孩长得慢是什么原因| 什么是抗氧化| 人大副主任是什么级别| 阴道镜是检查什么的| 中成药是什么| 崩溃什么意思| 凌晨一点是什么时辰| 傍晚是什么时候| 头发掉的多是什么原因| 扯证是什么意思| 乌龙是什么意思| 兰台是什么意思| 电话停机是什么意思| 8月27日什么星座| 营卫不和吃什么中成药| 三个子念什么| 天加一笔变成什么字| 二甲双胍什么时候吃最好| 鹰嘴豆是什么| 水牛吃什么| cas是什么意思| 天狗是什么意思| 兵字五行属什么| 丙申五行属什么| 血脂高吃什么药| 什么东西软化鱼刺最快| 4月15日是什么星座| 红糖有什么功效| 眼睛一直跳是什么原因| 什么情况要割包皮| 巨蟹座的幸运色是什么颜色| 马云父母是做什么的| 伶牙俐齿是什么生肖| 18罗汉都叫什么名字| 手足口病有什么症状| 什么是圆周率| 廿二是什么意思| 梦见前男友死了是什么意思| 喝蒲公英根有什么好处| mri是什么检查| 苹果有什么功效和营养| 八月十三什么星座| 伤口为什么会痒| 恐龙吃什么| 出国旅游需要什么手续和证件| 肾窦分离是什么意思| 吃什么解酒快| 青蒿素是什么| 骨折挂什么科| 正团级是什么军衔| 急忙的反义词是什么| 早醒是什么原因| 吃什么有助于消化| 米粉用什么做的| silk是什么意思| 烂好人什么意思| MD是什么| 胆结石是什么| 乳腺囊实性结节是什么意思| 御史相当于现在什么官| 碎片是什么意思| 93鸡和94狗生什么宝宝| 了解是什么意思| 胎菊和金银花一起泡水有什么效果| 1994属什么生肖| 叩拜是什么意思| 男人结扎有什么好处| 0.5什么意思| 得了幽门螺杆菌是什么症状| 子宫增大是什么原因| 精索静脉曲张是什么意思| 介入超声是什么意思| 什么一气| 脾胃虚寒者有什么症状| 呃是什么意思| 卖淫是什么意思| 协警是什么编制| 射手座男和什么星座最配| 手抖吃什么药马上控制| 小便短赤什么意思| 制动什么意思| 转氨酶高对身体有什么影响| 转氨酶偏高是什么意思| 荨麻疹是由什么引起的| 肾结石吃什么好| 梦见花开是什么预兆| 璟五行属什么| 百度

中国人寿2017年净利润大增68.6%

百度 索网建成后将形成一系列成果,例如,高疲劳性能钢索制造工艺、大跨度索网安装方案等,将对我国索工业水平起到显著提升作用。

Component Object Model (COM) is a binary-interface technology for software components from Microsoft that enables using objects in a language-neutral way between different programming languages, programming contexts, processes and machines.

COM
Component Object Model
AbbreviationCOM
StatusIn force
First published1993; 32 years ago (1993)
Latest versionLiving standard
2021
OrganizationMicrosoft
SeriesSystem Services
Base standardsMIDL, UUID
Related standards
DomainComponent Interfacing
Websitelearn.microsoft.com/en-us/windows/win32/com/the-component-object-model

COM is the basis for other Microsoft domain-specific component technologies including OLE, OLE Automation, ActiveX, COM+, and DCOM as well as implementations such as DirectX, Windows shell, UMDF, Windows Runtime, and Browser Helper Object.

COM enables object use with only knowing its interface; not its internal implementation. The component implementer defines interfaces that are separate from the implementation.

Support for multiple programming contexts is handled by relying on the object for aspects that would be challenging to implement as a facility. Supporting multiple uses of an object is handled by requiring each object to destroy itself via reference-counting. Access to an object's interfaces (similar to Type conversion) is provided by each object as well.

COM is available only in Microsoft Windows and Apple's Core Foundation 1.3 and later plug-in application programming interface (API).[1] The latter only implements a subset of the whole COM interface.[2]

Over time, COM is being replaced with other technologies such as Microsoft .NET and web services (i.e. via WCF). However, COM objects can be used in a .NET language via COM Interop.

COM is similar to other component technologies such as SOM, CORBA and Enterprise JavaBeans, although each has its strengths and weaknesses.

Unlike C++, COM provides a stable application binary interface (ABI) that is unaffected by compiler differences.[3] This makes using COM advantageous for object-oriented C++ libraries that are to be used by clients compiled via different compilers.

History

edit

Introduced in 1987, Dynamic Data Exchange (DDE) was one of the first interprocess communication technologies in Windows.[4][5] It allowed sending and receiving messages in so-called conversations between applications.

Antony Williams, involved in architecting COM, distributed two papers within Microsoft that embraced the concept of software components: Object Architecture: Dealing With the Unknown – or – Type Safety in a Dynamically Extensible Class Library in 1988 and On Inheritance: What It Means and How To Use It in 1990. These provided the foundation of many of the ideas behind COM.

Object Linking and Embedding (OLE), Microsoft's first object-based framework, was built on DDE and designed specifically for compound documents. It was introduced with Word and Excel in 1991, and was later included with Windows, starting with version 3.1 in 1992. An example of a compound document is a spreadsheet embedded in a Word document. As changes are made to the spreadsheet in Excel, they appear automatically in the Word document.

In 1991, Microsoft introduced the Visual Basic Extension (VBX) technology with Visual Basic 1.0. A VBX is a packaged extension in the form of a dynamic-link library (DLL) that allows objects to be graphically placed in a form and manipulated by properties and methods. These were later adapted for use by other languages such as Visual C++. Windows 3.1 integrated OLE 1.0.

In 1992, Microsoft released OLE 2 with its new underlying object model, COM. The COM application binary interface (ABI) was the same as the MAPI ABI (released in 1992), and like it was based on MSRPC and ultimately on the Open Group's DCE/RPC. COM was created to replace DDE since its text-based conversation and Windows messaging design was not flexible enough to allow sharing application features in a robust and extensible way. The COM introduced UUID as identifier.

In 1994, the OLE custom control (OCX) technology, based on COM, was introduced as the successor to VBX. At the same time, Microsoft stated that OLE 2 would be known simply as "OLE". Windows NT 3.5 and Windows 95 integrated OLE 2.0.[6]

In early 1996, Microsoft found a new use for OCX – extending their web browser's capability. Microsoft renamed some parts of OLE relating to the Internet as ActiveX, and gradually renamed all OLE technologies to ActiveX, except the compound document technology that was used in Microsoft Office.

Later in 1996, Microsoft extended COM to work across the network with DCOM.[7]

edit

MSRPC

edit

The COM IDL is based on the feature-rich DCE/RPC IDL, with object-oriented extensions. Microsoft's implementation of DCE/RPC, MSRPC, is used as the primary inter-process communication mechanism for Windows NT services and internal components, making it an obvious choice of foundation.

DCOM

edit

DCOM extends COM from merely supporting a single user with separate applications communicating on the Windows desktop, to activating objects running under different security contexts, and on different machines across the network. With this were added necessary features for configuring which users have authority to create, activate and call objects, for identifying the calling user, as well as specifying required encryption for security of calls.

COM+

edit

Microsoft introduced Microsoft Transaction Server (MTS) in Windows NT 4 in order to provide developers with support for distributed transactions, resource pooling, disconnected applications, event publication and subscription, better memory and processor (thread) management, as well as to position Windows as an alternative to other enterprise-level operating systems.

Renamed to COM+ in Windows 2000, the feature set was incorporated into the operating system as opposed to the series of external tools provided by MTS. At the same time, Microsoft de-emphasized DCOM as a separate entity. Components that used COM+ were handled more directly by the added layer of COM+; in particular by operating system support for interception. In the first release of MTS, interception was tacked on – installing an MTS component would modify the Windows Registry to call the MTS software, and not the component directly.

Windows 2000 included Component Services control panel updates for configuring COM+ components.

An advantage of COM+ was that it could be run in "component farms". Instances of a component, if coded properly, could be pooled and reused by new calls to its initializing routine without unloading it from memory. Components could also be distributed (called from another machine). COM+ and Microsoft Visual Studio provided tools to make it easy to generate client-side proxies, so although DCOM was used to make the remote call, it was easy to do for developers. COM+ also introduced a subscriber/publisher event mechanism called COM+ Events, and provided a new way of leveraging MSMQ (a technology that provides inter-application asynchronous messaging) with components called Queued Components. COM+ events extend the COM+ programming model to support late-bound (see Late binding) events or method calls between the publisher or subscriber and the event system.

.NET

edit

.NET is Microsoft's component technology that supersedes COM. .NET hides many details of component creation and therefore eases development.

.NET provides wrappers to commonly used COM controls.

.NET can leverage COM+ via the System.EnterpriseServices namespace, and several of the services that COM+ provides have been duplicated in .NET. For example, the System.Transactions namespace provides the TransactionScope class, which provides transaction management without resorting to COM+. Similarly, queued components can be replaced by Windows Communication Foundation (WCF) with an MSMQ transport.

There is limited support for backward compatibility. A COM object may be used in .NET by implementing a Runtime Callable Wrapper (RCW).[8] NET objects that conform to certain interface restrictions may be used in COM objects by calling a COM callable wrapper (CCW).[9] From both the COM and .NET sides, objects using the other technology appear as native objects. See COM Interop.

WCF eases a number of COM's remote execution challenges. For instance, it allows objects to be transparently marshalled by value across process or machine boundaries more easily.

Windows Runtime

edit

Windows Runtime (WinRT) is a COM-based API, albeit an enhanced COM variant. Because of its COM-like basis, WinRT supports interfacing from multiple programming contexts, but it is an unmanaged, native API. The API definitions are stored in ".winmd" files, which are encoded in ECMA 335 metadata format; the same CLI metadata format that .NET uses with a few modifications. This metadata format allows for significantly lower overhead than P/Invoke when WinRT is invoked from .NET applications.

Nano-COM

edit

Nano-COM is a subset of COM focused on the application binary interface (ABI) aspects of COM that enable function and method calls across independently compiled modules/components. Nano-COM can be expressed in a portable C++ header file. Nano-COM extends the native ABI of the underlying instruction architecture and OS to support typed object references – whereas a typical ABI focuses on atomic types, structures, arrays and function calling conventions.

A Nano-COM header file defines or names at least three types:

  • GUID – identifies an interface type
  • HRESULT – method result codes such as S_OK, E_FAIL, E_OUTOFMEMORY
  • IUnknown – base type for object references; abstract virtual functions to support dynamic_cast<T>-style acquisition of new interface types and ref counting a la shared_ptr<T>

Many uses of Nano-COM define two functions to address callee-allocated memory buffers as results:

  • <NanoCom>Alloc – called by method implementations to allocate raw buffers (not objects) that are returned to the caller
  • <NanoCom>Free – called by method callers to free callee-allocated buffers when no longer in use

Some implementations of Nano-COM such as Direct3D eschew the allocator functions and restrict themselves to only use caller-allocated buffers.

Nano-COM has no notion of classes, apartments, marshaling, registration, etc. Rather, object references are simply passed across function boundaries and allocated via standard language constructs (e.g., C++ new operator).

The basis of Nano-COM was used by Mozilla to bootstrap Firefox (called XPCOM), and is currently in use as the base ABI technology for DirectX/Direct3D/DirectML.

Security

edit

In Internet Explorer

edit

Since an ActiveX control (any COM component) runs as native code, with no sandboxing protection, there are few restrictions on what it can do. Using ActiveX components, as Internet Explorer supported, in a web page lead to problems with malware infections. Microsoft recognized the problem as far back as 1996 when Charles Fitzgerald said, "We never made the claim up front that ActiveX is intrinsically secure".[10] Later versions of Internet Explorer prompt the user before installing an ActiveX control, allowing them to block installation.

As a level of protection, an ActiveX control is signed with a digital signature to guarantee authenticity.

It is also possible to disable ActiveX controls altogether, or to allow only a selected few.

Process corruption

edit

The transparent support for out-of-process COM servers promotes software safety in terms of process isolation. This can be useful for decoupling subsystems of large application into separate processes. Process isolation limits state corruption in one process from negatively affecting the integrity of the other processes, since they only communicate through strictly defined interfaces. Thus, only the affected subsystem needs to be restarted in order to regain valid state. This is not the case for subsystems within the same process, where a rogue pointer in one subsystem can randomly corrupt other subsystems.

Binding

edit

COM is supported via bindings in several languages, such as C, C++, Visual Basic, Delphi, Python[11][12] and several of the Windows scripting contexts. Component access is via interface methods. This allows for direct calling in-process and via the COM/DCOM sub-system access between processes and computers.

Type system

edit

Coclass

edit

A coclass, a COM class, implements one or more interfaces. It is identified by a class ID, called CLSID which is GUID, and by a human-readable programmatic identifier, called ProgID. A coclass is created via one of these identifiers.

Interface

edit

Each COM interface extends the IUnknown interface, which exposes methods for reference counting and for accessing the other interfaces of the object – similar to type conversion, a.k.a. type casting.

An interface is identified by an interface ID (IID), a GUID.

A custom interface, anything derived from IUnknown, provides early bound access via a pointer to a virtual method table that contains a list of pointers to the functions that implement the functions declared in the interface, in the order they are declared. An in-process invocation overhead is, therefore, comparable to a C++ virtual method call.

Dispatching, a.k.a. late bound access, is provided by implementing IDispatch. Dispatching allows access from a wider range of programming contexts than a custom interface.

Like many object-oriented languages, COM provides a separation of interface from implementation. This distinction is especially strong in COM where an object has no default interface. A client must request an interface to have any access. COM supports multiple implementations of the same interface, so that clients can choose which implementation of an interface to use.

Type library

edit

A COM type library defines COM metadata, such as coclasses and interfaces. A library can be defined as Interface definition language (IDL); a programming language independent syntax. IDL is similar to C++ with additional syntax for defining interfaces and coclasses. IDL also supports bracketed attributes before declarations to define metadata such as identifiers and relationships between parameters.

An IDL file is compiled via the MIDL compiler. For use with C/C++, the MIDL compiler generates a header file with struct definitions to match the vtbls of the declared interfaces and a C file containing declarations of the interface GUIDs. C++ source code for a proxy module can also be generated by the MIDL compiler. This proxy contains method stubs for converting COM calls into remote procedure calls to enable DCOM for out-of-process communication.

MIDL can generate a binary type library (TLB) that can be used by other tools to support access from other context.

Examples

edit

The following IDL code declares a coclass named SomeClass which implements an interface named ISomeInterface.

coclass SomeClass {
  [default] interface ISomeInterface;
};

This is conceptually equivalent to the following C++ code where ISomeInterface is a pure virtual class, a.k.a. abstract base class.

class ISomeInterface {};
class SomeClass : public ISomeInterface {
};

In C++, COM objects are instantiated via the COM subsystem CoCreateInstance function that takes the CLSID and IID. SomeClass can be created as follows:

ISomeInterface* interface_ptr = NULL;
HRESULT hr = CoCreateInstance(CLSID_SomeClass, NULL, CLSCTX_ALL, IID_ISomeInterface, (void**)&interface_ptr);

Reference counting

edit

A COM object uses reference counting to manage object lifetime. An object's reference count is controlled by the clients through the IUnknown AddRef and Release methods. COM objects are responsible for freeing their own memory when the reference count drops to zero. Some programming contexts (e.g. Visual Basic) provide automatic reference counting to simplify object use. In C++, a smart pointer can be used to automate reference count management.

The following are guidelines for when to AddRef and Release should called:

  • A functions that returns an interface reference (via return value or via "out" parameter) increments the count of the returned object
  • Release is called before the interface pointer is overwritten or goes out of scope
  • If a copy is made on an interface reference pointer, AddRef is called
  • AddRef and Release are called on the interface which is being referenced (not a different interface of the same object) since an object may implement per-interface reference counts in order to allocate internal resources only for the interfaces which are being referenced

For remote objects, not all reference count calls are sent over the wire. A a proxy keeps only one reference on the remote object and maintains its own local reference count.

To simplify COM development for C++ developers, Microsoft introduced ATL (Active Template Library). ATL provides a relatively high-level COM development paradigm. It also shields COM client application developers from the need to directly maintain reference counting, by providing smart pointer types. Other libraries and languages that are COM-aware include the Microsoft Foundation Classes, the VC Compiler COM Support,[13] VBScript, Visual Basic, ECMAScript (JavaScript) and Borland Delphi.

Programming context

edit

COM is a language agnostic binary standard that allows objects to be used in any programming context able to access its binary interfaces.

COM client software is responsible for enabling the COM sub-system, instantiating and reference-counting COM objects and querying objects for supported interfaces.

The Microsoft Visual C++ compiler supports extensions to the C++ language, referred to as C++ Attributes, [14] that are designed to simplify COM development and minimize boilerplate code required to implement COM servers in C++.[15]

Type metadata storage

edit

Originally, type library metadata was required to be stored in the system registry. A COM client would use the registry information for object creation.

Registration-free (RegFree) COM was introduced with Windows XP to allow storing type library metadata as an assembly manifest either as a resource in the executable file or in a separate file installed with the component.[16] This allows multiple versions of the same component to be installed on the same computer, in different directories. And it allows for XCOPY deployment.[17] This technology has limited support for EXE COM servers[18] and cannot be used for system-wide components such as MDAC, MSXML, DirectX or Internet Explorer.

During application loading, the Windows loader searches for the manifest.[19] If it is present, the loader adds information from it to the activation context.[17] When the COM class factory tries to instantiate a class, the activation context is first checked to see if an implementation for the CLSID can be found. Only if the lookup fails, the registry is scanned.[17]

A COM object can be created without type library information; with only a path to the DLL file and CLSID. A client can use the COM DLL function DllGetClassObject with the CLSID and IID_IClassFactory to create an instance of a factory object. The client can then use the factory object's CreateInstance to create an instance.[20] This is the same process the COM sub-system uses.[21] If an object created this way creates another object, it will do so in the usual way (using the registry or manifest). But it can create internal objects (which may not be registered at all), and hand out references to interfaces to them, using its own private knowledge.

Marshalling

edit

A COM object can be transparently created and used from within the same process (in-process), across process boundaries (out-of-process), or remotely over the network (DCOM). Out-of-process and remote objects use marshalling to serialize method calls and return values over process or network boundaries. This marshalling is invisible to the client, which accesses the object as if it were a local in-process object.

Threading

edit

In COM, threading is addressed through a concept known as apartments.[22] An individual COM object lives in exactly one apartment, which might either be single-threaded or multi-threaded. There are three types of apartments in COM: Single-Threaded Apartment (STA), Multi-Threaded Apartment (MTA), and Thread Neutral Apartment (NA). Each apartment represents one mechanism whereby an object's internal state may be synchronized across multiple threads. A process can consist of multiple COM objects, some of which may use STA and others of which may use MTA. All threads accessing COM objects similarly live in one apartment. The choice of apartment for COM objects and threads are determined at run-time, and cannot be changed.

Apartment type Threading model Description
Single-Threaded Apartment[23] (STA)

Apartment

A single thread is dedicated to execute the methods of the object. Method calls from threads outside of the apartment are marshalled and automatically queued by the system (via Windows messaging). Thus, the COM run-time provides synchronization to ensure that each method call to the object is executed to completion before another is invoked.

Multi-Threaded Apartment[24] (MTA) Free

The COM run-time provides no synchronization, and multiple threads are allowed to call object methods simultaneously. The object need to handle synchronization to prevent simultaneous access from multiple threads from problems. Calls to an MTA object from a thread in an STA are also marshalled.

Dynamically determined apartment

Both

The server auto-selects STA or MTA at object creation to match the apartment type of the calling thread.[25] This can be useful to avoid marshalling overhead when MTA servers are accessed by a STA thread.

Thread Neutral Apartment (NA) Neutral

A special apartment without any assigned threads. When an STA or MTA thread calls an NA object in the same process, then the calling thread temporarily leaves its apartment and executes code directly in the NA without any thread switching.[26] Therefore, one can think of NA as an optimization for efficient interapartment method calls.

Threads and objects which belong to the same apartment follow the same thread access rules. Method calls which are made inside the same apartment are therefore performed directly without any assistance from COM. Method calls made across apartments are achieved via marshalling. This requires the use of proxies and stubs.

Criticisms

edit

Complexity

edit

COM is relatively complex especially compared to more modern component technologies such as .NET.

Message pumping

edit

When an STA is initialized it creates a hidden window that is used for inter-apartment and inter-process message routing. This window must have its message queue regularly "pumped". This construct is known as a "message pump". On earlier versions of Windows, failure to do so could cause system-wide deadlocks. This problem is complicated by some Windows APIs that initialize COM as part of their implementation, which causes a "leak" of implementation details.[27]

Reference counting

edit

Reference counting within COM may cause problems if two or more objects are circularly referenced. The design of an application must take this into account so that objects are not left orphaned. Objects may also be left with active reference counts if the COM "event sink" model is used. Since the object that fires the event needs a reference to the object reacting to the event, the latter's reference count will never reach zero. Reference cycles are typically broken using either out-of-band termination or split identities. In the out-of-band termination technique, an object exposes a method which, when called, forces it to drop its references to other objects, thereby breaking the cycle. In the split identity technique, a single implementation exposes two separate COM objects (also known as identities). This creates a weak reference between the COM objects, preventing a reference cycle.[28]

DLL Hell

edit

Because in-process COM components are implemented in DLL files and registration only allows for a single version per CLSID, they might in some situations be subject to the "DLL Hell" effect. Registration-free COM capability eliminates this problem for in-process components; registration-free COM is not available for out-of-process servers.

See also

edit

Notes

edit
  1. ^ "Documentation Archive". developer.apple.com.
  2. ^ "Plug-ins and Microsoft's COM". Apple Inc. Retrieved October 5, 2010.
  3. ^ Microsoft forum: Binary compatibility across Visual C++ versions
  4. ^ "About Network DDE - Windows applications". Microsoft.com. May 30, 2018.
  5. ^ "Code Execution Technique Takes Advantage of Dynamic Data Exchange". McAfee.com. October 27, 2017.
  6. ^ Advanced Windows (The Developer's Guide to the Win32 API for Windows NT 3.5 and Windows 95)
  7. ^ Brown, Nina; Kindel, Charlie (March 11, 1998). "draft-brown-dcom-v1-spec-03 - Distributed Component Object Model Protocol -- DCOM/1.0". Ietf Datatracker. Retrieved August 29, 2019.
  8. ^ rpetrusha (April 19, 2023). "Runtime Callable Wrapper". msdn.microsoft.com.
  9. ^ rpetrusha (September 15, 2021). "COM Callable Wrapper". msdn.microsoft.com.
  10. ^ Steinberg, Jill (March 1, 1997). "Competing components make for prickly panelists". JavaWorld. Retrieved 2025-08-06.
  11. ^ "win32com Documentation Index". docs.activestate.com.
  12. ^ "Python and COM". www.boddie.org.uk.
  13. ^ "Compiler COM Support". MSDN. Microsoft. August 3, 2021.
  14. ^ Microsoft MSDN: C++ Attributes Reference
  15. ^ MSDN Magazine: C++ Attributes: Make COM Programming a Breeze with New Feature in Visual Studio .NET
  16. ^ "Assembly Manifests". MSDN. Retrieved November 5, 2009.
  17. ^ a b c Dave Templin. "Simplify App Deployment with ClickOnce and Registration-Free COM". MSDN Magazine. Retrieved April 22, 2008.
  18. ^ "How to use an out-of-process COM server without its tlb file". Retrieved April 16, 2011.
  19. ^ "Concepts of Isolated Applications and Side-by-side Assemblies". MSDN. Retrieved February 5, 2016.
  20. ^ Arkhipov, Mikhail (April 1, 2005). "Registration-free COM". MSDN Blogs. Retrieved April 29, 2016.
  21. ^ "DllGetClassObject entry point (COM)". MSDN. If a call to the CoGetClassObject function finds the class object that is to be loaded in a DLL, CoGetClassObject uses the DLL's exported DllGetClassObject function.
  22. ^ Microsoft MSDN: Processes, Threads, and Apartments
  23. ^ Microsoft MSDN: Single-Threaded Apartments
  24. ^ Microsoft MSDN: Multithreaded Apartments
  25. ^ Microsoft MSDN: Understanding and Using COM Threading Models
  26. ^ Codeguru: Understanding COM Apartments Archived May 24, 2021, at the Wayback Machine
  27. ^ Brumme, Chris. "Apartments and Pumping in the CLR". Chris Brumme's Weblog. Retrieved June 26, 2025.
  28. ^ Wolfe, Mike (March 31, 2022). "Reference Counting's Fatal Flaw: Circular References". No Longer Set. Retrieved June 26, 2025.

References

edit
edit
蒟蒻是什么东西 办香港通行证要准备什么材料 想吃咸的是身体缺什么 文艺范是什么意思 胃痛可以吃什么水果
什么茶好喝 mchc偏低是什么意思 图灵是什么意思 银行降息意味着什么 顶到子宫是什么感觉
高胆固醇血症是什么病 为什么会长子宫肌瘤 为什么会胃酸反流 apc是什么药 医士是什么职称
久站腿肿是什么原因引起的 狗狗尾巴溃烂用什么药 丁丁是什么意思 五更是什么生肖 膈肌痉挛是什么症状
喝什么粥养胃hcv9jop3ns5r.cn 骨折不能吃什么hcv9jop0ns4r.cn 可以组什么词语hcv9jop5ns6r.cn ak是什么意思hcv8jop6ns8r.cn 撒是什么意思hcv8jop5ns5r.cn
吃什么水果能美白hcv8jop5ns1r.cn 6月13日是什么星座hcv8jop7ns4r.cn 胆大包天是什么生肖hcv8jop1ns5r.cn 喊6个1是什么意思hcv8jop6ns7r.cn 心率偏低是什么原因bjhyzcsm.com
羊水透声欠佳什么意思hcv7jop9ns0r.cn 世界上最大的鱼是什么hcv9jop4ns8r.cn 怀孕要检查什么项目hcv8jop3ns9r.cn 吃什么药hcv9jop2ns4r.cn 头三个月保胎喝什么汤hcv9jop2ns0r.cn
宫腔线不清晰什么意思hcv9jop0ns1r.cn 脚侧面骨头突出叫什么hcv8jop1ns0r.cn benny是什么意思hcv7jop5ns2r.cn 检查有没有怀孕挂什么科hcv8jop5ns5r.cn 感冒吃什么消炎药hcv8jop6ns3r.cn
百度