Thomas Ward <[EMAIL PROTECTED]> wrote:
> I'm writing a hack that is going to patch two different system traps. Both
> of these patches need to call a common subroutine, which is pretty large, so
> I don't want to have 2 copies in my code.
>
> With the way hacks are compiled (using GCC), is there a way to have some
> shared code?
You would need to manually do some kind of "standalone code resource"
arrangement. This means compiling the common code as another code
resource, ensuring that the subroutine can be called correctly by
jumping to the first byte (say) of the resource.
You then call it something like this:
typedef int CommonFn (int, int, whatever);
/* Or maybe you want to open your database first... */
MemHandle commoncodeH = DmGet1Resource (whatever);
CommonFn *commonfunc = MemHandleLock (commoncodeH);
...
commonfunc (x, y, z); /* commonfunc is a pointer to the start of
the other resource */
...
MemHandleUnlock (commoncodeH);
DmReleaseResource (commoncodeH);
You can use further tricks to have several separate shared functions in
the common code resource.
Doug Anderson tells me that there is a good example of this sort of thing
in his FlipHack hack. See especially FlipHack.h from
http://www-cs-students.stanford.edu/~dianders/palm/
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/