Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!oliveb!apple!austing From: austing@Apple.COM (Glenn L. Austin) Newsgroups: comp.sys.mac.programmer Subject: Re: Calling Code resources? Message-ID: <28576@apple.Apple.COM> Date: 7 Apr 89 19:31:07 GMT References: <11817@ut-emx.UUCP> Distribution: usa Organization: Apple Computer Inc, Cupertino, CA Lines: 35 In article <11817@ut-emx.UUCP> newman@ut-emx.UUCP (David Newman) writes: >Here is another question for the net-gods: how do you call a >code resource (like an XCMD or whatever) from another piece of >code? Can it be done from a high-level language? How might it >be done in Pascal? In C, it is really *relatively* simple -- all you need to do is create a function pointer. In Pascal, however, you need to have an assembly-language routine to do the actual call. Basically, in order to call a code resource, you need to do the following steps: 1) Load the resource into the heap (with your favorite GetResource call) 2) Move the resource high into the heap (with MoveHHi) 3) Lock the resource (with HLock) 4) Dereference the Handle (C: *handle, Pascal: handle^) 5) Assign the dereferenced handle to your function pointer in C. In Pascal, it depends upon the implementation of your assembly language routine. 6) Call the function! Remember that in C, your function assignment is: functionname = (type (*)()) pointer or easier yet: functionname = (void *) pointer but your function call is (*functionname)() ----------------------------------------------------------------------------- | Glenn L. Austin | The nice thing about standards is that | | Apple Computer, Inc. | there are so many of them to choose from. | | Internet: austing@apple.com | -Andrew S. Tanenbaum | ----------------------------------------------------------------------------- | All opinions stated above are mine -- who else would want them? | -----------------------------------------------------------------------------