[comp.sys.mac.programmer] Inits and Dialogs

mikeoro@hubcap.clemson.edu (Michael K O'Rourke) (09/29/89)

I am trying to get a dialog to display in an init and having loads of
troubles.  My init loads a driver i wrote and i want a dialog displayed
in case of an error when tring to load the driver.

Is there something special that has to be done?  Can someone take a look at
the code below and offer suggestions (possibly as to my stupidity) or could
someone send me example code?

The following init dies when it hits the DisposDialog.  Macsbug says it
dies in the PaintOne routine, if that helps at all.  

Michael O'Rourke
Clemson Unversity

***************************************************************

#include "Color.h"
#include "Appletalk.h"
#include "nAppletalk.h"
#include "SetUpA4.h"

main()
{
int installed;
int refNum;
	RememberA0();
	SetUpA4();
		
	InitGraf(&thePort);
	InitFonts();
	InitWindows();
	InitMenus();
   	TEInit(); 
 	InitDialogs(0L);

	installed = OpenDriver("\p.LABtools",&refNum);
	installed = -98;
	
	if (installed != 0) {
	  switch (installed) {
	   case -1  :
	   case -98 :	
		Error("\pLABtools needs AppleTalk to run."); 
		break;
	   case -2 :
		Error("\pNot enough memory");
	  }
	RestoreA4();
}


Error(s)
Str255 s;
{
#define ErrorID 0
DialogPtr Dptr;
int itemhit;

	ParamText(s,"\p","\p","\p");
	Dptr = GetNewDialog(ErrorID,0L,(Ptr) -1);
	itemhit = 0;
	while (itemhit != 1)
		ModalDialog(0L,&itemhit);
	DisposDialog(Dptr);
}

lsr@Apple.COM (Larry Rosenstein) (09/30/89)

There's a low memory hook that paints the desktop (DeskHook=$A6C).  Tech 
Note 247 says you have to clear this on machines before the Macintosh II.  

Larry Rosenstein, Apple Computer, Inc.
Object Specialist

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1

kingman@tci.bell-atl.com (Matt Kingman) (10/03/89)

mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes:

>I am trying to get a dialog to display in an init and having loads of
>troubles.  My init loads a driver i wrote and i want a dialog displayed
>in case of an error when tring to load the driver.

I noticed a couple of problems with your code.  First you're initializing
QuickDraw by using 'thePort'.  You can't do this in an INIT because 'thePort'
hasn't been set-up yet.  On entry, A5 points to the end of the QuickDraw
globals.  Since 'thePort' is the last one you can use the following code
(THINK C) to initialize QuickDraw:

	asm
	    {
	    PEA -4(A5)		;Get address of 'thePort'
	    _InitGraf		;Initialize QuickDraw
	    }

Second, you should lock down your code resource.  On entry, A0 is a pointer
to your code resource.  You should call RecoverHandle to get the handle to
your code resource and then lock it.  Unlock it before exiting.  The following
code is an example of how to do what I have described.

Good Luck
/Matt

******************

#include	<SetUpA4.h>

main()
{
Handle myHdl;

	/* be 100% sure we're locked down. See LSC 3.0 manual p.86 */
	RememberA0();
	SetUpA4();
	asm
		{
		_RecoverHandle		;A0 is pointer to our code resource
		move.l a0, myHdl	;save A0 in 'myHdl'
		}
	HLock(ourHdl);
	
	/* Initialize QuickDraw */
	asm
		{
		PEA		-4(A5)
		_InitGraf
		}
	InitFonts();
	InitWindows();
	InitCursor();
	InitMenus();
	InitDialogs(0L);
	TEInit();

	/*
	** Do your stuff in here
	*/

	HUnlock(myHdl);
	RestoreA4();
}
-- 
Matt Kingman  Technology Concepts Inc.  Sudbury, MA.  (508)443-7311
      ...!uunet!tci!kingman         kingman@tci.bell-atl.com
     TCI is not responsible for my opinions, nor I for theirs...