QueryInterface Implementation Rules

Source: Internet
Author: User

This section describes some rules that must be followed by all implementations of QueryInterface, this allows the customer to gain sufficient knowledge about components and implement some control and other useful processing. Without these rules, it is impossible to compile components, because in this case, the behavior of QueryInterface will be uncertain. Specifically, these rules are:
The same iunknown pointer is always returned by QueryInterface.
If the customer has obtained an interface, it will always obtain this interface.
The customer can obtain the existing interfaces again.
The customer can return to the starting interface.
If you can obtain a specific interface from an interface, you can obtain it from any interface.

// The component has only one iunknown interface.
Bool samecomponents (IX * pix, Iy * piy)
{
Iunknown * PI1 = NULL;
Iunknown * Pi2 = NULL;
// Obtain the iunknown interface from the PIX
PIX-> QueryInterface (iid_iunknown, (void **) & PI1 );

// Obtain the iunknown interface from piy
Piy-> QueryInterface (iid_iunknown, (void **) & Pi2 );

// Are these two pointers equal?
Return PI1 = Pi2;

};

// Obtain an existing interface again

Void getinteragain (IX * pix)
{
IX * pix2 = NULL;
// Query the IX interface from IX
Hresult hR = pix-> QueryInterface (iid_ix, (void **) & pix2 );
Assert (succeeded (HR ));
};

 

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.