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.

273 lines
7.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dhcpsnap.cpp
  7. DHCP 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 "dhcpcomp.h"
  16. #include "classed.h"
  17. #include "ncglobal.h" // network console global defines
  18. #include "cmptrmgr.h" // computer management snapin NODETYPE
  19. #include "ipaddr.h"
  20. #include "locale.h" // setlocall function call
  21. #ifdef _DEBUG
  22. void DbgVerifyInstanceCounts();
  23. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  24. #else
  25. #define DEBUG_VERIFY_INSTANCE_COUNTS
  26. #endif
  27. CComModule _Module;
  28. BEGIN_OBJECT_MAP(ObjectMap)
  29. OBJECT_ENTRY(CLSID_DhcpSnapin, CDhcpComponentDataPrimary)
  30. OBJECT_ENTRY(CLSID_DhcpSnapinExtension, CDhcpComponentDataExtension)
  31. OBJECT_ENTRY(CLSID_DhcpSnapinAbout, CDhcpAbout)
  32. END_OBJECT_MAP()
  33. #ifdef _DEBUG
  34. #define new DEBUG_NEW
  35. #undef THIS_FILE
  36. static char THIS_FILE[] = __FILE__;
  37. #endif
  38. //
  39. // CDhcpSnapinApp
  40. //
  41. BEGIN_MESSAGE_MAP(CDhcpSnapinApp, CWinApp)
  42. //{{AFX_MSG_MAP(CDhcpSnapinApp)
  43. //ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  44. //}}AFX_MSG_MAP
  45. // Standard file based document commands
  46. //ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  47. //ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  48. // Standard print setup command
  49. //ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  50. // Global help commands
  51. ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpFinder)
  52. ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
  53. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  54. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  55. ON_COMMAND(ID_DEFAULT_HELP, CWinApp::OnHelpIndex)
  56. END_MESSAGE_MAP()
  57. CDhcpSnapinApp theApp;
  58. BOOL CDhcpSnapinApp::InitInstance()
  59. {
  60. _Module.Init(ObjectMap, m_hInstance);
  61. //
  62. // Initialize the CWndIpAddress control window class IPADDRESS
  63. //
  64. CWndIpAddress::CreateWindowClass( m_hInstance ) ;
  65. // register the window class for the hex editor (class ID)
  66. ::RegisterHexEditClass(m_hInstance);
  67. //
  68. // Initialize use of the WinSock routines
  69. //
  70. WSADATA wsaData ;
  71. if ( ::WSAStartup( MAKEWORD( 1, 1 ), & wsaData ) != 0 )
  72. {
  73. m_bWinsockInited = TRUE;
  74. Trace0("InitInstance: Winsock initialized!\n");
  75. }
  76. else
  77. {
  78. m_bWinsockInited = FALSE;
  79. }
  80. // set the default locale for the c runtime to system locale
  81. setlocale(LC_ALL, "");
  82. ::IPAddrInit(m_hInstance);
  83. return CWinApp::InitInstance();
  84. }
  85. int CDhcpSnapinApp::ExitInstance()
  86. {
  87. _Module.Term();
  88. DEBUG_VERIFY_INSTANCE_COUNTS;
  89. //
  90. // Terminate use of the WinSock routines.
  91. //
  92. if ( m_bWinsockInited )
  93. {
  94. WSACleanup() ;
  95. }
  96. return CWinApp::ExitInstance();
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // Used to determine whether the DLL can be unloaded by OLE
  100. STDAPI DllCanUnloadNow(void)
  101. {
  102. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  103. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // Returns a class factory to create an object of the requested type
  107. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  108. {
  109. return _Module.GetClassObject(rclsid, riid, ppv);
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // DllRegisterServer - Adds entries to the system registry
  113. STDAPI DllRegisterServer(void)
  114. {
  115. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  116. //
  117. // registers object, typelib and all interfaces in typelib
  118. //
  119. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  120. ASSERT(SUCCEEDED(hr));
  121. if (FAILED(hr))
  122. return hr;
  123. CString strDesc, strExtDesc, strRootDesc, strVersion;
  124. strDesc.LoadString(IDS_SNAPIN_DESC);
  125. strExtDesc.LoadString(IDS_SNAPIN_EXTENSION_DESC);
  126. strRootDesc.LoadString(IDS_ROOT_DESC);
  127. strVersion.LoadString(IDS_ABOUT_VERSION);
  128. //
  129. // register the snapin into the console snapin list
  130. //
  131. hr = RegisterSnapinGUID(&CLSID_DhcpSnapin,
  132. &GUID_DhcpRootNodeType,
  133. &CLSID_DhcpSnapinAbout,
  134. strDesc,
  135. strVersion,
  136. TRUE);
  137. ASSERT(SUCCEEDED(hr));
  138. if (FAILED(hr))
  139. return hr;
  140. hr = RegisterSnapinGUID(&CLSID_DhcpSnapinExtension,
  141. NULL,
  142. &CLSID_DhcpSnapinAbout,
  143. strExtDesc,
  144. strVersion,
  145. FALSE);
  146. ASSERT(SUCCEEDED(hr));
  147. if (FAILED(hr))
  148. return hr;
  149. //
  150. // register the snapin nodes into the console node list
  151. //
  152. hr = RegisterNodeTypeGUID(&CLSID_DhcpSnapin,
  153. &GUID_DhcpRootNodeType,
  154. strRootDesc);
  155. ASSERT(SUCCEEDED(hr));
  156. #ifdef __NETWORK_CONSOLE__
  157. hr = RegisterAsRequiredExtensionGUID(&GUID_NetConsRootNodeType,
  158. &CLSID_DhcpSnapinExtension,
  159. strExtDesc,
  160. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  161. &CLSID_DhcpSnapinExtension); // doesn't matter what this is,
  162. // just needs to be non-null
  163. ASSERT(SUCCEEDED(hr));
  164. #endif
  165. // extending computer management snapin
  166. hr = RegisterAsRequiredExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  167. &CLSID_DhcpSnapinExtension,
  168. strExtDesc,
  169. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  170. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS); // doesn't matter what this is
  171. // just needs to be non-null
  172. ASSERT(SUCCEEDED(hr));
  173. return hr;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. // DllUnregisterServer - Removes entries from the system registry
  177. STDAPI DllUnregisterServer(void)
  178. {
  179. HRESULT hr = _Module.UnregisterServer();
  180. ASSERT(SUCCEEDED(hr));
  181. if (FAILED(hr))
  182. return hr;
  183. // un register the snapin
  184. //
  185. hr = UnregisterSnapinGUID(&CLSID_DhcpSnapin);
  186. ASSERT(SUCCEEDED(hr));
  187. if (FAILED(hr))
  188. return hr;
  189. hr = UnregisterSnapinGUID(&CLSID_DhcpSnapinExtension);
  190. ASSERT(SUCCEEDED(hr));
  191. if (FAILED(hr))
  192. return hr;
  193. // unregister the snapin nodes
  194. //
  195. hr = UnregisterNodeTypeGUID(&GUID_DhcpRootNodeType);
  196. ASSERT(SUCCEEDED(hr));
  197. #ifdef __NETWORK_CONSOLE__
  198. hr = UnregisterAsExtensionGUID(&GUID_NetConsRootNodeType,
  199. &CLSID_DhcpSnapinExtension,
  200. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  201. #endif
  202. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  203. &CLSID_DhcpSnapinExtension,
  204. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  205. return hr;
  206. }
  207. #ifdef _DEBUG
  208. void DbgVerifyInstanceCounts()
  209. {
  210. DEBUG_VERIFY_INSTANCE_COUNT(CHandler);
  211. DEBUG_VERIFY_INSTANCE_COUNT(CMTHandler);
  212. DEBUG_VERIFY_INSTANCE_COUNT(CTaskList);
  213. DEBUG_VERIFY_INSTANCE_COUNT(CDhcpActiveLease);
  214. DEBUG_VERIFY_INSTANCE_COUNT(CDhcpOptionItem);
  215. DEBUG_VERIFY_INSTANCE_COUNT(COptionsConfig);
  216. }
  217. #endif // _DEBUG