>How to implement this. Let's imagine tomorrow I get
>another shared library which i want to include to my
>footprint application but i don't want to modify
>anything in foot print application how can i
>dynamically add another shared Library.

If you only call the one function, you can do it like this. But first say a 
loud "Thank you!" to Aaron Ardiri, whose archived PalmSource talk taught me 
how to do this.

In this example, the shared library is "SharedLibraryXYZ", and the function 
in the shared library is "theLibraryFunction" that takes a Char * and a 
UInt32 as arguments and returns an Int16:

     Int16 (*theLibraryFunction)(Char *a, UInt32 b);
     LocalID dbID;
     DmOpenRef dbRef;
     MemHandle codeRes;

     dbID = DmFindDatabase(0, "SharedLibraryXYZ");
     dbRef = DmOpenDatabase(0, dbID, dmModeReadOnly);
     codeRes = DmGet1Resource('code', 1);
     retval = MemHandleLock(codeRes);
     DmReleaseResource(codeRes);
     DmCloseDatabase(dbRef);
     ...
     i = theLibraryFunction("abc", 5);

Error checking is left as an exercise for the reader.

If you want to unload this shared library and load a different one, just 
MemHandleUnlock(codeRes), then repeat the above procedure with a different 
library name.

IMPORTANT NOTES!!!:

1) The code runs as a readonly text segment. This means it had better not 
have any globals or statics, unless you play some other tricks I won't go 
into because I didn't perfect them and gave up on them.

2) The function that you call in this manner must be the VERY FIRST 
FUNCTION on the code segment that you load. All you are really doing is 
JSR'ing to the top of the code segment. So make sure it is the first 
function in the first module on the link line.

3) If you put hardcoded strings into a function, the compiler stores them 
immediately before that function in the code segment. This will cause you, 
using the above method, to attempt to execute character data as code and 
will cause hot acid death. If you must have string constants, make the 
topmost function that you call just a shunt to a function that does the 
real work, and then you can safely use string constants there.

4) I am a novice Palm programmer. I made the decision to go ahead and 
release the resource and close the database immediately after locking down 
the code segment; it saves a lot of tracking and housekeeping when my 
application exits. So far there have been no ill effects from doing so, but 
the gurus from Palm may well come up with a scenario in which this is a BAD 
THING. If so, I'd love to hear about it so I can mend my evil ways.


Curtis Jackson
Director of Engineering
Aniwhere, Inc.
[EMAIL PROTECTED]



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to