Ok, I resourt to ask you why this doesn't work. :-o
This painfully was stripped down from some program I'm doing, or should I say, trying to...
Here's the deal. Two programs, the MainTask and the OtherProcess. MainTask loads and creates the OtherProcess, wich is compiled sperately, from Ram: using CreateNewProc() (or CreateProc() wich older AOS versions). After loading OtherProcess Maintask sets up a message and a port to receive a reply.
The problem is the MainTask simply stops and hangs and I can't close the window. Given the code it should stop print a message and exit if it doesn't find the OtherProcess port. So I take it it finds it? But it just stops and the OtherProcess doesn't even output the initial message.
I managed to make it work like this. Runing the OtherProcess first from workbench(haven't tried from another shell but i guess it should work too) and then running the MainTask.
But in this case two instances of OtherProcess are running right?
So I take it that the MainTask is missing something to make the OtherProcess run. I wanted also know what's missing for it to display the messages in the same Window as the MainTask, cause that's what was intended when I wrote the code.
Here's the code for both, no clean up is included for simplicity, don't bother I just want to know why it doesn't work, my main program has cleanup for this part of the ini process.
MainTask
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <exec/execbase.h>
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/exec.h>
#include <utility/utility.h>
#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <stdio.h>
#include <stdlib.h>
struct Library *UtilityBase;
struct MsgPort *ReplyPort;
struct MsgPort *OtherProcessPort;
BPTR OtherProcessSegList = 0;
struct Message_to_OtherProcess
{ struct Message MesstoOP;
struct Task *MainTask;
struct Task *OtherProcess;
};
struct Message_to_OtherProcess *Message_to_OtherProcess, *OtherProcessResponse;
struct Task *MainTask; /*This task*/
struct Task *OtherProcess;
int main (int argc, char **argv)
{
extern struct ExecBase *SysBase;
char *OtherProcessName = "Ram:OtherProcess";
struct MsgPort *OtherProcess35;
struct Process *OtherProcess;
BPTR MainTaskOutputHandle;
if (!(Message_to_OtherProcess = (struct Message_to_OtherProcess *)AllocMem (sizeof(Message_to_OtherProcess),MEMF_PUBLIC|MEMF_CLEAR)))
{printf ("Couldn't allocate memory for Message to OtherProcess\n");
exit (0);}
if (!(ReplyPort = CreatePort (0,0)))
{printf ("Couldn't create ReplyPort\n");
exit (0);}
Message_to_OtherProcess->MesstoOP.mn_ReplyPort = ReplyPort;
if (!(OtherProcessSegList=LoadSeg(OtherProcessName)))
{printf ("Couldn't find OtherProcess\n");
exit (0);}
MainTaskOutputHandle = Output();
printf("Exec Version is %d.%d\n",SysBase->LibNode.lib_Version,SysBase->LibNode.lib_Revision);
if (SysBase->LibNode.lib_Version<=36)
{if (!(OtherProcess35 = CreateProc("OtherProcess", 0L, OtherProcessSegList, 1000L)))
{printf ("Couldn't find OtherProcess35\n");
exit(0);}
printf ("Loaded OtherProcess35\n");
}
/* else Kickstart is >=v36, add OtherProcess using CreateNewProc */
else
{
struct TagItem TagsforCrtNewPr[5];
/*open utility library*/
if (!(UtilityBase = OpenLibrary ("utility.library",0L)))
{printf ("Couldn't open utility.library\n");
exit(0);}
TagsforCrtNewPr[0].ti_Tag = NP_Seglist;
TagsforCrtNewPr[0].ti_Data = OtherProcessSegList;
TagsforCrtNewPr[1].ti_Tag = NP_Name;
TagsforCrtNewPr[1].ti_Data = (ULONG)"OtherProcess";
TagsforCrtNewPr[2].ti_Tag = NP_Cli;
TagsforCrtNewPr[2].ti_Data = TRUE;
TagsforCrtNewPr[3].ti_Tag = NP_Output;
TagsforCrtNewPr[3].ti_Data = MainTaskOutputHandle;
TagsforCrtNewPr[4].ti_Tag = TAG_DONE;
if (!(OtherProcess = CreateNewProc (TagsforCrtNewPr)))
{printf("Couldn't find OtherProcess\n");
exit(0);}
printf("Other Process Loaded Successfully\n");
}
/*Locate MainTask*/
MainTask = FindTask(NULL);
Message_to_OtherProcess->MainTask = MainTask;
/******************** WAIT FOR OTHER PROCESS TO SET UP IT'S PORT*************************/
Delay (250);
/*Send message to OtherProcess and wait for reply*/
if (!(OtherProcessPort = FindPort ("OtherProcessPort")))
{printf("Couldn't find OtherProcessPort\n");
exit (0);}
PutMsg (OtherProcessPort, (struct Message *)Message_to_OtherProcess);
WaitPort (ReplyPort);
if (!(OtherProcessResponse = (struct Message_to_OtherProcess *)GetMsg (ReplyPort)))
{printf ("No message at port\n");
exit (0);}
printf ("Message from OtherProcess received dude!!!\n");
OtherProcess = OtherProcessResponse->OtherProcess;
/*void CleanUp (void)*/
/* Should have something like that ;) */
exit (0);
}
OtherProcess
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct Task *MainTask;
struct Task *OtherProcess; /*This one actually*/
struct MsgPort *OtherProcessPort;
struct Message_to_OtherProcess {
struct Message MesstoOP;
struct Task *MainTask;
struct Task *OtherProcess;
};
struct Message_to_OtherProcess *ReceivedMessage;
int main (int argc, char **argv)
{
printf("OtherProcess Ver1.0, 2004\n");
if (!(OtherProcessPort = CreatePort ("OtherProcessPort", 0)))
{printf ("Couldn't create OtherProcessPort\n");
exit (0);}
WaitPort (OtherProcessPort);
if (!(ReceivedMessage = (struct Message_to_OtherProcess *)GetMsg (OtherProcessPort)))
{printf ("No message received");
Delay (200UL);
exit (0);}
printf ("Message from MainTask received DUDE!!\n");
MainTask = ReceivedMessage->MainTask;
OtherProcess = FindTask(NULL);
ReceivedMessage->OtherProcess = OtherProcess;
ReplyMsg ((struct Message *)ReceivedMessage);
printf ("Message replyed...");
exit (0);
}
And by the way, could someone write a very short idiot's guide to linking with SAS C? I have it complaining about some undefined symbols and I'm pretty sure that the stub it prompts to link with as default could be the cause of some programs crashing (not in the exaple above) :oops: