[comp.sys.mac.programmer] Launching a program from LightSpeed C and returning...

mithomas@bsu-cs.UUCP (Michael Thomas Niehaus) (09/01/88)

Can someone tell me how to launch another program from a LSC 3.0 program
and get it to return to the C program after the program terminates?  I know
it is possible; however, we do not have any Mac references right now, and
guessing is out of the question.

Thanks,
Michael Niehaus

atieu@skat.usc.edu (Anthony Tieu) (09/02/88)

I would also be interested in doing the same thing. I just got 
LightSpeed C 3.0. I like to do a menu system.

Thanks!!!

shane@chianti.cc.umich.edu (Shane Looker) (09/02/88)

In article <3833@bsu-cs.UUCP> mithomas@bsu-cs.UUCP (Michael Thomas Niehaus) writes:
>Can someone tell me how to launch another program from a LSC 3.0 program
>and get it to return to the C program after the program terminates?  I know
>it is possible; however, we do not have any Mac references right now, and
>guessing is out of the question.
>
>Thanks,
>Michael Niehaus


By popular request, and comming to you from the magic of MultiLauncher...
 
struct	launch_struct {
						char *filename;
						short	setup;
						char	LC[2];
						long	ExtBlockLen;
						short	fFlags;
						long	LaunchFlags;
					}
main()
{
	[ Insert your code here... ]


	Launch_Data.filename = &finalname[0];	/* Set the path name */
	Launch_Data.setup = 0;					
	Launch_Data.ExtBlockLen = 6;	/* Size of following data */
	Launch_Data.LaunchFlags = 0xC0000000;	/* Set the launch flags */
	Launch_Data.LC[0] = 'L';Launch_Data.LC[1]='C';
	/* ^ Flags to indicate the extended launch structure follows  ^ */
	
	Launch_Data.fFlags = targetInfo.fileParam.ioFlFndrInfo.fdFlags;
					/* ^ from PBGetFInfo */
	
	

	/* Hand assemble the _Launch trap.  Put the parameter block */
	/* pointer in register A0, then away we go.                 */
	asm {
			LEA	Launch_Data, A0
			_Launch
		}

--------------

The extended data structure is described in TechNote 126, "Sublaunching:
Playing the Shell Game".

The Launch flags should have BOTH high bits set according to TN126.  Some
research shows that under MultiFinder, these settings seem to have these
effects:
 
         LaunchFlags         Effect
         -----------         ------
         0xC0000000          SubLaunch and continue first task.
         0x80000000          Transfer control.  No Return.
         0x40000000          SubLaunch and continue first task.
         0x00000000          Transfer control.  No Return.


Under UniFinder, If you set the high bits, it should return correctly.
Remember, you can't be guaranteed to run under UniFinder, however.

(If Apple has a way to suspend execution and then reload, I would love to
 use it.)

Shane Looker
Looker@um.cc.umich.edu