Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: main.cpp
  4. //
  5. // Module: CMUTIL.DLL
  6. //
  7. // Synopsis: Main entry point for cmutil.dll
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. // Author: henryt Created 03/01/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include "cmlog.h"
  16. HINSTANCE g_hInst = NULL;
  17. //
  18. // thread local storage index
  19. //
  20. DWORD g_dwTlsIndex;
  21. extern HANDLE g_hProcessHeap; // defined in mem.cpp
  22. extern void EndDebugMemory(); // impemented in mem.cpp
  23. extern "C" BOOL WINAPI DllMain(
  24. HINSTANCE hinstDLL, // handle to DLL module
  25. DWORD fdwReason, // reason for calling function
  26. LPVOID lpvReserved // reserved
  27. )
  28. {
  29. if (fdwReason == DLL_PROCESS_ATTACH)
  30. {
  31. //
  32. // First Things First, lets initialize the U Api's
  33. //
  34. if (!InitUnicodeAPI())
  35. {
  36. //
  37. // Without our U api's we are going no where. Bail.
  38. //
  39. return FALSE;
  40. }
  41. g_hProcessHeap = GetProcessHeap();
  42. //
  43. // alloc tls index
  44. //
  45. g_dwTlsIndex = TlsAlloc();
  46. if (g_dwTlsIndex == TLS_OUT_OF_INDEXES)
  47. {
  48. return FALSE;
  49. }
  50. MYVERIFY(DisableThreadLibraryCalls(hinstDLL));
  51. g_hInst = hinstDLL;
  52. }
  53. else if (fdwReason == DLL_PROCESS_DETACH)
  54. {
  55. //
  56. // free the tls index
  57. //
  58. if (g_dwTlsIndex != TLS_OUT_OF_INDEXES)
  59. {
  60. TlsFree(g_dwTlsIndex);
  61. }
  62. if (!UnInitUnicodeAPI())
  63. {
  64. CMASSERTMSG(FALSE, TEXT("cmutil Dllmain, UnInitUnicodeAPI failed - we are probably leaking a handle"));
  65. }
  66. #ifdef DEBUG
  67. EndDebugMemory();
  68. #endif
  69. }
  70. return TRUE;
  71. }