home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / DLLSKEL.PAK / DLLMAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  97 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   DllEntryPoint.c
  9. //
  10. //  PURPOSE:  Contains the DLL's entry point function.
  11. //
  12. //  FUNCTIONS:
  13. //    DllEntryPoint   - The entry point function
  14. //
  15.  
  16. #include <windows.h>
  17. #include "dllglob.h"
  18.  
  19.  
  20. //
  21. //  FUNCTION: DllEntryPoint(HINSTANCE, DWORD, LPVOID)
  22. //
  23. //  PURPOSE:  Called when DLL is loaded by a process, and when new
  24. //    threads are created by a process that has already loaded the
  25. //    DLL.  Also called when threads of a process that has loaded the
  26. //    DLL exit cleanly and when the process itself unloads the DLL.
  27. //
  28. //  PARAMETERS:
  29. //    hDLLInst    - Instance handle of the DLL
  30. //    fdwReason   - Process attach/detach or thread attach/detach
  31. //    lpvReserved - Reserved and not used
  32. //
  33. //  RETURN VALUE:  (Used only when fdwReason == DLL_PROCESS_ATTACH)
  34. //    TRUE  -  Used to signify that the DLL should remain loaded.
  35. //    FALSE -  Used to signify that the DLL should be immediately unloaded.
  36. //
  37. //  COMMENTS:
  38. //
  39. //    If you want to use C runtime libraries, keep this function named
  40. //    "DllEntryPoint" and you won't have to do anything special to initialize
  41. //    the runtime libraries.
  42. //
  43. //    When fdwReason == DLL_PROCESS_ATTACH, the return value is used to
  44. //    determine if the DLL should remain loaded, or should be immediately
  45. //    unloaded depending upon whether the DLL could be initialized properly.
  46. //    For all other values of fdwReason, the return value is ignored.
  47. //
  48.  
  49. #pragma argsused
  50. BOOL WINAPI DllEntryPoint(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
  51. {
  52.  
  53.     switch (fdwReason)
  54.     {
  55.         case DLL_PROCESS_ATTACH:
  56.             // The DLL is being loaded for the first time by a given process.
  57.             // Perform per-process initialization here.  If the initialization
  58.             // is successful, return TRUE; if unsuccessful, return FALSE.
  59.  
  60.  
  61.             // In this DLL, we want to initialize a critical section used
  62.             // by one of its exported functions, DLLFunction2().
  63.  
  64.             InitializeCriticalSection(&gCriticalSection);
  65.  
  66.             break;
  67.  
  68.         case DLL_PROCESS_DETACH:
  69.             // The DLL is being unloaded by a given process.  Do any
  70.             // per-process clean up here, such as undoing what was done in
  71.             // DLL_PROCESS_ATTACH.  The return value is ignored.
  72.  
  73.  
  74.             // In this DLL, we need to clean up the critical section we
  75.             // created in the DLL_PROCESS_ATTACH message.
  76.  
  77.             DeleteCriticalSection(&gCriticalSection);
  78.  
  79.             break;
  80.  
  81.         case DLL_THREAD_ATTACH:
  82.             // A thread is being created in a process that has already loaded
  83.             // this DLL.  Perform any per-thread initialization here.  The
  84.             // return value is ignored.
  85.  
  86.             break;
  87.  
  88.         case DLL_THREAD_DETACH:
  89.             // A thread is exiting cleanly in a process that has already
  90.             // loaded this DLL.  Perform any per-thread clean up here.  The
  91.             // return value is ignored.
  92.  
  93.             break;
  94.     }
  95.     return TRUE;
  96. }
  97.