• Keine Ergebnisse gefunden

Compiling a Method Table

Im Dokument PenPomt GO (Seite 56-59)

To match messages sent to objects created by a class, add a line to the end of the MSG_INFO array that uses objWildCard as the message name and specifies a method as usual. For example:

MSG_INFO foo = {

msgNew, "HandleMsgNew", 0,

objWildCard, "HandleAllOtherMsgs" , 0,

°

Compiling a Method Table

To compile a method table you need

• The C compiler (including DOS4GW.EXE)

• The method table compiler, MT.EXE.

45 GIl:

l

46 PENPOINT ARCHITECTURAL REFERENCE Part 1 I Class Manager

The method table compiler is delivered with the PenPoint SDK in the directory

\PENPOINT\SDK\ UTIL\MT.

~. Running MT

Usually you compile your method table simply by running the method table compiler, MT.EXE. Before you run the method table compiler, you must make sure that MT.EXE is in your local directory or your path includes the directory that contains MT.EXE.

The run command for the method table compiler has the following syntax:

NT infile

If the input file has a .C or .TBL extension, the method table compiler:

• Compiles your method table with the C compiler, which results in an intermediate object file

• Processes the resulting object file to produce the method table object file and corresponding header file.

Compiling Method Tables With Wildcards

When you compile method tables that use wildcards, the method table compiler uses the assembler.

You must specify a path that includes the assembler during the compile phase for method tables if you use wildcards. The simplest strategy is to put the assembler in the same directory as the compiler executable files.

MT Output Files

The method table compiler produces a header file and an object file. These files have the same name as the .TBL file, but with the extensions .H and .OBJ, respectively. If you already have a file with the same name and the extension .H, the method table compiler will overwrite it. For example, FOO.TBL will generate FOO.H and overwrite any previous version of FOO.H.

The header file contains the declarations for each of the methods. You must

#include this file in the sources that define the methods for your class.

The object file contains the method table code used by the Class Manager when it routes a message to an instance of your class.

"'~. Compiling in Two Steps

Although the method table compiler will run the C compiler for you, if you run MT from MAKE, you may run out of memory. If this happens, you should compile your method table in two steps:

1 Use the C compiler to compile your method table.

2 Run MT on the resulting intermediate object file to create the method table object and header files. If MT does not detect a .C or .TBL extension, it does not run the C compiler.

3.8.3.2

3.8.3.4

·.nstalling a Class in PenPoint

CHAPTER 3 I CREATING A NEW CLASS Installing a Class in Pen Point

The way that you compile and link your class affects the way in which PenPoint finds the routine used to install your class. You can compile and link your classes one of two ways:

• If your class is part of an application and will not be used by any other clients, you can link your class with your application to create an application executable file.

• If your class might be used by a number of clients (including your appli-cation), you can link your class separately to create a DLL file.

Your class must contain some code that sends msgNew to clsClass to install your class. If the class is part of your application executable file, you install your class when you install your application (that is, in mainO when process equals 0).

If the class is in a DLL file, you install the class from the DLLMainO routine. If your application requires a class in a DLL file, it can name the DLL file in the application installation .DLC file. For more information on DLL and .DLC files, see PenPoint Application Writing Guide.

The Class Initialization Routine

The purpose of the class initialization routine is to send msgNew to clsClass.

clsClass is a special class that exists solely to install new classes.

Before you send msgNew to clsClass, you must create, initialize, and modifY a CLASS_NEW structure that describes the new class. You initialize the CLASS_NEW structure by sending msgN ewDefaults to clsClass.

The CLASS_NEW structure contains an OBJECT_NEW_ONLY structure (object) and a CLASS_NEW_ONLY structure (cls). The OBJECT_NEW_ONLY structure contains:

uid the well-known UID that you will use for this class.

key a key value for the class.

cap the capabilities for the class.

The CLASS_NEW_ONLY structure contains:

pMsg a pointer to the method table for your class. The method table name is the first field in the CLASS_INFO entry that you created in your method table definition file. If this is an abstract class (one that defines messages but has no methods), you can specifY pNull.

ancestor the UID of the class that is the immediate ancestor of this class.

size The size of the instance data for instances of this class. The size of instance data must be less than 64K bytes. If the size is not 0, you should usually have methods for msgSave and msgRestore to handling filing of the instance data.

47

48 PEN POINT ARCHITECTURAL REFERENCE Part 1 / Class Manager

The instance data can be be a pointer to a heap where the data is stored.

Pointers are useful when you do not know what the exact size of the data for a given instance will be.

newArgsSize The size of the _NEW structure used to create instances of this class. It is usually set by SizeOf(..._NEW).

When you send msgN ew to clsClass, the message returns a status value. If the Class Manager creates the class successfully, msgNew returns stsOK and the object.uid field contains the UID of the new class.

Example 3~2

Im Dokument PenPomt GO (Seite 56-59)