home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / ODFLibrary / Sources / ODFLibrary.cpp next >
Encoding:
Text File  |  1996-09-17  |  4.3 KB  |  164 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ODFLib.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993-1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWENVDEF_H
  13. #include "FWEnvDef.h"
  14. #endif
  15.  
  16. #ifdef FW_BUILD_MAC
  17.  
  18. #ifndef FWCFMRES_H
  19. #include "FWCFMRes.h"
  20. #endif
  21.  
  22. #ifndef _ODMEMORY_
  23. #include <ODMemory.h>
  24. #endif
  25.  
  26. #ifndef SLSTRREP_H
  27. #include "SLStrRep.h"
  28. #endif
  29.  
  30. #include <CodeFragments.h>
  31. #include <Events.h>
  32. //#include "SLExcept.h"
  33.  
  34. #endif
  35.  
  36. #if defined(SYMANTEC_CPLUS) && defined(FW_BUILD_MAC)
  37.     #define ODF_LIBRARY_CFMINIT PartCFMInit
  38. #endif
  39.  
  40. //========================================================================================
  41. // Prototypes
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. extern "C" pascal OSErr ODF_LIBRARY_CFMINIT (CFragInitBlockPtr initBlkPtr);
  46. extern "C" pascal void  ODF_LIBRARY_CFMTERM (void);
  47.  
  48. #ifdef __MWERKS__
  49. #    if __MWERKS__ < 0x0800
  50. extern "C" void __sinit();
  51. extern "C" void    __destroy_global_chain(void);
  52. #    else
  53. extern "C" short __initialize();
  54. extern "C" void    __terminate(void);
  55. #    endif
  56. #elif defined __MRC__
  57. extern "C" __init_lib(CFragInitBlockPtr initBlkPtr);
  58. #endif
  59.  
  60. #endif // FW_BUILD_MAC
  61.  
  62. //========================================================================================
  63. //    Global Variable
  64. //========================================================================================
  65. //    FW_gInstance is initialized in DLLMain for Windows
  66. //    FW_gInstance is defined in FWCFMRes.cpp for the Mac
  67. #ifdef FW_BUILD_WIN
  68. FW_Instance FW_gInstance = NULL;
  69. #endif
  70.  
  71. //========================================================================================
  72. // Initialization methods
  73. //========================================================================================
  74.  
  75. #ifdef FW_BUILD_WIN32
  76. //----------------------------------------------------------------------------------------
  77. // DllMain
  78. //----------------------------------------------------------------------------------------
  79. extern "C" BOOL WINAPI DllMain(HINSTANCE    hDLL,
  80.                                 DWORD        dwReason,
  81.                                 LPVOID        /* lpReserved */)
  82. {
  83.     if(dwReason == DLL_PROCESS_ATTACH)
  84.     {
  85.         // Save instance handle for future use
  86.         FW_gInstance = hDLL;
  87.     }
  88.  
  89.     return TRUE;
  90. }
  91. #endif
  92.  
  93. #ifdef FW_BUILD_MAC
  94. //----------------------------------------------------------------------------------------
  95. // ODF_LIBRARY_CFMINIT (Has to be upper case because of the 68K Linker)
  96. //----------------------------------------------------------------------------------------
  97.  
  98. extern "C" pascal OSErr ODF_LIBRARY_CFMINIT(CFragInitBlockPtr initBlkPtr)
  99. {
  100.  
  101. #ifdef FW_DEBUG
  102.     #define FW_COMMAND 0x37
  103.     
  104.     KeyMap theKeyMap;
  105.     ::GetKeys(theKeyMap);
  106.     const unsigned char *theKeys = (const unsigned char *) theKeyMap;
  107.     if ((theKeys[FW_COMMAND >> 3] >> (FW_COMMAND & 7)) & 1)
  108.         ::DebugStr("\p ODF_LIBRARY_CFMINIT");
  109. #endif
  110.  
  111.     // Shared libraries don't get their static objects initialized correctly without
  112.     // calling __initialize or __CPlusInit for MetroWerks or MrC respectively.
  113.  
  114. #ifdef __MWERKS__
  115.     #if __MWERKS__ < 0x0800
  116.         __sinit();
  117.     #else
  118.         __initialize();
  119.     #endif
  120. #elif defined __MRC__
  121.     __init_lib(initBlkPtr);
  122. #endif
  123.  
  124. #ifndef FW_NATIVE_EXCEPTIONS
  125.     // FW_gInStaticInit is initialized to a special magic number before static initialization (at linktime)
  126.     // within SLExcept.cpp.  Here we clear it to zero.  This allows FWExcLib to
  127.     // understand when static objects are being constructed.
  128.     extern long FW_gInStaticInit;
  129.     FW_gInStaticInit = 0L;
  130. #endif
  131.     
  132.     OSErr err1  = ::InitODMemory();
  133.  
  134.     OSErr err2 = FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(initBlkPtr);
  135.  
  136.     ::FW_PrivInitStringData();
  137.  
  138.     return (OSErr)(err1 != noErr) ? err1 : err2;
  139.  
  140. //    return FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(initBlkPtr);
  141. }
  142. #endif
  143.  
  144. #ifdef FW_BUILD_MAC
  145. //----------------------------------------------------------------------------------------
  146. // ODFCFMTERM
  147. //----------------------------------------------------------------------------------------
  148.  
  149. extern "C" pascal void ODF_LIBRARY_CFMTERM(void)
  150. {
  151.     FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources();
  152.     
  153. #ifdef __MWERKS__
  154. #    if __MWERKS__ < 0x0800
  155.         __destroy_global_chain();
  156. #    else
  157.         __terminate();
  158. #    endif
  159. #endif
  160. }
  161.  
  162. #endif
  163.  
  164.