wilson@csli.Stanford.EDU (Nathan Wilson) (09/20/89)
I'm trying to write my first Init/Trap patch and am having a problem. I've got the init part working. In addition if I call GetTrapAddress before and after the call to SetTrapAddress they differ and the new address is the one I expect it to be. Finally, if I run an application version of the code, the initial call to GetTrapAddress returns the same address as I used in the SetTrapAddress the Init. All this seem to be fine and wonderful, except there is no change in the behavior of the trap. The complete code for MPW 3.0 follows. In addition to comments on the bug I would be happy to get any stylistic comments people care to make. FYI, the ultimate goal of this is to have an init for multi-screen systems that patches the ZoomWindow call so it will zoom to the screen containing the center of the window rather than the "main" screen. This is suggested by IM-V but isn't implemented. Does anyone know why? The system I'm working on is a MacIIcx with 8 meg of RAM, TMON installed, running MultiFinder, PowerStation, and assorted inits. Thanks in advance, Nathan Wilson Teleos Research nathan%teleos.com@ai.sri.com Here's the code for the Init part: ***** File ZoomMain.p ***** Unit ZoomMain; Interface Uses Memtypes,QuickDraw,OSIntf,ToolIntf,Packages; Procedure LoadNewZoomWindow; Implementation Procedure MacsBugPrint( theMesg : Str255 ); inline $ABFF; Procedure LoadNewZoomWindow; const rsrcNum = 0; zoomID = $A83A; var aZoomProc : Handle; aStr : Str255; begin SysBeep( 30 ); SetZone( SystemZone ); aZoomProc := GetResource( 'Zoom', rsrcNum ); if ResError <> noErr then SysBeep( 30 ); DetachResource( aZoomProc ); if ResError <> noErr then SysBeep( 30 ); HLock( aZoomProc ); NumToString( GetTrapAddress( zoomID ), aStr ); MacsbugPrint( aStr ); NumToString( LongInt( StripAddress( aZoomProc^ ) ), aStr ); MacsbugPrint( aStr ); SetTrapAddress( LongInt( StripAddress( aZoomProc^ ) ), zoomID ); NumToString( GetTrapAddress( zoomID ), aStr ); MacsbugPrint( aStr ); end; end. {Unit} ***** End File ZoomMain.p And the code in Zoom resource is just: ***** File ZoomFunc.p ***** Unit ZoomInit; Interface Uses Memtypes,QuickDraw,OSIntf,ToolIntf,Windows; Procedure MyZoomWindow( theWindow: WindowPtr; partCode: Integer; front: Boolean); Implementation Procedure MyZoomWindow( theWindow: WindowPtr; partCode: Integer; front: Boolean); begin Sysbeep( 30 ); end; end. {Unit} ***** End File ZoomFunc.p ***** and the makefile is: ***** File Makefile ***** ZoomInit D ZoomFunc ZoomMain ZoomInit.r Rez ZoomInit.r -t INIT -c 'Zoom' -o ZoomInit ZoomFunc D ZoomFunc.p.o Link -rt Zoom=0 6 -ra =16 6 -m MYZOOMWINDOW 6 ZoomFunc.p.o 6 -o ZoomFunc ZoomMain D ZoomMain.p.o Link -rt INIT=0 6 -ra =16 6 -m LOADNEWZOOMWINDOW 6 ZoomMain.p.o 6 "{Libraries}"Interface.o 6 -o ZoomMain ZoomAppl D ZoomFunc ZoomMain.p.o ZoomInit.r Link ZoomMain.p.o 6 -m LOADNEWZOOMWINDOW 6 "{Libraries}"Interface.o 6 "{PLibraries}"PasLib.o 6 -o ZoomAppl Rez ZoomAppl.r -c 'Zoom' -o ZoomInit -append ***** End File Makefile ***** finally the .r files are: ***** File ZoomInit.r ***** include "ZoomFunc"; include "ZoomMain"; ***** End File ZoomInit.r ***** and ***** File ZoomAppl.r ***** include "ZoomFunc"; ***** End File ZoomAppl.r *****
oster@dewey.soe.berkeley.edu (David Phillip Oster) (09/20/89)
If you are running under multi-finder, you won't see the effect of patching a trap from an application in any other application, because multi-finder swaps each application's patched trap set when it swaps the application. The best way to debug something like this is to add the code to a demo text editor application, get it working there, then brea k it loose as a free standing init.