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.

258 lines
6.1 KiB

  1. #include "private.h"
  2. #include "mlmain.h"
  3. #include "mlstr.h"
  4. #include "convobj.h"
  5. #include "cpdetect.h"
  6. #ifdef NEWMLSTR
  7. #include "attrstrw.h"
  8. #include "attrstra.h"
  9. #include "attrloc.h"
  10. #include "util.h"
  11. #endif
  12. #define DECL_CRTFREE
  13. #include <crtfree.h>
  14. #define _WINDLL
  15. #include <atlimpl.cpp>
  16. #include <shlwapi.h> // for IsOS() flags
  17. BEGIN_OBJECT_MAP(ObjectMap)
  18. OBJECT_ENTRY(CLSID_CMultiLanguage, CMultiLanguage)
  19. OBJECT_ENTRY(CLSID_CMLangString, CMLStr)
  20. OBJECT_ENTRY(CLSID_CMLangConvertCharset, CMLangConvertCharset)
  21. #ifdef NEWMLSTR
  22. OBJECT_ENTRY(CLSID_CMLStrAttrWStr, CMLStrAttrWStr)
  23. OBJECT_ENTRY(CLSID_CMLStrAttrAStr, CMLStrAttrAStr)
  24. OBJECT_ENTRY(CLSID_CMLStrAttrLocale, CMLStrAttrLocale)
  25. #endif
  26. END_OBJECT_MAP()
  27. //
  28. // Globals
  29. //
  30. HINSTANCE g_hInst = NULL;
  31. HINSTANCE g_hUrlMon = NULL;
  32. CRITICAL_SECTION g_cs;
  33. CComModule _Module;
  34. #ifdef NEWMLSTR
  35. CMLAlloc* g_pMalloc;
  36. #endif
  37. BOOL g_bIsNT5;
  38. BOOL g_bIsNT;
  39. BOOL g_bIsWin98;
  40. UINT g_uACP;
  41. //
  42. // Build Global Objects
  43. //
  44. void BuildGlobalObjects(void)
  45. {
  46. DebugMsg(DM_TRACE, TEXT("BuildGlobalObjects called."));
  47. EnterCriticalSection(&g_cs);
  48. // Build CMimeDatabase Object
  49. if (NULL == g_pMimeDatabase)
  50. g_pMimeDatabase = new CMimeDatabase;
  51. #ifdef NEWMLSTR
  52. if (NULL == g_pMalloc)
  53. g_pMalloc = new CMLAlloc;
  54. #endif
  55. LeaveCriticalSection(&g_cs);
  56. }
  57. void FreeGlobalObjects(void)
  58. {
  59. DebugMsg(DM_TRACE, TEXT("FreeGlobalObjects called."));
  60. // Free CMimeDatabase Object
  61. if (NULL != g_pMimeDatabase)
  62. {
  63. delete g_pMimeDatabase;
  64. g_pMimeDatabase = NULL;
  65. }
  66. #ifdef NEWMLSTR
  67. if (NULL != g_pMalloc)
  68. {
  69. delete g_pMalloc;
  70. g_pMalloc = NULL;
  71. }
  72. #endif
  73. // LCDETECT
  74. if ( NULL != g_pLCDetect )
  75. {
  76. delete (LCDetect *)g_pLCDetect;
  77. g_pLCDetect = NULL;
  78. }
  79. if (NULL != g_pCpMRU)
  80. {
  81. delete g_pCpMRU;
  82. g_pCpMRU = NULL;
  83. }
  84. if (g_pMimeDatabaseReg)
  85. {
  86. delete g_pMimeDatabaseReg;
  87. g_pMimeDatabaseReg = NULL;
  88. }
  89. CMLangFontLink_FreeGlobalObjects();
  90. }
  91. //
  92. // DLL part of the Object
  93. //
  94. extern "C" BOOL WINAPI DllMain(HMODULE hInstance, DWORD dwReason, LPVOID)
  95. {
  96. BOOL fRet = TRUE;
  97. DebugMsg(DM_TRACE, TEXT("DllMain called. dwReason=0x%08x"), dwReason);
  98. switch (dwReason)
  99. {
  100. LPVOID lpv;
  101. case DLL_PROCESS_ATTACH:
  102. SHFusionInitializeFromModule(hInstance);
  103. InitializeCriticalSection(&g_cs);
  104. g_hInst = (HINSTANCE)hInstance;
  105. DisableThreadLibraryCalls(g_hInst);
  106. _Module.Init(ObjectMap, g_hInst);
  107. // HACKHACK (reinerf) - because ATL2.1 bites the big one, we have to malloc some memory
  108. // here so that it will cause _Module.m_hHeap to be initialized. They do not init this
  109. // member variable in a thread safe manner, so we will alloc and free a small chunk of
  110. // memory right now to ensure that the heap is created only once.
  111. lpv = malloc(2 * sizeof(CHAR));
  112. if (lpv)
  113. {
  114. free(lpv);
  115. }
  116. g_bIsNT5 = staticIsOS(OS_WIN2000ORGREATER);
  117. g_bIsNT = staticIsOS(OS_NT);
  118. g_bIsWin98 = staticIsOS(OS_WIN98ORGREATER);
  119. g_uACP = GetACP();
  120. break;
  121. case DLL_PROCESS_DETACH:
  122. FreeGlobalObjects();
  123. _Module.Term();
  124. DeleteCriticalSection(&g_cs);
  125. if (g_hUrlMon)
  126. {
  127. FreeLibrary(g_hUrlMon);
  128. }
  129. SHFusionUninitialize();
  130. break;
  131. }
  132. return TRUE;
  133. }
  134. void DllAddRef(void)
  135. {
  136. _Module.Lock();
  137. }
  138. void DllRelease(void)
  139. {
  140. _Module.Unlock();
  141. }
  142. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppvObj)
  143. {
  144. DebugMsg(DM_TRACE, TEXT("DllGetClassObject called."));
  145. if (NULL == g_pMimeDatabase)
  146. BuildGlobalObjects();
  147. //
  148. // See comments in util.cpp NeedToLoadMLangForOutlook()
  149. //
  150. if (NeedToLoadMLangForOutlook())
  151. LoadLibrary(TEXT("mlang.dll"));
  152. return _Module.GetClassObject(rclsid, riid, ppvObj);
  153. }
  154. STDAPI DllCanUnloadNow(void)
  155. {
  156. return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE;
  157. }
  158. //
  159. // Self Registration part
  160. //
  161. #if 0
  162. HRESULT CallRegInstall(LPCSTR szSection)
  163. {
  164. HRESULT hr = E_FAIL;
  165. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  166. DebugMsg(DM_TRACE, TEXT("CallRegInstall called for %s."), szSection);
  167. if (NULL != hinstAdvPack)
  168. {
  169. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, achREGINSTALL);
  170. if (NULL != pfnri)
  171. hr = pfnri(g_hInst, szSection, NULL);
  172. FreeLibrary(hinstAdvPack);
  173. }
  174. return hr;
  175. }
  176. #endif
  177. STDAPI DllRegisterServer(void)
  178. {
  179. HRESULT hr;
  180. DebugMsg(DM_TRACE, TEXT("DllRegisterServer called."));
  181. #if 0
  182. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  183. OSVERSIONINFO osvi;
  184. BOOL fRunningOnNT;
  185. // Determine which version of NT or Windows we're running on
  186. osvi.dwOSVersionInfoSize = sizeof(osvi);
  187. GetVersionEx(&osvi);
  188. fRunningOnNT = (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId);
  189. // Delete any old registration entries, then add the new ones.
  190. // Keep ADVPACK.DLL loaded across multiple calls to RegInstall.
  191. CallRegInstall("UnReg");
  192. hr = CallRegInstall(fRunningOnNT? "Reg.NT": "Reg");
  193. if (NULL != hinstAdvPack)
  194. FreeLibrary(hinstAdvPack);
  195. // Need to register TypeLib here ...
  196. // Get the full path of this module
  197. GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule));
  198. // Register our TypeLib
  199. MultiByteToWideChar(CP_ACP, 0, szModule, -1, wszTemp, ARRAYSIZE(wszTemp));
  200. hr = LoadTypeLib(wszTemp, &pTypeLib);
  201. if (SUCCEEDED(hr))
  202. {
  203. hr = RegisterTypeLib(pTypeLib, wszTemp, NULL);
  204. pTypeLib->Release();
  205. }
  206. #else
  207. hr = RegisterServerInfo();
  208. // Legacy registry MIME DB code, keep it for backward compatiblility
  209. MimeDatabaseInfo();
  210. #endif
  211. return hr;
  212. }
  213. STDAPI DllUnregisterServer(void)
  214. {
  215. HRESULT hr;
  216. DebugMsg(DM_TRACE, TEXT("DllUnregisterServer called."));
  217. #if 0
  218. hr = CallRegInstall("UnReg");
  219. #else
  220. hr = UnregisterServerInfo();
  221. #endif
  222. return hr;
  223. }