home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
- From: peter@cujo.curtin.edu.au (Peter N Lewis)
- Subject: Re: Calling external code resources - how?
- Message-ID: <peter-260193110401@rocky.curtin.edu.au>
- Followup-To: comp.sys.mac.programmer
- Lines: 60
- Sender: news@ncrpda.curtin.edu.au
- Nntp-Posting-Host: ncrpda.curtin.edu.au
- Organization: NCRPDA, Curtin University
- References: <01050014.odph61@blanc.north.de> <1993Jan25.005216.12749@kth.se>
- Date: Tue, 26 Jan 1993 03:10:29 GMT
-
- In article <1993Jan25.005216.12749@kth.se>, d88-jwa@dront.nada.kth.se (Jon
- Wtte) wrote:
- >
- > In <01050014.odph61@blanc.north.de> jochen@blanc.north.de (Jochen Meyer) writes:
- >
- > >Where can I find information on how to do this? The Segment Manager
- > >chapter of IM gives no clues on this. Anyone has got some sample code
- > >on this?
-
- > Define an interface for the extensions, consisting of ONE
- > function that takes a lot of interesting parameters,
- > like a handle to some data and a command, and a handle to
- > put retusn data in, and returns an err code.
- >
- > The just load in the resource, lock it, and call the dereferenced
- > resource as a function pointers with the right arguments.
-
- If you want other people to be able to write externals in Pascal, give the
- function a Pascal interface.
-
- Another good idea is to pass a single param block containg all the
- parmaeters, with a version parameter at the front, so if you decide to add
- more parameters later, you don't need to rewrite all the externals, you
- just bump the version number, and add the new parameters to the end. An
- OSErr is often a good return result.
-
- In Pascal:
-
- type MyExternalParamBlock = record
- version:longInt;
- { other stuff }
- end;
- function External(var pb:MyExternalParamBlock): OSErr;
-
- [
- In C, something like this I think
- OSErr External(MyExternalParamBlock *pb)
- ]
-
- Call it something like this:
-
- function CallExternal(var pb:MyExternalParamBlock; proc:Ptr):OSErr;
- inline $205F, $4E90;
-
- var h:handle;
-
- h:=GetResource('Xtns',128);
- HLockHi(h);
- oe:=CallExternal(pb,h^);
- ReleaseResource(h)
-
- I did something akin to this in the external tokens for Finger, the source
- of which should be on sumex or umich, as well as
- redback.cs.uwa.edu.au:/others/peterlewis.
-
- Have fun,
- Peter.
-
- _______________________________________________________________________
- Peter N Lewis <peter@cujo.curtin.edu.au> Ph: +61 9 368 2055
-