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.

250 lines
7.1 KiB

  1. //
  2. // Microsoft Corporation 1998
  3. //
  4. // RIGPSNAP.CPP - DLL entry and registration routines
  5. //
  6. #include "main.h"
  7. #include <initguid.h>
  8. #include <rigpsnap.h>
  9. #include <gpedit.h>
  10. // Globals
  11. LONG g_cRefThisDll = 0;
  12. HINSTANCE g_hInstance;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // DLL Entry Point
  15. extern "C"
  16. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  17. {
  18. if (dwReason == DLL_PROCESS_ATTACH)
  19. {
  20. g_hInstance = hInstance;
  21. DisableThreadLibraryCalls(hInstance);
  22. InitNameSpace();
  23. #if DBG
  24. InitDebugSupport();
  25. #endif
  26. }
  27. return TRUE; // ok
  28. }
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Used to determine whether the DLL can be unloaded by OLE
  31. STDAPI DllCanUnloadNow(void)
  32. {
  33. return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
  34. }
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Returns a class factory to create an object of the requested type
  37. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  38. {
  39. return (CreateComponentDataClassFactory (rclsid, riid, ppv));
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // DllRegisterServer - Adds entries to the system registry
  43. const TCHAR szSnapInLocation[] = TEXT("%SystemRoot%\\System32\\RIGPSNAP.dll");
  44. STDAPI DllRegisterServer(void)
  45. {
  46. TCHAR szSnapInKey[50];
  47. TCHAR szSubKey[200];
  48. TCHAR szSnapInName[100];
  49. TCHAR szGUID[50];
  50. DWORD dwDisp, dwIndex;
  51. LONG lResult;
  52. HKEY hKey;
  53. StringFromGUID2 (CLSID_GPTRemoteInstall, szSnapInKey, ARRAYSIZE( szSnapInKey ));
  54. //
  55. // Register SnapIn in HKEY_CLASSES_ROOT
  56. //
  57. LoadString (g_hInstance, IDS_SNAPIN_NAME, szSnapInName, ARRAYSIZE( szSnapInName ));
  58. wsprintf (szSubKey, TEXT("CLSID\\%s"), szSnapInKey);
  59. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  60. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  61. &hKey, &dwDisp);
  62. if (lResult != ERROR_SUCCESS) {
  63. return SELFREG_E_CLASS;
  64. }
  65. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)szSnapInName,
  66. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  67. RegCloseKey (hKey);
  68. wsprintf (szSubKey, TEXT("CLSID\\%s\\InProcServer32"), szSnapInKey);
  69. lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, NULL,
  70. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  71. &hKey, &dwDisp);
  72. if (lResult != ERROR_SUCCESS) {
  73. return SELFREG_E_CLASS;
  74. }
  75. RegSetValueEx (hKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)szSnapInLocation,
  76. (lstrlen(szSnapInLocation) + 1) * sizeof(TCHAR));
  77. RegCloseKey (hKey);
  78. //
  79. // Register SnapIn with MMC
  80. //
  81. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szSnapInKey);
  82. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  83. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  84. &hKey, &dwDisp);
  85. if (lResult != ERROR_SUCCESS) {
  86. return SELFREG_E_CLASS;
  87. }
  88. TCHAR szModuleFileName[MAX_PATH];
  89. ZeroMemory(szModuleFileName, sizeof(szModuleFileName));
  90. DWORD dwRet = GetModuleFileName(
  91. g_hInstance,
  92. szModuleFileName,
  93. ARRAYSIZE(szModuleFileName));
  94. if (0 != dwRet) {
  95. TCHAR strNameIndirect[MAX_PATH];
  96. wsprintf(strNameIndirect, TEXT("@%s,-%u"), szModuleFileName, IDS_SNAPIN_NAME);
  97. RegSetValueEx(
  98. hKey,
  99. TEXT("NameStringIndirect"),
  100. 0,
  101. REG_SZ,
  102. (LPBYTE)strNameIndirect,
  103. (lstrlen(strNameIndirect) + 1) * sizeof(TCHAR));
  104. }
  105. RegSetValueEx (hKey, TEXT("NameString"), 0, REG_SZ, (LPBYTE)szSnapInName,
  106. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  107. RegCloseKey (hKey);
  108. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  109. {
  110. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szGUID, ARRAYSIZE( szGUID ));
  111. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s\\NodeTypes\\%s"),
  112. szSnapInKey, szGUID);
  113. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  114. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  115. &hKey, &dwDisp);
  116. if (lResult != ERROR_SUCCESS) {
  117. return SELFREG_E_CLASS;
  118. }
  119. RegCloseKey (hKey);
  120. }
  121. //
  122. // Register in the NodeTypes key
  123. //
  124. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  125. {
  126. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szGUID, ARRAYSIZE( szGUID ));
  127. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"), szGUID);
  128. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  129. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  130. &hKey, &dwDisp);
  131. if (lResult != ERROR_SUCCESS) {
  132. return SELFREG_E_CLASS;
  133. }
  134. RegCloseKey (hKey);
  135. }
  136. //
  137. // Register as an extension for various nodes
  138. //
  139. StringFromGUID2 (NODEID_User, szGUID, 50);
  140. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  141. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0, NULL,
  142. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  143. &hKey, &dwDisp);
  144. if (lResult != ERROR_SUCCESS) {
  145. return SELFREG_E_CLASS;
  146. }
  147. RegSetValueEx (hKey, szSnapInKey, 0, REG_SZ, (LPBYTE)szSnapInName,
  148. (lstrlen(szSnapInName) + 1) * sizeof(TCHAR));
  149. RegCloseKey (hKey);
  150. return S_OK;
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // DllUnregisterServer - Removes entries from the system registry
  154. STDAPI DllUnregisterServer(void)
  155. {
  156. TCHAR szSnapInKey[50];
  157. TCHAR szSubKey[200];
  158. TCHAR szGUID[50];
  159. DWORD dwIndex;
  160. LONG lResult;
  161. HKEY hKey;
  162. DWORD dwDisp;
  163. StringFromGUID2 (CLSID_GPTRemoteInstall, szSnapInKey, ARRAYSIZE( szSnapInKey ));
  164. wsprintf (szSubKey, TEXT("CLSID\\%s"), szSnapInKey);
  165. RegDelnode (HKEY_CLASSES_ROOT, szSubKey);
  166. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\SnapIns\\%s"), szSnapInKey);
  167. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  168. for (dwIndex = 0; dwIndex < NUM_NAMESPACE_ITEMS; dwIndex++)
  169. {
  170. StringFromGUID2 (*g_NameSpace[dwIndex].pNodeID, szGUID, ARRAYSIZE( szGUID ));
  171. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s"), szGUID);
  172. RegDelnode (HKEY_LOCAL_MACHINE, szSubKey);
  173. }
  174. StringFromGUID2 (NODEID_User, szGUID, ARRAYSIZE( szGUID ));
  175. wsprintf (szSubKey, TEXT("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\NameSpace"), szGUID);
  176. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szSubKey, 0,
  177. KEY_WRITE, &hKey);
  178. if (lResult == ERROR_SUCCESS) {
  179. RegDeleteValue (hKey, szSnapInKey);
  180. RegCloseKey (hKey);
  181. }
  182. return S_OK;
  183. }