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.

214 lines
6.8 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. CString strSnapinExtensionNameIndirect;
  92. TCHAR szModuleFileName[MAX_PATH * 2 + 1] = {0};
  93. BOOL fGotModuleName = TRUE;
  94. DWORD dwRet;
  95. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  96. dwRet = ::GetModuleFileName(_Module.GetModuleInstance(),
  97. szModuleFileName,
  98. DimensionOf(szModuleFileName)-1);
  99. // According to BUG# 559631,
  100. // when truncation happens, GetModuleFileName will null terminate the
  101. // string and the size of the buffer is returned. The size returned is
  102. // the same as the size of the passed in parameter.
  103. // 0 return or string truncation are considered as failure
  104. fGotModuleName = ( (0 != dwRet) && ((DimensionOf(szModuleFileName)-1) != dwRet) );
  105. //
  106. // registers object, typelib and all interfaces in typelib
  107. //
  108. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  109. ASSERT(SUCCEEDED(hr));
  110. if (FAILED(hr))
  111. return hr;
  112. strSnapinExtension.LoadString(IDS_SNAPIN_DESC);
  113. strSnapinExtensionNameIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_DESC);
  114. //
  115. // register the snapin as an extension snapin in the console snapin list
  116. //
  117. hr = RegisterSnapinGUID(&CLSID_SnmpSnapinExtension,
  118. NULL,
  119. &CLSID_SnmpSnapinAbout,
  120. strSnapinExtension,
  121. _T("1.0"),
  122. FALSE,
  123. fGotModuleName ? (LPCTSTR)strSnapinExtensionNameIndirect : NULL);
  124. ASSERT(SUCCEEDED(hr));
  125. if (FAILED(hr))
  126. return hr;
  127. //
  128. // register as an extension of the system service snapin
  129. //
  130. // EricDav 2/18/98 - this now means register as a dynamic extension
  131. // so until the parent of this snapin supports dynamic extensions,
  132. // leave the last parameter NULL.
  133. hr = RegisterAsRequiredExtensionGUID(&CLSID_NodetypeService,
  134. &CLSID_SnmpSnapinExtension,
  135. strSnapinExtension,
  136. EXTENSION_TYPE_PROPERTYSHEET,
  137. NULL //&CLSID_NodetypeServices
  138. );
  139. return hr;
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllUnregisterServer - Removes entries from the system registry
  143. STDAPI DllUnregisterServer(void)
  144. {
  145. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  146. HRESULT hr = _Module.UnregisterServer();
  147. ASSERT(SUCCEEDED(hr));
  148. if (FAILED(hr))
  149. return hr;
  150. // un register the snapin
  151. //
  152. hr = UnregisterSnapinGUID(&CLSID_SnmpSnapinExtension);
  153. ASSERT(SUCCEEDED(hr));
  154. if (FAILED(hr))
  155. return hr;
  156. // unregister the snapin nodes
  157. //
  158. hr = UnregisterAsRequiredExtensionGUID(&CLSID_NodetypeService,
  159. &CLSID_SnmpSnapinExtension,
  160. EXTENSION_TYPE_PROPERTYSHEET,
  161. NULL //&CLSID_NodetypeServices
  162. );
  163. ASSERT(SUCCEEDED(hr));
  164. return hr;
  165. }