home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Doco ƒ / CSMP ƒ / CSMP-V1-091.TXT < prev    next >
Encoding:
Text File  |  1992-06-30  |  50.0 KB  |  1,336 lines

  1. C.S.M.P. Digest             Sat, 23 May 92       Volume 1 : Issue 91
  2.  
  3. Today's Topics:
  4.  
  5.     How to convert bitmap to PICT resource
  6.     Gestalt() doesn't know about 'rsrc'!
  7.     File System Question
  8.     Fast Screen Drawing
  9.     THINK Pascal: Need to wait for single keypress
  10.     Writing  apps that use plug-ins?
  11.  
  12.  
  13. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  14.  
  15. These digests are available (by using FTP, account anonymous, your email
  16. address as password) in the pub/mac/csmp-digest directory on ftp.cs.uoregon.
  17. edu.  This is also the home of the comp.sys.mac.programmer Frequently Asked
  18. Questions list.  The last several issues of the digest are available from
  19. sumex-aim.stanford.edu as well.
  20.  
  21. These digests are also available via email.  Just send a note saying that you
  22. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  23. automatically receive each new digest as it is created.
  24.  
  25. The digest is a collection of articles from the internet newsgroup comp.sys.
  26. mac.programmer.  It is designed for people who read c.s.m.p. semi-regularly
  27. and want an archive of the discussions.  If you don't know what a newsgroup
  28. is, you probably don't have access to it.  Ask your systems administrator(s)
  29. for details.  (This means you can't post questions to the digest.)
  30.  
  31. The articles in these digests are taken directly from comp.sys.mac.programmer.
  32. They are not edited; all articles included in this digest are in their original
  33. posted form.  The only articles that are -not- included in these digests are
  34. those which didn't receive any replies (except those that give information
  35. rather than ask a question).  All replies to each article are concatenated
  36. onto the original article in the order in which they were received.  Article
  37. threads are not added to the digests until the last article added to the
  38. thread is at least one month old (this is to ensure that the thread is dead
  39. before adding it to the digests).
  40.  
  41. Send administrative mail to mkelly@cs.uoregon.edu.
  42.  
  43. -------------------------------------------------------
  44.  
  45. From: tcn40292@uxa.cso.uiuc.edu (Tony Ng)
  46. Subject: How to convert bitmap to PICT resource
  47. Date: 20 Apr 92 03:41:00 GMT
  48. Organization: University of Illinois at Urbana
  49.  
  50. I don't know if this is a FAQ or not. But I really would like to 
  51. know how one can convert the bitmap of a window/port into
  52. PICT resource. In other words, how one can copy the image of a window
  53. into the clipboard so that the picture can be pasted somewhere else.
  54.  
  55. Any suggestions or help appreciated!
  56.  
  57.  
  58. - -- 
  59. Tony Ng
  60. tony-ng@uiuc.edu
  61.  
  62. +++++++++++++++++++++++++++
  63.  
  64. From: scott@mcl.mcl.ucsb.edu (Scott Bronson)
  65. Date: 20 Apr 92 20:43:45 GMT
  66.  
  67. In <1992Apr20.034100.16990@ux1.cso.uiuc.edu> tcn40292@uxa.cso.uiuc.edu (Tony Ng) writes:
  68.  
  69. >... But I really would like to 
  70. >know how one can convert the bitmap of a window/port into
  71. >PICT resource.
  72.  
  73. This is a question I've had also.  I solved it by creating an offscreen
  74. pixmap of the same size and depth of the window.  Then, be sure to set
  75. forecolor to black and backcolor to white or the pixmap's colors will
  76. be very odd.  Then I opened the picture, copied the bits from the screen
  77. to the offscreen pixmap, closed the picture, and sent it off to the
  78. clipboard.  Worked like a charm.  I'll send anyone who wants some code
  79. that I did in Pascal to do this.
  80.  
  81. Problem is that this is overkill.  A copy of the picture exists on screen,
  82. off screen, and in the picture.  Really, allocating and deallocating the
  83. offscreen pixmap is totally unneccessary because it doesn't do anything
  84. useful--it just fools the pict into picking those bits up also.
  85.  
  86. I tried to CopyBits from the portbits to the portbits, but it didn't
  87. do anything.  Then I tried to go from the window's portbits to the WMgrPort
  88. portbits, but CopyBits was too smart for me there, also.  I just gave up
  89. and lived with the redundancy because I had to get the project done by
  90. the end of the week.
  91.  
  92. I had forgotten about it until just now when I read that message.  It
  93. still bugs me.  Is there any way to go directly from bits to pict?  It
  94. should not be neccessary to allocate more bits when they won't even get
  95. used except to waste memory and processor time.
  96.  
  97.     - Scott
  98.  
  99. +++++++++++++++++++++++++++
  100.  
  101. From: krk@itl.itd.umich.edu (Kenneth Knight)
  102. Organization: Instructional Technology Laboratory, University of Michigan
  103. Date: Mon, 20 Apr 92 22:18:55 GMT
  104.  
  105. In article <1992Apr20.034100.16990@ux1.cso.uiuc.edu> tcn40292@uxa.cso.uiuc.edu (Tony Ng) writes:
  106. >I don't know if this is a FAQ or not. But I really would like to 
  107. >know how one can convert the bitmap of a window/port into
  108. >PICT resource. In other words, how one can copy the image of a window
  109. >into the clipboard so that the picture can be pasted somewhere else.
  110.  
  111. Here is a code fragment that will first make a QuickDraw PICT out of the
  112. contents within a window and then copy that PICT into the cliboard.
  113.  
  114. PicHandle    thePict;
  115. long        picSize;
  116. OSErr        err;
  117.  
  118. err = ZeroScrap();
  119. if (err == noErr) {
  120. thePict = OpenPicture(&(theWindow->portRect));
  121.   CopyBits((GrafPtr)theWindow)->portBits, (GrafPtr)theWindow)->portBits,
  122.            &(theWindow->portRect, &(theWindow->portRect), srcCopy, nil);
  123. ClosePicture();
  124. picSize = GetHandleSize((Handle)thePict);
  125. HLock((Handle)thePict);
  126. PutScrap(picSize, 'PICT', (Ptr)*thePict);
  127. HUnlock((Handle)thePict);
  128. DisposeHandle((Handle)thePict);
  129. } /* if */
  130.  
  131. This fragment first makes a QD picture by simply CopyBitt() the
  132. contents of the window onto itself. Then that PICT is placed in
  133. the cliboard with the PutScrap() call. 
  134.  
  135. Hope that helps.
  136.  
  137.  
  138. +++++++++++++++++++++++++++
  139.  
  140. From: jmatthews@desire.wright.edu
  141. Date: 21 Apr 92 22:02:59 EST
  142. Organization: Wright State University 
  143.  
  144. In article <1992Apr20.221855.13043@terminator.cc.umich.edu>, krk@itl.itd.umich.edu (Kenneth Knight) writes:
  145. > Here is a code fragment that will first make a QuickDraw PICT out of the
  146. > contents within a window and then copy that PICT into the cliboard.
  147. > PicHandle    thePict;
  148. > long        picSize;
  149. > OSErr        err;
  150. > err = ZeroScrap();
  151. > if (err == noErr) {
  152. > thePict = OpenPicture(&(theWindow->portRect));
  153. >   CopyBits((GrafPtr)theWindow)->portBits, (GrafPtr)theWindow)->portBits,
  154. >            &(theWindow->portRect, &(theWindow->portRect), srcCopy, nil);
  155. > ClosePicture();
  156. > picSize = GetHandleSize((Handle)thePict);
  157. > HLock((Handle)thePict);
  158. > PutScrap(picSize, 'PICT', (Ptr)*thePict);
  159. > HUnlock((Handle)thePict);
  160. > DisposeHandle((Handle)thePict);
  161. > } /* if */
  162.  
  163. Also do ClipRect(theWindow^.portRect) before the call to OpenPicture.
  164.  
  165. Is DisposeHandle((Handle)thePict) <-> KillPicture(thePicture)?
  166.  
  167. o----------------------------------------------------------------------------o
  168. | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
  169. | "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
  170. o----------------------------------------------------------------------------o
  171.  
  172. +++++++++++++++++++++++++++
  173.  
  174. From: d88-jwa@crn.nada.kth.se (Jon W{tte)
  175. Date: 22 Apr 92 12:05:23 GMT
  176. Organization: Royal Institute of Technology, Stockholm, Sweden
  177.  
  178. > jmatthews@desire.wright.edu writes:
  179.  
  180.    > HLock((Handle)thePict);
  181.    > PutScrap(picSize, 'PICT', (Ptr)*thePict);
  182.    > HUnlock((Handle)thePict);
  183.    > DisposeHandle((Handle)thePict);
  184.  
  185.    Also do ClipRect(theWindow^.portRect) before the call to OpenPicture.
  186.  
  187. Very true ! You cando it after opening the picture, though, and
  188. the call will be recorded, too.
  189.  
  190. However, if you DON'T, you'll have problems drawing this picture
  191. in any other position than it's "home" position.
  192.  
  193.    Is DisposeHandle((Handle)thePict) <-> KillPicture(thePicture)?
  194.  
  195. No. It may work now, if the user has no accelerated graphics
  196. card, but in general, don't assume it is. Dispose regions
  197. with DisposeRgn, and resources with ReleaseResource etc.
  198.  
  199. Never mix different manager calls, since the picture data in
  200. theory could be accumulated on a graphics card, and the mac
  201. Memory Manager wouldn't get at it as a memory manager block.
  202.  
  203. - -- 
  204. "You should meet yourself someday. I'm sure you would hate it."
  205. - - Me: h+@nada.kth.se; Jon W{tte (The Diplomat - NOT!)
  206.  
  207. ---------------------------
  208.  
  209. From: dougm@cns.caltech.edu (Doug McNaught)
  210. Subject: Gestalt() doesn't know about 'rsrc'!
  211. Date: 19 Apr 92 02:09:23 GMT
  212. Organization: California Institute of Technology
  213.  
  214.  
  215.   My application uses the System 7 partial resource routines, so I call
  216. Gestalt() with the selector gestaltResourceMgrAttr (which is defined in IM6
  217. and the C header files as 'rsrc'). However, Gestalt doesn't know this selector!
  218. It returns gestaltUndefSelectorErr (-5551) as its result code. I know the
  219. routines are there, because when I blindly go ahead and use them, they work.
  220. It's not a huge deal, because I test for a bunch of other sys7-specific stuff,
  221. and I figure anything that has real TempMem handles, the new Standard File
  222. calls, and FindFolder will have the partial resource routines. But I'm trying
  223. to be Apple-obedient, and it bugs me that this selector doesn't work. BTW,
  224. I know it's not the glue that's causing the problem, because I watched it
  225. call the actual trap with Macsbug, and that's where the error code comes from.
  226. So has anybody else run into this? Should I submit it to Apple.Bugs? Oh, I'm
  227. using 7.0.1 + Tuneup 1.1.1 on a 4meg Classic.
  228. thanks,
  229. doug
  230.  
  231. - --
  232. <><><><><><><><><><><><><><><>Go Orioles<><><><><><><><><><><><><><><><>
  233. <> Doug McNaught                                dougm@cns.caltech.edu <>
  234. <>  Help!!! I'm addicted to *Spaceward Ho!* Is there a support group? <>
  235. <><><><><><><><><><><><><><><>Go Orioles<><><><><><><><><><><><><><><><>
  236.  
  237. +++++++++++++++++++++++++++
  238.  
  239. From: nerm@apple.com (Dean Yu)
  240. Date: 22 Apr 92 01:48:32 GMT
  241. Organization: Apple Computer, Inc.
  242.  
  243. In article <DOUGM.92Apr18180923@bradbury.cns.caltech.edu>, dougm@cns.caltech.edu (Doug McNaught) writes:
  244. >   My application uses the System 7 partial resource routines, so I call
  245. > Gestalt() with the selector gestaltResourceMgrAttr (which is defined in IM6
  246. > and the C header files as 'rsrc'). However, Gestalt doesn't know this selector!
  247. > It returns gestaltUndefSelectorErr (-5551) as its result code. I know the
  248. > routines are there, because when I blindly go ahead and use them, they work.
  249. > It's not a huge deal, because I test for a bunch of other sys7-specific stuff,
  250. > and I figure anything that has real TempMem handles, the new Standard File
  251. > calls, and FindFolder will have the partial resource routines. But I'm trying
  252. > to be Apple-obedient, and it bugs me that this selector doesn't work. BTW,
  253. > I know it's not the glue that's causing the problem, because I watched it
  254. > call the actual trap with Macsbug, and that's where the error code comes from.
  255. > So has anybody else run into this? Should I submit it to Apple.Bugs? Oh, I'm
  256. > using 7.0.1 + Tuneup 1.1.1 on a 4meg Classic.
  257. > thanks,
  258. > doug
  259.  
  260.   You're right.  We forgot.  This was one of those things that slipped through
  261. the cracks in the heat of trying to go final.  This well of course, be remedied
  262. in a future version of system software.  Just don't ask when.
  263.  
  264.  
  265.   -- Dean Yu
  266.      Blue Meanie, Negative Ethnic Role Model, Window Cleaner,
  267.       Skanky Hack Consultant, etc.
  268.      Apple Computer, Inc.
  269.  
  270. ---------------------------
  271.  
  272. Organization: University of Illinois at Chicago
  273. Date: Monday, 20 Apr 1992 11:20:15 CDT
  274. From: John Galidakis <U21192@uicvm.uic.edu>
  275. Subject: File System Question
  276.  
  277.  Howdy gurus, again.
  278. IM IV states that the file manager has the capability to read consequtive
  279. bytes from files in the so called "newline mode" where a sentinel
  280. (usually a CR) is used to terminate the Read. (page 95)
  281. However I can't find any references on how this is done.
  282. Somebody out there knows anything about it, or do I simply have to
  283. use FSRead one byte at a time and store the chars in a buffer?
  284. If I have to do the above (simulating a readln myself) I suppose the
  285. Note in IM is pretty much useless...
  286. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  287. + John "the Baptist" Galidakis +  "Only JCN won the fight with +
  288. + Programmer/Designed Data Co. + the great goddess. The rest   +
  289. + Paranoid Evangelist          +  just tried..." HLC           +
  290. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  291.  
  292. +++++++++++++++++++++++++++
  293.  
  294. From: wysocki@husc.harvard.edu (Chris Wysocki)
  295. Date: 21 Apr 92 01:51:08 GMT
  296. Organization: Harvard University, Cambridge, MA
  297.  
  298. In article <92111.112015U21192@uicvm.uic.edu>, U21192@uicvm.uic.edu (John Galidakis) writes:
  299.  
  300. > IM IV states that the file manager has the capability to read consequtive
  301. > bytes from files in the so called "newline mode" where a sentinel
  302. > (usually a CR) is used to terminate the Read. (page 95)
  303. > However I can't find any references on how this is done.
  304.  
  305. I used newline mode in a DA I wrote a couple of years ago; here's the 
  306. relevant section of code:
  307.  
  308.     /*
  309.      *  Here we use "newline mode", meaning that all read operations will
  310.      *  terminate at a newline character.  We select newline mode by setting
  311.      *  bit 7 of ioPosMode and specifying the newline character (here, the
  312.      *  ASCII CR (0D hex)) in the high-order byte of ioPosMode (leading to
  313.      *  the "0x0D80" below)
  314.      */
  315.      
  316.     pb.ioRefNum = refNum;
  317.     pb.ioBuffer = (Ptr) str + 1;
  318.     pb.ioReqCount = sizeof(Str255) - 1;
  319.     pb.ioPosMode = fsAtMark | 0x0D80;       /* set newline mode */
  320.     err = PBReadSync(&pb);
  321.  
  322. See the note on IM IV-121 for the complete story.
  323.  
  324. Chris Wysocki
  325. wysocki@husc.harvard.edu
  326.  
  327.  
  328. +++++++++++++++++++++++++++
  329.  
  330. From: orpheus@reed.edu (P. Hawthorne)
  331. Date: 22 Apr 92 14:48:08 GMT
  332. Organization: Reed College, Portland OR
  333.  
  334.  
  335.    U21192@uicvm.uic.edu (John Galidakis) writes:
  336. .  IM IV states that the file manager has the capability to read consequtive
  337. .  bytes from files in the so called "newline mode" where a sentinel
  338. .  (usually a CR) is used to terminate the Read. (page 95)
  339. .  However I can't find any references on how this is done.
  340.  
  341.    It's significantly faster to read as much as you can, then parse it,
  342. even if it means you have to write your own white-space recognizer. You
  343. can always have the Script Manager tokenize for you.
  344.    Just an observation,
  345.    Theus (orpheus@reed.edu)
  346.  
  347. ---------------------------
  348.  
  349. Subject: Fast Screen Drawing
  350. From: Michael Joseph Raneri <MJR145@psuvm.psu.edu>
  351. Date: Tuesday, 21 Apr 1992 16:03:38 EDT
  352. Organization: Penn State University
  353.  
  354. I am hoping someone could help me out with drawing PICTs on screen rapidly.
  355. I need this for the creation of a game of mine.  I'm somewhat experienced in
  356. Mac programming but I've never written this type of program.  I need to paste
  357. small 256 color PICT resources (preloaded, of course) on screen.  These will
  358. all use the same color table, which is different than the standard palette used
  359. by the system.  Should I abandon quickdraw and write a dedicated procedure?
  360. (using Think C, by the way.)  Should I use the Palette manager for color?
  361. (Probably not.) Should I use the graphics device manager to change the CLUT of
  362. the screen device???  Any help on this matter would be greatly appreciated.
  363.                                           -Mike
  364.                                            MJR145@PSUVM.PSU.EDU
  365. P.S.  Forgive me if this is a FAQ.
  366.  
  367. +++++++++++++++++++++++++++
  368.  
  369. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  370. Date: 22 Apr 92 14:05:44 GMT
  371. Organization: Kalamazoo College
  372.  
  373. MJR145@psuvm.psu.edu (Michael Joseph Raneri) writes:
  374. >
  375. >I am hoping someone could help me out with drawing PICTs on screen rapidly.
  376. >I need to paste
  377. >small 256 color PICT resources (preloaded, of course) on screen.  These will
  378. >all use the same color table, which is different than the standard palette used
  379. >by the system.
  380. >
  381. >Should I abandon quickdraw and write a dedicated procedure?
  382.  
  383. No.  Or at least, you should go through QuickDraw first, and then if you
  384. don't have enough speed, then you can go ahead.  But that shouldn't be
  385. your first route.
  386.  
  387. >Should I use the Palette manager for color? (Probably not.)
  388.  
  389. Yes!
  390.  
  391. >Should I use the graphics device manager to change the CLUT of
  392. >the screen device???
  393.  
  394. No!
  395.  
  396. If you read the Color Manager chapter, do so for informational purposes
  397. only.  The Palette Manager has a fairly steep learning curve, but it's
  398. worth it.  Trust me on this one.
  399.  
  400. What you want to do is set up your palette with pmExplicit+pmTolerant
  401. colors, with zero tolerance, and draw a PICT into an off-screen PixMap.
  402. Save the pixels of that PixMap to disk, probably as a custom resource
  403. type.  Repeat for every PICT you have.
  404.  
  405. Then, to display them, read in the pixel data, set up a PixMap around it
  406. properly, activate a palette of the same colors, and CopyBits the data
  407. to the screen.  CopyBits will work much faster because (1) it's
  408. optimized for fast animation, and (2) it doesn't have to decompress the
  409. PICT before displaying it.
  410.  
  411. When displaying the pixels, you may want to use pmExplicit+pmAnimated
  412. colors instead of pmExplicit+pmTolerant, if you're going to do special
  413. effects like fades or whatnot.  _Don't_ do this when you're creating the
  414. pixel data in the first place;  DrawPicture() will not use pmAnimated
  415. colors, so your data would end up not using all the colors that you
  416. so carefully chose for it.
  417.  
  418. If none of that made sense, go read the Palette Manager chapter a few
  419. times.  :-)  Those last three paragraphs are just kind of an overview of
  420. what you have to do;  if you need more specific help, try me or the
  421. net again, we'll be glad to lend a hand...
  422. - -- 
  423.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  424.  Youth culture killed my dog...
  425.  
  426. ---------------------------
  427.  
  428. From: ja1cs247@troi.cc.rochester.edu (Eric Hansen)
  429. Subject: THINK Pascal: Need to wait for single keypress
  430. Date: 22 Apr 92 03:52:30 GMT
  431. Organization: University of Rochester - Rochester, New York
  432.  
  433. I'm writing a program where I'd like to wait for the user to hit a key on
  434. the keyboard (in THINK Pascal).  I would like to figure out how to wait
  435. (keep monitoring the keyboard) until a key is pressed, and then somehow
  436. put the 'key pressed' into a variable.  This is similar to a 
  437. 10 get a$: if a$ = "" then goto10
  438. kind of thing in BASIC, but how can I do this in Mac Pascal?!  I thought the
  439. read(X) command was supposed to do this, but it requires a <return> after the
  440. keypress, and that won't do...  Any help would be much appreciated!
  441. reply to:
  442.  
  443. ja1cs247@troi.cc.rochester.edu
  444.  
  445. Thanks!!
  446.  
  447. Eric Hansen
  448.  
  449. +++++++++++++++++++++++++++
  450.  
  451. From: mhall@occs.cs.oberlin.edu (Matthew Hall)
  452. Organization: Oberlin College Computer Science
  453. Date: Wed, 22 Apr 1992 20:11:43 GMT
  454.  
  455. In article <1992Apr22.035230.8995@galileo.cc.rochester.edu> ja1cs247@troi.cc.rochester.edu (Eric Hansen) writes:
  456.  
  457.  
  458. >   I'm writing a program where I'd like to wait for the user to hit a key on
  459. >   the keyboard (in THINK Pascal).  I would like to figure out how to wait
  460. >   (keep monitoring the keyboard) until a key is pressed, and then somehow
  461. >   put the 'key pressed' into a variable.  This is similar to a 
  462.  
  463.  
  464. Okay, hold on.  This may sound a little difficult, but it's worth it
  465. to understand.
  466.  
  467. Probably the best way to do this is to use the event queue.  The event
  468. queue is how the macintosh stores keypresses, mouse clicks, disk
  469. inserted events, etc.  until it wants to deal with them.  Each item in
  470. the queue contains informaction as to where the mouse was when it
  471. happened, what time it happened, what type of event happened, what
  472. modifier keys(shift,control,option,command) were held down when
  473. pressed, and
  474. additional information that pertains to specific types of event.  
  475.     I don't have inside mac I in front of me now (which, by the
  476. way it sounds as if you don't have it.  It would be a very good idea
  477. to buy it, or download the inside mac DA (vols. 1-3) from sumex-aim info-mac/da,
  478. or the Spinside Mac (vols 1-5) card stack from ftp.apple.com
  479. /dts/mac/docs/stacks/spinside.  The DA is smaller and faster, but is
  480. pre-mac plus information.  Still, volumes I and II are necessary to
  481. program the mac) but, assuming that you have declared a var of type
  482. EventRecord, you can get the pending event with:
  483.  
  484. var TheEvent  : eventrecord;
  485.     IsEventPending : boolean;
  486. ...
  487. isEventPending:=GetNextEvent(Everyevent,TheEvent);
  488.  
  489. isEventPending will be true if a key pressed, mouse down, etc. event
  490. is in the queue.
  491.  
  492. EveryEvent is a constant (predefined in Think) that tells GetNextEvent
  493. what events you want to look at.  If you use the constant KeyDownMask
  494. (might not be the actual name, can't remeber for sure) then
  495. isEventPending will only be true if a key pressed event is in the
  496. queue.
  497.  
  498. Now TheEvent has a field called .message which comtains the character
  499. code of the key pressed, as well as some other stuff.  The way to get
  500. the character is
  501. ch:=char(band(TheEvent.message,CharCodeMask))
  502.  
  503. should work.  All this does is takes away all the stuff in message
  504. that you don't want.
  505.  
  506. so, synopsis-
  507.  
  508. var TheEvent : EventRecord;
  509.     IsEventPending : Boolean;
  510.     ch : char;
  511.  
  512. ...
  513. repeat
  514.   IsEventPending:=GetNextEvent(everyevent,TheEvent); {Get the next event}
  515.   if IsEventPending = TRUE then           {If there's something there then}
  516.      If TheEvent.what = KeyDownEvt then   {If it's a key pressed event then}
  517.        begin
  518.      ch:=chr(BAND(TheEvent.message,CharCodeMask)); {extract the char}
  519.      {Do what you want with ch}            {do something with it}
  520.        end;
  521.  
  522. until you want to stop    
  523.  
  524.  
  525. Note: som constants may be wrong - Get Inside Mac I
  526.       If you want to check for mouse clicks, check if theevent.what =
  527. mousedownevt, theevt.where is the global coordinates (from topleft
  528. corner of screen) whereit was clicked.
  529.       You should use WaitNextEvent, actually, to be nice to
  530. multifinder, but that's a little involved.
  531.  
  532. Hope This Helps
  533.  
  534. - -Matt Hall
  535. - --
  536.  
  537.  
  538. - -------------------------------------------------------------------------------
  539. Matt Hall.    mhall@occs.cs.edu  OR  SMH9666@OBERLIN.BITNET
  540.               (216)-775-5805 (That's a Cleveland Area code. Lucky Me)
  541.  
  542. "If a man comes up to you and says:
  543.     'A dog just carried away your ear.'
  544. Do you run after the dog, or search first for your ear?" - Moon over Morocco
  545.   
  546.  
  547. ---------------------------
  548.  
  549. From: ccs011@fred.ucdavis.edu (James Davis)
  550. Subject: Writing  apps that use plug-ins?
  551. Date: 6 Apr 92 17:28:35 GMT
  552. Organization: Computing Services, UC Davis
  553.  
  554. Hi,
  555.     I want to write something, that can take plug-ins that reside
  556. in different files.  Similar to Superpaint, etc etc..
  557. Anyway, the theory seems easy.  If I have a code resource sitting
  558. in this external file, I should be able to just load the resource and
  559. make a call to it. But how?  Since which resources are available (which plugins)
  560. is determined dynamicly, none of them can reside in the jump-table can they?
  561. Anyway, if anyone can point me in the right direction, or refrence me
  562. off to the correct example or paper Id appreciate it.
  563.  
  564. THanks
  565. James Davis (jedavis@ucdavis.edu) Computing Services, U of Cal.
  566.  
  567. +++++++++++++++++++++++++++
  568.  
  569. From: ivanski@world.std.com (Ivan M CaveroBelaunde)
  570. Date: 7 Apr 92 02:55:16 GMT
  571. Organization: The World Public Access UNIX, Brookline, MA
  572.  
  573. Calling plug-ins is pretty straightforward. Pseudocode follows:
  574.  
  575. typedef pascal OSErr (*PlugInProcPtr)(short selector, long param1, etc);
  576.  
  577. short refNum;
  578. Handle plugInResource;
  579. PlugInProcPtr plugInProc;
  580.  
  581. plugInResource = Get1Resource(kPlugInType,kPlugInID);
  582. HLock (plugInResource);
  583. plugInProc = (PlugInProcPtr)StripAddress(*plugInResource);
  584. err = (*plugInProc)(selector, param1, ...);
  585.  
  586. You should also have error checking code (nil empty handle for the
  587. code resource, resource file not opening, etc) as well. If you're 
  588. designing the plug-in specs, it might be useful to have descriptive
  589. resources in the plug-in as well, which you can then parse.
  590.  
  591. Hope this helps,
  592.  
  593. - -Ivanski
  594. - ---
  595. Ivan Cavero Belaunde
  596. DiVA Corporation
  597. #include <std.disclaimer.h>
  598.  
  599. +++++++++++++++++++++++++++
  600.  
  601. From: edw@caligula.cts.com (Ed Watkeys)
  602. Date: 7 Apr 92 10:17:22 GMT
  603. Organization: Guerrilla Networking Project
  604.  
  605.  
  606. In article <BMBHG5.1oG@world.std.com> (comp.sys.mac.programmer), ivanski@world.std.com (Ivan M CaveroBelaunde) writes:
  607. > Calling plug-ins is pretty straightforward. Pseudocode follows:
  608. > typedef pascal OSErr (*PlugInProcPtr)(short selector, long param1, etc);
  609. > [...]
  610. > You should also have error checking code (nil empty handle for the
  611. > code resource, resource file not opening, etc) as well. If you're 
  612. > designing the plug-in specs, it might be useful to have descriptive
  613. > resources in the plug-in as well, which you can then parse.
  614. > Hope this helps,
  615. > -Ivanski
  616.  
  617. While I didn't make the original post, I have a question about this... I'm
  618. writing a BBS program, and I have routines to do i/o over the connection (with
  619. the CTB, of course...); how can I have the plug-in call routines within my
  620. program's code?
  621.  
  622. Ed
  623.  
  624. - --
  625. Ed Watkeys (Drexel U. Comp Sci)  "...if you wish to strive for peace
  626. edw@caligula.cts.com              of soul and pleasure, then believe;
  627. edw%caligula@phlpa.uucp           if you wish to be a devotee of truth,
  628. ls.com!phlpa!caligula!edw         then inquire...." -- Nietzsche
  629.  
  630. +++++++++++++++++++++++++++
  631.  
  632. From: ivanski@world.std.com (Ivan M CaveroBelaunde)
  633. Date: 7 Apr 92 13:36:26 GMT
  634. Organization: The World Public Access UNIX, Brookline, MA
  635.  
  636. edw@caligula.cts.com (Ed Watkeys) writes:
  637. >While I didn't make the original post, I have a question about this... I'm
  638. >writing a BBS program, and I have routines to do i/o over the connection (with
  639. >the CTB, of course...); how can I have the plug-in call routines within my
  640. >program's code?
  641.  
  642. Basically, one of the parameters you pass to the plug-in must be a procPtr
  643. with well-defined calling conventions. The procptr could be one of the
  644. explicit parameters (this I haven't seen done), or a field inside a
  645. parameter block (XCMDs and Photoshop plug-ins do it this way). Then you
  646. would take the procPtr, cast it to the right type (if necessary), and issue
  647. the callback to your program.  HyperCard's callback structure is a good
  648. example of a flexible callback spec that allows a wide variety of callbacks
  649. with widely varying parameters via the same procPtr, and it's pretty well
  650. documented as well. You might want to use that as a model.
  651.  
  652. BTW, when you process the callbacks from the plug-in in your code, be careful
  653. not to do things like unlocking the plug-in resource or closing the resource
  654. file; also, the spec for the callback should specify what you expect the
  655. world to look like (chances are you should expect it restored to the state
  656. it was when the plug-in was initially called. This means that if the plug-in
  657. creates an A5 world for its globals, or changes the graphics world
  658. (port/gdevice) and the like, they should be restored to the ones on entry
  659. before calling. I know these might sound obvious, but they are easily
  660. avoidable pitfalls that you should be careful about.
  661.  
  662. - -Ivanski
  663. - ---
  664. Ivan Cavero Belaunde
  665. DiVA Corporation
  666. #include <std_disclaimer.h>
  667.  
  668. +++++++++++++++++++++++++++
  669.  
  670. From: ccs011@jane.ucdavis.edu (James Davis)
  671. Date: 7 Apr 92 16:33:14 GMT
  672. Organization: Computing Services, UC Davis
  673.  
  674. In article <01050133.0do71a@caligula.cts.com> edw@caligula.cts.com (Ed Watkeys) writes:
  675. >
  676. >While I didn't make the original post, I have a question about this... I'm
  677. >writing a BBS program, and I have routines to do i/o over the connection (with
  678. >the CTB, of course...); how can I have the plug-in call routines within my
  679. >program's code?
  680. >
  681. >Ed
  682. >
  683.  
  684. This is an important point that I was wondering too.  I sort of assumed
  685. that you could access routines in the main code the same way you 
  686. can access global variables.  Something about setting up the A5 World.
  687. At any rate I had intended to do some more reading of IM, before showing
  688. my ignorance in this area, but since at least one other soul was confused,
  689. thought it'd be safe to add my voice. :-)
  690.  
  691. James Davis (jedavis@ucdavis.edu) : Computing Services : UCDavis
  692.  
  693. +++++++++++++++++++++++++++
  694.  
  695. From: rhorn@csws11.ic.sunysb.edu (Robert Horn)
  696. Organization: SUNY at Stony Brook where no one gets an education
  697. Date: Tue, 7 Apr 1992 23:20:48 GMT
  698.  
  699. In article <01050133.0do71a@caligula.cts.com> edw@caligula.cts.com (Ed Watkeys) writes:
  700. >
  701. >
  702. >While I didn't make the original post, I have a question about this... I'm
  703. >writing a BBS program, and I have routines to do i/o over the connection (with
  704. >the CTB, of course...); how can I have the plug-in call routines within my
  705. >program's code?
  706. >
  707.  
  708. The plug in has no access to your applications jump tables (?) (at least in 
  709. THINK languages) and so would not be able to call your application's routines 
  710. unless you pass the addresses of the routines to your plug-in resource/routine, 
  711. and could only then call your routines through the pointers to the functions.
  712. (Pascal can't do this as it doesn't allow you to call a function through a
  713. pointer.) (you might want to glance at your favorite(sp?) C book's section on
  714. pointers to functions)
  715.  
  716. i.e., 
  717.  
  718. <<File FuncBlock.h>>
  719. typedef struct FuncBlock FuncBlock, *FuncBlockPtr;
  720. typedef pascal void (**MagicFunctionHandle)(const FuncBlockPtr);
  721.  
  722. struct FuncBlock
  723. {
  724.     /* pointers to functions, NOT methods */
  725.     void (*func1)(short, short);
  726.     pascal OSErr (*fluffyFunc)(const Rect *);
  727. };
  728.  
  729. <<File Plug-In.c>>
  730. #include "FuncBlock.h"
  731. // this gets compiled as a resource, in a seperate project.
  732. pascal void main(const FuncBlockPtr pBlock)
  733. {
  734.     Rect        theRect;
  735.     OSErr        theErr;
  736.     // assorted other stuff... (Lock down this handle)
  737.  
  738.     theErr = (*pBlock->fluffyFunc)(&theRect);
  739.         // valid call.
  740.     
  741.     // assorted other things...
  742. }
  743.  
  744. <<File app.c>>
  745.  
  746.     ...
  747.     MagicFunctionHandle    hFunc;
  748.     FuncBlock        block;
  749.  
  750.     block.func1 = some_function;
  751.     block.fluffyFunc = some_other_function;
  752.  
  753.     hFunc = GetResource(your_resource_type, your_resource_id);
  754.  
  755.     // Lock hFunc if it doesn't lock itself
  756.  
  757.     (**hFunc)(&block);        // call plug in module
  758.                     // the plug in module has access to
  759.                     // some_function and
  760.                     // some_other_function through the 
  761.                     // FuncBlock's func1 and fluffyFunc
  762.                     // members.
  763.  
  764.     // Unlock and/or release plug-in?
  765.  
  766.     ...
  767.  
  768.  
  769. hope this helps,
  770. Rob
  771.  
  772. - ---
  773. rhorn@ic.sunysb.edu (not a wombat)
  774.  
  775. +++++++++++++++++++++++++++
  776.  
  777. From: mhall@occs.cs.oberlin.edu (Matthew Hall)
  778. Organization: Oberlin College Computer Science
  779. Date: Wed, 8 Apr 1992 00:54:13 GMT
  780.  
  781. In article <11980@ucdavis.ucdavis.edu> ccs011@fred.ucdavis.edu (James Davis) writes:
  782.  
  783. >   Hi,
  784. >       I want to write something, that can take plug-ins that reside
  785. >   in different files.  Similar to Superpaint, etc etc..
  786. >   Anyway, the theory seems easy.  If I have a code resource sitting
  787. >   in this external file, I should be able to just load the resource and
  788. >   make a call to it. But how?  Since which resources are available (which plugins)
  789. >   is determined dynamicly, none of them can reside in the jump-table can they?
  790. >   Anyway, if anyone can point me in the right direction, or refrence me
  791. >   off to the correct example or paper Id appreciate it.
  792. >
  793.  
  794.  Tech note #256 goes into great detail in pascal and c on how to do
  795. this, including how to implement global data storage.
  796.  
  797. - -matt hall
  798. - --
  799.  
  800.  
  801. - -------------------------------------------------------------------------------
  802. Matt Hall.    mhall@occs.cs.edu  OR  SMH9666@OBERLIN.BITNET
  803.               (216)-775-5805 (That's a Cleveland Area code. Lucky Me)
  804.  
  805. "If a man comes up to you and says:
  806.     'A dog just carried away your ear.'
  807. Do you run after the dog, or search first for your ear?" - Moon over Morocco
  808.   
  809.  
  810. +++++++++++++++++++++++++++
  811.  
  812. From: dnebing@bgsu.edu (Mr. Neb)
  813. Date: 8 Apr 92 06:53:50 GMT
  814. Organization: Bowling Green State University B.G., Oh.
  815.  
  816. >From article <1992Apr7.232048.9295@sbcs.sunysb.edu>, by rhorn@csws11.ic.sunysb.edu (Robert Horn):
  817. > The plug in has no access to your applications jump tables (?) (at least in 
  818. > THINK languages) and so would not be able to call your application's routines 
  819. > unless you pass the addresses of the routines to your plug-in resource/routine, 
  820. > and could only then call your routines through the pointers to the functions.
  821. > (Pascal can't do this as it doesn't allow you to call a function through a
  822. > pointer.) (you might want to glance at your favorite(sp?) C book's section on
  823. > pointers to functions)
  824.  [stuff deleted...]
  825.  
  826.     Just making the call to the code resource should not change the value
  827. of the A5 register, which points to the application's global variables as
  828. well as the jump table.  If you knew (through previous compilation) the
  829. correct offset into the jump table, couldn't you just jump to that location
  830. in the jump table, using the A5 offset?
  831.  
  832.     As far as I know, it would seem that this should work.  Does anyone
  833. agree or disagree with this.  I am curious to see if it is felt that this 
  834. method would work or not.
  835.  
  836.  
  837.     dnebing@andy.bgsu.edu
  838.  
  839. +++++++++++++++++++++++++++
  840.  
  841. From: rhorn@csws8.ic.sunysb.edu (Robert Horn)
  842. Organization: SUNYat Stony Brook where no one gets an education
  843. Date: Wed, 8 Apr 1992 16:44:04 GMT
  844.  
  845. In article <9813@bgsuvax.bgsu.edu> dnebing@bgsu.edu (Mr. Neb) writes:
  846. >From article <1992Apr7.232048.9295@sbcs.sunysb.edu>, by rhorn@csws11.ic.sunysb.edu (That's me!):
  847.  [ stuff deleted ]
  848. > [stuff deleted...]
  849. >
  850. >    Just making the call to the code resource should not change the value
  851. >of the A5 register, which points to the application's global variables as
  852. >well as the jump table.  If you knew (through previous compilation) the
  853. >correct offset into the jump table, couldn't you just jump to that location
  854. >in the jump table, using the A5 offset?
  855. >
  856. >    As far as I know, it would seem that this should work.  Does anyone
  857. >agree or disagree with this.  I am curious to see if it is felt that this 
  858. >method would work or not.
  859. >
  860. >
  861. >    dnebing@andy.bgsu.edu
  862.  
  863. I've tried something like that: passing an object to a code resource, and
  864. could not access any of the objects methods. (and when i checked the link it
  865. complained that they were not defined) I would assume that the same is true
  866. for functions. When you are compiling your code resource, the compiler would
  867. have no way of knowing where in the application's jump table to look for a 
  868. function or procedure or method; and if this were possible, it would have to
  869. resolve the function's location in the jump table at runtime. I don't think
  870. that the jump table has the names of functions or anything else that might
  871. identify the functions in it (Of course, i could be entirely wrong, have never
  872. looked at the jump table in any way, and probably wouldn't understand it if I
  873. did. This last part is pure speculation on my part. Any similarity between it
  874. and any real events or persons is purely coincidental.)
  875.  
  876. (I was hoping that objects would contain a pointer to a block of pointers to
  877. functions to implement its methods, but I was apparently wrong.)
  878.  
  879. Rob
  880. - ---
  881. rhorn@ic.sunysb.edu (not an aardvark)
  882.  
  883.  
  884. +++++++++++++++++++++++++++
  885.  
  886. From: edw@caligula.cts.com (Ed Watkeys)
  887. Date: Wed, 8 Apr 92 19:47:02 EDT
  888. Organization: Guerrilla Networking Project
  889.  
  890.  
  891. In article <1992Apr8.164404.18051@sbcs.sunysb.edu> (comp.sys.mac.programmer), rhorn@csws8.ic.sunysb.edu (Robert Horn) writes:
  892. > In article <9813@bgsuvax.bgsu.edu> dnebing@bgsu.edu (Mr. Neb) writes:
  893. > >From article <1992Apr7.232048.9295@sbcs.sunysb.edu>, by rhorn@csws11.ic.sunysb.edu (That's me!):
  894. >  [ stuff deleted ]
  895. > > [stuff deleted...]
  896. > >
  897. > >    Just making the call to the code resource should not change the value
  898. > >of the A5 register, which points to the application's global variables as
  899. > >well as the jump table.  If you knew (through previous compilation) the
  900. > >correct offset into the jump table, couldn't you just jump to that location
  901. > >in the jump table, using the A5 offset?
  902. > >
  903. > >    As far as I know, it would seem that this should work.  Does anyone
  904. > >agree or disagree with this.  I am curious to see if it is felt that this 
  905. > >method would work or not.
  906. > >
  907. > >
  908. > >    dnebing@andy.bgsu.edu
  909. > I've tried something like that: passing an object to a code resource, and
  910. > could not access any of the objects methods. (and when i checked the link it
  911. > complained that they were not defined) I would assume that the same is true
  912. > for functions. When you are compiling your code resource, the compiler would
  913. > have no way of knowing where in the application's jump table to look for a 
  914. > function or procedure or method; and if this were possible, it would have to
  915. > resolve the function's location in the jump table at runtime. I don't think
  916. > that the jump table has the names of functions or anything else that might
  917. > identify the functions in it (Of course, i could be entirely wrong, have never
  918. > looked at the jump table in any way, and probably wouldn't understand it if I
  919. > did. This last part is pure speculation on my part. Any similarity between it
  920. > and any real events or persons is purely coincidental.)
  921. > (I was hoping that objects would contain a pointer to a block of pointers to
  922. > functions to implement its methods, but I was apparently wrong.)
  923. > Rob
  924. > ---
  925. > rhorn@ic.sunysb.edu (not an aardvark)
  926.  
  927. Is the object you wanted to pass to the CODE resource used in the program
  928. anywhere? If I recall correctly, THINK C (or Pascal or both) will, as an
  929. optimization, not include methods in an object that are not called when it
  930. does a smart link, therfore your methods won't exist if you don't use them
  931. from inside the application.
  932.  
  933. Or I could just be dead wrong...
  934.  
  935. Ed
  936.  
  937. - --
  938. Ed Watkeys (Drexel U. Comp Sci)  "...if you wish to strive for peace
  939. edw@caligula.cts.com              of soul and pleasure, then believe;
  940. edw%caligula@phlpa.pha.pa.us      if you wish to be a devotee of truth,
  941. ls.com!phlpa!caligula!edw         then inquire...." -- Nietzsche
  942.  
  943. +++++++++++++++++++++++++++
  944.  
  945. From: zobkiw@world.std.com (Joe Zobkiw)
  946. Date: 9 Apr 92 14:15:49 GMT
  947. Organization: The World Public Access UNIX, Brookline, MA
  948.  
  949. << If I recall correctly, THINK C (or Pascal or both) will, as an
  950. optimization, not include methods in an object that are not called when it
  951. does a smart link, therfore your methods won't exist if you don't use them
  952. from inside the application. >>
  953.  
  954. I think you're wrong. I've alwasy understoodthat THINK C's Smart Link is 
  955. on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  956.  
  957.  
  958. - -- 
  959. <--------------------------------------------------->
  960.  joe zobkiw                     zobkiw@world.std.com
  961.  mac.synthesis.MIDI.development.C.asm.communications
  962. >---------------------------------------------------<
  963.  
  964. +++++++++++++++++++++++++++
  965.  
  966. From: time@ice.com (Tim Endres)
  967. Date: 9 Apr 92 14:51:07 GMT
  968. Organization: ICE Engineering, Inc.
  969.  
  970.  
  971. Please take a look at integrating "tcl" into your applications
  972. instead of external code resources!!!
  973.  
  974. Tickle-tcl gives you a COMPLETE scripting language, plus Apple Events,
  975. PLUS external code resources (including the ability to load your own
  976. "coercion" routines for Apple Events)! Furthermore, Ed Lai at Apple
  977. is writing code to let Tickle run HyperCard XCMDs and XFCNs, as well
  978. as FKeys (Shift-Cmd-Number). All of this for free with NO effort.
  979.  
  980. To see what "tcl" is, go get tickle from the MSEN ftp server and have
  981. a look (ftp.msen.com - pub/vendor/ice/tickle).
  982. Why go to all the effort that has alread been done for you?
  983.  
  984. Several applications are currently being written to include "tcl"
  985. including Alpha and Harvest C. More will be forthcoming and all will
  986. be "script-compatbile".
  987.  
  988. tim.
  989.  
  990. In article <9813@bgsuvax.bgsu.edu> (comp.sys.mac.programmer), dnebing@bgsu.edu (Mr. Neb) writes:
  991. > >From article <1992Apr7.232048.9295@sbcs.sunysb.edu>, by rhorn@csws11.ic.sunysb.edu (Robert Horn):
  992. > > The plug in has no access to your applications jump tables (?) (at least in 
  993. > > THINK languages) and so would not be able to call your application's routines 
  994. > > unless you pass the addresses of the routines to your plug-in resource/routine, 
  995. > > and could only then call your routines through the pointers to the functions.
  996. > > (Pascal can't do this as it doesn't allow you to call a function through a
  997. > > pointer.) (you might want to glance at your favorite(sp?) C book's section on
  998. > > pointers to functions)
  999. > > 
  1000. >  [stuff deleted...]
  1001. >     Just making the call to the code resource should not change the value
  1002. > of the A5 register, which points to the application's global variables as
  1003. > well as the jump table.  If you knew (through previous compilation) the
  1004. > correct offset into the jump table, couldn't you just jump to that location
  1005. > in the jump table, using the A5 offset?
  1006. >     As far as I know, it would seem that this should work.  Does anyone
  1007. > agree or disagree with this.  I am curious to see if it is felt that this 
  1008. > method would work or not.
  1009.  
  1010.  
  1011. tim endres - time@ice.com  -or-  uupsi!tbomb!time
  1012. ICE Engineering, Inc. - Phone (313) 449 8288 - FAX (313) 449-9208
  1013. 8840 Main Street, Whitmore Lake, MI  48189
  1014. USENET - a slow moving self parody... ph
  1015.  
  1016. +++++++++++++++++++++++++++
  1017.  
  1018. From: gavin.eadie@umich.edu (Gavin Eadie)
  1019. Date: 9 Apr 92 13:24:19 GMT
  1020. Organization: University of Michigan
  1021.  
  1022. >writing a BBS program, and I have routines to do i/o over the connection
  1023. (with
  1024. >the CTB, of course...); how can I have the plug-in call routines within
  1025. my
  1026. >program's code?
  1027.  
  1028. +++++++++++++++++++++++++++
  1029.  
  1030. From: gavin.eadie@umich.edu (Gavin Eadie)
  1031. Date: 9 Apr 92 13:25:16 GMT
  1032. Organization: University of Michigan
  1033.  
  1034. >writing a BBS program, and I have routines to do i/o over the connection
  1035. (with
  1036. >the CTB, of course...); how can I have the plug-in call routines within
  1037. my
  1038. >program's code?
  1039.  
  1040.     The usual trick for this is to pass a parameter to your plug-in that is
  1041. the
  1042.     address of a list of routine addresses (sometimes called a transfer
  1043. vector).
  1044.     Then the plug in can call back to your main program via the addresses
  1045. that
  1046.     you provide therein ...
  1047.  
  1048. Gavin Eadie, U of Michigan Information Systems
  1049.  
  1050. +++++++++++++++++++++++++++
  1051.  
  1052. From: edw@caligula.cts.com (Ed Watkeys)
  1053. Date: 9 Apr 92 18:28:37 GMT
  1054. Organization: Guerrilla Networking Project
  1055.  
  1056.  
  1057. In article <BMG2AE.273@world.std.com> (comp.sys.mac.programmer), zobkiw@world.std.com (Joe Zobkiw) writes:
  1058. > << If I recall correctly, THINK C (or Pascal or both) will, as an
  1059. > optimization, not include methods in an object that are not called when it
  1060. > does a smart link, therfore your methods won't exist if you don't use them
  1061. > from inside the application. >>
  1062. > I think you're wrong. I've alwasy understoodthat THINK C's Smart Link is 
  1063. > on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  1064.  
  1065. If that's the case, then that's a stupid way to do a smart link.
  1066.  
  1067. >  joe zobkiw                     zobkiw@world.std.com
  1068.  
  1069. - --
  1070. Ed Watkeys (Drexel U. Comp Sci)  "...if you wish to strive for peace
  1071. edw@caligula.cts.com              of soul and pleasure, then believe;
  1072. edw%caligula@phlpa.pha.pa.us      if you wish to be a devotee of truth,
  1073. ls.com!phlpa!caligula!edw         then inquire...." -- Nietzsche
  1074.  
  1075. +++++++++++++++++++++++++++
  1076.  
  1077. From: jcav@quads.uchicago.edu (JohnC)
  1078. Date: 9 Apr 92 20:11:31 GMT
  1079. Organization: The Royal Society for Putting Things on Top of Other Things
  1080.  
  1081. In article <BMG2AE.273@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
  1082. ><< If I recall correctly, THINK C (or Pascal or both) will, as an
  1083. >optimization, not include methods in an object that are not called when it
  1084. >does a smart link, therfore your methods won't exist if you don't use them
  1085. >from inside the application. >>
  1086. >
  1087. >I think you're wrong. I've alwasy understoodthat THINK C's Smart Link is 
  1088. >on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  1089.  
  1090. I know for certain that THINK Pascal 3.0 or newer does smart linking on a
  1091. routine-by-routine basis, and I would suspect recent versions of THINK C
  1092. would work in a similar fashion.
  1093.  
  1094.  
  1095. - -- 
  1096. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  1097. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  1098. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  1099. B0 f++ c+ g+ k s++ e+ h- pv     |         Chicago, IL  60637
  1100.  
  1101. +++++++++++++++++++++++++++
  1102.  
  1103. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  1104. Date: 10 Apr 92 14:37:24 GMT
  1105. Organization: Symantec Corp.
  1106.  
  1107. >>>>> On 9 Apr 92 20:11:31 GMT, jcav@quads.uchicago.edu (JohnC) said:
  1108.  
  1109.  > In article <BMG2AE.273@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
  1110. In article <1992Apr9.201131.3517@midway.uchicago.edu> jcav@quads.uchicago.edu (JohnC) writes:
  1111.  
  1112. >><< If I recall correctly, THINK C (or Pascal or both) will, as an
  1113. >>optimization, not include methods in an object that are not called when it
  1114. >>does a smart link, therfore your methods won't exist if you don't use them
  1115. >>from inside the application. >>
  1116. >>
  1117. >>I think you're wrong. I've alwasy understoodthat THINK C's Smart Link is 
  1118. >>on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  1119.  
  1120.  > I know for certain that THINK Pascal 3.0 or newer does smart
  1121.  > linking on a routine-by-routine basis, and I would suspect recent
  1122.  > versions of THINK C would work in a similar fashion.
  1123.  
  1124. You'd think so, right :) ? Well, THINK C 4.x and 5.x both have the
  1125. same level of "smart linking" that C 3.x had. They will only leave out
  1126. code if an entire file of it is not referenced at all. There are a
  1127. couple other things to note:
  1128.  
  1129.  - if you add a project file to use as a library (like ANSI), you'll
  1130.  get smart linking on a file by file basis *inside* the library. Eg,
  1131.  if you just call sin(), you'll just get math.c.
  1132.  
  1133.  - C 5.0 lets you create objects by name, like Pascal 3 and 4. You
  1134.  can run into cases where you try to create a class on the fly that
  1135.  has been linked out. TCL programmers should check out CApplication
  1136.  ::ForceClassReferences for more info.
  1137.  
  1138.     -phil
  1139. - --
  1140.    Phil Shapiro                                   Software Engineer
  1141.    Language Products Group                     Symantec Corporation
  1142.            Internet: phils@cs.brandeis.edu
  1143.  
  1144. +++++++++++++++++++++++++++
  1145.  
  1146. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  1147. Date: 10 Apr 92 17:17:11 GMT
  1148. Organization: Kalamazoo College
  1149.  
  1150. jcav@midway.uchicago.edu writes:
  1151. >zobkiw@world.std.com (Joe Zobkiw) writes:
  1152. >>
  1153. >>I've alwasy understoodthat THINK C's Smart Link is 
  1154. >>on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  1155. >
  1156. >I know for certain that THINK Pascal 3.0 or newer does smart linking on a
  1157. >routine-by-routine basis, and I would suspect recent versions of THINK C
  1158. >would work in a similar fashion.
  1159.  
  1160. No, it's by file.  See the User's Manual, p. 96.  There was also a
  1161. ReadMe file that clarified this, maybe the one on the TCL 1.1.2 upgrade.
  1162.  
  1163. Out of curiosity, how fast are ThP 3.0's smart links?
  1164. - -- 
  1165.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  1166.  "Almost all portables today employ passive-matrix LCDs, and no one expects
  1167.  active-matrix screens to be cost-competitive for a few years" -PC World 2/92
  1168.  
  1169. +++++++++++++++++++++++++++
  1170.  
  1171. From: roy@adeptsln.cts.com
  1172. Date: 10 Apr 92 19:28:58 GMT
  1173. Organization: Adept Solutions
  1174.  
  1175. In article <1992Apr7.232048.9295@sbcs.sunysb.edu> rhorn@csws11.ic.sunysb.edu  
  1176. (Robert Horn) writes:
  1177. > In article <01050133.0do71a@caligula.cts.com> edw@caligula.cts.com (Ed  
  1178. Watkeys) writes:
  1179. > (Pascal can't do this as it doesn't allow you to call a function through a
  1180. > pointer.) (you might want to glance at your favorite(sp?) C book's section on
  1181. > pointers to functions)
  1182.  
  1183. If HyperCard can, then you certainly can, and here's how. First you define a  
  1184. calling structure for your code resource. I usually use one parameter, a  
  1185. app-specific param block, so the code-resource routine looks something like:
  1186.  
  1187. Function CodeMain(blockPtr:myParamBlockPtr):OSErr;
  1188.  
  1189. Then in my app, I have a stub that looks like:
  1190.  
  1191. function CallCodeRSRC(blockPtr:myParamBlockPtr; codeResource:Handle):OSErr;
  1192. INLINE $205F, $2050, $4E90;
  1193.  
  1194. The inline's basically pop the handle off the stack, dereference it, then jump  
  1195. to it. Be sure to lock down the codeResource after getting it.
  1196.  
  1197. If have a routine in your app, that you wanted to call in the resource, first  
  1198. make a procPtr field in your parameter block. (myParamBlockRec, in our case);
  1199.     
  1200.     myParamBlockRec.myRoutine := @myRoutine;
  1201.     ..
  1202.     codeResource := GetResource('myCO',128);    { What you compiled }
  1203.     HLock(codeResource);
  1204.     err := CallCodeRSRC(&myParamBlockRec,codeResource);
  1205.     ..
  1206.  
  1207. Assuming there is a 
  1208.  
  1209.     Function myRoutine(var r:Rect):Boolean;
  1210.  
  1211. in your app, you would call back this routine, in your code resource, by
  1212. having a stub that has the same parameters, (including return value), with an  
  1213. additional procPtr at the end.
  1214.  
  1215.     Function appMyRoutine(var r:Rect; callback:ProcPtr):Boolean;
  1216.     INLINE $205F,$4E90;
  1217.  
  1218. Therefore, in your code resource, to call the app routine, you have this:
  1219.  
  1220.     Function CodeMain(blockPtr:myParamBlockPtr):OSErr;
  1221.     var
  1222.         b:Boolean;
  1223.         r:Rect;
  1224.     begin
  1225.         ..
  1226.         b := appMyRoutine(r,myParamBlockPtr^.myRoutine);
  1227.         ..
  1228.     end;
  1229.  
  1230. The INLINE stuff is an assembly glue to do what 'c' can do syntactically.
  1231. the code would have simply been:
  1232.  
  1233.     b = (*myParamBlockPtr->myRoutine)(&r);
  1234.  
  1235. and for calling a handle:
  1236.  
  1237.     err = (**codeResource)(&myParamBlockRec);
  1238.  
  1239. (With all the appropriate prototyping & type checking left as an exercise for  
  1240. the reader). :-)
  1241.  
  1242. Hope this helps.
  1243. - -- 
  1244. Roy Lovejoy      | internet:  roy@adeptsln.cts.com
  1245. Head RGB Guy     | AppleLink: adept
  1246. Adept Solutions  | CIS:       72447,1447
  1247. .................| dual certified developer: NeXT & Apple ;)
  1248.  
  1249. +++++++++++++++++++++++++++
  1250.  
  1251. From: scott@mcl.mcl.ucsb.edu (Scott Bronson)
  1252. Date: 12 Apr 92 03:59:20 GMT
  1253.  
  1254. In <BMG2AE.273@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
  1255.  
  1256. ><< If I recall correctly, THINK C (or Pascal or both) will, as an
  1257. >optimization, not include methods in an object that are not called when it
  1258. >does a smart link, therfore your methods won't exist if you don't use them
  1259. >from inside the application. >>
  1260.  
  1261. >I think you're wrong. I've alwasy understoodthat THINK C's Smart Link is 
  1262. >on a FILE BY FILE and NOT a ROUTINE BY ROUTINE "smartness."
  1263.  
  1264.  
  1265. Yes, it does do it file by file.  But, can you trust this not to change?
  1266. Defensive programming now might save you a lot of debugging time in
  1267. the future.
  1268.  
  1269.     - Scott
  1270.  
  1271. +++++++++++++++++++++++++++
  1272.  
  1273. From: tom@dtint.uucp (Thomas R. Kimpton)
  1274. Date: 22 Apr 92 17:30:06 GMT
  1275. Organization: Digital Technology, International
  1276.  
  1277. Since I haven't seen anyone mention it, 4D can use externals
  1278. in it's scripting.  As has been discussed (in the abstract),
  1279. 4D uses a "dispatcher" routine that is visible to it (located
  1280. at the beginning of the resource), with selectors to call your
  1281. routines.  The programmer makes his routines available to
  1282. 4D by filling in a STR# resource with the name of the routine
  1283. and it's arguments:
  1284.  
  1285.     myRoutine(&I,&R,&S):&I
  1286.  
  1287. meaning a function returning an integer(short) whose arguments
  1288. are an integer, real(float), and str255.  All arguments are
  1289. passed by pointer in an array of arguments.  The index into
  1290. the STR# is the number of the selector passed to the "dispatcher".
  1291.  
  1292. In addition 4D passes a pointer to a global data handle.  When
  1293. the external is first loaded it is called with a selector of
  1294. - -1, this tells the external to do any initialization it needs
  1295. and to allocate any global storage it needs. When the external
  1296. is to be disposed it is called with a selector of -2 allowing
  1297. it to dispose of any allocated memory.
  1298.  
  1299. There is an entire manual full of callback routines, but I
  1300. never had the need to use them for what I was doing.
  1301.  
  1302.  
  1303.  
  1304.  
  1305. - -- 
  1306. - ---
  1307. Tom Kimpton                            tom@dtint.dtint.com
  1308. Digital Technology Int.                (801)226-2984    
  1309. 500 W. 1200 South, Orem UT, 84057      FAX (801) 226-8438
  1310.  
  1311. ---------------------------
  1312.  
  1313. End of C.S.M.P. Digest
  1314. **********************
  1315.