Automation Clients: Using Type Libraries

OverviewHow Do ISample

Automation clients must have information about server objects’ properties and methods if the clients are to manipulate the servers’ objects. Properties have data types; methods often return values and accept parameters. The client requires information about the data types of all of these in order to statically bind to the server object type.

This type information can be made known in several ways. The recommended way is to create a type library.

For information on Microsoft and , see the OLE Programmer's Reference in the Win32 SDK.

ClassWizard can read a type-library file and create a dispatch class derived from . An object of that class has properties and operations duplicating those of the server object. Your application calls this object’s properties and operations, and functionality inherited from COleDispatchDriver routes these calls to the OLE system, which in turn routes them to the server object.

ClassWizard automatically maintains this type-library file for you if you chose to include Automation when the project was created. As part of each build, the .tlb file will be built with MkTypLib.

To create a dispatch class from a type-library (.tlb) file

  1. In ClassWizard, click the Add Class button. The Add Class button appears on each tab of ClassWizard.

    The Add Class menu appears.

  2. On the Add Class menu, click From a type library.

    An Import from Type Library dialog box appears.

  3. In the Import from Type Library dialog box, select the .TLB file.

    Tip   Some type library information is stored in files with .DLL, .OCX, or .OLB file extensions.

  4. Click OK.

    The Confirm Classes dialog box appears. The list contains the external names of the classes described in the type-library file. Other controls in the Confirm Classes dialog box show the proposed names for the dispatch classes and for the header and implementation files for those classes. As you select a class in the list box, the Class Name box shows the name for the corresponding class.

    You can use the Browse buttons to select other files, if you prefer to have the header and implementation information written in existing files or in a directory other than the project directory.

  5. In the Confirm Classes dialog box, edit the names of the new dispatch classes and their files.

  6. Click OK to close the Confirm Classes dialog box.

    The Type Library Tool writes header and implementation code for your dispatch class, using the class names and file names you have supplied, and adds the .CPP file to your project.

See Also   ClassWizard: Adding Automation Properties and Methods