Adding a Method to an MFC Dispinterface

OverviewHow Do I ... Topics

You can define new methods for automation-enabled MFC classes that were created by using the MFC AppWizard or ClassWizard.

To add a method to an MFC dispinterface

  1. Open the Add Method dialog box in one of the following ways:
    • In ClassView, rest your cursor on the interface, and click the right mouse button to invoke the shortcut menu, then choose Add Method.

    • In ClassWizard, for an automation-enabled class, choose the Automation tab and then click the Add Method button.
  2. In the External Name drop-down list box, enter the name you want to use to identify this method to automation clients.

    This name is reflected in the Internal Name text box.

  3. If you would like to specify a distinct internal name for this method, type it into the Internal Name box.

    This is the name of the member function that will send the method.

  4. Select a return type from the drop-down list.

  5. In the Parameter list area, for each parameter you wish to define:
    • Enter a name for the parameter in the Name text box.

    • Select a valid type from the Type drop-down list.
  6. When you are satisfied with the method as you’ve defined it, click OK to exit the Add Method dialog box.

Visual C++ adds the new method declaration to the .odl file, a stub method implementation to the .cpp file, and a reference to the method in the .h file for the class.

The new method is displayed as an icon in ClassView under the interface where it is defined. By double-clicking the method icon, you can examine the .odl file to see its declaration.