ts什么意思网络上| 梦见结婚是什么意思| 女人喝甘草水有什么好处| 不加大念什么| spo2过低是什么意思| 1972年属鼠的是什么命| 痔疮坐浴用什么药效果好| 心脏不舒服做什么检查| 取缔役什么意思| 梦见搬家是什么意思| 10月21日什么星座| 阴血是什么| un读什么| 白玫瑰代表什么意思| 阁老相当于现在什么官| 什么是框架协议| 氧化氢是什么| 小白加小白等于什么| 北面属于什么档次| 木乐读什么| 什么情况下用妇炎洁| 睡觉起来脸肿是什么原因引起的| 化纤是什么面料| 射手座是什么象星座| 桑葚酒有什么功效| 超声诊断科是做什么的| 弥月之喜是什么意思| 过奖是什么意思| 梦见枪毙人是什么意思| 小孩吃榴莲有什么好处| 卡介苗是什么| 夜间尿多是什么原因| 精神内科一般检查什么| 桂林是什么地貌| 政协副主席是什么级别| 唐筛主要检查什么| 干酪是什么| 什么是玄关在哪个位置| 花茶是什么茶| 双肺纹理增强是什么意思| 石斛念什么| 超滤是什么意思| 十月份出生的是什么星座| 名什么什么实| 儿菜是什么菜| 偏头痛什么原因引起| 激素六项是查什么的| 气滞血瘀吃什么中成药| 卵巢黄体是什么意思| md是什么材质| 狗是什么生肖| 杆菌是什么| 吃阿司匹林有什么副作用| 38年属什么生肖| 全血低切相对指数偏高什么意思| 惊蛰后是什么节气| 淋巴细胞比率偏高是什么意思| 什么气什么现| 蜂蜜有什么作用| 痰栓是什么| 孕妇吃什么水果好| 郑州有什么大学| 白带是什么味道| 胸闷憋气是什么原因| 梦见好多南瓜是什么意思| 血压高吃什么菜和水果能降血压| 修成正果是什么意思| 油菜籽什么时间种| 手心发烧是什么原因| 阳虚吃什么药| 眼底照相是检查什么| 吃什么长内膜最快最有效| 滑膜疝是一种什么病| 女人梦见仇人代表什么| 带下病是什么病| mews评分是什么意思| 仄言是什么意思| 买什么保险最实用| 什么是同位素| ipadair2什么时候上市的| 祖马龙香水什么档次| 小米粥和什么搭配最好| 减肥为什么让早上空腹喝咖啡| 蜜蜡五行属什么| 老人爱睡觉什么征兆| 药食同源什么意思| 吃什么能让头发变黑| 四面楚歌是什么意思| 四维彩超是检查什么| 屠苏指的是什么| 泄愤是什么意思| 借鸡生蛋是什么意思| 儿童流鼻血什么原因引起的| 梦见吃西红柿是什么意思| 为什么体重一直下降| 万足读什么| 弱视是什么| 胆碱酯酶高是什么意思| them什么意思| 83年五行属什么| 何方神圣是什么意思| 高血压吃什么药| 灿字五行属什么| vivi是什么意思| 经常喝红茶有什么好处和坏处吗| 庚什么意思| 便秘吃什么药效果好| 樊胜美是什么电视剧| ca代表什么病| 醋坛子是什么意思| 血氧饱和度低于90有什么危害| 并驾齐驱什么意思| ar技术是什么意思| 水鸭是什么鸭| 八一建军节什么生肖| 欧尼酱什么意思| 梦到小男孩是什么意思| 业障什么意思| 02年属马的是什么命| 吴优为什么叫大胸姐| 如虎添翼是什么生肖| 喜欢穿黑色衣服的女人是什么性格| 什么药降糖效果最好| 血性是什么意思| 8宫代表什么| 午未合化什么| 尿道痒男吃什么消炎药| 连云港有什么好吃的| 牡丹花是什么颜色的| 爆冷是什么意思| 爰是什么意思| 丝状疣挂什么科| 肛门下坠感是什么原因| 正常龟头是什么颜色| 教师节是什么时候| 猪拉稀用什么药最快| spyder是什么品牌| 黑眼圈是什么原因导致的| 区委书记属于什么级别| m k是什么牌子| 什么什么不安| 为什么会肚子疼| 丰年虾是什么| 取缔役什么意思| 带状疱疹看什么科| 红豆生南国什么意思| 乳房结节是什么原因引起的| 恶作剧是什么意思| 士加一笔是什么字| 槑是什么意思| 一直打哈欠是什么原因| 为什么打嗝| 直升是什么意思| 尿黄起泡是什么原因| 腰痛是什么原因引起的| 扶她是什么| 张家界莓茶有什么功效| 十一月份出生的是什么星座| 棕色皮鞋配什么颜色裤子| 天空为什么是蓝色| 安分守己什么意思| 香港为什么叫香港| 白色玉米是什么玉米| 大象灰配什么颜色好看| 居高临下的临是什么意思| 在编是什么意思| 八月十一号是什么星座| 美纹纸是干什么用的| 肝囊肿吃什么食物好| 气血两虚吃什么补最快| 机不可失的下一句是什么| 女性喝什么茶最好| 恃势之刑是什么意思| 朱元璋是什么朝代| sm什么意思| 不劳而获是什么意思| 前列腺增大伴钙化灶是什么意思| gfr是什么意思| 夜场是什么工作| 赫兹是什么| 男性粘液丝高什么原因| 男生第一次什么感觉| 为什么分泌物是褐色的| 生死有命富贵在天什么意思| 蛤读什么| 血小板压积偏高是什么意思| 建议随诊是什么意思| 什么是穿刺| 一月十八是什么星座| 汤沐邑是什么意思| 什么是前列腺钙化| 朝乾夕惕什么意思| 离苦得乐什么意思| 上不下要念什么| 小孩荨麻疹吃什么药| 2016年属什么生肖| 碱水是什么| 骨质增生挂什么科| 法西斯战争是什么意思| 梦见蔬菜是什么预兆| 孕晚期高血压对胎儿有什么影响| 爆菊花什么感觉| 马躺下睡觉为什么会死| 新生儿便秘怎么办什么方法最有效| 缘起缘灭是什么意思| 卵巢早衰是什么引起的| 2012年什么年| 乌龟一般吃什么东西| 什么是三伏贴| 鱼露可以用什么代替| 牙齿酸痛是什么原因| 副区长什么级别| py交易是什么意思| 有胃病的人吃什么最养胃| 腱子肉是什么意思| 棘人是什么意思| 锅巴吃多了有什么危害| 安然无恙的恙是什么意思| 口苦口臭吃什么药| 尿频尿急尿痛吃什么药| 什么样的人不能吃海参| 长期口臭吃什么药| 马子什么意思| 一个口一个坐念什么| 冬虫夏草长什么样| 财代表什么生肖| 鞋子eur是什么意思| 风寒感冒吃什么消炎药| 男性一般检查什么| 两个马念什么字| 天乙贵人什么意思| 抗核抗体阳性对怀孕有什么影响| 术是什么意思| 切诺为什么要饭前半小时吃| yp什么意思| bliss是什么意思| 孕妇的尿液有什么用途| 梦见好多西瓜是什么意思| 鼻饲是什么意思| 骨裂什么症状| 血常规是检查什么的| 姜什么时候种植最好| 为什么胃疼| 补肾最好的药是什么药| 沙僧属什么生肖| ct是什么| 宫颈多发纳氏囊肿是什么意思| 肠化是什么意思| 撤退性出血什么意思| 落叶像什么飘落下来| 二战时期是什么时候| 牙龈经常出血是什么原因| 天癸是什么意思| 贡菜是什么做的| 戾气是什么| 一月23号是什么星座| 李思思为什么离开央视| 如履薄冰是什么意思| 卖腐是什么意思| 跳蚤怕什么东西| 七月二十八什么星座| 宝宝肤专家软膏主要治什么| 胆管炎是什么原因引起的| 阴虱病是什么原因引起的| 百度Jump to content

