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.

357 lines
10 KiB

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