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.

257 lines
5.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: dllmain.cpp
  7. //
  8. // Contents: Module, Object Map and DLL entry points. Most of the code
  9. // in this file is taken from Dns Manager Snapin implementation
  10. //
  11. // History: 07-26-2001 Hiteshr Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "headers.h"
  15. //
  16. //CRoleMgrModule Implementation
  17. //
  18. HRESULT WINAPI CRoleMgrModule::UpdateRegistryCLSID(const CLSID& clsid,
  19. BOOL bRegister)
  20. {
  21. TRACE_METHOD_EX(DEB_DLL, CRoleMgrModule, UpdateRegistryCLSID);
  22. static const WCHAR szIPS32[] = _T("InprocServer32");
  23. static const WCHAR szCLSID[] = _T("CLSID");
  24. HRESULT hRes = S_OK;
  25. LPOLESTR lpOleStrCLSIDValue = NULL;
  26. ::StringFromCLSID(clsid, &lpOleStrCLSIDValue);
  27. if (lpOleStrCLSIDValue == NULL)
  28. {
  29. DBG_OUT_HRESULT(E_OUTOFMEMORY);
  30. return E_OUTOFMEMORY;
  31. }
  32. CRegKey key;
  33. if (bRegister)
  34. {
  35. LONG lRes = key.Open(HKEY_CLASSES_ROOT, szCLSID);
  36. CHECK_LASTERROR(lRes);
  37. if (lRes == ERROR_SUCCESS)
  38. {
  39. lRes = key.Create(key, lpOleStrCLSIDValue);
  40. CHECK_LASTERROR(lRes);
  41. if (lRes == ERROR_SUCCESS)
  42. {
  43. WCHAR szModule[_MAX_PATH + 1];
  44. ZeroMemory(szModule,sizeof(szModule));
  45. ::GetModuleFileName(m_hInst, szModule, _MAX_PATH);
  46. lRes = key.SetKeyValue(szIPS32, szModule);
  47. CHECK_LASTERROR(lRes);
  48. }
  49. }
  50. if (lRes != ERROR_SUCCESS)
  51. hRes = HRESULT_FROM_WIN32(lRes);
  52. }
  53. else
  54. {
  55. key.Attach(HKEY_CLASSES_ROOT);
  56. if (key.Open(key, szCLSID) == ERROR_SUCCESS)
  57. key.RecurseDeleteKey(lpOleStrCLSIDValue);
  58. }
  59. ::CoTaskMemFree(lpOleStrCLSIDValue);
  60. return hRes;
  61. }
  62. //
  63. //Module
  64. //
  65. CRoleMgrModule _Module;
  66. //
  67. //Object Pikcer Clipboard format
  68. //
  69. UINT g_cfDsSelectionList = 0;
  70. //
  71. //Object Map
  72. //
  73. BEGIN_OBJECT_MAP(ObjectMap)
  74. OBJECT_ENTRY(CLSID_RoleSnapin, CRoleComponentDataObject) // standalone snapin
  75. OBJECT_ENTRY(CLSID_RoleSnapinAbout, CRoleSnapinAbout) // standalone snapin about
  76. END_OBJECT_MAP()
  77. CCommandLineOptions commandLineOptions;
  78. //
  79. //CRoleSnapinApp implementation
  80. //
  81. BOOL CRoleSnapinApp::InitInstance()
  82. {
  83. #if (DBG == 1)
  84. CDbg::s_idxTls = TlsAlloc();
  85. #endif // (DBG == 1)
  86. TRACE_METHOD_EX(DEB_DLL,CRoleSnapinApp,InitInstance);
  87. _Module.Init(ObjectMap, m_hInstance);
  88. g_cfDsSelectionList = RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
  89. //
  90. // Add theming support
  91. //
  92. SHFusionInitializeFromModuleID(m_hInstance, 2);
  93. //
  94. //Load Menus, Header Strings etc.
  95. //
  96. if (!CRoleComponentDataObject::LoadResources())
  97. return FALSE;
  98. commandLineOptions.Initialize();
  99. //Register Class for link window
  100. LinkWindow_RegisterClass();
  101. return CWinApp::InitInstance();
  102. }
  103. int CRoleSnapinApp::ExitInstance()
  104. {
  105. TRACE_METHOD_EX(DEB_DLL,CRoleSnapinApp,ExitInstance);
  106. //
  107. //Theming support
  108. //
  109. SHFusionUninitialize();
  110. //Unregister class for link window
  111. LinkWindow_UnregisterClass(m_hInstance);
  112. //
  113. //CComModule Termintaion
  114. //
  115. _Module.Term();
  116. return CWinApp::ExitInstance();
  117. }
  118. CRoleSnapinApp theApp;
  119. //
  120. //Exported Functions
  121. //
  122. STDAPI DllCanUnloadNow(void)
  123. {
  124. TRACE_FUNCTION_EX(DEB_DLL,DllCanUnloadNow);
  125. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  126. if ((AfxDllCanUnloadNow() == S_OK) && (_Module.GetLockCount()==0))
  127. {
  128. Dbg(DEB_DLL, "Can Unload\n");
  129. return S_OK;
  130. }
  131. else
  132. {
  133. Dbg(DEB_DLL, "Cannot Unload, %u locks\n",_Module.GetLockCount());
  134. return S_FALSE;
  135. }
  136. }
  137. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  138. {
  139. TRACE_FUNCTION_EX(DEB_DLL, DllGetClassObject);
  140. return _Module.GetClassObject(rclsid, riid, ppv);
  141. }
  142. //
  143. //Add the Guids of nodes which can be extended by other snapin
  144. //
  145. static _NODE_TYPE_INFO_ENTRY NodeTypeInfoEntryArray[] = {
  146. { NULL, NULL }
  147. };
  148. STDAPI DllRegisterServer(void)
  149. {
  150. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  151. TRACE_FUNCTION_EX(DEB_DLL, DllRegisterServer);
  152. //
  153. // registers all objects
  154. //
  155. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  156. if (FAILED(hr))
  157. {
  158. DBG_OUT_HRESULT(hr);
  159. return hr;
  160. }
  161. CString szVersion = VER_PRODUCTVERSION_STR;
  162. CString szProvider = VER_COMPANYNAME_STR;
  163. CString szSnapinName;
  164. szSnapinName.LoadString(IDS_SNAPIN_NAME);
  165. //
  166. // Register the standalone Role snapin into the console snapin list
  167. //
  168. hr = RegisterSnapin(&CLSID_RoleSnapin,
  169. &CRoleRootData::NodeTypeGUID,
  170. &CLSID_RoleSnapinAbout,
  171. szSnapinName,
  172. szVersion,
  173. szProvider,
  174. FALSE,
  175. NodeTypeInfoEntryArray,
  176. IDS_SNAPIN_NAME);
  177. if (FAILED(hr))
  178. {
  179. DBG_OUT_HRESULT(hr);
  180. return hr;
  181. }
  182. return hr;
  183. }
  184. STDAPI DllUnregisterServer(void)
  185. {
  186. TRACE_FUNCTION_EX(DEB_DLL, DllUnregisterServer);
  187. HRESULT hr = _Module.UnregisterServer();
  188. ASSERT(SUCCEEDED(hr));
  189. //
  190. // Un register the standalone snapin
  191. //
  192. hr = UnregisterSnapin(&CLSID_RoleSnapin);
  193. ASSERT(SUCCEEDED(hr));
  194. //
  195. // unregister the snapin nodes,
  196. // this removes also the server node, with the Services Snapin extension keys
  197. //
  198. for (_NODE_TYPE_INFO_ENTRY* pCurrEntry = NodeTypeInfoEntryArray;
  199. pCurrEntry->m_pNodeGUID != NULL; pCurrEntry++)
  200. {
  201. hr = UnregisterNodeType(pCurrEntry->m_pNodeGUID);
  202. ASSERT(SUCCEEDED(hr));
  203. }
  204. ASSERT(SUCCEEDED(hr));
  205. return S_OK;
  206. }