11

Building VxDCOM Applications



11.1    Introduction

This chapter describes the step-by-step process of creating and building VxDCOM applications using Tornado. To more easily create VxDCOM applications, the basic VxDCOM support includes the following tools:

an application wizard

a C++ template class library

an IDL compiler

For a detailed description of the VxDCOM technology, see the VxWorks Programmer's Guide: VxDCOM Applications.



11.2    The VxDCOM Development Process

VxDCOM clients and servers for VxWorks can be created either as bootable or downloadable applications. The following step-by-step overview summarizes the VxDCOM development process:

Step 1:   Create a Bootable Image with VxDCOM Support

Build a VxWorks bootable image with VxDCOM support components. You will need this image whether you are creating a bootable or a downloadable application. This step is covered in Configuring a VxDCOM Bootable Image on p. 373.

Step 2:   Configure Any DCOM Component Parameters

Optionally configure the parameters for the DCOM components. This step is covered in Configuring the DCOM Parameters on p. 374.

Step 3:   Generate Skeleton Project Files with the VxDCOM Wizard

Run the VxDCOM wizard from the command line. Use the wizard to define the CoClass and interfaces, to choose the server model and client skeleton program. This generates skeleton files for header prototypes, coclass definitions, interface and library definitions, and so on. These steps are described in Using the VxDCOM Wizard on p. 375.

Step 4:   Implement the Server and Client

Complete the implementation of the server by editing the CoClass files to implement the interface methods. These files also contains (auto-generated) code to auto-register the server. This step is covered in the Implementing the Server and Client on p. 386.

Step 5:   Add the Files to Project and Build It

Choose a bootable or downloadable application model. You can use either the project facility or the makefile, generated by the wizard, to build your application. Build and link the application. This step is covered in Building and Linking the Application on p. 387.

  1. Build the application.
  1. Ensure that it is correctly linked with proxy/stub code.
  1. Build the client program, if your project includes one.

Step 6:   Register and Deploy Your VxDCOM Application

Deploy your application by registering the type library and setting the proper configurations for server authentication. These steps, listed below, are described in Registering, Deploying, and Running Your Application on p. 388.

  1. Register any necessary proxy DLLs on Windows.
  1. Register the type library.
  1. Register the server.
  1. Authenticate the server.
  1. Run the application and activate the server.


11.3    Configuring a VxDCOM Bootable Image

Whether you choose to create a bootable or downloadable client or server, you need a VxWorks bootable image that contains a kernel and VxDCOM support. You need such an image for all VxDCOM applications.

If you are creating a bootable application, add your VxDCOM application files to the bootable system image. If you are creating a downloadable application, add your VxDCOM files to this downloadable module. Then download that module to the bootable system containing the VxDCOM support.

11.3.1   Adding VxDCOM Component Support

After you have created the kernel, add the appropriate VxDCOM support components. Some components are required for all VxDCOM applications, some are required only for DCOM, and some are optional, providing additional functionality. This section describes VxDCOM support and when to add it to your kernel.

COM Core Component

This component is called COM_CORE and provides support for C COM projects as well as C++ COM and DCOM projects.

COM Support Component

The COM support component is required for all C++ COM and DCOM applications.

DCOM Support Components

The DCOM and DCOM_PROXY support components are required for DCOM applications. The DCOM component provides support for distributed COM. The DCOM_PROXY component provides support for proxy/stub code. Both of these components require the basic COM support, described above.

OPC Program Support

The DCOM_OPC support component is required if you are writing your own OPC server. If you are using the VxOPC product it is not required. For more information, see the VxWorks Programmer's Guide: VxDCOM Applications.

ComShow Routines Support

The COM_SHOW support component is required only if you want to use the COM show routines. Including this component adds diagnostic routines that may be used to interrogate the registry held within the VxWorks run-time.

DCOMShow Routines Support

The DCOM_SHOW component is required only if you want to debug the VxDCOM wire protocol. Including this component adds a significant overhead; therefore, it should only be used at the request of Wind River Customer Support to provide debug information. It should not be shipped as part of a production system.

11.3.2   Configuring the DCOM Parameters

If your application includes DCOM, you can optionally configure parameters for this component. Change the parameter values from within the project facility by selecting Properties from the popup menu on the appropriate binary component.

The DCOM parameter descriptions, their default values, and the value ranges are described in VxWorks Programmer's Guide: VxDCOM Applications.



11.4    Using the VxDCOM Wizard

The VxDCOM Wizard lets you generate a completely new VxDCOM project, or import an existing COM or DCOM server. To run the wizard, type at the command line:

% installDir/host/hostType/bin/torVars.bat  
% comwizard projDir 

