阿q精神是什么意思| 清创手术是什么意思| 肝囊性灶是什么意思| ce是什么元素| 吃什么补充雌激素| 六尘不染的生肖是什么| 吃什么水果减肥| 东南角风水代表什么| 以至于是什么意思| 大姨妈来的少是什么原因| 孩子睡觉磨牙是什么原因| 奶粉罐可以做什么手工| 薏米有什么功效| 冬至吃什么| 驻马店以前叫什么名字| 蚊虫叮咬过敏用什么药| 梦到丢了一只鞋是什么意思| 喀秋莎什么意思| 属狗女和什么属相最配| 为什么气血不足| 小暑是什么时候| 出家当尼姑需要什么条件| 宫外孕有什么危害| 脑心通主治什么病| 腿抽筋吃什么药| 什么时候大阅兵| 做胃镜前喝的那个液体是什么| 摆地摊卖什么最赚钱而且很受欢迎| 百合病是什么病| 为什么会基因突变| 什么叫蛇胆疮| 浮躁的意思是什么| 女性雄激素过高是什么原因引起的| 金疮是什么病| 什么的讲| 肿气肿用什么药比较好| 负重是什么意思| wifi用户名是什么| 哥德巴赫猜想是什么| 痧是什么| 角质是什么意思| 陈小春什么星座| 春梦是什么意思啊| 额头青筋凸起是什么原因| 头发稀少是什么原因| 梦到被蛇咬是什么意思周公解梦| 男人肾虚吃什么补得快| 糖吃多了有什么危害| 溺爱什么意思| 补铁吃什么| 唯女子与小人难养也什么意思| 纪委是什么| 什么是脂溢性脱发| 安居乐业什么意思| 肚子经常疼是什么原因| 10000mah是什么意思| 95棉5氨纶是什么面料| 牛皮革是什么意思| 吃什么能降血压最有效| 契丹族现在是什么族| 夏天补什么| wz是什么意思| belkin是什么牌子| 什么雨| 茉莉花茶属于什么茶| 麻药过敏什么症状| 手链突然断了预示什么| 武则天什么朝代| 亢奋是什么意思| 残疾证有什么好处| 9月28是什么星座| 梦见狗打架是什么意思| 什么叫代孕| 大包子什么馅好吃| 丁毒豆泡酒能治什么病| 红参和高丽参有什么区别| 71年属什么| 首鼠两端什么意思| 胃不舒服吃什么药好| 农历7月20日是什么星座| mlb是什么品牌| 吃西兰花有什么好处| 翘首以盼是什么意思| af是什么| 今年闰六月有什么说法| 什么的琴声| 新生儿湿疹用什么药膏| 什么富什么车| 织物是什么材质| 竹勿念什么| 酉时左眼跳是什么预兆| 为什么总是头疼| kiki是什么意思| 姑姑的孙子叫我什么| 何炅和谢娜是什么关系| sid是什么| 香肉是什么肉| 美人鱼2什么时候上映| 日语一个一个是什么意思| 什么是体液| 6月4号是什么星座| 16 5是什么码| 众里寻他千百度是什么意思| 喉咙痛头痛吃什么药| 4月5号是什么星座| 气血不足什么原因引起的| 什么情况下会缺钾| 味精是什么提炼出来的| 拍胸片挂什么科| 心悸是什么病| 蜜蜡属于什么五行属性| 倍增是什么意思| 月经多是什么原因| 45年属什么| 说风就是雨什么意思| 什么无为| 鸡拉稀吃什么药| 慢性肾功能不全是什么意思| 为什么身份证后面有个x| 孕期感冒可以吃什么药| 啫啫煲为什么念jue| 所剩无几是什么意思| 胃不好吃什么水果好| 月经结束一周后又出血是什么原因| kub是什么检查| 伊朗是什么派| 老道是什么意思| 嗓子疼喝什么茶最有效| 无极调光是什么意思| 乳房检查挂什么科| 大便有凹槽是什么原因| 谢谢谬赞是什么意思| tpp是什么意思| 呵呵的含义是什么意思| 怀孕两周有什么症状| 肠痈是什么病| 属狗的和什么属相最配| chd医学上是什么意思| 政绩是什么意思| 窦性心律t波改变是什么意思| 军绿色裤子配什么上衣| 心大是什么意思| 子宫痉挛是什么症状| 病毒疣是什么| 血脂高是什么原因引起| 睾酮高有什么影响| DHL是什么| 老打瞌睡犯困是什么原因| 大运是什么| 孕妇忌吃什么| 什么是复利| 基底是什么意思| 晚上睡觉尿多是什么原因| 造化弄人是什么意思| mdzz是什么意思| 血糖高能喝什么粥| cupid什么意思| 开塞露是什么| 流清鼻涕是什么原因| 县局局长什么级别| a7是什么意思| 大快朵颐是什么意思| 县法院院长是什么级别| 4月10号什么星座| 苹果a1660是什么型号| 隐性基因是什么意思| 黄风怪是什么动物| 98年属虎的是什么命| 胖脸女人适合什么发型| 阴道干燥是什么原因| 走花路是什么意思| 什么是飞机杯| 什么是基数| 黑无常叫什么| 4月20日是什么星座| 多吃醋有什么好处和坏处| 工匠精神的核心是什么| 红光对皮肤有什么作用| 频繁做噩梦是什么原因| 胚轴发育成什么| 女人吃什么补充胶原蛋白| 什么是偏爱| 岱字五行属什么| 犀利是什么意思| 什么的莲蓬| 为什么夏天热冬天冷| 生孩子大出血是什么原因造成的| 埋线是什么| 凌晨一点是什么时辰| 吃什么最容易减肥| 腊月初八是什么日子| 肉字是什么结构| 为什么要长征| 芥末是什么植物| 吃什么减肥效果最快| 对戒是什么意思| 流水生财是什么意思| 绿色食品是什么意思| 下身灼热感什么原因| 身份证是什么字体| 梦见前男友死了是什么意思| 梦见自己大笑是什么意思| 蚂蚱吃什么食物| 中指戴戒指是什么意思| 女儿取什么名字好听| 心电图异常q波什么意思| 备孕需要做什么准备| 吃猪皮有什么好处和坏处| 什么猫| gi什么意思| 锅底灰能治什么病| 什么是潜意识| 是谁在敲打我窗是什么歌| 怀孕了什么不可以吃| lok是什么意思| 小孩拉肚子吃什么食物好| 三聚氰胺是什么| 节气是什么意思| 夏季吃什么水果好| 枯草芽孢杆菌治什么病| 心里害怕紧张恐惧是什么症状| 4月29日是什么星座| 嗦是什么意思| 肺活量大有什么好处| 庚辰五行属什么| 做梦手机坏了什么预兆| 乐极生悲是什么意思| 金木水火土各代表什么| 输卵管堵塞是什么原因| 长沙有什么山| 为什么天天做梦| 什么不安| 1983年五行属什么| 秘密是什么意思| 医师是什么级别| 玉米有什么功效| 乳突炎是什么病| 鲑鱼是什么鱼| 吃什么可以提高代谢| 牙髓是什么| 脸上肉跳动是什么原因| 月经不调是什么原因造成的| 近视是什么原因造成的| 胃寒湿气重吃什么药效果最好| 奥利奥是什么意思| 静是什么意思| 星标朋友是什么意思| n t是什么检查| 眼睛有眼屎用什么眼药水| 泌尿科挂什么科| 益生菌的食物是什么| 雷人是什么意思| cp是什么的缩写| 柿子什么季节成熟| 老是口腔溃疡是什么原因| 金色葡萄球菌最怕什么| 内敛什么意思| 跌打损伤用什么药好得快| 孩子爱咬指甲是什么原因| 尿液结晶是什么意思| 胆结石是什么原因造成的| 什么是崩漏| 凌晨两点多是什么时辰| 鱼腥草破壁饮片有什么功效| 百度

