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.

328 lines
12 KiB

  1. // --------------------------------------------------------------------------
  2. // DLLMAIN.CPP
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include "htmlstr.h"
  7. #include "instance.h"
  8. #include "conman.h"
  9. #include "spengine.h"
  10. #include "msglist.h"
  11. #include "baui.h"
  12. #include "wabapi.h"
  13. #include "shared.h"
  14. #include "rulesmgr.h"
  15. #ifndef WIN16 //RUN16_MSLU
  16. #include <msluapi.h>
  17. #include <msluguid.h>
  18. #endif //!WIN16
  19. #include "demand.h"
  20. #include "note.h"
  21. #include "mirror.h"
  22. // #ifdef _ATL_STATIC_REGISTRY
  23. // #include <statreg.h>
  24. // #include <statreg.cpp>
  25. // #endif
  26. #undef SubclassWindow
  27. #include <atlimpl.cpp>
  28. #include <atlctl.cpp>
  29. #include <atlwinx.cpp>
  30. // --------------------------------------------------------------------------------
  31. // Globals
  32. // --------------------------------------------------------------------------------
  33. HINSTANCE g_hLocRes = NULL;
  34. HINSTANCE g_hInst=NULL;
  35. LPMALLOC g_pMalloc=NULL; // From memutil.h
  36. CRITICAL_SECTION g_csDBListen={0};
  37. CRITICAL_SECTION g_csgoCommon={0};
  38. CRITICAL_SECTION g_csgoMail={0};
  39. CRITICAL_SECTION g_csgoNews={0};
  40. CRITICAL_SECTION g_csFolderDlg={0};
  41. CRITICAL_SECTION g_csFmsg={0};
  42. CRITICAL_SECTION s_csPasswordList={0};
  43. CRITICAL_SECTION g_csAccountPropCache={0};
  44. CRITICAL_SECTION g_csMsgrList={0};
  45. CRITICAL_SECTION g_csThreadList={0};
  46. COutlookExpress *g_pInstance=NULL;
  47. HWND g_hwndInit=NULL,
  48. g_hwndActiveModal=NULL;
  49. UINT g_msgMSWheel=0;
  50. HACCEL g_haccelNewsView=0;
  51. DWORD g_dwAthenaMode=0;
  52. IImnAccountManager2 *g_pAcctMan=NULL;
  53. HMODULE g_hlibMAPI=NULL;
  54. CBrowser *g_pBrowser=NULL;
  55. IMimeAllocator *g_pMoleAlloc=NULL;
  56. CConnectionManager *g_pConMan=NULL;
  57. DWORD g_dwSecurityCheckedSchemaProp=0;
  58. IFontCache *g_lpIFontCache=NULL;
  59. ISpoolerEngine *g_pSpooler=NULL;
  60. // bobn: brianv says we have to take this out...
  61. //DWORD g_dwBrowserFlags=0;
  62. UINT CF_FILEDESCRIPTORA=0;
  63. UINT CF_FILEDESCRIPTORW=0;
  64. UINT CF_FILECONTENTS=0;
  65. UINT CF_HTML=0;
  66. UINT CF_INETMSG=0;
  67. UINT CF_OEFOLDER=0;
  68. UINT CF_SHELLURL=0;
  69. UINT CF_OEMESSAGES=0;
  70. UINT CF_OESHORTCUT=0;
  71. CStationery *g_pStationery=NULL;
  72. ROAMSTATE g_rsRoamState=RS_NO_ROAMING;
  73. IOERulesManager *g_pRulesMan = NULL;
  74. IMessageStore *g_pStore=NULL;
  75. CRITICAL_SECTION g_csFindFolder={0};
  76. LPACTIVEFINDFOLDER g_pHeadFindFolder=NULL;
  77. DWORD g_dwTlsTimeout=0xFFFFFFFF;
  78. BOOL g_fPluralIDs=0;
  79. UINT g_uiCodePage=0;
  80. IDatabaseSession *g_pDBSession=NULL;
  81. BOOL g_bMirroredOS=FALSE;
  82. SYSTEM_INFO g_SystemInfo={0};
  83. OSVERSIONINFO g_OSInfo={0};
  84. // --------------------------------------------------------------------------------
  85. // Debug Trace Tags
  86. // --------------------------------------------------------------------------------
  87. IF_DEBUG(DWORD TAG_OBJECTDB=0;)
  88. IF_DEBUG(DWORD TAG_INITTRACE=0;)
  89. IF_DEBUG(DWORD TAG_SERVERQ=0;)
  90. IF_DEBUG(DWORD TAG_IMAPSYNC=0;)
  91. // --------------------------------------------------------------------------------
  92. // global OE type-lib. Defer-created in BaseDisp.Cpp
  93. // freed on process detach, protected with CS
  94. // --------------------------------------------------------------------------------
  95. ITypeLib *g_pOETypeLib=NULL;
  96. CRITICAL_SECTION g_csOETypeLib={0};
  97. // --------------------------------------------------------------------------------
  98. // Debug Globals
  99. // --------------------------------------------------------------------------------
  100. #ifdef DEBUG
  101. DWORD dwDOUTLevel=0; // From msoert.h
  102. DWORD dwDOUTLMod=0; // From msoert.h
  103. DWORD dwDOUTLModLevel=0; // From msoert.h
  104. DWORD dwATLTraceLevel=0; // From msoert.h
  105. #endif
  106. // Language DLL
  107. // __declspec( dllimport ) HINSTANCE hLangDll;
  108. // ATL Module Define
  109. CComModule _Module;
  110. BEGIN_OBJECT_MAP(ObjectMap)
  111. OBJECT_ENTRY(CLSID_MessageList, CMessageList)
  112. OBJECT_ENTRY(CLSID_MsgrAb, CMsgrAb)
  113. END_OBJECT_MAP()
  114. // --------------------------------------------------------------------------------
  115. // Dll Entry Point
  116. // --------------------------------------------------------------------------------
  117. extern "C" BOOL WINAPI DllMain(HANDLE hInst, DWORD dwReason, LPVOID lpReserved)
  118. //extern "C" BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved);
  119. {
  120. // Process Attach
  121. if (DLL_PROCESS_ATTACH == dwReason)
  122. {
  123. SHFusionInitialize(NULL);
  124. // Save hInstance
  125. g_hInst = (HINSTANCE)hInst;
  126. g_bMirroredOS = IS_MIRRORING_ENABLED();
  127. // We now want thread calls.
  128. // We don't care about thread attachs
  129. // SideAssert(DisableThreadLibraryCalls((HINSTANCE)hInst));
  130. // Get the OLE Task Memory Allocator
  131. CoGetMalloc(1, &g_pMalloc);
  132. AssertSz(g_pMalloc, "We are in trouble now.");
  133. // Initialize Demand Loader
  134. InitDemandLoadedLibs();
  135. // Get System & OS Info
  136. GetPCAndOSTypes(&g_SystemInfo, &g_OSInfo);
  137. // Get Resources from Lang DLL
  138. g_hLocRes = LoadLangDll(g_hInst, c_szOEResDll, fIsNT5());
  139. if(g_hLocRes == NULL)
  140. {
  141. Assert(FALSE);
  142. return FALSE;
  143. }
  144. // Initialize TLS Globals
  145. InitTlsActiveNote();
  146. g_dwTlsTimeout = TlsAlloc();
  147. Assert(0xFFFFFFFF != g_dwTlsTimeout);
  148. TlsSetValue(g_dwTlsTimeout, NULL);
  149. // Initialize all global critical sections
  150. InitializeCriticalSection(&g_csFindFolder);
  151. InitializeCriticalSection(&g_csDBListen);
  152. InitializeCriticalSection(&g_csgoCommon);
  153. InitializeCriticalSection(&g_csgoMail);
  154. InitializeCriticalSection(&g_csgoNews);
  155. InitializeCriticalSection(&g_csFolderDlg);
  156. InitializeCriticalSection(&g_csFmsg);
  157. InitializeCriticalSection(&g_csOETypeLib);
  158. InitializeCriticalSection(&s_csPasswordList);
  159. InitializeCriticalSection(&g_csAccountPropCache);
  160. InitializeCriticalSection(&g_csMsgrList);
  161. InitializeCriticalSection(&g_csThreadList);
  162. // Initialize DOUTs
  163. #ifdef DEBUG
  164. dwDOUTLevel = GetPrivateProfileInt("Debug", "Level", 0, "athena.ini");
  165. dwDOUTLMod = GetPrivateProfileInt("Debug", "Mod", 0, "athena.ini");
  166. dwDOUTLModLevel = GetPrivateProfileInt("Debug", "ModLevel", 0, "athena.ini");
  167. dwATLTraceLevel = GetPrivateProfileInt("ATL", "TraceLevel", 0, "athena.ini");
  168. TAG_OBJECTDB = GetDebugTraceTagMask("Database", TAG_OBJECTDB);
  169. TAG_INITTRACE = GetDebugTraceTagMask("CoIncrementTracing", TAG_INITTRACE);
  170. TAG_SERVERQ = GetDebugTraceTagMask("ServerQ", TAG_SERVERQ);
  171. TAG_IMAPSYNC = GetDebugTraceTagMask("IMAPSync", TAG_IMAPSYNC);
  172. #endif
  173. // Initialize ATL module
  174. _Module.Init(ObjectMap, g_hInst);
  175. _Module.m_hInstResource = g_hLocRes;
  176. // Create Application Object (Don't initialize yet)
  177. g_pInstance = new COutlookExpress;
  178. AssertSz(g_pInstance, "We are in trouble now.");
  179. }
  180. // Thread Attach
  181. else if (DLL_THREAD_ATTACH == dwReason)
  182. {
  183. SetTlsGlobalActiveNote(NULL);
  184. TlsSetValue(g_dwTlsTimeout, NULL);
  185. }
  186. // Thread Attach
  187. else if (DLL_THREAD_DETACH == dwReason)
  188. {
  189. HWND hwndTimeout = (HWND)TlsGetValue(g_dwTlsTimeout);
  190. if (hwndTimeout && IsWindow(hwndTimeout))
  191. DestroyWindow(hwndTimeout);
  192. TlsSetValue(g_dwTlsTimeout, NULL);
  193. }
  194. // Process Detach
  195. else if (DLL_PROCESS_DETACH == dwReason)
  196. {
  197. // Free Type Lib
  198. SafeRelease(g_pOETypeLib);
  199. // Release Application
  200. SafeRelease(g_pInstance);
  201. // Free the ATL module
  202. _Module.Term();
  203. // Delete all global critical sections
  204. DeleteCriticalSection(&g_csgoCommon);
  205. DeleteCriticalSection(&g_csgoMail);
  206. DeleteCriticalSection(&g_csgoNews);
  207. DeleteCriticalSection(&g_csFolderDlg);
  208. DeleteCriticalSection(&g_csFmsg);
  209. DeleteCriticalSection(&g_csOETypeLib);
  210. DeleteCriticalSection(&s_csPasswordList);
  211. DeleteCriticalSection(&g_csAccountPropCache);
  212. DeleteCriticalSection(&g_csDBListen);
  213. DeleteCriticalSection(&g_csMsgrList);
  214. AssertSz(NULL == g_pHeadFindFolder, "Process is terminating with active finders running.");
  215. DeleteCriticalSection(&g_csFindFolder);
  216. DeleteCriticalSection(&g_csThreadList);
  217. // Free demand loaded libs
  218. FreeDemandLoadedLibs();
  219. // Free Timeout
  220. HWND hwndTimeout = (HWND)TlsGetValue(g_dwTlsTimeout);
  221. if (hwndTimeout && IsWindow(hwndTimeout))
  222. DestroyWindow(hwndTimeout);
  223. // Free TLS
  224. DeInitTlsActiveNote();
  225. if (0xFFFFFFFF != g_dwTlsTimeout)
  226. TlsFree(g_dwTlsTimeout);
  227. // Release the task allocator
  228. SafeRelease(g_pMalloc);
  229. // Free Resource Lib
  230. if (NULL != g_hLocRes)
  231. FreeLibrary(g_hLocRes);
  232. SHFusionUninitialize();
  233. }
  234. // Done
  235. return TRUE;
  236. }
  237. // --------------------------------------------------------------------------------
  238. // DllCanUnloadNow
  239. // --------------------------------------------------------------------------------
  240. STDAPI DllCanUnloadNow(void)
  241. {
  242. // If no instance, we can definately unload
  243. if (NULL == g_pInstance)
  244. return S_OK;
  245. // Otherwise, check with the instance object
  246. return g_pInstance->DllCanUnloadNow();
  247. }
  248. // --------------------------------------------------------------------------------
  249. // RegTypeLib
  250. // --------------------------------------------------------------------------------
  251. __inline HRESULT RegTypeLib(HINSTANCE hInstRes)
  252. {
  253. AssertSz(hInstRes, "[ARGS] RegTypeLib: NULL hInstRes");
  254. HRESULT hr = E_FAIL;
  255. CHAR szDll[MAX_PATH];
  256. WCHAR wszDll[MAX_PATH];
  257. GetModuleFileName(g_hInst, szDll, ARRAYSIZE(szDll));
  258. // Convert the module path to Wide-String
  259. if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szDll, -1, wszDll, ARRAYSIZE(wszDll)))
  260. {
  261. ITypeLib *pTypeLib;
  262. hr = LoadTypeLib(wszDll, &pTypeLib);
  263. if (SUCCEEDED(hr))
  264. {
  265. // Register the typelib
  266. hr = RegisterTypeLib(pTypeLib, wszDll, NULL);
  267. pTypeLib->Release();
  268. }
  269. }
  270. return hr;
  271. }
  272. // --------------------------------------------------------------------------------
  273. // DllRegisterServer
  274. // --------------------------------------------------------------------------------
  275. STDAPI DllRegisterServer(void)
  276. {
  277. // CallRegInstall and RegTypeLib are in staticRT/shared.cpp
  278. return(CallRegInstall(g_hInst, g_hInst, c_szReg, NULL));
  279. }
  280. // --------------------------------------------------------------------------------
  281. // DllUnregisterServer
  282. // --------------------------------------------------------------------------------
  283. STDAPI DllUnregisterServer(void)
  284. {
  285. return CallRegInstall(g_hInst, g_hInst, c_szUnReg, NULL);
  286. }