The "COM components and Interfaces" of the basic concept of automation

Source: Internet
Author: User
Tags inheritance

In the previous article, I have announced that I will begin to introduce Winx support for automation (automation). First I intend to explain the concept of automation (automation).

We will be divided into 3 sections:

· COM Basics: COM components (Component) and Interfaces (Interface)

• Variant (variant) and IDispatch (Dispatch call)

• Automation (Automation), OA (Office Automation), two development interfaces (application development interface, API) and type library (TYPELIB)

This is the first article.

COM components (Component) Intuitive understanding is a class, but this is not a rigorous definition. There are two reasons:

Some languages, such as the C language, do not have classes, but they can implement COM components.

A COM component (Component) is usually a class, but it may also be implemented with multiple classes. But for the customer of the component, it is a class, or multiple classes to implement, it does not know, and does not care. For more information about implementing COM components with multiple classes, you can look at the content of the "nested classes implementing COM interfaces (as MFC prefers, ATL tends to use multiple inheritance)" and "Aggregation (AGGREGATION)" in COM components.

A COM component (Component) is a concept based on a binary object protocol. It can also be understood that this is a binary sense of "class". A COM component that exposes not a set of methods (method) but a set of interfaces (Interface).

The concept of Interface (INTERFACE) is widely used and is generally referred to as "class specification (Contract)". Understanding Interfaces (Interface) in COM sense is a binary protocol compatible with the current VTBL mechanism, and the first three items of VTBL are compatible with the IUnknown interface (from an inheritance point of view, it can be understood as requiring inheritance from IUnknown, but only in this sense). For example, you can define the following interface:

Interface Ifoo:iunknown
{
virtual void __stdcall Fooa () = 0;
virtual int __stdcall Foob (int arg1, int arg2) = 0;
};

But you can not write this, but the pure C-style:

struct IFOOVTBL
{
HRESULT (__stdcall *queryinterface) (void* pThis, const guid* IID, void** PPV);
ULONG (__stdcall *addref) (void* pThis);
ULONG (__stdcall *release) (void* pThis);
void (__stdcall *fooa) (void* pThis);
Int (__stdcall *foob) (void* pThis, int arg1, int arg2);
};

struct IFOO
{
struct ifoovtbl* vptr;
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.