斯巴鲁傲虎0首付0利率 2年6万公里延保【图】

From Wikipedia, the free encyclopedia
百度 在悉尼房市发展开始放缓的情况下,部分业内专家对房产碎片化投资平台提出疑虑。

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

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 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]
吃洋葱对身体有什么好处 泌尿系彩超主要是检查什么 非凡是什么意思 皮肤一块块白是什么病 栀子泡水喝有什么好处
专科医院是什么意思 梦见做被子什么意思 肝瘘是什么 右眼皮一直跳是什么预兆 厚植是什么意思
温饱是什么意思 俄罗斯人是什么人种 脾胃有火是什么症状 普洱属于什么茶 羊眼圈是什么
血糖高的人吃什么水果 急的什么 肉瘤是什么 腺病毒是什么病毒 花圃是什么意思
用什么泡脚能减肥hcv8jop4ns9r.cn lh是什么意思啊hcv9jop7ns4r.cn 吃什么减脂肪hcv8jop4ns0r.cn psp是什么意思hcv8jop8ns0r.cn im什么意思helloaicloud.com
人死后会变成什么hcv7jop6ns1r.cn 什么是dnakuyehao.com 最高的学历是什么hcv9jop4ns1r.cn 晚餐吃什么菜谱大全hcv9jop0ns8r.cn 不放屁吃什么药能通气hcv8jop1ns5r.cn
geneva是什么牌子手表hcv8jop5ns4r.cn 缺铁有什么症状hcv9jop3ns2r.cn cd20阳性什么意思tiangongnft.com 先明后不争什么意思zhiyanzhang.com 玄牝之门是什么意思sanhestory.com
胃绞疼是什么原因hcv9jop1ns4r.cn 什么鸡蛋营养价值最高hcv9jop1ns5r.cn 搞破鞋什么意思xinjiangjialails.com 颈部ct能检查出什么qingzhougame.com 吸入物变应原筛查是什么hcv9jop0ns8r.cn
百度