where the projDir is the directory for your project. The files generated by the wizard are generated in this directory. The directory name you type in is the default name for your CoClass for new projects. You have an option to modify this name in the wizard.

11.4.1   Choosing the Project Type

The first page of the VxDCOM wizard, shown in Figure 11-1,lets you choose the project type. The options are:

Figure 11-1:   Choosing the VxDCOM Project Type

Create COM/DCOM Skeleton Project

Import existing files into new Project

Choose the type of project and click Next.

11.4.2   Creating a COM/DCOM Skeleton Project

If you are creating a new project, you simply specify your server type and implementation language, and define your CoClass and interfaces using the wizard GUI. You do not have to write then in IDL (Interface Definition Language); nor do you have to write proxy/stub code.

From the information you enter, the wizard generates the primary IDL definition file and the additional files appropriate to the server model and client program selected. These output files are described in The Generated Output on p. 383.

Defining the CoClass

Figure 11-2 shows the CoClass Input dialog of the wizard. From this dialog you define the CoClass by adding interface methods and parameters. This dialog defaults to a CoClass named for the argument you passed to comwizard.

Figure 11-2:   Defining the CoClass

You can modify the name of the CoClass (or any items), by highlighting the item and choosing Edit.

To define the CoClass, you add interfaces and interface methods, and you specify parameter types for those methods. You typically do this in steps:

  • Add one or more interfaces to the CoClass.

  • For each interface, add one or more methods.

  • For each method, add one or more parameters, specifying the attribute and type of each.

When your CoClass definition is complete, click Next.

Adding Items

To add an item, highlight the item and choose Add, as shown in Figure 11-3. This opens the appropriate Add dialog. These dialogs let you enter names for new interfaces, interface methods, or interface method parameters.

Figure 11-3:   Adding Interfaces

Adding Method Parameters

When adding interface method parameters, you must also specify the attribute and type of each parameter. As shown in Figure 11-4, edit boxes for the parameter attribute and type appear with defaults. To change these, select the correct option from the dropdown listboxes. Once you click Apply, your selections will appear in the CoClass definition.

Figure 11-4:   Adding Method Parameters


Figure 11-5:   Method Parameter Data Types


It is also possible to use non-automation types, however these are not available from the VxDCOM wizard dialog and may require additional linking. If you need to use non-automation data types, see the Adding Non-Automation Types.

The widl tool compiles both automation data types and non-automation data types. The types compiled by widl are listed in the VxWorks Programmer's Guide: VxDCOM Applications.

Choosing CoClass Options

Once your CoClass definition is complete, clicking Next displays the CoClass Options dialog of the wizard, shown in Figure 11-6. From this dialog you specify the CoClass server model, implementation language, and any optional client programs. Then click Next.

Figure 11-6:   Choosing CoClass Options

Server Models

Choose the Server Model for which you want to generate project files.

COM

DCOM

Language
Choose the language used to implement the server CoClass.
C++

C

Client Skeleton Programs

Depending upon the server model, you can select from among several client application types. If you have a COM server, you can have only one C++ COM client project. If you have a DCOM server, you can choose more than one client program and clients of any type. Choosing a client program is optional.

C++ COM Client Program

C++ DCOM Client Program

Visual Basic DCOM Client Program

Generating the Skeleton Files

The last dialog of the wizard, Project Creation, appears. Simply click Finish to generate your project.

11.4.3   Importing Existing Files into a New Project

Porting Existing Applications

If you have an existing COM application, choose the option to Import existing files into new Project and choose Next. This brings up the Import Existing Project dialog shown in Figure 11-7.

Figure 11-7:   Adding Existing VxDCOM Files

The files to add are the .idl file, the server implementation file, and the CoClass header file.

Editing IDL Files

If you wish to edit your .idl file by hand, you can refer to the VxWorks Programmer's Guide for details on the IDL file structure and the correct syntax for defining elements in that file. Remember to specify an HRESULT as the return type for all interface methods and to use automation data-types and directional attributes appropriately for your interface parameters.

If you do not use automation data types, refer to Adding Non-Automation Types below. As a guide for writing in these files you can use the wizard GUI dialogs and wizard generated IDL files, and the CoMathDemo.idl file.

If for any reason you need to add additional interface definitions manually to the auto-generated .idl file, for each additional interface you must:

  • Generate a new GUID (you can use the UUIDGEN utility to do this).

  • Specify this value as the [uuid] attribute of your interface.

Adding Non-Automation Types

If you are using non-automation data types, the simplest way to add them is to generate all of the simple automation data types for the interface first using the wizard, generate the skeleton code. Then edit the .idl file and server implementation file by hand, adding the interface methods that could not be added with the wizard because they use non-automation types.

