COM for the iunknown Interface

Source: Internet
Author: User

Each interface defined by COM must be inherited from iunknown, mainly because the iunknown interface provides two very important features: Lifetime Control and interface query. The client program can only communicate with the COM object through interfaces. Although the client program can control the existence of the object regardless of the Implementation Details within the object. If the customer wants to continue the operation on the object, it must ensure that the object can always exist in the memory. If the customer has completed the operation on the object, the object will not be needed in the future, it must release the object in time to improve resource utilization. Iunknown introduces the reference counting method to effectively control the object lifecycle.

On the other hand, if a COM Object implements multiple interfaces, at the initial time, the client program is unlikely to obtain all the interface pointers of the object, and it will only have one interface pointer. If the client program needs other pointers, how does it obtain another interface pointer through this interface pointer? Iunknown uses the interface query ("QueryInterface") method to complete the bar between interfaces.

The following is the definition of iunknown:

Class iunknown {public: Virtual hresult _ stdcall QueryInterface (const IID & IID, void ** bp) = 0; virtual ulong _ stdcall addref () = 0; vittual ulong _ stdcall release () = 0 ;};
 
Among them, QueryInterface is used to query other interfaces of the COM object, and addref and release are used to operate the reference count.

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.