Implementing Properties of a Dispatch Interface

AutoClik’s document class has two member variables, m_pt and m_str. They can be exposed to Automation by using AutoClik’s document dispatch interface.

Suggested Reading in the Microsoft Foundation Class Reference

There are two ways to expose member variables of an automated CCmdTarget-derived class.

When should you expose a member variable directly, as a dispatch interface property, and when should you expose it indirectly, by using dispatch interface Get and Set methods? Again, the question is analogous to: when should you declare a member variable protected or private and provide Get and Set member functions? If you do not need to monitor access to a member variable, you can expose it directly. If your application needs to know when the member variable is being accessed, you should expose it indirectly.

In the case of AutoClik, it makes the most sense to expose both m_pt and m_str indirectly by using Get and Set methods. This way, any time m_pt and m_str are updated through Automation, AutoClik updates its view. For tutorial purposes, however, you handle m_pt and m_str differently. You expose m_pt indirectly, whereas you expose m_str directly. Both approaches are easy to do with the help of ClassWizard.