If you are defining interface methods that use non-automation types, you would not use the [oleautomation] attribute in your interface definition.

For more information on IDL, see the Microsoft documentation. Be aware that some of that information applies only to RPC interfaces and not to COM interfaces.



11.5    The Generated Output

The wizard generates output files in several subdirectories of your project name directory referred to here as basename. The content of those directories differs depending upon the options you selected in the wizard.

Output Directories

When the wizard finishes running it generates output files and creates 2 directories, which are:

  • basename
  • basename/Client

Subsequent sections describe the additional files that appear in these two directories. Depending upon the type of server and client you selected in the wizard, the content of these directories differs.

Project Work Files

These are the primary files to identify for working with your project. You can use these files to write code, compile, edit, or browse. Some are used for compiling, linking, building, and deployment of your application.

Makefile

basename.idl

basenameImpl.cpp

basenameImpl.h

Client/basenameClient.cpp

Client/basenameDCOMClient.cpp

Client/basename.rgs (DCOM -only)

Client/nmakefile (C++ Client only)

Server Output Files

The COM and DCOM server files differ only in the proxy stub code file used for marshaling.

COM Server Output

These are the files output to the basename directory for a COM server application.

  • basename.h
  • basename.idl
  • basenameImpl.cpp
  • basenameImpl.h
  • basename_i.c
DCOM Server Output

These are the files output to the basename directory for a COM server application.

  • basename.h
  • basename.idl
  • basenameImpl.cpp
  • basenameImpl.h
  • basename_i.c
  • basename_ps.cpp

This file is output to the basename/Client directory, whether or not a client type is selected from the wizard:

  • basename.rgs file

Client Output Files

If you selected more than one client program with your server choice, then all files necessary for each client are output into the basename/Client directory. Remember that, for DCOM server projects, the basename/Client directory also contains the basename.rgs file. However, this file is only used by DCOM clients to register the type library.

COM Client Output

For a COM client, the following files are generated in the Client directory:

  • basenameClient.cpp

DCOM C++ Client Output

For a DCOM C++ client, the following files are generated in the Client directory:

  • basenameDCOMClient.cpp

  • nmakefile

DCOM Visual Basic Client Output

For a DCOM Visual Basic client, the following files are generated in the Client directory:

  • basenameClient.bas



11.6    Implementing the Server and Client

Once your system is created, you are ready to implement your CoClass methods for the server component and write the code for any client programs.

  • COM server code in the implementation file basenameImpl.cpp, located in your project directory.

  • COM client code in the implementation files, which are either basenameClient.cpp for a C++ COM client, or basenameDCOMClient.cpp for a C++ DCOM client. The client implementation files are located in the /Client subdirectory of your project directory.

The VxWorks Programmer's Guide: VxDCOM Applications describes this process. That chapter includes a reference for WOTL, the C++ template library used to write VxDCOM applications. It also covers the topics of using real-time extensions, adding OPC interfaces, working with HRESULT return values, and details of the SAFEARRAY types supported under VxDCOM.



11.7    Building and Linking the Application

Add the appropriate files, generated by the wizard, to your project. These files include the implementation code for the server and client. If you are creating a bootable application, add the files to the bootable system image. If you are creating a downloadable application, add the files to a downloadable module, ensuring that the module is downloaded to a bootable system containing the required VxDCOM support for you application.

Then, build the project. Although you can use the project facility from the IDE to build, the recommended method is to use the wizard-generated Makefile from the command line. The generated Makefile automatically runs widl. If you are building from the project facility, you must run widl manually. Running widl generates the proxy/stub code, the identification GUIDs, and the interface header prototypes. The build process also links the proxy/stub code.

Linking Proxy/Stub Code

The proxy/stub components generated by widl are required for the marshaling method used to remotely invoke interface methods across task boundaries.1 In order for your application to use marshaling, server and client code must be linked with proxy/stub code. The proxy/stub code source file is basename_ps.cpp and the derived object file is basename_ps.o. You will find these in the workspace under each client and server component. The proxy/stub code is automatically linked to your client and server components when the system is built in the IDE.

On an NT machine, proxy/stub code is not required for automation data types.

Building the Win32 Client

To build the client application for Win32, be sure that you have Visual C++ installed with the path to nmake configured in the command shell. Then, from the command line, run:

nmake -f nmakefile


11.8    Registering, Deploying, and Running Your Application

This section describes registering proxy DLLs, the type library, and the server, authenticating and activating the server.

11.8.1   Registering Proxy DLLs on Windows

If your project uses non-automation types, you must register the proxy DLLs on Windows.

