(10) Chengye defeat also Sho Ho? Iunknowex

Source: Internet
Author: User
Related UML:


Look at the code for a query interface:
//////////////////////////////////////////////////////////////////////////

Interface Query macros
#define QueryInterface (Interface,guid,dwqueryver) \
if ((guid==iid_# #Interface) && (Interfaceversioncheck (dwqueryver,ver_# #Interface)) \
Return to Static_cast<interface *> (this);

#define QUERYINTERFACE_IUNKNOWNEX (baseinterface,guid,dwqueryver) \
if ((Guid==iid_iunknownex) && (Interfaceversioncheck (Dwqueryver,ver_iunknownex)) \
Return Static_cast<iunknownex *> (Static_cast<baseinterface *>);

Get interface macros
#define GET_MYSELF_INTERFACE (INTERFACE) \
((Interface *) QueryInterface (iid_# #Interface, ver_# #Interface))

#define GET_OBJECT_INTERFACE (object,interface) \
((Interface *) object.queryinterface (iid_# #Interface, ver_# #Interface))

#define GET_OBJECTPTR_INTERFACE (pobject,interface) \
((pobject==null)? NULL: ((Interface *) pobject->queryinterface (iid_# #Interface, ver_# #Interface)))

//////////////////////////////////////////////////////////////////////////


Interface Query
void * __cdecl ceventservice::queryinterface (const IID & Guid, DWORD dwqueryver)
{
QueryInterface (Ieventservice,guid,dwqueryver);
Queryinterface_iunknownex (Ieventservice,guid,dwqueryver);
return NULL;
}

Because of the existence of this function, the interface passes the type check from the compile time to the runtime.
The delivery of any interface only needs to pass a Iunknowex pointer, and then the receiver uses IUNKNOWEX to determine whether it is the interface it needs.
This mechanism is good or bad, it's hard to say,

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.