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.

176 lines
5.7 KiB

  1. // --------------------------------------------------------------------------------
  2. // Dllmain.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include <shfusion.h>
  8. #define DEFINE_STRING_CONSTANTS
  9. #include "strconst.h"
  10. #include "dllmain.h"
  11. #include "demand.h"
  12. #include "shared.h"
  13. // --------------------------------------------------------------------------------
  14. // Globals - Object count and lock count
  15. // --------------------------------------------------------------------------------
  16. HINSTANCE g_hInst=NULL;
  17. HINSTANCE g_hInstRes=NULL;
  18. LONG g_cRef=0;
  19. LONG g_cLock=0;
  20. CRITICAL_SECTION g_csDllMain={0};
  21. CRITICAL_SECTION g_csAcctMan={0};
  22. BOOL g_fAttached = FALSE;
  23. CAccountManager *g_pAcctMan=NULL;
  24. IMalloc *g_pMalloc=NULL;
  25. BOOL g_fCachedGUID=FALSE;
  26. GUID g_guidCached;
  27. SYSTEM_INFO g_SystemInfo={0};
  28. OSVERSIONINFO g_OSInfo={0};
  29. #ifdef DEBUG
  30. DWORD dwDOUTLevel;
  31. DWORD dwDOUTLMod;
  32. DWORD dwDOUTLModLevel;
  33. #endif
  34. inline BOOL fIsNT5() { return((g_OSInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && (g_OSInfo.dwMajorVersion >= 5)); }
  35. void InitDemandMimeole(void);
  36. void FreeDemandMimeOle(void);
  37. // --------------------------------------------------------------------------------
  38. // GetDllMajorVersion
  39. // --------------------------------------------------------------------------------
  40. OEDLLVERSION WINAPI GetDllMajorVersion(void)
  41. {
  42. return OEDLL_VERSION_CURRENT;
  43. }
  44. // --------------------------------------------------------------------------------
  45. // Dll Entry Point
  46. // --------------------------------------------------------------------------------
  47. EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
  48. {
  49. // Handle Attach - detach reason
  50. switch (dwReason)
  51. {
  52. case DLL_PROCESS_ATTACH:
  53. SHFusionInitialize(NULL);
  54. g_hInst = hInst;
  55. CoGetMalloc(1, &g_pMalloc);
  56. InitializeCriticalSection(&g_csAcctMan);
  57. InitializeCriticalSection(&g_csDllMain);
  58. g_fAttached = TRUE;
  59. InitDemandLoadedLibs();
  60. InitDemandMimeole();
  61. DisableThreadLibraryCalls(hInst);
  62. // Get System & OS Info
  63. GetPCAndOSTypes(&g_SystemInfo, &g_OSInfo);
  64. // Get Resources from Lang DLL
  65. g_hInstRes = LoadLangDll(g_hInst, c_szAcctResDll, fIsNT5());
  66. if(g_hInstRes == NULL)
  67. {
  68. Assert(FALSE);
  69. return FALSE;
  70. }
  71. #ifdef DEBUG
  72. dwDOUTLevel=GetPrivateProfileInt("Debug", "ICLevel", 0, "athena.ini");
  73. dwDOUTLMod=GetPrivateProfileInt("Debug", "Mod", 0, "athena.ini");
  74. dwDOUTLModLevel=GetPrivateProfileInt("Debug", "ModLevel", 0, "athena.ini");
  75. #endif
  76. break;
  77. case DLL_PROCESS_DETACH:
  78. FreeDemandLoadedLibs();
  79. FreeDemandMimeOle();
  80. SafeFreeLibrary(g_hInstRes);
  81. g_fAttached = FALSE;
  82. DeleteCriticalSection(&g_csAcctMan);
  83. DeleteCriticalSection(&g_csDllMain);
  84. // Don't release anything but g_pMalloc here or suffer at the hands of kernel
  85. SafeRelease(g_pMalloc);
  86. SHFusionUninitialize();
  87. break;
  88. }
  89. // Done
  90. return TRUE;
  91. }
  92. // --------------------------------------------------------------------------------
  93. // DllAddRef
  94. // --------------------------------------------------------------------------------
  95. ULONG DllAddRef(void)
  96. {
  97. return (ULONG)InterlockedIncrement(&g_cRef);
  98. }
  99. // --------------------------------------------------------------------------------
  100. // DllRelease
  101. // --------------------------------------------------------------------------------
  102. ULONG DllRelease(void)
  103. {
  104. return (ULONG)InterlockedDecrement(&g_cRef);
  105. }
  106. // --------------------------------------------------------------------------------
  107. // DllCanUnloadNow
  108. // --------------------------------------------------------------------------------
  109. STDAPI DllCanUnloadNow(void)
  110. {
  111. HRESULT hr = S_OK;
  112. if(!g_fAttached) // critacal sections was deleted (or not created): we defently can be unloaded
  113. return S_OK;
  114. EnterCriticalSection(&g_csDllMain);
  115. // DebugTrace("DllCanUnloadNow: %s - Reference Count: %d, LockServer Count: %d\n", __FILE__, g_cRef, g_cLock);
  116. hr = (0 == g_cRef && 0 == g_cLock) ? S_OK : S_FALSE;
  117. LeaveCriticalSection(&g_csDllMain);
  118. return hr;
  119. }
  120. // --------------------------------------------------------------------------------
  121. // DllRegisterServer
  122. // --------------------------------------------------------------------------------
  123. STDAPI DllRegisterServer(void)
  124. {
  125. HRESULT hr;
  126. // Trace This
  127. DebugTrace("MSOEACCT.DLL: DllRegisterServer called\n");
  128. // Register my self
  129. hr = CallRegInstall(g_hInst, g_hInst, c_szReg, NULL);
  130. #if !defined(NOHTTPMAIL)
  131. // Register HTTPMAIL Domains in InternetDomains
  132. if (SUCCEEDED(hr))
  133. hr = CallRegInstall(g_hInst, g_hInst, c_szRegHTTPDomains, NULL);
  134. #endif
  135. return(hr);
  136. }
  137. // --------------------------------------------------------------------------------
  138. // DllUnregisterServer
  139. // --------------------------------------------------------------------------------
  140. STDAPI DllUnregisterServer(void)
  141. {
  142. HRESULT hr;
  143. // Trace This
  144. DebugTrace("MSOEACCT.DLL: DllUnregisterServer called\n");
  145. hr = CallRegInstall(g_hInst, g_hInst, c_szUnReg, NULL);
  146. return(hr);
  147. }