[comp.sys.mac.programmer] INITs and ShutDown routines

leonardr@uxe.cso.uiuc.edu (12/31/88)

buffington@radar.UUCP(Jon Buffington) in comp.sys.mac.programmer

>I am interested in writing an INIT which installs a
>ShutDown routine.  I am using LSC 3.0 on an Mac II.
>All I have been able to accomplish so far is to bring
>up a PICT to identify what's happening and presumably
>install a routine using ShutDwnInstall().  When
>the routine is called *blammo* ID=01.  I understand
>my routine is getting scrapped my the memory munger.
>(Oddly, the INIT works sometimes on an SE.)
>What I am interested in learning is how to prevent the
>vaporization of my code.  Below is the INIT so far:
>
>[Code Follows]

	What I would recommend is what I did for my ShutDownSound INIT -
rather than keeping ALL the code in the INIT resource, actually
create two resources - the INIT and another code-type resource (I call
mine PROC).
	This scheme implies that your INIT is simply a loader.  It gets the
other resource, puts it into the system heap and locks it down.  Then it
sets it up with ShutDwnInstall.  The PROC is the actual code that you want
executed at ShutDown time.  Much cleaner and easier...
	If you need some example source, let me know!


+---------------------------------+-----------------------------------+
+                                 +  Any thing I say may be taken as  +
+   Leonard Rosenthol             +  fact, then again you might decide+
+   President, LazerWare, inc.    +  that it really isn't, so you     +
+                                 +  never know, do you??             +
+   leonardr@uxe.cso.uiuc.edu     +                                   +
+   GEnie:  MACgician             +  MacNET: MACgician                +
+   Delphi: MACgician             +  AppleLink: D0025                 +
+                                 +                                   +
+---------------------------------+-----------------------------------+

leonardr@uxe.cso.uiuc.edu (01/01/89)

Since I had a couple of requests for example source, here is the source for
my ShutDownSoundINIT loader. The code is simple enough that comments are not
included (like they should be :-)
 
{This is the loader procedure for ShutDownSoundINIT}
{It has hereby been put into the public domain by Leonard Rosenthol}
PROCEDURE Main;
		VAR
			savedZone : THz;
			theSize : integer;
			tempPtr : ptr;
			theHandle : handle;
	BEGIN
		theHandle := GetResource('PROC', 128);
		HLock(theHandle);
		theSize := SizeResource(theHandle);
		savedZone := GetZone;
		SetZone(SystemZone);
		tempPtr := NewPtr(theSize);
		IF tempPtr <> NIL THEN {It worked, let's do it!}
			BEGIN
				BlockMove(theHandle^, tempPtr, theSize);
				ShutDwnInstall(ProcPtr(tempPtr), 8);
				ShowInit(128, -1);		{This will show the ICON for us on startup}
			END
		ELSE
			SysBeep(10);
		SetZone(savedZone);
	END;
END.

P.S. I wrote this code over a year ago, and if I were to do it today I 
might change a few things.  it does however work!

+---------------------------------+-----------------------------------+
+                                 +  Any thing I say may be taken as  +
+   Leonard Rosenthol             +  fact, then again you might decide+
+   President, LazerWare, inc.    +  that it really isn't, so you     +
+                                 +  never know, do you??             +
+   leonardr@uxe.cso.uiuc.edu     +                                   +
+   GEnie:  MACgician             +  MacNET: MACgician                +
+   Delphi: MACgician             +  AppleLink: D0025                 +
+                                 +                                   +
+---------------------------------+-----------------------------------+