Adding an ATL Class

OverviewHow Do I

To add an ATL (Active Template Library) class to your project, your project must have been created as an ATL COM application, or contain ATL support for MFC applications. You can use the to create an ATL COM application, or add an ATL object to your MFC application to implement MFC support for the Active Template Library.

You can define COM interfaces for your new ATL class when you first create it, or add them later by using the Implement Interface command from the ClassView popup menu.

To add an ATL class to your ATL COM project

  1. Open the New Class dialog as described in the New Class dialog box.

  2. In the Class type drop-down list, select ATL Class.

  3. In the Name box, specify the name of the new class.

    The name you specify is reflected in the read-only File name box, where the implementation (.cpp) file is specified. By default, the header file and the implementation file have the same name as the class (except for a leading capital 'C' in the name).

    • To change the names of the header and implementation files for this class, click the Change button and type the names into the Change Files dialog box.

    • To add the new class to existing files, click Change, then click the Browse button and locate the files you wish to add it to.

  4. Under Interface Type, specify whether you want the interfaces for this class to be Dual or Custom.

    Implementing a dual interface, derived from IDispatch, enables both COM clients and automation controllers to access your class functions. Custom interfaces are derived from IUnknown and have no restrictions on the data types you can use, such as data structures or unsigned arguments.

  5. Under Interfaces, specify the number of interfaces for the new class.

    The Names box displays the names of the interfaces.

  6. Click Edit to edit the default interface data.

    If you do so, the Edit Interface Information dialog box appears:

    • In the Object short name box, enter the control name;

    • In CoClass name, type the name of the CoClass class that contains a list of interfaces supported by the object;

    • In Type name, type an object description that will appear in the registry;

    • In Type ID (ProgID), type a name that containers can use instead of the CLSID of the object.

    The related fields display text based on what you type in the Object short name box.

  7. Click OK to save changes and return to the New Class dialog box.

  8. Select the Aggregatable checkbox if you want this class to enable objects that can directly expose another object's interface pointer (default setting).

  9. Click OK to save your entries and exit the New Class dialog box.

This creates the associated implementation and header files for the new class, which you can view from the ClassView pane of the Project workspace.

For more information on ATL projects and ATL COM classes, see the .

See Also   , , , Adding an MFC Class, Adding a Generic Class