Share via


Adding a Property to an MFC Dispinterface

OverviewHow Do I ... Topics

When defining a property for an MFC dispinterface, you can implement the property with a member variable or with Get/Set methods. Using the member variable implementation provides direct access to the property, whereas using Get and Set methods to implement the property enforces a controlled access. If you do implement the property via a member variable, you can also provide a notification function to alert you when the value of the property changes.

To add a property to an MFC dispinterface

  1. Open the Add Property dialog box in one of the following ways:

    • In ClassView, rest your cursor on the interface, click the right mouse button to invoke the shortcut menu, then choose Add Property.

    • In ClassWizard, for an automation-enabled class, select the Automation tab, then choose Add Property.

  2. In the External Name box, type in a name for the property.

    This is the name automation clients will use to access the property.

  3. Select a type from the Type list.

  4. Choose an Implementation type for the property.

    Your choice is reflected in the two text boxes below the Type list. By default, Member variable is selected, displaying the Variable name and Notification function boxes. Choosing Get/Set methods displays the Get function and Set function boxes.

    The Stock implementation choice is available only for ActiveX controls.

  5. If you’ve selected a Get/Set property implementation, specify any custom parameters you’d like this property to take. In the Parameter list area, for each parameter you wish to define:

    • Enter a name for the parameter in the Name box.

    • Select a valid type from the Type list.

    The Parameter list is unavailable for a member variable implementation.

  6. When you’ve completed the property definition, click OK to exit the Add Property dialog box.

The property in its Get/Set or member variable implementation is visible in ClassView under the interface where it is defined, and under the class where it is implemented. Double-click an icon under the interface to jump to the .idl or .odl file. Double-click an icon under the class to jump to the .cpp file.