When using the interface pointer: unhandled exception... Stack Overflow

Source: Internet
Author: User

Symptom:
Com external components have a createdog (iunknown ** ppunk) method to create an idog interface. When you want to directly pass the spdog smart pointer to the createdog method, the interface passed back is found to be non-empty, and the returned value is s_ OK. However, when this pointer is used to call its method (the Qi function is no problem), an asserted pops up: unhandled exception... stack Overflow.

With the help of many parties, I finally found the root of the problem:
Because it is a component outside the process, you can only pass the iunknown ** interface pointer, (a classmate: I certainly know this, or else the parameter will not be iunknonw ), but why do I pass spdog to the function as a [out] parameter? You may assume that it is a "common and convenient" method to forcibly convert from iunknown to idog!
This is the problem! In the in-process components, it is no problem if we force the conversion in this way, because there is no column set operation for parameter transfer within the process (or exactly within the suite, however, the passed iunknown between processes is another one you get in the process. How can you expect that it also contains an idog vtable, therefore, the correct method should be that you get the iunknown pointer and then QueryInterface idog again. In this way, the obtained pointer is correct.

Summary:
In terms of Interface Usage, it is best not to forcibly convert from iunknown to the interface you want, but to adopt the standard practice: QueryInterface

Haha .. I made another mistake!

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.