Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!rutgers!bpa!tci!kingman
From: kingman@tci.bell-atl.com (Matt Kingman)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Inits and Dialogs
Message-ID: <387@tci.bell-atl.com>
Date: 2 Oct 89 18:16:00 GMT
References: <6632@hubcap.clemson.edu>
Organization: Technology Concepts, Inc.  Sudbury Mass.
Lines: 68

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	

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...