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.

285 lines
8.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2000 **/
  4. /**********************************************************************/
  5. /*
  6. ipsmsnap.cpp
  7. IPWirelessMon 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. Based on IPSecMon snapin (files copied, then modified)
  13. */
  14. #include "stdafx.h"
  15. #include "initguid.h"
  16. #include "ncglobal.h" // network console global defines
  17. #include "cmptrmgr.h" // computer menagement snapin stuff
  18. #include "spdutil.h"
  19. #ifdef _DEBUG
  20. void DbgVerifyInstanceCounts();
  21. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  22. #else
  23. #define DEBUG_VERIFY_INSTANCE_COUNTS
  24. #endif
  25. const TCHAR c_szHelpFile[] = _T("wireless.hlp");
  26. CComModule _Module;
  27. BEGIN_OBJECT_MAP(ObjectMap)
  28. OBJECT_ENTRY(CLSID_IpsmSnapin, CIpsmComponentDataPrimary)
  29. OBJECT_ENTRY(CLSID_IpsmSnapinExtension, CIpsmComponentDataExtension)
  30. OBJECT_ENTRY(CLSID_IpsmSnapinAbout, CIpsmAbout)
  31. END_OBJECT_MAP()
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. //
  38. // CIpsmSnapinApp
  39. //
  40. BEGIN_MESSAGE_MAP(CIpsmSnapinApp, CWinApp)
  41. //{{AFX_MSG_MAP(CIpsmSnapinApp)
  42. //ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  43. //}}AFX_MSG_MAP
  44. // Standard file based document commands
  45. //ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  46. //ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  47. // Standard print setup command
  48. //ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  49. // Global help commands
  50. ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpFinder)
  51. ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
  52. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  53. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  54. ON_COMMAND(ID_DEFAULT_HELP, CWinApp::OnHelpIndex)
  55. END_MESSAGE_MAP()
  56. CIpsmSnapinApp theApp;
  57. BOOL CIpsmSnapinApp::InitInstance()
  58. {
  59. _Module.Init(ObjectMap, m_hInstance);
  60. //
  61. // Initialize the CWndIpAddress control window class IPADDRESS
  62. //
  63. CWndIpAddress::CreateWindowClass( m_hInstance ) ;
  64. //
  65. // Initialize use of the WinSock routines
  66. //
  67. WSADATA wsaData ;
  68. if ( ::WSAStartup( MAKEWORD( 1, 1 ), & wsaData ) != 0 )
  69. {
  70. m_bWinsockInited = TRUE;
  71. Trace0("InitInstance: Winsock initialized!\n");
  72. }
  73. else
  74. {
  75. m_bWinsockInited = FALSE;
  76. }
  77. if (m_pszHelpFilePath)
  78. free((void*)m_pszHelpFilePath);
  79. m_pszHelpFilePath=_tcsdup(c_szHelpFile);
  80. return CWinApp::InitInstance();
  81. }
  82. int CIpsmSnapinApp::ExitInstance()
  83. {
  84. _Module.Term();
  85. DEBUG_VERIFY_INSTANCE_COUNTS;
  86. //
  87. // Terminate use of the WinSock routines.
  88. //
  89. if ( m_bWinsockInited )
  90. {
  91. WSACleanup() ;
  92. }
  93. return CWinApp::ExitInstance();
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // Used to determine whether the DLL can be unloaded by OLE
  97. STDAPI DllCanUnloadNow(void)
  98. {
  99. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // Returns a class factory to create an object of the requested type
  104. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  105. {
  106. return _Module.GetClassObject(rclsid, riid, ppv);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////
  109. // DllRegisterServer - Adds entries to the system registry
  110. STDAPI DllRegisterServer(void)
  111. {
  112. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  113. TCHAR szModuleFileName[MAX_PATH * 2 + 1] = {0};
  114. BOOL fGotModuleName = TRUE;
  115. fGotModuleName = (0 != ::GetModuleFileName(
  116. _Module.GetModuleInstance(),
  117. szModuleFileName,
  118. DimensionOf(szModuleFileName) - 1));
  119. szModuleFileName[MAX_PATH * 2] = 0;
  120. //
  121. // registers object, typelib and all interfaces in typelib
  122. //
  123. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  124. ASSERT(SUCCEEDED(hr));
  125. if (FAILED(hr))
  126. return hr;
  127. CString stName;
  128. CString stNameStringIndirect;
  129. stName.LoadString(IDS_SNAPIN_NAME);
  130. stNameStringIndirect.Format(
  131. L"@%s,-%-d", szModuleFileName,
  132. IDS_SNAPIN_DESC);
  133. //
  134. // register the snapin into the console snapin list
  135. //
  136. hr = RegisterSnapinGUID(&CLSID_IpsmSnapin,
  137. &GUID_IpsmRootNodeType,
  138. &CLSID_IpsmSnapinAbout,
  139. (LPCTSTR) stName,
  140. _T("1.0"),
  141. TRUE,
  142. fGotModuleName ? (LPCTSTR)stNameStringIndirect : NULL);
  143. ASSERT(SUCCEEDED(hr));
  144. if (FAILED(hr))
  145. return hr;
  146. CString stExtensionName;
  147. CString stExtensionNameIndirect;
  148. stExtensionName.LoadString(IDS_SNAPIN_EXTENSION);
  149. stExtensionNameIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_EXTENSION);
  150. hr = RegisterSnapinGUID(&CLSID_IpsmSnapinExtension,
  151. NULL,
  152. &CLSID_IpsmSnapinAbout,
  153. (LPCTSTR) stExtensionName,
  154. _T("1.0"),
  155. FALSE,
  156. fGotModuleName ? (LPCTSTR)stExtensionNameIndirect : NULL);
  157. ASSERT(SUCCEEDED(hr));
  158. if (FAILED(hr))
  159. return hr;
  160. //
  161. // register the snapin nodes into the console node list
  162. //
  163. hr = RegisterNodeTypeGUID(&CLSID_IpsmSnapin,
  164. &GUID_IpsmRootNodeType,
  165. _T("Root of Manager"));
  166. ASSERT(SUCCEEDED(hr));
  167. #ifdef __NETWORK_CONSOLE__
  168. hr = RegisterAsRequiredExtensionGUID(&GUID_NetConsRootNodeType,
  169. &CLSID_IpsmSnapinExtension,
  170. (LPCTSTR) stExtensionName,
  171. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  172. &GUID_NetConsRootNodeType); // doesn't matter what this is, just
  173. // needs to be non-null guid
  174. ASSERT(SUCCEEDED(hr));
  175. #endif
  176. hr = RegisterAsRequiredExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  177. &CLSID_IpsmSnapinExtension,
  178. (LPCTSTR) stExtensionName,
  179. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  180. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS); // NULL makes it not dynamic
  181. ASSERT(SUCCEEDED(hr));
  182. return hr;
  183. }
  184. /////////////////////////////////////////////////////////////////////////////
  185. // DllUnregisterServer - Removes entries from the system registry
  186. STDAPI DllUnregisterServer(void)
  187. {
  188. HRESULT hr = _Module.UnregisterServer();
  189. ASSERT(SUCCEEDED(hr));
  190. if (FAILED(hr))
  191. return hr;
  192. // un register the snapin
  193. //
  194. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapin);
  195. ASSERT(SUCCEEDED(hr));
  196. if (FAILED(hr))
  197. return hr;
  198. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapinExtension);
  199. ASSERT(SUCCEEDED(hr));
  200. if (FAILED(hr))
  201. return hr;
  202. // unregister the snapin nodes
  203. //
  204. hr = UnregisterNodeTypeGUID(&GUID_IpsmRootNodeType);
  205. ASSERT(SUCCEEDED(hr));
  206. #ifdef __NETWORK_CONSOLE__
  207. hr = UnregisterAsExtensionGUID(&GUID_NetConsRootNodeType,
  208. &CLSID_IpsmSnapinExtension,
  209. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  210. ASSERT(SUCCEEDED(hr));
  211. #endif
  212. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  213. &CLSID_IpsmSnapinExtension,
  214. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  215. ASSERT(SUCCEEDED(hr));
  216. return hr;
  217. }
  218. #ifdef _DEBUG
  219. void DbgVerifyInstanceCounts()
  220. {
  221. DEBUG_VERIFY_INSTANCE_COUNT(CHandler);
  222. DEBUG_VERIFY_INSTANCE_COUNT(CMTHandler);
  223. DEBUG_VERIFY_INSTANCE_COUNT(CSpdInfo);
  224. }
  225. #endif // _DEBUG