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.

194 lines
5.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997-1999 **/
  4. /**********************************************************************/
  5. /*
  6. smplsnap.cpp
  7. Snapin entry points/registration functions
  8. Note: Proxy/Stub Information
  9. To build a separate proxy/stub DLL,
  10. run nmake -f Snapinps.mak in the project directory.
  11. FILE HISTORY:
  12. */
  13. #include "stdafx.h"
  14. #include "initguid.h"
  15. #include "register.h"
  16. #include "tfsguid.h"
  17. //
  18. // NOTE: The next three items should be changed for each different snapin.
  19. //
  20. // {7AF60DD2-4979-11d1-8A6C-00C04FC33566}
  21. const CLSID CLSID_SnmpSnapin =
  22. { 0x7af60dd2, 0x4979, 0x11d1, { 0x8a, 0x6c, 0x0, 0xc0, 0x4f, 0xc3, 0x35, 0x66 } };
  23. // {7AF60DD3-4979-11d1-8A6C-00C04FC33566}
  24. const GUID CLSID_SnmpSnapinExtension =
  25. { 0x7af60dd3, 0x4979, 0x11d1, { 0x8a, 0x6c, 0x0, 0xc0, 0x4f, 0xc3, 0x35, 0x66 } };
  26. // {7AF60DD4-4979-11d1-8A6C-00C04FC33566}
  27. const GUID CLSID_SnmpSnapinAbout =
  28. { 0x7af60dd4, 0x4979, 0x11d1, { 0x8a, 0x6c, 0x0, 0xc0, 0x4f, 0xc3, 0x35, 0x66 } };
  29. // {7AF60DD5-4979-11d1-8A6C-00C04FC33566}
  30. const GUID GUID_SnmpRootNodeType =
  31. { 0x7af60dd5, 0x4979, 0x11d1, { 0x8a, 0x6c, 0x0, 0xc0, 0x4f, 0xc3, 0x35, 0x66 } };
  32. // Copied and defined from ..\..\filemgmt for structuuidNodetypeService due to compiler error
  33. // {4e410f16-abc1-11d0-b944-00c04fd8d5b0}
  34. const CLSID CLSID_NodetypeService =
  35. { 0x4e410f16, 0xabc1, 0x11d0, { 0xb9, 0x44, 0x0, 0xc0, 0x4f, 0xd8, 0xd5, 0xb0 } };
  36. // {58221C66-EA27-11CF-ADCF-00AA00A80033}
  37. const CLSID CLSID_NodetypeServices =
  38. { 0x58221C66, 0xEA27, 0x11CF, { 0xAD, 0xCF, 0x0, 0xAA, 0x0, 0xA8, 0x0, 0x33 } };
  39. //
  40. // Internal private format
  41. //
  42. //const wchar_t* SNAPIN_INTERNAL = _T("SNAPIN_INTERNAL");
  43. CComModule _Module;
  44. BEGIN_OBJECT_MAP(ObjectMap)
  45. OBJECT_ENTRY(CLSID_SnmpSnapin, CSnmpComponentDataPrimary)
  46. OBJECT_ENTRY(CLSID_SnmpSnapinExtension, CSnmpComponentDataExtension)
  47. OBJECT_ENTRY(CLSID_SnmpSnapinAbout, CSnmpAbout)
  48. END_OBJECT_MAP()
  49. #ifdef _DEBUG
  50. #define new DEBUG_NEW
  51. #undef THIS_FILE
  52. static char THIS_FILE[] = __FILE__;
  53. #endif
  54. class CSnmpSnapinApp : public CWinApp
  55. {
  56. public:
  57. virtual BOOL InitInstance();
  58. virtual int ExitInstance();
  59. };
  60. CSnmpSnapinApp theApp;
  61. CString g_strMachineName;
  62. BOOL CSnmpSnapinApp::InitInstance()
  63. {
  64. _Module.Init(ObjectMap, m_hInstance);
  65. return CWinApp::InitInstance();
  66. }
  67. int CSnmpSnapinApp::ExitInstance()
  68. {
  69. _Module.Term();
  70. return CWinApp::ExitInstance();
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Used to determine whether the DLL can be unloaded by OLE
  74. STDAPI DllCanUnloadNow(void)
  75. {
  76. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  77. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // Returns a class factory to create an object of the requested type
  81. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  82. {
  83. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  84. return _Module.GetClassObject(rclsid, riid, ppv);
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // DllRegisterServer - Adds entries to the system registry
  88. STDAPI DllRegisterServer(void)
  89. {
  90. CString strSnapinExtension;
  91. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  92. //
  93. // registers object, typelib and all interfaces in typelib
  94. //
  95. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  96. ASSERT(SUCCEEDED(hr));
  97. if (FAILED(hr))
  98. return hr;
  99. strSnapinExtension.LoadString(IDS_SNAPIN_DESC);
  100. //
  101. // register the snapin as an extension snapin in the console snapin list
  102. //
  103. hr = RegisterSnapinGUID(&CLSID_SnmpSnapinExtension,
  104. NULL,
  105. &CLSID_SnmpSnapinAbout,
  106. strSnapinExtension,
  107. _T("1.0"),
  108. FALSE);
  109. ASSERT(SUCCEEDED(hr));
  110. if (FAILED(hr))
  111. return hr;
  112. //
  113. // register as an extension of the system service snapin
  114. //
  115. // EricDav 2/18/98 - this now means register as a dynamic extension
  116. // so until the parent of this snapin supports dynamic extensions,
  117. // leave the last parameter NULL.
  118. hr = RegisterAsRequiredExtensionGUID(&CLSID_NodetypeService,
  119. &CLSID_SnmpSnapinExtension,
  120. strSnapinExtension,
  121. EXTENSION_TYPE_PROPERTYSHEET,
  122. NULL //&CLSID_NodetypeServices
  123. );
  124. return hr;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. // DllUnregisterServer - Removes entries from the system registry
  128. STDAPI DllUnregisterServer(void)
  129. {
  130. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  131. HRESULT hr = _Module.UnregisterServer();
  132. ASSERT(SUCCEEDED(hr));
  133. if (FAILED(hr))
  134. return hr;
  135. // un register the snapin
  136. //
  137. hr = UnregisterSnapinGUID(&CLSID_SnmpSnapinExtension);
  138. ASSERT(SUCCEEDED(hr));
  139. if (FAILED(hr))
  140. return hr;
  141. // unregister the snapin nodes
  142. //
  143. hr = UnregisterAsRequiredExtensionGUID(&CLSID_NodetypeService,
  144. &CLSID_SnmpSnapinExtension,
  145. EXTENSION_TYPE_PROPERTYSHEET,
  146. NULL //&CLSID_NodetypeServices
  147. );
  148. ASSERT(SUCCEEDED(hr));
  149. return hr;
  150. }