Leaked source code of windows server 2003
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.

213 lines
3.6 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation 1993-1995
  4. //
  5. // File: dll.c
  6. //
  7. // This file contains the library entry points
  8. //
  9. // History:
  10. // 12-23-93 ScottH Created
  11. // 9-22-95 ScottH Ported to NT
  12. //
  13. //---------------------------------------------------------------------------
  14. #include "proj.h"
  15. #include <rovdbg.h> // debug assertion code
  16. // Global data
  17. //
  18. BOOL g_bAdminUser;
  19. #ifdef WIN32
  20. CRITICAL_SECTION g_csDll = { 0 };
  21. #endif // WIN32
  22. /*----------------------------------------------------------
  23. Purpose: Initialize the DLL
  24. Returns:
  25. Cond: --
  26. */
  27. BOOL PRIVATE Dll_Initialize(void)
  28. {
  29. BOOL bRet = TRUE;
  30. InitCommonControls();
  31. return bRet;
  32. }
  33. /*----------------------------------------------------------
  34. Purpose: Attach a process to this DLL
  35. Returns: --
  36. Cond: --
  37. */
  38. BOOL PRIVATE Dll_ProcessAttach(HINSTANCE hDll)
  39. {
  40. BOOL bSuccess = TRUE;
  41. __try {
  42. InitializeCriticalSection(&g_csDll);
  43. } __except (EXCEPTION_EXECUTE_HANDLER ) {
  44. return FALSE;
  45. }
  46. g_bAdminUser = IsAdminUser();
  47. if (bSuccess)
  48. {
  49. g_hinst = hDll;
  50. DEBUG_MEMORY_PROCESS_ATTACH("serialui");
  51. #ifdef DEBUG
  52. // We do this simply to load the debug .ini flags
  53. //
  54. RovComm_ProcessIniFile();
  55. TRACE_MSG(TF_GENERAL, "Process Attach (hDll = %lx)", hDll);
  56. DEBUG_BREAK(BF_ONPROCESSATT);
  57. #endif
  58. bSuccess = Dll_Initialize();
  59. }
  60. return bSuccess;
  61. }
  62. /*----------------------------------------------------------
  63. Purpose: Detach a process from the DLL
  64. Returns: --
  65. Cond: --
  66. */
  67. BOOL PRIVATE Dll_ProcessDetach(HINSTANCE hDll)
  68. {
  69. BOOL bSuccess = TRUE;
  70. ASSERT(hDll == g_hinst);
  71. DEBUG_CODE( TRACE_MSG(TF_GENERAL, "Process Detach (hDll = %lx)",
  72. hDll); )
  73. DEBUG_CODE( DEBUG_BREAK(BF_ONPROCESSDET); )
  74. DEBUG_MEMORY_PROCESS_DETACH();
  75. DeleteCriticalSection(&g_csDll);
  76. return bSuccess;
  77. }
  78. HINSTANCE g_hinst = 0;
  79. // **************************************************************************
  80. // WIN32 specific code
  81. // **************************************************************************
  82. #ifdef WIN32
  83. #ifdef DEBUG
  84. BOOL g_bExclusive=FALSE;
  85. #endif
  86. /*----------------------------------------------------------
  87. Purpose: Enter an exclusive section
  88. Returns: --
  89. Cond: --
  90. */
  91. void PUBLIC Dll_EnterExclusive(void)
  92. {
  93. EnterCriticalSection(&g_csDll);
  94. #ifdef DEBUG
  95. g_bExclusive = TRUE;
  96. #endif
  97. }
  98. /*----------------------------------------------------------
  99. Purpose: Leave an exclusive section
  100. Returns: --
  101. Cond: --
  102. */
  103. void PUBLIC Dll_LeaveExclusive(void)
  104. {
  105. #ifdef DEBUG
  106. g_bExclusive = FALSE;
  107. #endif
  108. LeaveCriticalSection(&g_csDll);
  109. }
  110. /*----------------------------------------------------------
  111. Purpose: Win32 Libmain
  112. Returns: --
  113. Cond: --
  114. */
  115. BOOL APIENTRY LibMain(
  116. HANDLE hDll,
  117. DWORD dwReason,
  118. LPVOID lpReserved)
  119. {
  120. switch(dwReason)
  121. {
  122. case DLL_PROCESS_ATTACH:
  123. Dll_ProcessAttach(hDll);
  124. break;
  125. case DLL_PROCESS_DETACH:
  126. Dll_ProcessDetach(hDll);
  127. break;
  128. case DLL_THREAD_ATTACH:
  129. #ifdef DEBUG
  130. DEBUG_BREAK(BF_ONTHREADATT);
  131. #endif
  132. break;
  133. case DLL_THREAD_DETACH:
  134. #ifdef DEBUG
  135. DEBUG_BREAK(BF_ONTHREADDET);
  136. #endif
  137. break;
  138. default:
  139. break;
  140. }
  141. return TRUE;
  142. }
  143. #else // WIN32
  144. #endif // WIN32