Program startup code

From Amiga Development Wiki
Jump to: navigation, search

When started from the Workbench the program must read WBStartup message from the process message port before proceeding. Following code supports program startup from the Shell and Workbench. To parse command line arguments, use ReadArgs().

#include <exec/execbase.h>
#include <workbench/startup.h>
#include <proto/exec.h>
 
int main()
{
   struct ExecBase *SysBase = *(struct ExecBase **)4;
   struct Process *process = SysBase->ThisTask;
   struct WBStartup * wbmsg = NULL;
 
   if (process->pr_CLI == 0)
   {
      WaitPort(&process->pr_MsgPort);
      wbmsg = (struct WBStartup *)GetMsg(&process->pr_MsgPort);
   }
 
   /* program code ... */
 
   if (wbmsg)
   {
      Forbid();
      ReplyMsg(wbmsg);
   }
 
   return 0;
}