国内多地出台无人车路测政策

百度 物理学家最终花了几十年才找到正确的数学方法,解决了该问题。

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-07.
  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
汗管瘤什么原因造成 d二聚体是检查什么的 去湿气喝什么 雌二醇凝胶有什么作用 喉咙干是什么原因
肠道功能紊乱吃什么药 隐形眼镜护理液可以用什么代替 木属于五行属什么 怀孕前三个月需要注意什么 巨细胞病毒igg阳性是什么意思
火影忍者大结局是什么 炸鸡用什么油 梦到发大水是什么意思 玉米和什么不能一起吃 cln是什么意思
小鱼缸适合养什么鱼 氯丙嗪是什么药 检查是否怀孕要挂什么科 作数是什么意思 1985年属什么
金屋藏娇定富贵是什么生肖ff14chat.com 梦到男孩子是什么意思hcv7jop5ns0r.cn 干性皮肤适合什么牌子的护肤品hcv9jop2ns6r.cn 五个月宝宝吃什么辅食最好jinxinzhichuang.com 一什么尾巴shenchushe.com
朋友圈发女朋友照片配什么文字hcv8jop7ns7r.cn 为什么叫五十肩baiqunet.com 子宫内膜薄有什么症状imcecn.com 眼发花是什么病的征兆helloaicloud.com 熬夜眼睛红血丝用什么眼药水hcv9jop1ns4r.cn
结节是什么原因引起的hcv8jop7ns8r.cn 十一月六号是什么星座hcv8jop4ns8r.cn 5月22是什么星座hcv8jop2ns1r.cn 鸟屎掉头上有什么预兆hcv8jop3ns1r.cn 什么是总胆固醇fenrenren.com
指甲上的白色月牙代表什么hcv9jop5ns8r.cn 排卵试纸两条杠是什么意思hcv7jop6ns2r.cn 尿酸高吃什么药效果好hcv9jop4ns2r.cn 父亲节送什么hcv7jop4ns8r.cn 感冒吃什么消炎药效果好hcv8jop0ns0r.cn
百度