Walkthrough: Creating an ATL Multiplatform ActiveX Control for Smart Devices

You can use Visual C++ for devices to write ActiveX controls targeting multiple devices. The following walkthrough illustrates how to build a multiplatform ATL ActiveX control.

In this walkthrough, you perform these main tasks:

  • Create a multiplatform smart device ATL project.

  • Add an ActiveX control to the project using the wizard. Notice that most of the basic structure and code is generated by the wizard.

  • Modify the code in your stdafx.h and samplecontrol.h files to define your threading model and avoid compiler warnings.

  • Deploy the multiplatform solution. Note that an Internet Explorer file is also generated to ease the testing and running of the control.

This walkthrough was written using Visual C++ Development Settings.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Create a Multiplatform ATL ActiveX Control

To create a multiplatform ATL ActiveX control

  1. On the File menu, point to New, click Project, expand the Visual C++ node in the Project Types pane, and then click Smart Device.

  2. In the Templates pane, click ATL Smart Device Project.

  3. In the Name box, type ATLAXControl, and then click OK.

    The ATL Smart Device Project Wizard is launched.

  4. Click Next on the ATL Smart Device Project Wizard welcome page.

    The Platforms, ATL Smart Device Project Wizard is displayed so you can select the platform SDKs to be added to the current project.

  5. From the Installed SDKs list, select the platforms you want to add to the current project, such as Smartphone 2003 and Pocket PC 2003. To add a platform select the platform in the left pane, such as Smartphone 2003, and click the button with the right arrow > on it. To remove a platform select the platform in the right pane, such as Pocket PC 2003, and click the button with the left arrow < on it.

  6. Click Finish to complete and close the wizard.

Add an ActiveX Control to the Project

To add an ActiveX control to the project

  1. In Solution Explorer, right-click ATLAXControl, point to Add, and then click Class.

  2. In the Categories pane, click Smart Device.

  3. In the Templates pane, click ATL Control, and then click Add.

    The ATL Control Wizard dialog box appears.

  4. In the Short Name text box, type samplecontrol.

  5. Click Finish to complete and close the wizard.

Modify the Code in Header Files

To modify the code in stdafx.h

  1. In Solution Explorer, double-click stdafx.h to open it in the editor.

  2. Add the following define #define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA after the #pragma once, as shown here:

        // Add this define after 
        #pragma once
    #define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA
    
  3. Add an ActiveX Control to the project as shown in the following procedure.

To add an ActiveX Control to the project

  1. In Solution Explorer, double-click samplecontrol.h to open it in the editor.

  2. Replace the string ATL 8.0 : samplecontrol with Hello World ActiveX Control in the code defining Isamplecontrol.

Note

ActiveX controls for a DCOM platform should be marked as apartment-model threaded when built. This is the ATL control wizard's default setting. You can safely ignore the warning generated during compile. Also ATL, GUI, and EXE projects, such as those to which you have added atlwin.h, atlctl.h, or atlhost.h to an ATL EXE project, should have _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA defined in the stdafx.h before the inclusion of the ATL header files. This practice is the same as when you are developing for the desktop. For more information see, Building and Debugging Visual C++ Device Projects.

Deploy the Multiplatform ATL Solution

To deploy the solution

  1. On the Build menu, click Rebuild Solution to build the control.

  2. On the Build menu, click Deploy Solution.

  3. On the Target Device drop-down list on the Visual Studio toolbar, select your target, for example, Pocket PC 2003 SE Emulator or Pocket PC 2003 Device.

  4. On the Build menu, click Deploy.

Choosing a Target Device

To ensure that you are prompted to select a device when you deploy your solution, complete the following procedure.

To prompt for device choices at deployment

  1. On the Tools menu, click Options, expand the Device Tools node, and then click General.

  2. If Device Tools is not visible, select Show all settings at the bottom of the Options dialog box.

  3. Select the Show device choices before deploying a device project check box, and then click OK.

To run the control, use File Explorer on the device, navigate to Program Files\ATLAXControl, and double-click the Internet Explorer file ATLAXControl. One or more security messages will be displayed. Click Yes to run the page.

See Also

Reference

Visual C++ (How Do I in Smart Devices)

Other Resources

How to: Create a Multiplatform Device project (Visual C+)