Program startup code

From Amiga Development Wiki
Revision as of 06:47, 30 July 2015 by AmigaDeveloper (Talk | contribs) (Fixed SysBase read in the Amiga startup code)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;
}