Something that's never come up for me before, and neither Inside Mac nor
thae Carbon docs have anything to say about it (as far as I've been able
to spot):
Is it kosher to call the various "manager" initializations (InitGraf(),
InitFonts(), InitWhateverManager(), and so on) multiple times?
I'm banging away at porting a small Sockets-based library (currently
Linux/Windows targeted) to MacOS 8.1-9.x/Carbon and OpenTransport (But
have no interest whatsoever in trying to target "native" X - besides, it
should work there fine already, or with minimal changes), and I need to
be sure that certain managers (OpenTransport and Thread Manager, in
particular, maybe some others that I haven't yet realized will be
needed) have been properly initialized. But without calling the init
routines for itself, I can't spot any way for this library to be
absolutely certain that the ones it needs to use have been initialized,
and/or they've been done in the right order. (As in the old restriction
that says InitWindows() needs to be called after InitGraf(), InitFonts()
has to be called after calling InitGraf() and InitWindows(), and
InitDialogs() has to be called after calling all of the above, and
similar)
At the same time, I'd prefer to avoid, if possible, the concept of "To
use this library, you must first call InitX(), then InitY(), then
InitZ(), and then finally, call InitMyLibrary()". I'd greatly prefer the
simplicity of "slap a call to InitMyLibrary() into your program's
initialization, and you're good to go". No muss, no fuss, no bother, and
no weird "rules" about how it gets done. Just "call this routine
sometime before you try to use any of the other routines."
As far as I've been able to determine, there is nothing in any
documentation that I know about which addresses the concept of multiple
calls to the various "Init____()" routines and how they might be
certifiable Bad Things(TM).
Or does it matter? Perhaps I should just go with the concept of "My
Init() has been called. Make no assumptions - Init everything I need,
and let the caller worry about whether the items it needs have been
initialized"? Or by doing so, am I risking having the whole thing
explode in my face if/when I issue a call to one of the Inits that has
already been called (without my knowledge) someplace else? As I said,
Inside Mac and the Carbon docs don't seem to address this issue. Nor
does any code (Sample or production) that I've seen.
Any thoughts from folks out there in Internetville?

Signature
Don Bruder - dakidd@sonic.net <--- Preferred Email - SpamAssassinated.
Hate SPAM? See <http://www.spamassassin.org> for some seriously great info.
I will choose a path that's clear: I will choose Free Will! - N. Peart
Fly trap info pages: <http://www.sonic.net/~dakidd/Horses/FlyTrap/index.html>
Lawrence D¹Oliveiro - 01 Jan 2004 10:41 GMT
>Is it kosher to call the various "manager" initializations (InitGraf(),
>InitFonts(), InitWhateverManager(), and so on) multiple times?
For non-Carbon code, the UI Toolbox initializations (InitWindows,
InitMenus etc) should only be called once. I believe for Carbon code,
you don't need to call them.
InitGraf is slightly weird. It takes an explicit pointer to the
QuickDraw globals area, so in theory you should be able to initialize
multiple instances of these in the same process context. In practice
there's a complication involving the QuickDraw globals pointer (pointed
to by the 68K A5 register, which still exists on PowerPC Macs) --
basically, the longword at this location is set to point to the block
passed to the last call to InitGraf, and that's what QuickDraw uses
thereafter. To be safe, you should only call InitGraf once.
For QuickTime, it is explicitly safe to call EnterMovies multiple times.
It maintains an internal 32 bit counter which is incremented by
EnterMovies and decremented by ExitMovies. But the recommendation from
Apple for a long time now is not to bother with ExitMovies, since it all
gets cleaned up when the process exits anyway. This is just for the
Movie Toolbox: other parts of QuickTime (e.g. Image Compresion Manager)
don't need initializing/finalizing.
Open Transport is a tricky one, since the glue library comes in two
versions, one to use with application code and one for non-application
code. I'm not sure whether you can mix them or not.
>I'm banging away at porting a small Sockets-based library (currently
>Linux/Windows targeted) to MacOS 8.1-9.x/Carbon and OpenTransport (But
[quoted text clipped - 3 lines]
>particular, maybe some others that I haven't yet realized will be
>needed) have been properly initialized.
I don't think you will find you need to initialize too many managers.
For example, the Thread Manager doesn't need initializing--you can just
use it.
>At the same time, I'd prefer to avoid, if possible, the concept of "To
>use this library, you must first call InitX(), then InitY(), then
>InitZ(), and then finally, call InitMyLibrary()".
I think you will find that client code will need to initialize Open
Transport, but probably nothing else (beyond the usual QuickDraw and UI
Toolbox stuff, which it should be doing anyway).