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.

349 lines
8.4 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. NAPMMCDLL.cpp
  6. Abstract:
  7. Implementation of DLL Exports.
  8. Proxy/Stub Information:
  9. To build a separate proxy/stub DLL,
  10. run nmake -f NAPMMCps.mk in the project directory.
  11. Revision History:
  12. mmaguire 11/6/97 - created using MMC snap-in wizard
  13. --*/
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. // BEGIN INCLUDES
  17. //
  18. // standard includes:
  19. //
  20. #include "Precompiled.h"
  21. //
  22. // where we can find declaration for main class in this file:
  23. //
  24. //
  25. // where we can find declarations needed in this file:
  26. //
  27. #include "initguid.h"
  28. #include "NAPMMC_i.c"
  29. // For IComponent, IComponentData, and ISnapinAbout COM classes:
  30. #include "Component.h"
  31. #include "About.h"
  32. #include "LogComp.h"
  33. #include "LogAbout.H"
  34. // For AttributeInfo COM classes:
  35. #include "IASAttributeInfo.h"
  36. #include "IASEnumerableAttributeInfo.h"
  37. // SDO declarations
  38. //TODO: change it when TODD's CLSIDs are ready
  39. //
  40. // Need to include this at least once to compile it in from the common directory:
  41. #include "mmcutility.cpp"
  42. // We are hosting a few extra COM objects in this dll:
  43. // For AttributeEditor COM classes:
  44. #include "IASIPAttributeEditor.h"
  45. #include "IASMultivaluedAttributeEditor.h"
  46. #include "IASVendorSpecificAttributeEditor.h"
  47. #include "IASEnumerableAttributeEditor.h"
  48. #include "IASStringAttributeEditor.h"
  49. #include "IASBooleanAttributeEditor.h"
  50. #include "NTGroups.h"
  51. // For NASVendors COM object:
  52. #include "Vendors.h"
  53. #include <proxyext.h>
  54. #include <proxyres.h>
  55. unsigned int CF_MMC_NodeID = RegisterClipboardFormatW(CCF_NODEID2);
  56. //
  57. // END INCLUDES
  58. //////////////////////////////////////////////////////////////////////////////
  59. CComModule _Module;
  60. BEGIN_OBJECT_MAP(ObjectMap)
  61. OBJECT_ENTRY(CLSID_NAPSnapin, CComponentData)
  62. OBJECT_ENTRY(CLSID_NAPSnapinAbout, CSnapinAbout)
  63. OBJECT_ENTRY(CLSID_LoggingSnapin, CLoggingComponentData)
  64. OBJECT_ENTRY(CLSID_LoggingSnapinAbout, CLoggingSnapinAbout)
  65. OBJECT_ENTRY(CLSID_IASAttributeInfo, CAttributeInfo)
  66. OBJECT_ENTRY(CLSID_IASEnumerableAttributeInfo, CEnumerableAttributeInfo)
  67. OBJECT_ENTRY(CLSID_IASIPAttributeEditor, CIASIPAttributeEditor)
  68. OBJECT_ENTRY(CLSID_IASMultivaluedAttributeEditor, CIASMultivaluedAttributeEditor)
  69. OBJECT_ENTRY(CLSID_IASVendorSpecificAttributeEditor, CIASVendorSpecificAttributeEditor)
  70. OBJECT_ENTRY(CLSID_IASEnumerableAttributeEditor, CIASEnumerableAttributeEditor)
  71. OBJECT_ENTRY(CLSID_IASStringAttributeEditor, CIASStringAttributeEditor)
  72. OBJECT_ENTRY(CLSID_IASBooleanAttributeEditor, CIASBooleanAttributeEditor)
  73. OBJECT_ENTRY(CLSID_IASGroupsAttributeEditor, CIASGroupsAttributeEditor)
  74. OBJECT_ENTRY(CLSID_IASNASVendors, CIASNASVendors)
  75. OBJECT_ENTRY(__uuidof(ProxyExtension), ProxyExtension)
  76. END_OBJECT_MAP()
  77. #if 1 // Use CWinApp for MFC support -- some of the COM objects in this dll use MFC.
  78. class CNAPMMCApp : public CWinApp
  79. {
  80. public:
  81. virtual BOOL InitInstance();
  82. virtual int ExitInstance();
  83. };
  84. CNAPMMCApp theApp;
  85. DWORD g_dwTraceHandle = 0;
  86. //////////////////////////////////////////////////////////////////////////////
  87. /*++
  88. CNAPMMCApp::InitInstance
  89. MFC's dll entry point.
  90. --*/
  91. //////////////////////////////////////////////////////////////////////////////
  92. BOOL CNAPMMCApp::InitInstance()
  93. {
  94. _Module.Init(ObjectMap, m_hInstance);
  95. g_dwTraceHandle = TraceRegister(_T("NapMMC"));
  96. TracePrintf(g_dwTraceHandle, _T("DLL Init"));
  97. // Initialize static class variables of CSnapInItem.
  98. CSnapInItem::Init();
  99. // Initialize any other static class variables.
  100. CMachineNode::InitClipboardFormat();
  101. CLoggingMachineNode::InitClipboardFormat();
  102. return CWinApp::InitInstance();
  103. }
  104. //////////////////////////////////////////////////////////////////////////////
  105. /*++
  106. CNAPMMCApp::ExitInstance
  107. MFC's dll exit point.
  108. --*/
  109. //////////////////////////////////////////////////////////////////////////////
  110. int CNAPMMCApp::ExitInstance()
  111. {
  112. TracePrintf(g_dwTraceHandle, _T("DLL Exit"));
  113. TraceDeregister(g_dwTraceHandle);
  114. _Module.Term();
  115. return CWinApp::ExitInstance();
  116. }
  117. #else // Use CWinApp
  118. //////////////////////////////////////////////////////////////////////////////
  119. /*++
  120. DllMain
  121. Remarks
  122. DLL Entry Point
  123. --*/
  124. //////////////////////////////////////////////////////////////////////////////
  125. extern "C"
  126. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  127. {
  128. if (dwReason == DLL_PROCESS_ATTACH)
  129. {
  130. _Module.Init(ObjectMap, hInstance);
  131. // Initialize static class variables of CSnapInItem.
  132. CSnapInItem::Init();
  133. // Initialize any other static class variables.
  134. CMachineNode::InitClipboardFormat();
  135. DisableThreadLibraryCalls(hInstance);
  136. }
  137. else if (dwReason == DLL_PROCESS_DETACH)
  138. _Module.Term();
  139. return TRUE; // ok
  140. }
  141. #endif // Use CWinApp
  142. //////////////////////////////////////////////////////////////////////////////
  143. /*++
  144. DllCanUnloadNow
  145. Remarks
  146. Used to determine whether the DLL can be unloaded by OLE
  147. --*/
  148. //////////////////////////////////////////////////////////////////////////////
  149. STDAPI DllCanUnloadNow(void)
  150. {
  151. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  152. }
  153. //////////////////////////////////////////////////////////////////////////////
  154. /*++
  155. DllGetClassObject
  156. Remarks
  157. Returns a class factory to create an object of the requested type
  158. --*/
  159. //////////////////////////////////////////////////////////////////////////////
  160. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  161. {
  162. return _Module.GetClassObject(rclsid, riid, ppv);
  163. }
  164. //////////////////////////////////////////////////////////////////////////////
  165. /*++
  166. DllRegisterServer
  167. Remarks
  168. Adds entries to the system registry
  169. --*/
  170. //////////////////////////////////////////////////////////////////////////////
  171. STDAPI DllRegisterServer(void)
  172. {
  173. // Set the protocol.
  174. TCHAR NapName[IAS_MAX_STRING];
  175. TCHAR NapName_Indirect[IAS_MAX_STRING];
  176. TCHAR ModuleName[MAX_PATH];
  177. TCHAR LoggingName[IAS_MAX_STRING];
  178. TCHAR LoggingName_Indirect[IAS_MAX_STRING];
  179. GetModuleFileNameOnly(_Module.GetModuleInstance(), ModuleName, MAX_PATH);
  180. int iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_NAP, NapName, IAS_MAX_STRING );
  181. swprintf(NapName_Indirect, L"@%s,-%-d", ModuleName, IDS_SNAPINNAME_NAP);
  182. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_LOGGING, LoggingName, IAS_MAX_STRING );
  183. swprintf(LoggingName_Indirect, L"@%s,-%-d", ModuleName, IDS_SNAPINNAME_LOGGING);
  184. struct _ATL_REGMAP_ENTRY regMap[] = {
  185. {OLESTR("NAPSNAPIN"), NapName}, // subsitute %NAPSNAPIN% for registry
  186. {OLESTR("NAPSNAPIN_INDIRECT"), NapName_Indirect}, // subsitute %IASSNAPIN% for registry
  187. {OLESTR("LOGGINGSNAPIN"), LoggingName}, // subsitute %LOGGINGSNAPIN% for registry
  188. {OLESTR("LOGGINGSNAPIN_INDIRECT"), LoggingName_Indirect}, // subsitute %IASSNAPIN% for registry
  189. {0, 0}
  190. };
  191. HRESULT hr = _Module.UpdateRegistryFromResource(IDR_NAPSNAPIN, TRUE, regMap);
  192. if (SUCCEEDED(hr))
  193. {
  194. ResourceString proxyName(IDS_PROXY_EXTENSION);
  195. _ATL_REGMAP_ENTRY entries[] =
  196. {
  197. { L"PROXY_EXTENSION", proxyName },
  198. { NULL, NULL }
  199. };
  200. hr = _Module.UpdateRegistryFromResource(
  201. IDR_PROXY_REGISTRY,
  202. TRUE,
  203. entries
  204. );
  205. }
  206. return hr;
  207. }
  208. //////////////////////////////////////////////////////////////////////////////
  209. /*++
  210. DllUnregisterServer
  211. Remarks
  212. Removes entries from the system registry
  213. --*/
  214. //////////////////////////////////////////////////////////////////////////////
  215. STDAPI DllUnregisterServer(void)
  216. {
  217. // Set the protocol.
  218. TCHAR NapName[IAS_MAX_STRING];
  219. TCHAR LoggingName[IAS_MAX_STRING];
  220. int iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_NAP, NapName, IAS_MAX_STRING );
  221. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_LOGGING, LoggingName, IAS_MAX_STRING );
  222. struct _ATL_REGMAP_ENTRY regMap[] = {
  223. {OLESTR("NAPSNAPIN"), NapName}, // subsitute %NAPSNAPIN% for registry
  224. {OLESTR("LOGGINGSNAPIN"), LoggingName}, // subsitute %LOGGINGSNAPIN% for registry
  225. {0, 0}
  226. };
  227. _Module.UpdateRegistryFromResource(IDR_NAPSNAPIN, FALSE, regMap);
  228. _Module.UpdateRegistryFromResource(IDR_PROXY_REGISTRY, FALSE, NULL);
  229. return S_OK;
  230. }