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.

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