COM components and multi-interface

Source: Internet
Author: User

Previously, we always thought that a DLL (or EXE) is a COM component. Different classes in the DLL are different interfaces, and CLSID is used to identify a DLL or EXE.

In fact, this is wrong !!!

A component is not necessarily a DLL. a dll can contain many components. Generally, a dll contains more than one component. Each component in a DLL has its own
CLSID and progid. For an ATL Project, an ATL object is a component. Obviously, we can add many ATL objects to a project.

For ATL, a component corresponds to a C ++ class, which is called coclass in IDL. Generally, a coclas corresponds to an interface. In fact, a coclass can have many interfaces. This means that a component implements multiple interfaces and these interfaces share functions in a component.

For example, coclass A has an interface IA, and the interface exports a function Foo (), so coclass
A has a FOO () function to implement the Foo () function in the IA interface. Later, I want to upgrade component A and add an export function foo2 (), but I don't want to affect the previous users. Of course I want to redo it.
A new component is fine, but it is unnecessary and has repeated code. In this case, we can create a new interface ia2 in component A and ia2 to export two functions: Foo () and
Foo2 (), ia2 is still implemented by coclass A, that is, the current coclass
A has two functions: Foo () and foo2 (). The interfaces Ia and ia2 share coclass.
The Foo () function in. In this way, the previous users do not need to change, because the interface IA is not changed, new users can use the interface ia2, and ia2 can still complete the IA function, because
There are also Foo () functions.

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.