[comp.sys.mac.programmer] Trap patch questions

mcdan@dtg.nsc.com (Eric McDaniel) (06/05/90)

Reply-To: mcdan@dtg.nsc.com
Distribution: 

I am trying to write a patch to display a dialog box
under certain circumstances when an application is
launched, and am having a few problems:

1.  At first I tried patching the _Launch and _Chain
traps, but some launching utilities (notably OnCue)
apparently don't use these traps, as my code was not
always executed.  I now patch _LoadSeg and check if
the segment number being loaded is #1 before calling
my code. It works, but seems less efficient since _LoadSeg
can be called any number of times within an application.

Any suggestions?  How do OnCue and similar utilities
work?

2.  When I call ShowWindow to display the dialog box,
I consistently get some sort of system error.  I checked
the DialogPtr and all associated handles, and everything
seems to be valid and on the system heap.  I'm guessing
the problem has something to do with setting up A5 or
the GrafPort correctly.

Could my use of a 'tail-patch' be the problem, and if
so, how else could I write this thing?

I'mm using Lightspeed C 3.01 on a Mac Plus, if that makes
any difference.-- 
Eric McDaniel
mcdan@dtg.nsc.com

beard@ux1.lbl.gov (Patrick C Beard) (06/08/90)

In article <1101@haydn.nsc.com> mcdan@dtg.nsc.com (Eric McDaniel) writes:
#Reply-To: mcdan@dtg.nsc.com
#Distribution: 
#
#I am trying to write a patch to display a dialog box
#under certain circumstances when an application is
#launched, and am having a few problems:
#
#1.  At first I tried patching the _Launch and _Chain
#traps, but some launching utilities (notably OnCue)
#apparently don't use these traps, as my code was not
#always executed.  I now patch _LoadSeg and check if
#the segment number being loaded is #1 before calling
#my code. It works, but seems less efficient since _LoadSeg
#can be called any number of times within an application.

This is an adequate solution.  In fact MultiFinder itself doesn't use
the Launch trap.

#2.  When I call ShowWindow to display the dialog box,
#I consistently get some sort of system error.  I checked
#the DialogPtr and all associated handles, and everything
#seems to be valid and on the system heap.  I'm guessing
#the problem has something to do with setting up A5 or
#the GrafPort correctly.

You got it.  You have to perform the standard litany of manager
initialization calls, including InitGraf, InitWindows, etc.  It doesn't
seem to be a problem to do this and then have the application do it
again.


#Could my use of a 'tail-patch' be the problem, and if
#so, how else could I write this thing?

A tail patch is probably not a problem, but it is also probably unnecessary
for what you are trying to do.  A simple head patch of LoadSeg would be
adequate.

Good luck!

-------------------------------------------------------------------------------
-  Patrick Beard, Macintosh Programmer                        (beard@lbl.gov) -
-  Berkeley Systems, Inc.  ".......<dead air>.......Good day!" - Paul Harvey  -
-------------------------------------------------------------------------------