Typically, when you define your interface you use automation data types. These are the types you can select from the VxDCOM wizard for your interface method parameters. When you use these types, the parameters are defined by the [oleautomation] attribute, to indicate that they are automation types. This signals to the Win32 Automation Marshaler that no extra Win32 proxy/stub DLLs are required because the marshaling of these types is handled automatically.

However, if your project requires non-automation types then you cannot specify the [oleautomation] attribute nor automate the marshaling of the parameter types. For interfaces that use non-automation types, you must generate and install your own Win32 proxy/stub DLLs. The DLL containing the interface proxy must be distributed with all client applications that use that new interface.

The specific non-automation types that widl can compile are described in the VxWorks Programmer's Guide: VxDCOM Applications.

The details of generating Win32 proxy/stub DLLs is outside of the scope of this document. Please refer to the Win32SDK MIDL documentation for details.

11.8.2   Register the Type Library

The type library is a binary file with a .tlb extension, that stores information about a DCOM object's properties and methods in a form that is accessible to other applications at run time. Windows' client applications use a type library to determine which interfaces an object supports and how to invoke the interface methods. For this reason, the type library must be registered. To register the type library, run installDir\host\x86-win32\bin\vxreg32.exe. This command adds the type library to the Windows Registry at its current location, so that the object can be accessed from the Windows host. If you add interfaces to the IDL file, the type library must also be re-registered so that the interface becomes known to the Windows Automation Marshaler.

The registry will contain an entry called `vxworks.target' that needs to be modified to point to the actual target, so that it is available from, for example, Visual Basic. There are two ways to change the target machine entry and register the type library:

  • Edit the basename.rgs file (generated by the wizard) by changing the `vxworks.target' entry to the target IP address, and then run vxreg32 as described above.

  • Run vxreg32 first, and then change the Windows registry entry for the target by opening up DCOMCNFG and using that tool to change the location.

11.8.3   Registering the Server

You must register your DCOM server classes in the VxWorks COM registry, so that client applications can locate them. There is one server-class per object-module. The object-module contains the server-class code, the proxy/stub code, and a registration object. This registration object registers the server-class with the VxWorks Registry when its constructor runs, guaranteeing that modules are automatically registered, regardless of whether they are pre-linked or downloaded. This auto-registration process does not rely on constructor ordering and can, thus, be safely performed at any point during system initialization.

To automatically register a DCOM server at load time or system startup, include the AUTOREGISTER_COCLASS macro in the CoClass implementation file. This will create an entry for the class in the VxWorks COM registry. AUTOREGISTER_COCLASS associates the CoClass with its CLSID, and registers the module name in the VxRegistry against its CLSID.

This macro is automatically included when the skeleton implementation file is generated. Thus, you do not need to add the macro code yourself (unless you work with files that were not auto-generated.)

The AUTOREGISTER_COCLASS macro takes three arguments: the server implementation CoClass, priority-scheme, and the default priority. The priority parameters are used as part of the real-time extension priority schemes, and are discussed in the VxWorks AE Programmer's Guide: Writing COM and DCOM Clients and Servers.

11.8.4   Authenticating the Server

The DCOM registry under VxWorks is not the complex, multi-purpose registry that Win32 supports, but is designed specifically for that purpose of:

  • Allowing COM server classes to register their CLSIDs (class-IDs).

  • Providing a link to an instantiation procedure, given that CLSID.

  • Determining the correct proxy/stub configuration for any given interface, given its IID (unique identifier).

Therefore, the VxWorks registry works on a simple associative lookup method, keyed by the interface and class identifiers. The value that can be stored in the registry-entry is simply a string, which is used by various internal functions to look up proxy/stub classes, system-provided objects (such as the standard marshaler), and other objects identified by these values.

VxWorks also exposes non-Win32-compliant API calls to provide access to this registry. However, user/application code does not need to use these APIs, since widl automatically generates the code for registration of server-classes.

VxDCOM can participate in the basic NTLM authentication procedures when acting as a server, but not as a client. It can recognize incoming authentication requests from NT and correctly take part in the challenge/response transaction, but by default will not take any action based upon those transactions. Future versions of VxDCOM may more fully support the NTLM security system depending upon NT domain security, network trusts, and so on. However, for now the safest and most predictable approach is to disable client-side security by using either the registry/DCOMCNFG tool or by calling CoInitializeSecurity( ).

11.8.5   Activating the Server

After you have completed these steps you can run your program. See the VxWorks Programmer's Guide: VxDCOM Applications for descriptions of the MathDemo program client code, which activates the demo server component.

All VxDCOM threads must be created with VX_FP_TASK.


1:  Win32 uses type library based marshaling. VxDCOM generates custom marshaling code that is linked into the object module.