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.

174 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: SendCMsg.cpp
  7. //
  8. // Contents:
  9. //
  10. //----------------------------------------------------------------------------
  11. // SendCMsg.cpp : Implementation of DLL Exports.
  12. // Note: Proxy/Stub Information
  13. // To build a separate proxy/stub DLL,
  14. // run nmake -f SendCMsgps.mk in the project directory.
  15. #include "stdafx.h"
  16. #include "initguid.h"
  17. #include "SendCMsg.h"
  18. #include "SendCMsg_i.c"
  19. #include "debug.h"
  20. #include "util.h"
  21. #include "resource.h"
  22. #include "App.h"
  23. #include <atlimpl.cpp>
  24. HINSTANCE g_hInstance;
  25. CComModule _Module;
  26. BEGIN_OBJECT_MAP(ObjectMap)
  27. OBJECT_ENTRY(CLSID_SendConsoleMessageApp, CSendConsoleMessageApp)
  28. END_OBJECT_MAP()
  29. // GUID for the CSendConsoleMessageApp class
  30. #define d_szGuidSendConsoleMessageApp _T("{B1AFF7D0-0C49-11D1-BB12-00C04FC9A3A3}")
  31. #if 0
  32. // To have sendcmsg.dll to extend your context menu, add the following
  33. // key into the registry
  34. //
  35. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\NodeTypes\
  36. {476e6448-aaff-11d0-b944-00c04fd8d5b0}\Extensions\ContextMenu]
  37. "{B1AFF7D0-0C49-11D1-BB12-00C04FC9A3A3}"="Send Console Message"
  38. // where {476e6448-aaff-11d0-b944-00c04fd8d5b0} is
  39. // the GUID for the nodetype which you want to be extended.
  40. #endif
  41. // The following is an array of GUIDs of snapins that wants to be
  42. // automatically extended by the Send Console Message Snapin.
  43. // When the snapin registers itself, it will extend those nodetypes.
  44. const LPCTSTR rgzpszGuidNodetypeContextMenuExtensions[] =
  45. {
  46. _T("{476e6446-aaff-11d0-b944-00c04fd8d5b0}"), // Computer Management
  47. _T("{4e410f0e-abc1-11d0-b944-00c04fd8d5b0}"), // Root of File Service Management subtree
  48. _T("{4e410f0f-abc1-11d0-b944-00c04fd8d5b0}"), // FSM - Shares
  49. _T("{4e410f12-abc1-11d0-b944-00c04fd8d5b0}"), // System Service Management
  50. };
  51. // The following is an array of GUIDs of snapins that no longer want
  52. // to be automatically extended by the Send Console Message Snapin.
  53. const LPCTSTR rgzpszRemoveContextMenuExtensions[] =
  54. {
  55. _T("{476e6448-aaff-11d0-b944-00c04fd8d5b0}"), // Computer Management -> SystemTools
  56. _T("{0eeeeeee-d390-11cf-b607-00c04fd8d565}"), // invalid
  57. _T("{1eeeeeee-d390-11cf-b607-00c04fd8d565}"), // invalid
  58. _T("{7eeeeeee-d390-11cf-b607-00c04fd8d565}"), // invalid
  59. };
  60. /////////////////////////////////////////////////////////////////////////////
  61. // DLL Entry Point
  62. extern "C"
  63. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  64. {
  65. g_hInstance = hInstance;
  66. if (dwReason == DLL_PROCESS_ATTACH)
  67. {
  68. _Module.Init(ObjectMap, hInstance);
  69. DisableThreadLibraryCalls(hInstance);
  70. }
  71. else if (dwReason == DLL_PROCESS_DETACH)
  72. _Module.Term();
  73. return TRUE; // ok
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Used to determine whether the DLL can be unloaded by OLE
  77. STDAPI DllCanUnloadNow(void)
  78. {
  79. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // Returns a class factory to create an object of the requested type
  83. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  84. {
  85. return _Module.GetClassObject(rclsid, riid, ppv);
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // DllRegisterServer - Adds entries to the system registry
  89. STDAPI DllRegisterServer(void)
  90. {
  91. // registers object, typelib and all interfaces in typelib
  92. HRESULT hr = _Module.RegisterServer(TRUE);
  93. HKEY hkey = RegOpenOrCreateKey(
  94. HKEY_LOCAL_MACHINE,
  95. _T("Software\\Microsoft\\MMC\\SnapIns\\") d_szGuidSendConsoleMessageApp);
  96. if (hkey == NULL)
  97. {
  98. Assert(FALSE && "DllRegisterServer() - Unable to create key from registry.");
  99. return SELFREG_E_CLASS;
  100. }
  101. RegWriteString(hkey, _T("NameString"), IDS_CAPTION);
  102. RegCloseKey(hkey);
  103. for (int i = 0; i < LENGTH(rgzpszGuidNodetypeContextMenuExtensions); i++)
  104. {
  105. TCHAR szRegistryKey[256];
  106. Assert(rgzpszGuidNodetypeContextMenuExtensions[i] != NULL);
  107. wsprintf(OUT szRegistryKey,
  108. _T("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  109. rgzpszGuidNodetypeContextMenuExtensions[i]);
  110. Assert(lstrlen(szRegistryKey) < LENGTH(szRegistryKey));
  111. hkey = RegOpenOrCreateKey(HKEY_LOCAL_MACHINE, szRegistryKey);
  112. if (hkey == NULL)
  113. {
  114. Assert(FALSE && "DllRegisterServer() - Unable to create key from registry.");
  115. continue;
  116. }
  117. RegWriteString(hkey, d_szGuidSendConsoleMessageApp, IDS_CAPTION);
  118. RegCloseKey(hkey);
  119. } // for
  120. for (i = 0; i < LENGTH(rgzpszRemoveContextMenuExtensions); i++)
  121. {
  122. TCHAR szRegistryKey[256];
  123. Assert(rgzpszRemoveContextMenuExtensions[i] != NULL);
  124. wsprintf(OUT szRegistryKey,
  125. _T("Software\\Microsoft\\MMC\\NodeTypes\\%s\\Extensions\\ContextMenu"),
  126. rgzpszRemoveContextMenuExtensions[i]);
  127. Assert(lstrlen(szRegistryKey) < LENGTH(szRegistryKey));
  128. (void) RegOpenKey(HKEY_LOCAL_MACHINE, szRegistryKey, &hkey);
  129. if (hkey == NULL)
  130. {
  131. // not a problem
  132. continue;
  133. }
  134. (void) RegDeleteValue(hkey, d_szGuidSendConsoleMessageApp);
  135. // ignore error code, the only likely code is ERROR_FILE_NOT_FOUND
  136. RegCloseKey(hkey);
  137. hkey = NULL;
  138. } // for
  139. return hr;
  140. } // DllRegisterServer()
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllUnregisterServer - Removes entries from the system registry
  143. STDAPI DllUnregisterServer(void)
  144. {
  145. _Module.UnregisterServer();
  146. return S_OK;
  147. }