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.

335 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. dimmwrp.cpp
  5. Abstract:
  6. This file implements the CActiveIMMApp Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "dimmwrp.h"
  13. #include "resource.h"
  14. #include "cregkey.h"
  15. //
  16. // Check IE5.5 version
  17. //
  18. static BOOL g_fCachedIE = FALSE;
  19. static BOOL g_fNewVerIE = FALSE;
  20. #define IEVERSION55 0x00050032
  21. #define IEVERSION6 0x00060000
  22. //
  23. // REGKEY
  24. //
  25. const TCHAR c_szMSIMTFKey[] = TEXT("SOFTWARE\\Microsoft\\CTF\\MSIMTF\\");
  26. // REG_DWORD : 0 // No
  27. // 1 // Only Trident (default)
  28. // 2 // Always AIMM12
  29. const TCHAR c_szUseAIMM12[] = TEXT("UseAIMM12");
  30. // REG_MULTI_SZ
  31. // Known EXE module list for Trident aware applications.
  32. const TCHAR c_szKnownEXE[] = TEXT("KnownEXE");
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Check registry to decice load AIMM1.2
  36. //
  37. //----------------------------------------------------------------------------
  38. #define DIMM12_NO 0
  39. #define DIMM12_TRIDENTONLY 1
  40. #define DIMM12_ALWAYS 2
  41. DWORD
  42. IsAimm12Enable()
  43. {
  44. CMyRegKey Aimm12Reg;
  45. LONG lRet;
  46. lRet = Aimm12Reg.Open(HKEY_LOCAL_MACHINE, c_szMSIMTFKey, KEY_READ);
  47. if (lRet == ERROR_SUCCESS) {
  48. DWORD dw;
  49. lRet = Aimm12Reg.QueryValue(dw, c_szUseAIMM12);
  50. if (lRet == ERROR_SUCCESS) {
  51. return dw;
  52. }
  53. }
  54. return DIMM12_TRIDENTONLY;
  55. }
  56. //+---------------------------------------------------------------------------
  57. //
  58. // Is this trident module
  59. //
  60. // We should distinguish what exe module calls CoCreateInstance( CLSID_CActiveIMM ).
  61. // If caller is any 3rd party's or unknown modle,
  62. // then we could not support AIMM 1.2 interface.
  63. //
  64. //----------------------------------------------------------------------------
  65. BOOL
  66. IsTridentModule()
  67. {
  68. TCHAR szFileName[MAX_PATH + 1];
  69. if (::GetModuleFileName(NULL, // handle to module
  70. szFileName, // file name of module
  71. ARRAYSIZE(szFileName) - 1) == 0)
  72. return FALSE;
  73. szFileName[ARRAYSIZE(szFileName) - 1] = TEXT('\0');
  74. TCHAR szModuleName[MAX_PATH + 1];
  75. LPTSTR pszFilePart = NULL;
  76. DWORD dwLen;
  77. dwLen = ::GetFullPathName(szFileName, // file name
  78. ARRAYSIZE(szModuleName) - 1,
  79. szModuleName, // path buffer
  80. &pszFilePart); // address of file name in path
  81. if (dwLen > ARRAYSIZE(szModuleName) - 1)
  82. return FALSE;
  83. if (pszFilePart == NULL)
  84. return FALSE;
  85. szModuleName[ARRAYSIZE(szModuleName) - 1] = TEXT('\0');
  86. //
  87. // Setup system defines module list from registry value.
  88. //
  89. int len;
  90. CMyRegKey Aimm12Reg;
  91. LONG lRet;
  92. lRet = Aimm12Reg.Open(HKEY_LOCAL_MACHINE, c_szMSIMTFKey, KEY_READ);
  93. if (lRet == ERROR_SUCCESS) {
  94. TCHAR szValue[MAX_PATH];
  95. lRet = Aimm12Reg.QueryValueCch(szValue, c_szKnownEXE, ARRAYSIZE(szValue));
  96. if (lRet == ERROR_SUCCESS) {
  97. LPTSTR psz = szValue;
  98. while (*psz) {
  99. len = lstrlen(psz);
  100. if (lstrcmpi(pszFilePart, psz) == 0) {
  101. return TRUE; // This is Trident module.
  102. }
  103. psz += len + 1;
  104. }
  105. }
  106. }
  107. //
  108. // Setup default module list from resource data (RCDATA)
  109. //
  110. LPTSTR lpName = (LPTSTR) ID_KNOWN_EXE;
  111. HRSRC hRSrc = FindResourceEx(g_hInst, RT_RCDATA, lpName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  112. if (hRSrc == NULL)
  113. return FALSE;
  114. HGLOBAL hMem = LoadResource(g_hInst, hRSrc);
  115. if (hMem == NULL)
  116. return FALSE;
  117. LPTSTR psz = (LPTSTR)LockResource(hMem);
  118. while (*psz) {
  119. len = lstrlen(psz);
  120. if (lstrcmpi(pszFilePart, psz) == 0) {
  121. return TRUE; // This is Trident module.
  122. }
  123. psz += len + 1;
  124. }
  125. return FALSE;
  126. }
  127. BOOL
  128. IsTridentNewVersion()
  129. {
  130. BOOL fRet = FALSE;
  131. TCHAR szMShtmlName[MAX_PATH + 1];
  132. if (g_fCachedIE)
  133. {
  134. return g_fNewVerIE;
  135. }
  136. //
  137. // Get "mshtml.dll" module from system directory and read version.
  138. //
  139. if (GetSystemDirectory(szMShtmlName, ARRAYSIZE(szMShtmlName) - 1))
  140. {
  141. UINT cb;
  142. void *pvData;
  143. DWORD dwVerHandle;
  144. VS_FIXEDFILEINFO *pffi;
  145. HRESULT hr;
  146. szMShtmlName[ARRAYSIZE(szMShtmlName) - 1] = TEXT('\0');
  147. hr = StringCchCat(szMShtmlName, ARRAYSIZE(szMShtmlName), TEXT("\\"));
  148. if (hr != S_OK)
  149. return FALSE;
  150. hr = StringCchCat(szMShtmlName, ARRAYSIZE(szMShtmlName), TEXT("mshtml.dll"));
  151. if (hr != S_OK)
  152. return FALSE;
  153. cb = GetFileVersionInfoSize(szMShtmlName, &dwVerHandle);
  154. if (cb == 0)
  155. return FALSE;
  156. if ((pvData = cicMemAlloc(cb)) == NULL)
  157. return FALSE;
  158. if (GetFileVersionInfo(szMShtmlName, 0, cb, pvData) &&
  159. VerQueryValue(pvData, TEXT("\\"), (void **)&pffi, &cb))
  160. {
  161. g_fCachedIE = TRUE;
  162. //fRet = g_fNewVerIE = (pffi->dwProductVersionMS >= IEVERSION55);
  163. if ((pffi->dwProductVersionMS >= IEVERSION55) &&
  164. (pffi->dwProductVersionMS <= IEVERSION6))
  165. {
  166. fRet = g_fNewVerIE = TRUE;
  167. }
  168. else
  169. {
  170. fRet = g_fNewVerIE = FALSE;
  171. }
  172. }
  173. else
  174. {
  175. fRet = FALSE;
  176. }
  177. cicMemFree(pvData);
  178. }
  179. return fRet;
  180. }
  181. //+---------------------------------------------------------------------------
  182. //
  183. // GetCompatibility
  184. //
  185. //----------------------------------------------------------------------------
  186. VOID GetCompatibility(DWORD* dw, BOOL* fTrident, BOOL* _fTrident55)
  187. {
  188. //
  189. // Retrieve AIMM1.2 Enable flag from REGKEY
  190. //
  191. *dw = IsAimm12Enable();
  192. //
  193. // Retrieve Trident aware application flag from REGKEY and RESOURCE.
  194. //
  195. *fTrident = IsTridentModule();
  196. //
  197. // Check Trident version with "mshtml.dll" module
  198. //
  199. *_fTrident55 = FALSE;
  200. if (*fTrident)
  201. {
  202. *_fTrident55 = IsTridentNewVersion();
  203. }
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // VerifyCreateInstance
  208. //
  209. //----------------------------------------------------------------------------
  210. BOOL CActiveIMMApp::VerifyCreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
  211. {
  212. DWORD dw;
  213. BOOL fTrident;
  214. BOOL _fTrident55;
  215. GetCompatibility(&dw, &fTrident, &_fTrident55);
  216. if ( (dw == DIMM12_ALWAYS) ||
  217. ((dw == DIMM12_TRIDENTONLY) && fTrident))
  218. {
  219. //
  220. // CreateInstance AIMM1.2
  221. //
  222. return CComActiveIMMApp::VerifyCreateInstance(pUnkOuter, riid, ppvObj);
  223. }
  224. return FALSE;
  225. }
  226. //+---------------------------------------------------------------------------
  227. //
  228. // PostCreateInstance
  229. //
  230. //----------------------------------------------------------------------------
  231. void CActiveIMMApp::PostCreateInstance(REFIID riid, void *pvObj)
  232. {
  233. DWORD dw;
  234. BOOL fTrident;
  235. BOOL _fTrident55;
  236. GetCompatibility(&dw, &fTrident, &_fTrident55);
  237. imm32prev::CtfImmSetAppCompatFlags(IMECOMPAT_AIMM_LEGACY_CLSID | (_fTrident55 ? IMECOMPAT_AIMM_TRIDENT55 : 0));
  238. }
  239. #ifdef OLD_AIMM_ENABLED
  240. //+---------------------------------------------------------------------------
  241. //
  242. // Class Factory's CreateInstance (Old AIMM1.2)
  243. //
  244. //----------------------------------------------------------------------------
  245. HRESULT
  246. CActiveIMM_CreateInstance_Legacy(
  247. IUnknown *pUnkOuter,
  248. REFIID riid,
  249. void **ppvObj)
  250. {
  251. DWORD dw;
  252. BOOL fTrident;
  253. BOOL _fTrident55;
  254. GetCompatibility(&dw, &fTrident, &_fTrident55);
  255. if ( (dw == DIMM12_ALWAYS) ||
  256. ((dw == DIMM12_TRIDENTONLY) && fTrident))
  257. {
  258. //
  259. // CreateInstance AIMM1.2
  260. //
  261. g_fInLegacyClsid = TRUE;
  262. return CActiveIMM_CreateInstance(pUnkOuter, riid, ppvObj);
  263. }
  264. return E_NOINTERFACE;
  265. }
  266. #endif // OLD_AIMM_ENABLED