home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 3.5 KB | 139 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLibMai.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/25/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
-
- // Temporary, until build system guarantees one of these are defined
- #if !defined(FW_BUILD_WIN16) && !defined(FW_BUILD_WIN32S) && !defined(BUILD_WINNT)
- #define FW_BUILD_WIN16
- #endif
-
- #include <Windows.h>
-
- //========================================================================================
- //========================================================================================
-
- #ifdef FW_BUILD_WIN16
- //----------------------------------------------------------------------------------------
- // LibMain
- //----------------------------------------------------------------------------------------
-
- extern "C"
- {
- BOOL CALLBACK LibMain(HANDLE hInstance,
- WORD wDataSeg,
- WORD cbHeap,
- LPSTR lpszCmdLine);
- };
-
- BOOL FAR PASCAL LibMain(HANDLE hInstance,
- WORD wDataSeg,
- WORD cbHeap,
- LPSTR lpszCmdLine)
- {
- return hInstance != NULL;
- }
- #endif
-
- //========================================================================================
- //========================================================================================
-
- #ifdef FW_BUILD_WIN32S
- void* FW_PrivWinGetTaskGlobals();
- void FW_PrivWinSetTaskGlobals(void* p);
- #endif
-
- #ifdef FW_BUILD_WIN32S
- static DWORD gTlsIndex;
- #endif
-
- #ifdef FW_BUILD_WIN32S
- //----------------------------------------------------------------------------------------
- // FW_PrivWinGetTaskGlobals
- //----------------------------------------------------------------------------------------
- void* FW_PrivWinGetTaskGlobals()
- {
- return (void*) TlsGetValue(gTlsIndex);
- }
- #endif
-
- #ifdef FW_BUILD_WIN32S
- //----------------------------------------------------------------------------------------
- // FW_BedWinSetTaskGlobals
- //----------------------------------------------------------------------------------------
- void FW_BedWinSetTaskGlobals(void* p)
- {
- BOOL setValueSucceeded = TlsSetValue(gTlsIndex, p);
- }
- #endif
-
- //========================================================================================
- //========================================================================================
-
- #if defined(BUILD_WINNT) || defined(FW_BUILD_WIN32S)
- extern "C"
- {
- BOOL WINAPI DllMain(HANDLE hDLL,
- DWORD dwReason,
- LPVOID lpReserved);
- void _cinit(); // static constructors
- void _dodtors(); // static destructors
- }
-
- #pragma DOSSEG
- #pragma startaddress(DllMain)
-
- //----------------------------------------------------------------------------------------
- // DllMain
- //----------------------------------------------------------------------------------------
-
- BOOL WINAPI DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
- {
- static DWORD gProcessCount = 0;
-
- switch(ul_reason_being_called)
- {
- case DLL_PROCESS_ATTACH:
- {
- _cinit();
-
- // if this is the first process, allocate TLS
- if(gProcessCount ++ == 0)
- {
- #ifdef FW_BUILD_WIN32S
- gTlsIndex = TlsAlloc();
- #endif
- }
- break;
- }
-
- case DLL_PROCESS_DETACH:
- {
- _dodtors();
- // if this is the last process, deallocate TLS
- if(-- gProcessCount == 0)
- {
- #ifdef FW_BUILD_WIN32S
- TlsFree(gTlsIndex);
- #endif
- }
- break;
- }
- }
-
- return TRUE;
- }
- #endif
-
-
-
- #endif
-