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.

348 lines
9.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. rtrsnap.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 "ipxcomp.h"
  15. #include "ripcomp.h"
  16. #include "sapcomp.h"
  17. #include "register.h"
  18. #include "ipxguid.h"
  19. #include "dialog.h"
  20. #ifdef _DEBUG
  21. void DbgVerifyInstanceCounts();
  22. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  23. #else
  24. #define DEBUG_VERIFY_INSTANCE_COUNTS
  25. #endif
  26. CComModule _Module;
  27. BEGIN_OBJECT_MAP(ObjectMap)
  28. OBJECT_ENTRY(CLSID_IPXAdminExtension, CIPXComponentDataExtension)
  29. OBJECT_ENTRY(CLSID_IPXAdminAbout, CIPXAbout)
  30. OBJECT_ENTRY(CLSID_IPXRipExtension, CRipComponentData)
  31. OBJECT_ENTRY(CLSID_IPXRipExtensionAbout, CRipAbout)
  32. OBJECT_ENTRY(CLSID_IPXSapExtension, CSapComponentData)
  33. OBJECT_ENTRY(CLSID_IPXSapExtensionAbout, CSapAbout)
  34. END_OBJECT_MAP()
  35. /*---------------------------------------------------------------------------
  36. This is a list of snapins to be registered into the main snapin list.
  37. ---------------------------------------------------------------------------*/
  38. struct RegisteredSnapins
  39. {
  40. const GUID * m_pGuid;
  41. const GUID * m_pGuidAbout;
  42. UINT m_uDesc;
  43. LPCTSTR m_pszVersion;
  44. };
  45. const static RegisteredSnapins s_rgRegisteredSnapins[] =
  46. {
  47. { &CLSID_IPXAdminExtension, &CLSID_IPXAdminAbout,
  48. IDS_IPXADMIN_DISPLAY_NAME, _T("1.0") },
  49. { &CLSID_IPXRipExtension, &CLSID_IPXRipExtensionAbout,
  50. IDS_IPXRIP_DISPLAY_NAME, _T("1.0") },
  51. { &CLSID_IPXSapExtension, &CLSID_IPXSapExtensionAbout,
  52. IDS_IPXSAP_DISPLAY_NAME, _T("1.0") },
  53. };
  54. /*---------------------------------------------------------------------------
  55. This is a list of nodetypes that need to be registered.
  56. ---------------------------------------------------------------------------*/
  57. struct RegisteredNodeTypes
  58. {
  59. const GUID *m_pGuidSnapin;
  60. const GUID *m_pGuid;
  61. LPCTSTR m_pszName;
  62. };
  63. const static RegisteredNodeTypes s_rgNodeTypes[] =
  64. {
  65. { &CLSID_IPXAdminExtension, &GUID_IPXRootNodeType,
  66. _T("Root of IPX Admin Snapin") },
  67. { &CLSID_IPXAdminExtension, &GUID_IPXNodeType,
  68. _T("IPX Admin Snapin") },
  69. { &CLSID_IPXAdminExtension, &GUID_IPXSummaryNodeType,
  70. _T("IPX General") },
  71. { &CLSID_IPXAdminExtension, &GUID_IPXSummaryInterfaceNodeType,
  72. _T("IPX Interface General") },
  73. { &CLSID_IPXAdminExtension, &GUID_IPXNetBIOSBroadcastsNodeType,
  74. _T("IPX NetBIOS Broadcasts") },
  75. { &CLSID_IPXAdminExtension, &GUID_IPXNetBIOSBroadcastsInterfaceNodeType,
  76. _T("IPX Interface NetBIOS Broadcasts") },
  77. { &CLSID_IPXAdminExtension, &GUID_IPXStaticRoutesNodeType,
  78. _T("IPX Static Routes") },
  79. { &CLSID_IPXAdminExtension, &GUID_IPXStaticRoutesResultNodeType,
  80. _T("IPX Static Routes result item") },
  81. { &CLSID_IPXAdminExtension, &GUID_IPXStaticServicesNodeType,
  82. _T("IPX Static Services") },
  83. { &CLSID_IPXAdminExtension, &GUID_IPXStaticServicesResultNodeType,
  84. _T("IPX Static Services result item") },
  85. { &CLSID_IPXAdminExtension, &GUID_IPXStaticNetBIOSNamesNodeType,
  86. _T("IPX Static NetBIOS Names") },
  87. { &CLSID_IPXAdminExtension, &GUID_IPXStaticNetBIOSNamesResultNodeType,
  88. _T("IPX Static NetBIOS Names result item") },
  89. { &CLSID_IPXRipExtension, &GUID_IPXRipNodeType,
  90. _T("IPX RIP") },
  91. { &CLSID_IPXSapExtension, &GUID_IPXSapNodeType,
  92. _T("IPX SAP") },
  93. };
  94. /*---------------------------------------------------------------------------
  95. This is a list of GUIDs that the IPX admin extension extends.
  96. ---------------------------------------------------------------------------*/
  97. const static GUID * s_pExtensionGuids[] =
  98. {
  99. // &GUID_RouterIfAdminNodeType,
  100. &GUID_RouterMachineNodeType,
  101. };
  102. /*---------------------------------------------------------------------------
  103. This is a list of GUIDS that extend the IPX root node
  104. ---------------------------------------------------------------------------*/
  105. struct RegisteredExtensions
  106. {
  107. const CLSID *m_pClsid;
  108. LPCTSTR m_pszName;
  109. };
  110. const static RegisteredExtensions s_rgIPXExtensions[] =
  111. {
  112. { &CLSID_IPXRipExtension, _T("IPX RIP") },
  113. { &CLSID_IPXSapExtension, _T("IPX SAP") },
  114. };
  115. #ifdef _DEBUG
  116. #define new DEBUG_NEW
  117. #undef THIS_FILE
  118. static char THIS_FILE[] = __FILE__;
  119. #endif
  120. class CIPXAdminSnapinApp : public CWinApp
  121. {
  122. public:
  123. virtual BOOL InitInstance();
  124. virtual int ExitInstance();
  125. };
  126. CIPXAdminSnapinApp theApp;
  127. BOOL CIPXAdminSnapinApp::InitInstance()
  128. {
  129. _Module.Init(ObjectMap, m_hInstance);
  130. // Initialize the error handling system
  131. InitializeTFSError();
  132. // Create an error object for this thread
  133. CreateTFSErrorInfo(0);
  134. // Setup the proper help file
  135. free((void *) m_pszHelpFilePath);
  136. m_pszHelpFilePath = _tcsdup(_T("mprsnap.hlp"));
  137. // Setup the global help function
  138. extern DWORD * IpxSnapHelpMap(DWORD dwIDD);
  139. SetGlobalHelpMapFunction(IpxSnapHelpMap);
  140. return CWinApp::InitInstance();
  141. }
  142. int CIPXAdminSnapinApp::ExitInstance()
  143. {
  144. _Module.Term();
  145. // Destroy the TFS error information for this thread
  146. DestroyTFSErrorInfo(0);
  147. // Cleanup the entire error system
  148. CleanupTFSError();
  149. DEBUG_VERIFY_INSTANCE_COUNTS;
  150. return CWinApp::ExitInstance();
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // Used to determine whether the DLL can be unloaded by OLE
  154. STDAPI DllCanUnloadNow(void)
  155. {
  156. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  157. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  158. }
  159. /////////////////////////////////////////////////////////////////////////////
  160. // Returns a class factory to create an object of the requested type
  161. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  162. {
  163. return _Module.GetClassObject(rclsid, riid, ppv);
  164. }
  165. /////////////////////////////////////////////////////////////////////////////
  166. // DllRegisterServer - Adds entries to the system registry
  167. STDAPI DllRegisterServer(void)
  168. {
  169. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  170. int i;
  171. CString st;
  172. CString stNameStringIndirect;
  173. TCHAR moduleFileName[MAX_PATH * 2];
  174. GetModuleFileNameOnly(_Module.GetModuleInstance(), moduleFileName, MAX_PATH * 2);
  175. // registers object, typelib and all interfaces in typelib
  176. //
  177. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  178. Assert(SUCCEEDED(hr));
  179. if (FAILED(hr))
  180. return hr;
  181. // Register he extension snapins into the snapin list.
  182. for (i=0; i<DimensionOf(s_rgRegisteredSnapins); i++)
  183. {
  184. st.LoadString(s_rgRegisteredSnapins[i].m_uDesc);
  185. stNameStringIndirect.Format(L"@%s,-%-d", moduleFileName, s_rgRegisteredSnapins[i].m_uDesc);
  186. hr = RegisterSnapinGUID(s_rgRegisteredSnapins[i].m_pGuid,
  187. NULL,
  188. s_rgRegisteredSnapins[i].m_pGuidAbout,
  189. st,
  190. s_rgRegisteredSnapins[i].m_pszVersion,
  191. FALSE,
  192. stNameStringIndirect);
  193. Assert(SUCCEEDED(hr));
  194. // It would be REALLY bad if any one of these fails
  195. if (!FHrSucceeded(hr))
  196. break;
  197. }
  198. if (FAILED(hr))
  199. return hr;
  200. // register the snapin nodes into the console node list
  201. //
  202. for (i=0; i<DimensionOf(s_rgNodeTypes); i++)
  203. {
  204. hr = RegisterNodeTypeGUID(s_rgNodeTypes[i].m_pGuidSnapin,
  205. s_rgNodeTypes[i].m_pGuid,
  206. s_rgNodeTypes[i].m_pszName);
  207. Assert(SUCCEEDED(hr));
  208. }
  209. //
  210. // register as an extension of the router machine node extension
  211. //
  212. for (i=0; i<DimensionOf(s_pExtensionGuids); i++)
  213. {
  214. hr = RegisterAsRequiredExtensionGUID(s_pExtensionGuids[i],
  215. &CLSID_IPXAdminExtension,
  216. _T("Routing IPX Admin extension"),
  217. EXTENSION_TYPE_NAMESPACE,
  218. &CLSID_RouterSnapin);
  219. Assert(SUCCEEDED(hr));
  220. }
  221. for (i=0; i<DimensionOf(s_rgIPXExtensions); i++)
  222. {
  223. hr = RegisterAsRequiredExtensionGUID(&GUID_IPXNodeType,
  224. s_rgIPXExtensions[i].m_pClsid,
  225. s_rgIPXExtensions[i].m_pszName,
  226. EXTENSION_TYPE_NAMESPACE,
  227. &CLSID_IPXAdminExtension);
  228. Assert(SUCCEEDED(hr));
  229. }
  230. return hr;
  231. }
  232. /////////////////////////////////////////////////////////////////////////////
  233. // DllUnregisterServer - Removes entries from the system registry
  234. STDAPI DllUnregisterServer(void)
  235. {
  236. int i;
  237. HRESULT hr = _Module.UnregisterServer();
  238. Assert(SUCCEEDED(hr));
  239. if (FAILED(hr))
  240. return hr;
  241. // unregister the snapin nodes
  242. //
  243. for (i=0; i<DimensionOf(s_pExtensionGuids); i++)
  244. {
  245. hr = UnregisterAsRequiredExtensionGUID(s_pExtensionGuids[i],
  246. &CLSID_IPXAdminExtension,
  247. EXTENSION_TYPE_NAMESPACE,
  248. &CLSID_RouterSnapin);
  249. Assert(SUCCEEDED(hr));
  250. }
  251. for (i=0; i<DimensionOf(s_rgIPXExtensions); i++)
  252. {
  253. hr = UnregisterAsRequiredExtensionGUID(&GUID_IPXNodeType,
  254. s_rgIPXExtensions[i].m_pClsid,
  255. EXTENSION_TYPE_NAMESPACE,
  256. &CLSID_IPXAdminExtension);
  257. Assert(SUCCEEDED(hr));
  258. }
  259. for (i=0; i<DimensionOf(s_rgNodeTypes); i++)
  260. {
  261. hr = UnregisterNodeTypeGUID(s_rgNodeTypes[i].m_pGuid);
  262. Assert(SUCCEEDED(hr));
  263. }
  264. // un register the snapin
  265. //
  266. for (i=0; i<DimensionOf(s_rgRegisteredSnapins); i++)
  267. {
  268. hr = UnregisterSnapinGUID(s_rgRegisteredSnapins[i].m_pGuid);
  269. Assert(SUCCEEDED(hr));
  270. }
  271. return hr;
  272. }
  273. #ifdef _DEBUG
  274. void DbgVerifyInstanceCounts()
  275. {
  276. DEBUG_VERIFY_INSTANCE_COUNT(BaseIPXResultHandler);
  277. DEBUG_VERIFY_INSTANCE_COUNT(IPXAdminNodeHandler);
  278. DEBUG_VERIFY_INSTANCE_COUNT(IPXConnection);
  279. DEBUG_VERIFY_INSTANCE_COUNT(IpxInfoStatistics);
  280. DEBUG_VERIFY_INSTANCE_COUNT(IPXRootHandler);
  281. DEBUG_VERIFY_INSTANCE_COUNT(IpxSRHandler);
  282. DEBUG_VERIFY_INSTANCE_COUNT(RootHandler);
  283. }
  284. #endif