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.

358 lines
10 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CluAdmEx.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CCluAdmExApp class and DLL initialization
  10. // routines.
  11. //
  12. // Author:
  13. // David Potter (davidp) June 28, 1996
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "resource.h"
  22. #include <initguid.h>
  23. #include <aclui.h> // for ISecurityInformation
  24. #include <CluAdmEx.h>
  25. #include "CluAdmX.h"
  26. #include "ExtObj.h"
  27. #include "RegExt.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. #define IID_DEFINED
  34. #include "ExtObjID_i.c"
  35. CComModule _Module;
  36. #pragma warning(disable : 4701) // local variable may be used without having been initialized
  37. #include <atlimpl.cpp>
  38. #pragma warning(default : 4701)
  39. BEGIN_OBJECT_MAP(ObjectMap)
  40. OBJECT_ENTRY(CLSID_CoCluAdmEx, CExtObject)
  41. END_OBJECT_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // Global Function Prototypes
  44. /////////////////////////////////////////////////////////////////////////////
  45. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
  46. STDAPI DllCanUnloadNow(void);
  47. STDAPI DllRegisterServer(void);
  48. STDAPI DllUnregisterServer(void);
  49. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hcluster);
  50. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hcluster);
  51. /////////////////////////////////////////////////////////////////////////////
  52. // class CCluAdmExApp
  53. /////////////////////////////////////////////////////////////////////////////
  54. class CCluAdmExApp : public CWinApp
  55. {
  56. public:
  57. virtual BOOL InitInstance();
  58. virtual int ExitInstance();
  59. };
  60. CCluAdmExApp theApp;
  61. /////////////////////////////////////////////////////////////////////////////
  62. //++
  63. //
  64. // CCluAdmExApp::InitInstance
  65. //
  66. // Routine Description:
  67. // Initialize this instance of the application.
  68. //
  69. // Arguments:
  70. // None.
  71. //
  72. // Return Value:
  73. // TRUE Application initialized successfully.
  74. // FALSE Error initializing application.
  75. //
  76. //--
  77. /////////////////////////////////////////////////////////////////////////////
  78. BOOL CCluAdmExApp::InitInstance(void)
  79. {
  80. _Module.Init(ObjectMap, m_hInstance);
  81. // Construct the help path.
  82. {
  83. TCHAR szPath[_MAX_PATH];
  84. TCHAR szDrive[_MAX_PATH];
  85. TCHAR szDir[_MAX_DIR];
  86. int cchPath;
  87. VERIFY(::GetSystemWindowsDirectory(szPath, _MAX_PATH));
  88. cchPath = lstrlen(szPath);
  89. if (szPath[cchPath - 1] != _T('\\'))
  90. {
  91. szPath[cchPath++] = _T('\\');
  92. szPath[cchPath] = _T('\0');
  93. } // if: no backslash on the end of the path
  94. lstrcpy(&szPath[cchPath], _T("Help\\"));
  95. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  96. _tmakepath(szPath, szDrive, szDir, _T("cluadmin"), _T(".hlp"));
  97. free((void *) m_pszHelpFilePath);
  98. BOOL bEnable;
  99. bEnable = AfxEnableMemoryTracking(FALSE);
  100. m_pszHelpFilePath = _tcsdup(szPath);
  101. AfxEnableMemoryTracking(bEnable);
  102. } // Construct the help path
  103. return CWinApp::InitInstance();
  104. } //*** CCluAdmExApp::InitInstance()
  105. /////////////////////////////////////////////////////////////////////////////
  106. //++
  107. //
  108. // CCluAdmExApp::ExitInstance
  109. //
  110. // Routine Description:
  111. // Cleans up this instance of the application.
  112. //
  113. // Arguments:
  114. // None.
  115. //
  116. // Return Value:
  117. // Application's exit code. 0 indicates no errors.
  118. //
  119. //--
  120. /////////////////////////////////////////////////////////////////////////////
  121. int CCluAdmExApp::ExitInstance(void)
  122. {
  123. _Module.Term();
  124. return CWinApp::ExitInstance();
  125. } //*** CCluAdmExApp::ExitInstance()
  126. /////////////////////////////////////////////////////////////////////////////
  127. // Used to determine whether the DLL can be unloaded by OLE
  128. STDAPI DllCanUnloadNow(void)
  129. {
  130. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  131. return (AfxDllCanUnloadNow() && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // Returns a class factory to create an object of the requested type
  135. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  136. {
  137. return _Module.GetClassObject(rclsid, riid, ppv);
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. // DllRegisterServer - Adds entries to the system registry
  141. STDAPI DllRegisterServer(void)
  142. {
  143. // registers object, typelib and all interfaces in typelib
  144. return _Module.RegisterServer(FALSE /*bRegTypeLib*/);
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // DllUnregisterServer - Adds entries to the system registry
  148. STDAPI DllUnregisterServer(void)
  149. {
  150. _Module.UnregisterServer();
  151. return S_OK;
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. //++
  155. //
  156. // FormatError
  157. //
  158. // Routine Description:
  159. // Format an error.
  160. //
  161. // Arguments:
  162. // rstrError [OUT] String in which to return the error message.
  163. // dwError [IN] Error code to format.
  164. //
  165. // Return Value:
  166. // None.
  167. //
  168. //--
  169. /////////////////////////////////////////////////////////////////////////////
  170. void FormatError(CString & rstrError, DWORD dwError)
  171. {
  172. DWORD _cch;
  173. TCHAR _szError[512];
  174. _cch = FormatMessage(
  175. FORMAT_MESSAGE_FROM_SYSTEM,
  176. NULL,
  177. dwError,
  178. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  179. _szError,
  180. sizeof(_szError) / sizeof(TCHAR),
  181. 0
  182. );
  183. if (_cch == 0)
  184. {
  185. // Format the NT status code from NTDLL since this hasn't been
  186. // integrated into the system yet.
  187. _cch = FormatMessage(
  188. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  189. ::GetModuleHandle(_T("NTDLL.DLL")),
  190. dwError,
  191. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  192. _szError,
  193. sizeof(_szError) / sizeof(TCHAR),
  194. 0
  195. );
  196. if (_cch == 0)
  197. {
  198. // One last chance: see if ACTIVEDS.DLL can format the status code
  199. HMODULE activeDSHandle = ::LoadLibrary(_T("ACTIVEDS.DLL"));
  200. _cch = FormatMessage(
  201. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  202. activeDSHandle,
  203. dwError,
  204. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  205. _szError,
  206. sizeof(_szError) / sizeof(TCHAR),
  207. 0
  208. );
  209. ::FreeLibrary( activeDSHandle );
  210. } // if: error formatting status code from NTDLL
  211. } // if: error formatting status code from system
  212. if (_cch > 0)
  213. {
  214. rstrError = _szError;
  215. } // if: no error
  216. else
  217. {
  218. #ifdef _DEBUG
  219. DWORD _sc = GetLastError();
  220. TRACE(_T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), _sc, dwError);
  221. #endif
  222. rstrError.Format(_T("Error 0x%08.8x"), dwError);
  223. } // else: error formatting the message
  224. } //*** FormatError()
  225. /////////////////////////////////////////////////////////////////////////////
  226. //++
  227. //
  228. // DllRegisterCluAdminExtension
  229. //
  230. // Routine Description:
  231. // Register the extension with the cluster database.
  232. //
  233. // Arguments:
  234. // hCluster [IN] Handle to the cluster to modify.
  235. //
  236. // Return Value:
  237. // S_OK Extension registered successfully.
  238. // Win32 error code if another failure occurred.
  239. //
  240. //--
  241. /////////////////////////////////////////////////////////////////////////////
  242. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hCluster)
  243. {
  244. HRESULT hr;
  245. HRESULT hrReturn = S_OK;
  246. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  247. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  248. hrReturn = RegisterCluAdminClusterExtension(
  249. hCluster,
  250. &CLSID_CoCluAdmEx
  251. );
  252. if (S_OK == hrReturn)
  253. {
  254. while (*pwszResTypes != L'\0')
  255. {
  256. wprintf(L" %s\n", pwszResTypes);
  257. hr = RegisterCluAdminResourceTypeExtension(
  258. hCluster,
  259. pwszResTypes,
  260. &CLSID_CoCluAdmEx
  261. );
  262. if (hr != S_OK)
  263. hrReturn = hr;
  264. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  265. } // while: more resource types
  266. }
  267. return hrReturn;
  268. } //*** DllRegisterCluAdminExtension()
  269. /////////////////////////////////////////////////////////////////////////////
  270. //++
  271. //
  272. // DllUnregisterCluAdminExtension
  273. //
  274. // Routine Description:
  275. // Unregister the extension with the cluster database.
  276. //
  277. // Arguments:
  278. // hCluster [IN] Handle to the cluster to modify.
  279. //
  280. // Return Value:
  281. // S_OK Extension unregistered successfully.
  282. // Win32 error code if another failure occurred.
  283. //
  284. //--
  285. /////////////////////////////////////////////////////////////////////////////
  286. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hCluster)
  287. {
  288. HRESULT hr;
  289. HRESULT hrReturn = S_OK;
  290. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  291. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  292. hrReturn = UnregisterCluAdminClusterExtension(
  293. hCluster,
  294. &CLSID_CoCluAdmEx
  295. );
  296. if (S_OK == hrReturn)
  297. {
  298. while (*pwszResTypes != L'\0')
  299. {
  300. wprintf(L" %s\n", pwszResTypes);
  301. hr = UnregisterCluAdminResourceTypeExtension(
  302. hCluster,
  303. pwszResTypes,
  304. &CLSID_CoCluAdmEx
  305. );
  306. if (hr != S_OK)
  307. hrReturn = hr;
  308. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  309. } // while: more resource types
  310. }
  311. return hrReturn;
  312. } //*** DllUnregisterCluAdminExtension()