OOPortal OOPortal

ATL Development   «Prev  Next»
Lesson 12 Adding read-only properties
Objective Add MaxRecs and NumRecs to IReadPhBook.

Adding read-only Properties

We can now add read-only properties MaxRecs and NumRecs to interface IReadPhBook. MaxRecs holds the maximum number of phone records, and NumRecs holds the number of phone records currently stored in PhBookObj.
The following simulation will step you through the process of adding both MaxRecs and NumRecs.
Add Maxrecords Num Records
In PhBook.idl, IReadPhBook is now:

 helpstring("IReadPhBook Interface"),
interface IReadPhBook : IUnknown
     [propget, helpstring("property CurRec")
  ] HRESULT CurRec([out, retval] long *pVal);
     [propput, helpstring("property CurRec")
  ] HRESULT CurRec([in] long newVal);

     [propget, helpstring("property MaxRecs")
  ] HRESULT MaxRecs([out, retval] long *pVal);
     [propget, helpstring("property NumRecs")
  ] HRESULT NumRecs([out, retval] long *pVal);


Both MaxRecs and NumRecs are marked with the propget attributes. Visual C++ will generate methods get_MaxRecs and get_NumRecs.
The ClassView pane of the Workspace windows now shows now contains:
MaxRecs and NumRecs added.
MaxRecs and NumRecs added

Adding the properties NumRecs and MaxRecs adds method declarations to CPhBookObj.h in PhBookObj.h.
It also adds stub methods to the implementation file PhBookObj.cpp.

Add Read Only Properties - Exercise

Click the Exercise link below to apply what you have learned about adding read-only properties to a COM object.
Add Read Only Properties - Exercise