Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!apple!apple.com!rmh From: rmh@apple.com (Rick Holzgrafe) Newsgroups: comp.sys.mac.programmer Subject: Re: How do you execute a CODE resource? Message-ID: <9750@goofy.Apple.COM> Date: 14 Aug 90 22:14:06 GMT Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 30 References:<1990Aug14.003350.2055@vaxa.cc.uwa.oz.au> <1990Aug14.131735.21771@ux1.cso.uiuc.edu> <1348@anaxagoras.ils.nwu.edu> From C, something like this: Handle h; /* Handle to resource */ int (*myFuncPtr) (int arg1, int arg2); /* Ptr to function */ int theResult; /* Save the return value from the function */ /* Get handle to code resource */ h = GetResource ('myFN', 128); /* Lock it down - Very important! */ HLock (h); /* Get appropriately typed function pointer */ myFuncPtr = (int (*)(int, int))*h; /* Call the function */ theResult = (*myFuncPtr)(arg1, arg2); See? You de-reference the handle to get a pointer, and typecast that into a pointer to the kind of function you are going to call. Then just call it. After the call, you can clean up in whatever way is appropriate: release the resource, if you don't need it any more; or save the handle but unlock it until you need it again, to avoid heap fragmentation. I don't know how to do this in Pascal, I'm afraid. Hope this helps. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 3-PK | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."