At 12:12 PM 5/19/99 -0700, you wrote:
>Is it possible to have two copies of one shared library loaded in the system
>at one time?  When I say loaded, I mean that any one or all of the following
>conditions are met:
>
>* the OS's static SysLibTblEntryPtr global thinks there are two copies, thus
>* HwrSleep() will call into two identical copies of that lib's sleep/wake
>entry point and
>* there are two unique lib ref numbers, thus
>* two instances of the lib's globalsP exist, meaning there are two identical
>copies of the lib globals struct
>
>I wonder if SysLibLoad() will prevent a second, duplicate instance of a
>library from being loaded or not.
>
SysLibLoad() will fail the second time.

>If it's possible to load two versions of the same library, would there ever
>be any practicality in doing this?
>
There are reasons why you might want behavior like this.  For example, a
communications library might want to support multiple clients.  One way to
enable this is to add a client "magic cookie" parameter to your library's
open, close and other functions:

/*
   MyLibOpen:
   Opens a client session with the library.
   If the library has not been opened, initializes library.
   Allocates session resources and returns reference "magic cookie".
   Params:
      refNum - library reference number returned by SysLibLoad or SysLibFind.
      cookieP - out-param for client session "magic cookie".  This must be
         passed to all subsequent library functions.
*/      
Err MyLibOpen (UInt refNum, UIntPtr cookieP);

/*
   MyLibFunc:
   Perform some library domain-specific function.
   Params:
      refNum - library reference number returned by SysLibLoad or SysLibFind.
      cookie - client session reference "magic cookie" returned by MyLibOpen.
*/
Err MyLibFunc (UInt refNum, UInt cookie);

/*
   MyLibClose:
   Closes client session with library - frees resources for that session.
   If this is the last client, terminates library.
   Params:
      refNum - library reference number returned by SysLibLoad or SysLibFind.
      cookie - client session reference "magic cookie" returned by MyLibOpen.
*/
Err MyLibClose (UInt refNum, UInt cookie);

You get the idea...  Note that according to the sample shared library on
the Palm web-site, the MyLibClose should return an error if there are other
active clients.  This allows the client to determine whether or not to call
SysLibRemove; if you called SysLibRemove on a library with active clients,
those clients would crash the next time they tried to use the library.

So much for the theory.  Given the Palm's single-tasking approach to
application life-cycle, it is not entirely clear to me how you might have
two active clients of a library at a time.  You basically have two options:

1. Close the client session when the application stops.

2. Leave the client session open through app start and stop, waiting for
some specific situation (user selects "disconnect", for example) to close
the session.

With the first option, you would never have two applications that where
active clients at the same time (the first would exit before the second one
entered).  With the second option, you run the risk of the user never
coming back to the application - leaving your library dangling, perhaps
several times depending on the number of client apps taking this approach.
Of the two options, I prefer the first unless there is some tremendously
compelling reason why your library should stay loaded beyond the span of an
application.

Hope this helps,
Greg

Greg Winton
Bachmann Software and Services, LLC
mailto:[EMAIL PROTECTED]
http://www.bachmannsoftware.com
Software Development for Handheld & Mobile Computing, Windows and the Internet
Home of Bachmann Print Manager, the only graphical printing solution for
the Palm Computing Platform

Reply via email to