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.

371 lines
13 KiB

  1. #include "precomp.h"
  2. //
  3. // Global variables for this DLL
  4. //
  5. LONG g_cRefThisDll = 0;
  6. HINSTANCE g_hInstance;
  7. HINSTANCE g_hUIInstance;
  8. CRITICAL_SECTION g_LayoutCriticalSection;
  9. /////////////////////////////////////////////////////////////////////////////
  10. // DLL Entry Point
  11. extern "C"
  12. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  13. {
  14. if (dwReason == DLL_PROCESS_ATTACH)
  15. {
  16. g_hInstance = hInstance;
  17. if ((g_hUIInstance = LoadLibrary(TEXT("ieakui.dll"))) == NULL)
  18. return FALSE;
  19. DisableThreadLibraryCalls(hInstance);
  20. InitializeCriticalSection(&g_LayoutCriticalSection);
  21. }
  22. else if (dwReason == DLL_PROCESS_DETACH)
  23. {
  24. CleanUpGlobalArrays();
  25. if (g_hUIInstance != NULL)
  26. {
  27. FreeLibrary(g_hUIInstance);
  28. g_hUIInstance = NULL;
  29. }
  30. DeleteCriticalSection(&g_LayoutCriticalSection);
  31. }
  32. return TRUE; // ok
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Used to determine whether the DLL can be unloaded by OLE
  36. STDAPI DllCanUnloadNow(void)
  37. {
  38. return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Returns a class factory to create an object of the requested type
  42. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  43. {
  44. return (CreateComponentDataClassFactory (rclsid, riid, ppv));
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // DllRegisterServer - Adds entries to the system registry
  48. const TCHAR c_szSnapInLocation[] = TEXT("%SystemRoot%\\System32\\ieaksie.dll");
  49. const TCHAR c_szThreadingModel[] = TEXT("Apartment");
  50. STDAPI DllRegisterServer(void)
  51. {
  52. TCHAR szSnapInKey[64];
  53. TCHAR szRSoPSnapInKey[64];
  54. TCHAR szSubKey[MAX_PATH];
  55. TCHAR szName[128];
  56. TCHAR szNameIndirect[MAX_PATH];
  57. TCHAR szRSoPName[128];
  58. TCHAR szGUID[64];
  59. DWORD dwDisp, dwIndex;
  60. LONG lResult;
  61. HKEY hKey;
  62. //
  63. // Register Help About
  64. //
  65. StringFromGUID2(CLSID_AboutIEAKSnapinExt, szGUID, countof(szGUID));
  66. LoadString(g_hInstance, IDS_ABOUT_NAME, szName, countof(szName));
  67. wnsprintf(szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szGUID);
  68. lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  69. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  70. &hKey, &dwDisp);
  71. if (lResult != ERROR_SUCCESS)
  72. return SELFREG_E_CLASS;
  73. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  74. RegCloseKey (hKey);
  75. wnsprintf(szSubKey, countof(szSubKey), TEXT("CLSID\\%s\\InProcServer32"), szGUID);
  76. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  77. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  78. &hKey, &dwDisp);
  79. if (lResult != ERROR_SUCCESS)
  80. return SELFREG_E_CLASS;
  81. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)c_szSnapInLocation, (DWORD)StrCbFromSz(c_szSnapInLocation));
  82. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)c_szThreadingModel,
  83. (DWORD)StrCbFromSz(c_szThreadingModel));
  84. RegCloseKey (hKey);
  85. StringFromGUID2(CLSID_IEAKSnapinExt, szSnapInKey, countof(szSnapInKey));
  86. StringFromGUID2(CLSID_IEAKRSoPSnapinExt, szRSoPSnapInKey, countof(szRSoPSnapInKey));
  87. //
  88. // Register SnapIn in HKEY_CLASSES_ROOT
  89. //
  90. LoadString (g_hInstance, IDS_SIE_NAME, szName, 100);
  91. LoadString(g_hInstance, IDS_NAME_INDIRECT, szNameIndirect, countof(szNameIndirect));
  92. wnsprintf (szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szSnapInKey);
  93. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  94. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  95. &hKey, &dwDisp);
  96. if (lResult != ERROR_SUCCESS)
  97. return SELFREG_E_CLASS;
  98. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  99. RegCloseKey (hKey);
  100. wnsprintf (szSubKey, countof(szSubKey), TEXT("CLSID\\%s\\InProcServer32"), szSnapInKey);
  101. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  102. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  103. &hKey, &dwDisp);
  104. if (lResult != ERROR_SUCCESS)
  105. return SELFREG_E_CLASS;
  106. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)c_szSnapInLocation, (DWORD)StrCbFromSz(c_szSnapInLocation));
  107. RegCloseKey (hKey);
  108. //
  109. // Register RSoP SnapIn in HKEY_CLASSES_ROOT
  110. //
  111. StrCpy (szRSoPName, szName);
  112. StrCat (szRSoPName, TEXT(" - RSoP"));
  113. wnsprintf (szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szRSoPSnapInKey);
  114. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  115. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  116. &hKey, &dwDisp);
  117. if (lResult != ERROR_SUCCESS)
  118. return SELFREG_E_CLASS;
  119. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szRSoPName, (DWORD)StrCbFromSz(szRSoPName));
  120. RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, REG_SZ, (LPBYTE)c_szThreadingModel,
  121. (DWORD)StrCbFromSz(c_szThreadingModel));
  122. RegCloseKey (hKey);
  123. wnsprintf (szSubKey, countof(szSubKey), TEXT("CLSID\\%s\\InProcServer32"), szRSoPSnapInKey);
  124. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  125. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  126. &hKey, &dwDisp);
  127. if (lResult != ERROR_SUCCESS)
  128. return SELFREG_E_CLASS;
  129. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)c_szSnapInLocation, (DWORD)StrCbFromSz(c_szSnapInLocation));
  130. RegCloseKey (hKey);
  131. //
  132. // Register SnapIn with MMC
  133. //
  134. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szSnapInKey);
  135. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  136. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  137. &hKey, &dwDisp);
  138. if (lResult != ERROR_SUCCESS)
  139. return SELFREG_E_CLASS;
  140. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  141. //kirstenf: namestringindirect needs to be set for MUI support (Bug 17944)
  142. RegSetValueEx (hKey, TEXT("NameStringIndirect"),0,REG_SZ,(LPBYTE)szNameIndirect,(DWORD)StrCbFromSz(szNameIndirect));
  143. RegSetValueEx (hKey, TEXT("About"), 0, REG_SZ, (LPBYTE) szGUID, (DWORD)StrCbFromSz(szGUID));
  144. RegCloseKey (hKey);
  145. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  146. {
  147. StringFromGUID2(*g_NameSpace[dwIndex].pNodeID, szGUID, countof(szGUID));
  148. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  149. szSnapInKey, szGUID);
  150. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  151. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  152. &hKey, &dwDisp);
  153. if (lResult != ERROR_SUCCESS)
  154. return SELFREG_E_CLASS;
  155. RegCloseKey (hKey);
  156. }
  157. //
  158. // Register RSoP SnapIn with MMC
  159. //
  160. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szRSoPSnapInKey);
  161. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  162. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  163. &hKey, &dwDisp);
  164. if (lResult != ERROR_SUCCESS)
  165. return SELFREG_E_CLASS;
  166. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  167. //kirstenf: namestringindirect needs to be set for MUI support (Bug 17944)
  168. RegSetValueEx (hKey, TEXT("NameStringIndirect"),0,REG_SZ,(LPBYTE)szNameIndirect,(DWORD)StrCbFromSz(szNameIndirect));
  169. StringFromGUID2(CLSID_AboutIEAKSnapinExt, szGUID, countof(szGUID));
  170. RegSetValueEx (hKey, TEXT("About"), 0, REG_SZ, (LPBYTE) szGUID, (DWORD)StrCbFromSz(szGUID));
  171. RegCloseKey (hKey);
  172. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  173. {
  174. StringFromGUID2(*g_NameSpace[dwIndex].pNodeID, szGUID, countof(szGUID));
  175. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  176. szSnapInKey, szGUID);
  177. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  178. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  179. &hKey, &dwDisp);
  180. if (lResult != ERROR_SUCCESS)
  181. return SELFREG_E_CLASS;
  182. RegCloseKey (hKey);
  183. }
  184. //
  185. // Register in the NodeTypes key
  186. //
  187. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  188. {
  189. StringFromGUID2(*g_NameSpace[dwIndex].pNodeID, szGUID, countof(szGUID));
  190. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"), szGUID);
  191. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  192. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  193. &hKey, &dwDisp);
  194. if (lResult != ERROR_SUCCESS)
  195. return SELFREG_E_CLASS;
  196. RegCloseKey (hKey);
  197. }
  198. //
  199. // Register as an extension for various nodes
  200. //
  201. StringFromGUID2(NODEID_User, szGUID, countof(szGUID));
  202. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  203. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  204. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  205. &hKey, &dwDisp);
  206. if (lResult != ERROR_SUCCESS)
  207. return SELFREG_E_CLASS;
  208. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  209. RegCloseKey (hKey);
  210. //
  211. // Register RSoP as an extension for various nodes
  212. //
  213. StringFromGUID2(NODEID_RSOPUser, szGUID, countof(szGUID));
  214. wnsprintf (szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  215. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  216. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  217. &hKey, &dwDisp);
  218. if (lResult != ERROR_SUCCESS)
  219. return SELFREG_E_CLASS;
  220. RegSetValueEx (hKey, szRSoPSnapInKey, 0, REG_SZ, (LPBYTE)szName, (DWORD)StrCbFromSz(szName));
  221. RegCloseKey (hKey);
  222. return S_OK;
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. // DllUnregisterServer - Removes entries from the system registry
  226. STDAPI DllUnregisterServer(void)
  227. {
  228. TCHAR szSnapInKey[50];
  229. TCHAR szRSoPSnapInKey[50];
  230. TCHAR szSubKey[200];
  231. TCHAR szGUID[50];
  232. DWORD dwIndex;
  233. StringFromGUID2(CLSID_AboutIEAKSnapinExt, szSnapInKey, countof(szSnapInKey));
  234. wnsprintf(szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szSnapInKey);
  235. SHDeleteKey(HKEY_CLASSES_ROOT, szSubKey);
  236. StringFromGUID2(CLSID_IEAKSnapinExt, szSnapInKey, countof(szSnapInKey));
  237. wnsprintf(szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szSnapInKey);
  238. SHDeleteKey(HKEY_CLASSES_ROOT, szSubKey);
  239. StringFromGUID2(CLSID_IEAKRSoPSnapinExt, szRSoPSnapInKey, countof(szRSoPSnapInKey));
  240. wnsprintf(szSubKey, countof(szSubKey), TEXT("CLSID\\%s"), szRSoPSnapInKey);
  241. SHDeleteKey(HKEY_CLASSES_ROOT, szSubKey);
  242. wnsprintf(szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szSnapInKey);
  243. SHDeleteKey(HKEY_LOCAL_MACHINE, szSubKey);
  244. wnsprintf(szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szRSoPSnapInKey);
  245. SHDeleteKey(HKEY_LOCAL_MACHINE, szSubKey);
  246. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  247. {
  248. StringFromGUID2(*g_NameSpace[dwIndex].pNodeID, szGUID, countof(szGUID));
  249. wnsprintf(szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"), szGUID);
  250. SHDeleteKey(HKEY_LOCAL_MACHINE, szSubKey);
  251. }
  252. StringFromGUID2(NODEID_User, szGUID, countof(szGUID));
  253. wnsprintf(szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  254. SHDeleteValue(HKEY_LOCAL_MACHINE, szSubKey, szSnapInKey);
  255. StringFromGUID2(NODEID_RSOPUser, szGUID, countof(szGUID));
  256. wnsprintf(szSubKey, countof(szSubKey), TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  257. SHDeleteValue(HKEY_LOCAL_MACHINE, szSubKey, szRSoPSnapInKey);
  258. return S_OK;
  259. }