One of the ATL development techniques (Implementation of collection objects)

Source: Internet
Author: User

Typically, an enumerator is used in the collection of objects, but the enumerator is implemented primarily for the access control of the collection object, and we can use the CComEnumOnSTL template to define our own enumerator, which involves complex replication policy definitions and the definition of the collection method implementation.

If we do not use an enumerator and use only an array of interfaces, the collection object will have a relatively simple implementation, and this article will explore the implementation of this method and provide the complete source code.

The following is an example of a collection object implemented with an interface array for your reference:

Collection Object creation class: Cvoxsys Interface: Ivoxsys
Collection Object class: Cvoxchs Interface: Ivoxchs
Child object class: Cvoxch Interface: Ivoxch

First, about Cvoxch child objects:

To add a private member variable to the CVOXCH:

private:
  BSTR m_bstrMessage;

Initialize the value of a member variable in the Cvoxch constructor:

CVoxCh()
{
  m_bstrMessage = A2BSTR("No inited!");
}

Add BSTR type attribute for interface ivoxch: Message

To modify the Get_message function:

STDMETHODIMP CVoxCh::get_Message(BSTR *pVal)
{
  *pVal = m_bstrMessage;
  return S_OK;
}

Ii. about Cvoxchs Collection objects:

Add two private member variables to Cvoxchs:

private:
  CComPtr<IVoxCh> m_arrpCh[160];  //子对象接口数组
  long m_nChs;        //实例子对象计数

Initialize the value of a member variable in the Cvoxchs constructor:

CVoxChs()
{
  m_nChs = 0;
}

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.