home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWTaskG / Sources / FWLibMai.cpp next >
Encoding:
Text File  |  1994-04-21  |  3.5 KB  |  139 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLibMai.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/25/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifdef FW_BUILD_WIN
  13.  
  14. // Temporary, until build system guarantees one of these are defined
  15. #if !defined(FW_BUILD_WIN16) && !defined(FW_BUILD_WIN32S) && !defined(BUILD_WINNT)
  16. #define FW_BUILD_WIN16
  17. #endif
  18.  
  19. #include <Windows.h>
  20.  
  21. //========================================================================================
  22. //========================================================================================
  23.  
  24. #ifdef FW_BUILD_WIN16
  25. //----------------------------------------------------------------------------------------
  26. // LibMain
  27. //----------------------------------------------------------------------------------------
  28.  
  29. extern "C"
  30. {
  31.     BOOL CALLBACK LibMain(HANDLE    hInstance,
  32.                           WORD        wDataSeg,
  33.                           WORD        cbHeap,
  34.                           LPSTR        lpszCmdLine);
  35. };
  36.  
  37. BOOL FAR PASCAL LibMain(HANDLE hInstance,
  38.                         WORD wDataSeg,
  39.                         WORD cbHeap,
  40.                         LPSTR lpszCmdLine)
  41. {
  42.     return hInstance != NULL;
  43. }
  44. #endif
  45.  
  46. //========================================================================================
  47. //========================================================================================
  48.  
  49. #ifdef FW_BUILD_WIN32S
  50. void* FW_PrivWinGetTaskGlobals();
  51. void FW_PrivWinSetTaskGlobals(void* p);
  52. #endif
  53.  
  54. #ifdef FW_BUILD_WIN32S
  55. static DWORD gTlsIndex;
  56. #endif
  57.  
  58. #ifdef FW_BUILD_WIN32S
  59. //----------------------------------------------------------------------------------------
  60. // FW_PrivWinGetTaskGlobals
  61. //----------------------------------------------------------------------------------------
  62. void* FW_PrivWinGetTaskGlobals()
  63. {
  64.     return (void*) TlsGetValue(gTlsIndex);
  65. }
  66. #endif
  67.  
  68. #ifdef FW_BUILD_WIN32S
  69. //----------------------------------------------------------------------------------------
  70. // FW_BedWinSetTaskGlobals
  71. //----------------------------------------------------------------------------------------
  72. void FW_BedWinSetTaskGlobals(void* p)
  73. {
  74.     BOOL setValueSucceeded = TlsSetValue(gTlsIndex, p);
  75. }            
  76. #endif
  77.  
  78. //========================================================================================
  79. //========================================================================================
  80.  
  81. #if defined(BUILD_WINNT) || defined(FW_BUILD_WIN32S)
  82. extern "C"
  83. {
  84.     BOOL WINAPI DllMain(HANDLE    hDLL,
  85.                         DWORD    dwReason,
  86.                         LPVOID    lpReserved);
  87.     void _cinit();            // static constructors
  88.     void _dodtors();        // static destructors
  89. }
  90.  
  91. #pragma DOSSEG
  92. #pragma startaddress(DllMain)
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // DllMain
  96. //----------------------------------------------------------------------------------------
  97.  
  98. BOOL WINAPI DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
  99. {
  100.     static DWORD gProcessCount = 0;
  101.  
  102.     switch(ul_reason_being_called)
  103.     {
  104.         case DLL_PROCESS_ATTACH:
  105.         {
  106.             _cinit();
  107.             
  108.             // if this is the first process, allocate TLS
  109.             if(gProcessCount ++ == 0)
  110.             {
  111. #ifdef FW_BUILD_WIN32S
  112.                 gTlsIndex = TlsAlloc();
  113. #endif
  114.             }
  115.             break;
  116.         }
  117.  
  118.         case DLL_PROCESS_DETACH:
  119.         {
  120.             _dodtors();
  121.             // if this is the last process, deallocate TLS
  122.             if(-- gProcessCount == 0)
  123.             {
  124. #ifdef FW_BUILD_WIN32S
  125.                 TlsFree(gTlsIndex);
  126. #endif
  127.             }
  128.             break;
  129.         }
  130.     }
  131.  
  132.     return TRUE;
  133. }
  134. #endif
  135.  
  136.  
  137.  
  138. #endif
  139.