home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Apple Shared Library Manager / ASLM Examples / Sample INIT / Sources / SampleINIT.c next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  2.2 KB  |  75 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SampleINIT.c
  3.  
  4.     Contains:    Implementation of SampleINIT.
  5.  
  6.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include <types.h>
  11. #include <resources.h>
  12. #include <events.h>
  13.  
  14. #include <LibraryManager.h>
  15. #include <LibraryManagerUtilities.h>
  16.  
  17. #include "ShowINITLibrary.h"
  18.  
  19. #define  kSampleIconID    -4064
  20.  
  21. /*————————————————————————————————————————————————————————————————————————————————————
  22.     SampleINIT
  23.     
  24.     This is the begining of our INIT, it calls InitLibraryManager and displays an
  25.     ICON for out INIT. But before we call InitLibraryManager, we must first provide an 
  26.     A5 world.
  27. ————————————————————————————————————————————————————————————————————————————————————*/
  28.  
  29. pascal void SampleINIT()
  30. {    
  31.     /* InitCodeResource should be called before initlializing the LibraryManager
  32.        This create an A5 world for the stand alone code resources( INIT, cdevs,...etec),
  33.        and CleanupLibraryManager will dispose the A5 world */
  34.     
  35.     if( Button() )                            /* a way to exit init */
  36.         return;
  37.         
  38.     if (InitCodeResource() != kNoError)        /* create & initialize the global world */
  39.     {
  40.         DebugStr("\pInitCodeResource failed.");
  41.         return;
  42.     }
  43.  
  44.  
  45.     /* Now its safe to create a local instance of TLibraryManager if Library Manager
  46.        has been installed. */
  47.         
  48.     if( InitLibraryManager(0, kCurrentZone, kNormalMemory) != kNoError )
  49.     {
  50.         DebugStr("\pInitLibraryManager failed.");
  51.         FreeGlobalWorld();
  52.         return;
  53.     }
  54.  
  55.     // Stand alone code resources should always call EnterCodeResource before
  56.     // making any ASLM or shared library calls just in case an exception
  57.     // is thrown or the call wants to allocate memory of of the current
  58.     // clients pool. It also allows you to access any globals you may have.
  59.     EnterCodeResource();
  60.  
  61.     // We need to do a TRY to catch the exception that will be thrown if
  62.     // the function set that ShowInit is implemented in can't be found
  63.     // or loaded. We could also have done a LoadFunctionSet instead.
  64.     TRY
  65.         ShowInit( kSampleIconID );            /* call our function set here */
  66.     CATCH_ALL
  67.         DebugStr("\pShowInit threw an exception.");
  68.     ENDTRY
  69.     
  70.     CleanupLibraryManager();            /* delete the our local TLibrary Manager instance */
  71.                                         /* and disposes the A5 world */
  72.     
  73.     LeaveCodeResource();
  74. }
  75.