[comp.sys.mac.programmer] Loading and running XFCNs

terry@ists.ists.ca (Terry Lim) (01/03/91)

Supposing I have a HyperCard XFCN resource, the functionality of which
is pretty well independent of HyperCard (i.e. no [or hardly any]
callbacks).

Should I not be able to GetResource('XFCN',resid), lock down the
resulting handle, and use the dereferenced pointer as a ProcPtr, passing
it a homebrew XCmdBlock? Anyone have a code snippet in C showing how
it's done? I am assuming that any callbacks are handled by supplying
the entryPoint routine within the calling segment.

I've done this sort of thing with 'CODE' resources before and there
seems to be an UNLNK at the very beginning of XFCNs, so I would expect
this to be do-able...?

Cheers,
Terry Lim
terry@ists.ists.ca

daven@svc.portal.com (01/05/91)

In article <16819@ists.ists.ca> terry@ists.ists.ca (Terry Lim) writes:
>
>Should I not be able to GetResource('XFCN',resid), lock down the
>resulting handle, and use the dereferenced pointer as a ProcPtr, passing
>it a homebrew XCmdBlock? Anyone have a code snippet in C showing how
>it's done? I am assuming that any callbacks are handled by supplying
>the entryPoint routine within the calling segment.

Yes, this should work. Couple of things to watch out for.

o Save your critical CPU registers before JSR'ing to the XFCN, and
  restore them when you return. This is just in case the XFCN screws
  around with things like A5.

o If you implement the Hypercard callbacks, then be sure to save
  the critical CPU registers again (i.e. you're saving the XFCN's
  register state) and restore your critical registers. When finishing
  the callback, just before you return to the XFCN, save your critical
  registers again, and restore the XFCN's registers.

o What's the critical registers, well... at least A5 is. I play it safe
  and save D0-D7 and A0-A6.

>I've done this sort of thing with 'CODE' resources before and there
>seems to be an UNLNK at the very beginning of XFCNs, so I would expect
>this to be do-able...?

Uh, that's hopefully a "LINK" at the beginning of the XFCN.


-- 
-------------------------------------------------------------------------------
   Dave Newman              |  daven@svc.portal.com        |  AppleLink: D0025
   Sofware Ventures Corp.   |  AOL: MicroPhone             |  CIS: 76004,2161
   Berkeley, CA  94705      |  WELL: tinman@well.sf.ca.us  |  (415) 644-3232