home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22181 < prev    next >
Encoding:
Text File  |  1993-01-25  |  2.4 KB  |  74 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
  3. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  4. Subject: Re: Calling external code resources - how?
  5. Message-ID: <peter-260193110401@rocky.curtin.edu.au>
  6. Followup-To: comp.sys.mac.programmer
  7. Lines: 60
  8. Sender: news@ncrpda.curtin.edu.au
  9. Nntp-Posting-Host: ncrpda.curtin.edu.au
  10. Organization: NCRPDA, Curtin University
  11. References: <01050014.odph61@blanc.north.de> <1993Jan25.005216.12749@kth.se>
  12. Date: Tue, 26 Jan 1993 03:10:29 GMT
  13.  
  14. In article <1993Jan25.005216.12749@kth.se>, d88-jwa@dront.nada.kth.se (Jon
  15. Wtte) wrote:
  16. > In <01050014.odph61@blanc.north.de> jochen@blanc.north.de (Jochen Meyer) writes:
  17. > >Where can I find information on how to do this? The Segment Manager
  18. > >chapter of IM gives no clues on this. Anyone has got some sample code
  19. > >on this?
  20.  
  21. > Define an interface for the extensions, consisting of ONE
  22. > function that takes a lot of interesting parameters,
  23. > like a handle to some data and a command, and a handle to
  24. > put retusn data in, and returns an err code.
  25. > The just load in the resource, lock it, and call the dereferenced
  26. > resource as a function pointers with the right arguments.
  27.  
  28. If you want other people to be able to write externals in Pascal, give the
  29. function a Pascal interface.
  30.  
  31. Another good idea is to pass a single param block containg all the
  32. parmaeters, with a version parameter at the front, so if you decide to add
  33. more parameters later, you don't need to rewrite all the externals, you
  34. just bump the version number, and add the new parameters to the end.  An
  35. OSErr is often a good return result.
  36.  
  37. In Pascal:
  38.  
  39. type MyExternalParamBlock = record
  40.     version:longInt;
  41.     { other stuff }
  42.   end;
  43. function External(var pb:MyExternalParamBlock): OSErr;
  44.  
  45. [
  46. In C, something like this I think
  47. OSErr External(MyExternalParamBlock *pb)
  48. ]
  49.  
  50. Call it something like this:
  51.  
  52. function CallExternal(var pb:MyExternalParamBlock; proc:Ptr):OSErr;
  53. inline $205F, $4E90;
  54.  
  55. var h:handle;
  56.  
  57. h:=GetResource('Xtns',128);
  58. HLockHi(h);
  59. oe:=CallExternal(pb,h^);
  60. ReleaseResource(h)
  61.  
  62. I did something akin to this in the external tokens for Finger, the source
  63. of which should be on sumex or umich, as well as
  64. redback.cs.uwa.edu.au:/others/peterlewis.
  65.  
  66. Have fun,
  67.    Peter.
  68.  
  69. _______________________________________________________________________
  70. Peter N Lewis <peter@cujo.curtin.edu.au>             Ph: +61 9 368 2055
  71.