What You Need to Provide and What the Fortran COM Server Wizard Will Do

The Fortran COM Server Wizard generates a Developer Studio project and a number of source files that implement all of the infrastructure of a COM server. You use the Fortran COM Server Wizard's user interface to define the implementation of one or more object classes, including its interface(s), and method(s). You need to define fields in the derived-type for each instance and to write code for those fields, if necessary. You also need to write code needed to implement each method.

What Information You Need to Provide

To use the Fortran COM Server Wizard to create a COM server, you first need to describe to the Fortran COM Server Wizard the class(es) that you want to implement.

A class implements one or more COM interfaces. In COM terminology, an interface is a semantically related set of functions. The interface as a whole represents a "feature", or set of related functionality, that is implemented by the class. An interface contains methods, otherwise known as member functions. A method is a routine that performs one of the actions that make up the feature. When using the Fortran COM Server Wizard, methods are Fortran functions that take arguments and return a value like any other Fortran function.

Consider a simple example of a class that we will create using the Fortran COM Server Wizard, called AddingMachine. The class contains a single interface that we call IAdd. By convention, all interface names begin with a capital letter "I". We define three methods in the IAdd interface:

The Clear method, Add method, and GetValue method allow you to perform specific, distinct tasks with the IAdd interface from any language that supports a COM client. The Fortran COM Server Wizard provides a user interface to enter this information about the class (in this case the AddingMachine class), which is discussed later in Using the COM Server Wizard.

An interface can also contain properties. Properties are method pairs that set or return information about the state of an object. When you add a property to an interface, you are actually adding one or two methods. This is discussed further in Adding a Property.

Another important concept is the data associated with an object. A key concept of object-oriented programming is encapsulation. Encapsulation means that all of the details about how the object is implemented, including the data that it uses and the logic that it uses to perform its work, is hidden from the client. The client's only access to the object is through the interfaces that the object supports.

You need to define the data that the object uses and code the logic of the methods. For the data, the Fortran COM Server Wizard uses the model that each instance of the object has an associated instance of a Fortran derived-type. The code generated by the wizard takes care of creating and destroying the instances of the derived-type as objects are created and destroyed.

You define the fields of the derived-type. For example, with our AddingMachine, each AddingMachine object needs to store the current value. The derived-type associated with each AddingMachine object would contain a single field of type REAL. We name it CurrentValue. Note that each instance of the AddingMachine object has its own instance of the derived-type and its own CurrentValue. This means that the server could support multiple clients simultaneously and each client would see its own AddingMachine. That is, each client is unaffected by the existence of other clients. The derived-type associated with each object is discussed in detail in Creating a Fortran COM Server Project.

To summarize, at a high level, what you need to do to create a COM server using the Fortran COM Server Wizard:

What the COM Server Will Provide

The Fortran COM Server Wizard generates a Developer Studio project and a number of source files that implement all of the infrastructure, or "plumbing", of the COM server. The generated files take care of such tasks as:

The majority of these source files are generated fully by the Fortran COM Server Wizard and are not modified by you. Other files contain the skeleton or template of your derived-type and methods. You edit these Fortran source files to fill in your implementation. You will see how this is done as we work through the AddingMachine example.

For information on using the Fortran COM Server Wizard user interface to create a COM server, see Using the COM Server Wizard.