home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
programming
/
libtool_463
/
libtool.lzh
/
CComplex
/
ComplexC.DOC
< prev
next >
Wrap
Text File
|
1990-06-27
|
4KB
|
86 lines
This describes how to make the "complex.library" C example. If you have not
made the "simple.library" C example, do so first.
The primary difference between the complex and simple example is that the
complex example introduces the Init, Expunge, Open, and Close vectors, and a
scheme for avoiding global data.
When a library is first loaded, an initialization routine is called. This is
the routine that opens the intuition, graphics, DOS, and exec libraries on
behalf of your lib functions. There are some other things that you might want
to do (once only) when the lib is first loaded. For example, you might want
to set up a port, or start a separate task. These are things that you only
wish to do once at the beginning. If you need to do something like this, you
should write a function, and place it with your lib functions. Now, add a
##init line to your fd file followed by the name of your function. For example,
if your function is myInit().
##init myInit
You'll probably want to free that port, or remove that task when you're lib
finally gets removed from memory. You do this by writing a function to free/
close anything that you allocate/open in your Init function. Assume that we
wrote a function called myFree(). Add this line to the fd file
##expu myFree
On the other hand, there are things that you might need to do once for each
task that uses the lib. For example, you may want to allocate some memory for
each task to be used as a "work buffer". Each task needs its own memblock to
be allocated once when the task opens the lib. Write a function to do this, and
set it up as the Open vector. Here is an example of an Open vector, OpenIt().
##open OpenIt
Now, you'll want to free each task's memory when the task closes the lib. You
do this by writing a function and setting it up as the Close vector. For
example, you might add this line to the fd file for some CloseIt() function.
##clos CloseIt
You can set up one or all four of the above vectors. Just remember that the
Init function only gets executed once when the lib is loaded. The Open routine
gets executed everytime that an application opens the library. You should free/
close anything that you allocate/open in the Init function, with a corresponding
Expunge function. Likewise, a Close function complements an Open function.
The Close and Expunge vectors return VOID. The Init and Open vectors are BOOL
returns. TRUE means that everything went well, and FALSE for an error. If FALSE,
this will force the application's OpenLibrary to fail. Your Init and Open
routines are responsible for cleaning up their partially allocated resources.
The complex.library sets up an Open and complimentary Close vectors for the
above purpose. Each task gets a work buffer which we use for making a newWindow
structure. This work buffer gets linked into a master list so that I can keep
track of all of them. I use the address of each task to tag its work buffer.
Note these 2 functions, OpenUp() and CloseUp() in the file "Complex.c".
Also, note how I set them up in the fd file "ComplexC.fd".
This library also has 3 functions:
MakeWindow - opens a window
PrintMsg - prints a msg and waits for a CLOSEWINDOW
RemWindow - closes the window
Note that I have changed the name and id of the library. Also note how I
use the ##ret to declare the return values of the lib functions.
To make the library, compile and assemble "Complex.c" as "Complex.o". Use
LARGE CODE, LARGE DATA. For Manx, we also want +b to eliminate the .begin
statement. Invoke LibTool on "ComplexC.fd" to make our glue code and libstart
code.
LibTool -cmho glue.asm ComplexC.fd
You should see "glue.asm", "ComplexC.h", and "ComplexC.src". Assemble
"ComplexC.src" as "LibStart.o" and assemble "glue.asm" as "glue.o".
Link the library as follows
blink LibStart.o Complex.o LIB lib:lcnb.lib NODEBUG TO libs:complex.library
ln -o libs:complex.library LibStart.o Complex.o -lcl32
To make a test application, compile and assemble "ComplexCApp.c". Link as:
blink lib:c.o ComplexCApp.o glue.o LIB lib:lcnb.lib NODEBUG TO ram:TestProgram
ln -o ram:TestProgram ComplexCApp.o glue.o -lcl32
Now run ram:TestProgram.