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.

346 lines
10 KiB

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