Share via


Inserting the ATL Control Component

The next step is to add the ATL control component to your project. The Add Class dialog box provides a variety of frameworked components for insertion into a Visual C++ IDE project. One of these components is the ATL control component, located at the top level of the Add Class dialog box.

Procedures

To insert the ATL control object

  1. In Solution Explorer, right-click the MyAxCtrl project.

  2. On the shortcut menu, click Add, and then click Add Class.

    The Add Class dialog box appears.

  3. In the Templates pane, click the ATL Control icon.

  4. Click Open.

    The ATL Control Wizard appears.

  5. In the Short Name box, enter MyCtl.

    The remaining boxes are completed for you.

  6. Click Finish to accept the default choices and add the control to your project.

For more information on this wizard, see ATL Control Wizard.

Attributes Used in the ATL Control Component

Because the ATL control component makes use of attributes, several new attributes are now present in the sample project. These attributes implement the control object and the default control interface.

In MYCTL.H, you will find a new set of attributes (referred to as an attribute block) that implements a control framework, attached to the new CMyCtl class. This block contains the following attributes:

  • coclass   Specifies that the object is a COM object and automatically provides a class factory, auto registration, and an implementation of the IUnknown interface.

  • threading   Specifies that the control is safe to be used in an apartment thread. This is done by changing the generated reference counting and registration code.

  • vi_progid   Specifies a version-independent form of the ProgID.

  • progid   Declares a simple ProgID, used by clients of the new control.

  • version   Specifies the version of the control.

  • uuid   Declares the CLSID for the control.

  • helpstring   Specifies a help string, describing the object.

  • support_error_info   Specifies that the object implements support for detailed, contextual errors.

  • registration_script   Specifies the custom registration script to be executed for the object.

The other major element added by the ATL Control Wizard is another attribute block (attached to the IMyCtl interface), implementing the default interface for the control object. This is the default interface of your control and currently the only implemented interface. The interface is declared in your control's declaration file (in the example, MYCTL.H) and is very simple:

__interface IMyCtl: public IDispatch
{
};

This code declares a custom interface, IMyCtl, which is derived from the standard IDispatch interface and contains no methods.

This block contains the following attributes:

  • object   Specifies that the following interface definition is a custom interface and should be placed in the .idl file of the project.

  • uuid   Declares the IID for the IMyCtl interface.

  • dual   Declares the interface as a dual interface (supporting both early and late binding).

  • helpstring   A short description of the control object and its purpose.

  • pointer_default   Specifies the characteristics of any embedded pointers. In the sample control, unique means that embedded pointers can be NULL and there will be no duplicate values.

To move to the next step, see Adding a Property Using Attributes.

See Also

Concepts

Walkthrough: Creating an ActiveX Control with Attributes

Creating the ActiveX Control Project

Reference

Adding an Event Using Attributes

Other Resources

Attributes Walkthroughs