home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!apple!grobbins
- From: grobbins@Apple.COM (Grobbins)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Gestalt Selectors in APPL
- Message-ID: <75922@apple.apple.COM>
- Date: 24 Dec 92 06:19:14 GMT
- References: <BzqC31.FAM@world.std.com>
- Organization: Experimental System Software Investigations
- Lines: 66
-
- In article <BzqC31.FAM@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
- >1) Can I perform a "6-byte-xdef" type trick on this
- >code? I'm not sure I can since even if I mark the
- >6-byte resource as sysHeap the code it points to is
- >still in my application heap.
-
- It should work so long as the application is running, but since the
- application may quit and there is no way to remove a gestalt selector,
- you will need at least one totally stand-alone block of code. So the
- 6-byte trick won't solve this problem.
-
- (This limitation doesn't apply to things like time manager tasks; since
- they can be removed, it is appropriate to simply make the task code a
- function of the application, or to put an initial jump instruction in
- the system heap, and remove the task before the app quits.)
-
- You can copy a function from the application into a block in the
- system heap. If the function were called MySelectorFunction and
- it were followed by a procedure called NullProc, then this would
- work:
-
- mySelectorFunctionSize := Ord4(@NullProc) - Ord4(@MySelectorFunction);
- { mySelectorFunctionSize should be something reasonable, definitely >0 }
-
- { make space in the system heap }
- mySelectorFunctionPtr := NewPtrSys(mySelectorFunctionSize);
- IF mySelectorFunctionPtr <> NIL THEN
- BEGIN
- { copy the function into the system heap }
- BlockMove(@MySelectorFunction, mySelectorFunctionPtr,
- mySelectorFunctionSize);
- retCode := NewGestalt(kMySelector, mySelectorFunctionPtr);
- END;
-
- This is more fragile than just compiling a stand-alone code resource
- (on which you'd call set the SysHeap bit, call GetResource, DetachResource,
- HLock; see IM VI 3-43) since the BlockMove method makes the assumption
- that the functions in the compiled code are in the same relative order
- in memory as they are in the source file. Check the compiler output
- with a disassembler (like ResEdit's code viewer) to make certain that
- functions are sequential as expected in the final application code.
-
-
- >2) If I place my Gestalt selector function in a separate
- >CODE resource, can I mark that resource as sysHeap and
- >have it work properly? This would be WITHOUT any 6-byte
- >tricks.
-
- Yep, that's the canonical way. Be sure it's locked in memory before
- installation, too.
-
- >3) How can I remove the Gestalt selector once the app
- >quits? Will
- > err = ReplaceGestalt(selector, nil, &oldGestaltFunction);
- >work or will this cause the System to jump to location 0
- >the next time someone calls my selector?
- >What's the easiest way? Thanks in advance! :)
-
- Rather than try to remove the selector, just make a simple replacement
- selector function that returns zero or something else distinct and
- strand it in the System heap.
-
-
- Grobbins grobbins@apple.com
-
- Usual disclaimers apply.
-