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.

262 lines
7.4 KiB

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