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

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!data.nas.nasa.gov!taligent!kip-50.taligent.com!user
  3. From: keith@taligent.com (Keith Rollin)
  4. Subject: Re: Calling external code resources - how?
  5. Message-ID: <keith-240193175414@kip-50.taligent.com>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: usenet@taligent.com (More Bytes Than You Can Read)
  8. Organization: Taligent
  9. References: <01050014.odph61@blanc.north.de>
  10. Date: Mon, 25 Jan 1993 01:59:02 GMT
  11. Lines: 63
  12.  
  13. In article <01050014.odph61@blanc.north.de>, jochen@blanc.north.de (Jochen
  14. Meyer) wrote:
  15. > I am currently writing a program that I want to be extensible. The
  16. > most common way of handling extensibility seems to be using external
  17. > code resources, like in Canvas or BBEdit.
  18. > Where can I find information on how to do this? The Segment Manager
  19. > chapter of IM gives no clues on this. Anyone has got some sample code
  20. > on this?
  21.  
  22. If you have Technote #256, read it. If you don't, log onto ftp.apple.com,
  23. go to /dts/mac/tn/patforms.tools and download the file called
  24. stand-alone-code.hqx. It will tell you just what you want.
  25.  
  26. Just to whet your appetite, here's some code that I use to call CDEF's
  27. directly:
  28.  
  29.  
  30. typedef pascal long (*CDEFProc)(short varCode, ControlHandle theControl,
  31.                                     short msg, long param);
  32.  
  33. long CallCDEF(ControlHandle theControl, short msg, long param)
  34. {
  35.     CDEFProc*    defProcHandle;
  36.     GrafPtr        oldPort;
  37.     char        oldState;
  38.     long        result;
  39.             
  40.     defProcHandle = (CDEFProc*) StripAddress((**theControl).contrlDefProc);
  41.  
  42.     if (defProcHandle != nil) {
  43.  
  44.         if (*defProcHandle == nil)  {
  45.             LoadResource((Handle) defProcHandle);
  46.         }
  47.  
  48.         if (*defProcHandle != nil) {
  49.         
  50.             GetPort(&oldPort);
  51.             SetPort((**theControl).contrlOwner);
  52.             
  53.             oldState = HGetState((Handle) defProcHandle);
  54.             HLock((Handle) defProcHandle);
  55.             
  56.             result = (*defProcHandle)(GetCVariant(theControl), theControl, msg,
  57. param);
  58.                                         
  59.             HSetState((Handle) defProcHandle, oldState);
  60.             SetPort(oldPort);
  61.             
  62.             return result;
  63.         }
  64.     }
  65.  
  66.     SysError(dsCDEFNotFound);
  67. }
  68.  
  69.  
  70. -----
  71. Keith Rollin
  72. Phantom Programmer
  73. Taligent, Inc.
  74.