Share via


ActiveX Controls: Adding an ActiveX Control to an Existing CDK Project

OverviewHow Do IFAQSample

This article provides step-by-step instructions for combining two existing ActiveX control projects into an existing OLE Custom Control Developer’s Kit (CDK) project. For clarity, the first control project is named Proj1; the second is named Proj2. After you have successfully completed this procedure, you will need to follow the steps detailed in the article ActiveX Controls: Converting a CDK Project to a Visual C++ Project to use this project with Visual C++ 4.0.

To protect the original code from becoming corrupted, work with the two controls in a separate directory. For example purposes, we’ve named the directory COMBINED. It is also recommended that you use the development environment for modifying and saving project files.

To successfully add an ActiveX control to an existing CDK project, you must:

  • Collect all relevant .H, .CPP, .PPG, and .RC files

  • Combine both .ODL files into one .ODL file

  • Modify the PROJ2.MAK makefile

  • Combine the resources of both controls

  • Build the resultant project

Collecting Implementation Files

The Proj1 and Proj2 directories both contain files that you can simply copy to the COMBINED directory with no changes. These files are used mainly to initialize the DLL and provide basic implementation of the control classes. Copy the following files into the COMBINED directory:

  • STDAFX.H, STDAFX.CPP

  • PROJ2.RC, RESOURCE.H

  • PROJ2CTL.BMP, PROJ2.ICO

  • PROJ1.H

  • PROJ2.H, PROJ2.CPP

  • PROJ1CTL.H, PROJ1CTL.CPP

  • PROJ1PPG.H, PROJ1PPG.CPP

  • PROJ2CTL.H, PROJ2CTL.CPP

  • PROJ2PPG.H, PROJ2PPG.CPP

  • *PROJ2.*DEF

Also copy two other files, used as templates, to the COMBINED directory:

  • PROJ2.MAK

    In a following section, this makefile will be modified to include the necessary files from PROJ1.

  • PROJ2.ODL

    This file will eventually contain both the Proj1 and Proj2 ActiveX control interfaces.

Merging the .ODL Files

Because there are two controls in the project, you will have to merge PROJ1.ODL into PROJ2.ODL. The .ODL file contains definitions for interfaces, so you need copy only those interfaces unique to Proj1 and insert them into the PROJ2.ODL file.

To merge PROJ1.ODL with PROJ2.ODL

  1. From the PROJ1 .ODL file, copy the lines that are in the same position as the lines indicated in the following .ODL file:

    //
    //  Type Library for Proj1.DLL
    //
        #include <otldisp.h>
        [ uuid(A7A91CE8-B974-101A-8077-00AA00339DC7), version(1.0),
          helpstring("PROJ1 ActiveX control module") ]
        library Proj1
        {
        importlib("stdole.tlb");
        importlib("stdtype.tlb");
    
    // ****** Copy code below this line ********** //
            [ uuid(A7A91CE6-B974-101A-8077-00AA00339DC7),
              helpstring("Dispatch interface for PROJ1 Control") ]
            dispinterface IProj1Ctrl
            {
                properties:
                    //{{AFX_ODL_PROP(CProj1Ctrl)
                    //}}AFX_ODL_PROP
                   
                methods:
                //{{AFX_ODL_METHOD(CProj1Ctrl)
                //}}AFX_ODL_METHOD
       
            };
    
            [ uuid(A7A91CE7-B974-101A-8077-00AA00339DC7),
              helpstring("Event interface for PROJ1 Control") ]
            dispinterface IProj1CtrlEvents
            {
                properties:
                    //  Event interface has no properties
                   
                methods:
                    //{{AFX_ODL_EVENT(CProj1Ctrl)
                //}}AFX_ODL_EVENT
            };
    // ****** Copy code above this line ********** //
    //  Class information for CProj1Ctrl
    
         [ uuid(003256C3-AA78-11CE-8C98-00AA00339DC7),
           helpstring("Proj1 Control"), control ]
         coclass Proj1
         {
              [default] dispinterface _DProj1;
              [default, source] dispinterface
                _DProj1Events;
         };
    };
    
  2. Paste the code that you copied in the example above into PROJ2.ODL, just prior to the last closing brace.

Modifying the Proj2 Makefile

Now that you have moved the needed files from Proj1 to the COMBINED directory, incorporate them into the Proj2 makefile.

Note   If PROJ2.MAK is an external makefile, edit it directly to add the new files from Proj1.

To incorporate Proj1 files into the Proj2 makefile

  1. On the File menu, click Open.

  2. Select the drive and directory containing the project workspace that you want to open.

    For this example, select the COMBINED directory and choose the Proj2 project (Proj2.dsp).

  3. Click Open to open the project and close the Open dialog box.

  4. On the Insert menu, click File.

  5. In the Insert File dialog box, double-click PROJ1CTL.CPP.

    This inserts the file into the project.

  6. Repeat Steps 4 and 5 for PROJ1PPG.CPP.

  7. Click Close to save changes to the makefile and to close the Insert File dialog box.

Combining the Resources of Both Controls

The last modification required before building the project is to add the resources from PROJ1.RC to PROJ2.RC. This is easy to do because you can drag and drop resources from one project into another.

To add resources from Proj1 to Proj2

  1. On the File menu, click Open.

  2. Select the drive and directory containing the project workspace that you want to open.

    For this example select the COMBINED directory and choose the Proj2 project (Proj2.dsp).

  3. On the File menu, click Open.

  4. Select PROJ1.RC from the PROJ1 directory.

  5. Click OK to close the Open dialog box.

  6. Click the ResourceView tab in the Project Workspace window to see resource folders for the two projects.

  7. Click the ‘+” icons to expand the resource folders for the two projects.

  8. Double-click a folder for a particular resource type in Proj1 to open the folder.

  9. Drag and drop the bitmap, icon, string resources, and property pages from Proj1 into Proj2. Be sure to hold down the CTRL key so the resources are copied and not moved.

    For an example of a similar procedure, see in Tutorials.

  10. After you have added the resources, save the changes by clicking Save.

Building the New Project

After completing the preceding steps, you can build the new project as you would any ActiveX control project. Once the project has been successfully built, register the controls. You can then use Test Container, or another container application, to test your ActiveX control. For more information on this procedure, see the article Test Container.

Please note that the .CLW file for Proj2 needs to be rebuilt to include the new classes added from the PROJ1 project.

To rebuild your .CLW file

  1. On the File menu, click Open.

  2. Select the drive and directory containing the project workspace that you want to open.

    For this example, select the COMBINED directory and choose the Proj2 project (Proj2.dsp).

  3. Click the ResourceView tab to view resources in the project.

  4. Click ClassWizard on the View menu.

    A dialog box will appear, stating that your project’s .CLW file does not exist.

  5. Click Yes to select the source files to be used.

  6. Click OK to select all files in the project and rebuild the .CLW file.

ClassWizard will now open with all classes from Proj2 loaded and accessible.