[Contents] [index] [Help] [Retrace] [browse <] [Browse >]

When the user activates a project or tool icon, the program is run as a
separate process asynchronous to Workbench.  This allows the user to take
full advantage of the multitasking features of the Amiga.  A process is
simply a task with additional information needed to use DOS library.

When Workbench loads and starts a program, its sends the program a
wbstartup message containing the arguments as described earlier.  the
WBStartup also contains a pointer to the new process structure which
describes the execution environment of the program.  The WBStartup message
is posted to the message port of the program's Process structure.

The process message port is for the exclusive use of dos, so this message
must be removed from the port before using any DOS library functions.
Normally this is handled by the startup code module that comes with your
compiler so you don't have to worry about this unless you are writing your
own startup code.

Standard startup code modules also set up sysbase, the pointer to the exec
master library, and open the DOS library setting up dosbase.   that is why
Exec and AmigaDOS functions can be called by C applications without first
opening a library; the startup code that applications are linked with
handles this.  Some special startups may also set up NIL: input and output
streams, or may open a stdio window so that the Workbench applications can
use stdio functions such as printf().

The startup code can tell if it is running in the Workbench environment
because the pr_cli field of the process structure will contain null.  in
that case the startup code removes the wbstartup message from the process
message port with getmsg() before using any functions in the dos library.

    Do Not Use the Process Message Port for Anything Else.
    ------------------------------------------------------
    The message port in a process structure is for the exclusive use
    of the DOS library.

Standard startup code will pass the wbstartup message pointer in argv and
0 (zero) in argc if the program is started from Workbench.  These values
are pushed onto the stack, and the startup code calls the application code
that it is linked with as a function.  When the application code exits
back to the startup code, the startup code closes and frees all opens and
allocations it made.  It will then forbid(), and replymsg() the wbstartup
message, notifying Workbench that the application process may be
terminated and its code unloaded from memory.

    Avoid the DOS Exit() function.
    ------------------------------
    The DOS exit() function does not return an application to the
    startup code that called it.  If you wish to exit your application,
    use the exit function provided by your startup code (usually
    lower-case exit(), or _exit for assembler), passing it a valid
    DOS return code as listed in the include file <libraries/dos.h>.