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.

228 lines
6.3 KiB

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