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.

336 lines
8.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 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. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include <initguid.h>
  22. #include <CluAdmEx.h>
  23. #include "ClNetResEx.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_CoClNetResEx, 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 CClNetResApp
  52. /////////////////////////////////////////////////////////////////////////////
  53. class CClNetResApp : public CWinApp
  54. {
  55. public:
  56. virtual BOOL InitInstance();
  57. virtual int ExitInstance();
  58. }; //*** class CClNetResApp
  59. /////////////////////////////////////////////////////////////////////////////
  60. // The one and only CClNetResApp object
  61. CClNetResApp theApp;
  62. /////////////////////////////////////////////////////////////////////////////
  63. //++
  64. //
  65. // CClNetResApp::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 CClNetResApp::InitInstance( void )
  79. {
  80. // Construct the help path.
  81. {
  82. TCHAR szPath[_MAX_PATH];
  83. TCHAR szDrive[_MAX_PATH];
  84. TCHAR szDir[_MAX_DIR];
  85. int cchPath;
  86. VERIFY(::GetSystemWindowsDirectory(szPath, _MAX_PATH));
  87. cchPath = lstrlen(szPath);
  88. if (szPath[cchPath - 1] != _T('\\'))
  89. {
  90. szPath[cchPath++] = _T('\\');
  91. szPath[cchPath] = _T('\0');
  92. } // if: no backslash on the end of the path
  93. lstrcpy(&szPath[cchPath], _T("Help\\"));
  94. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  95. _tmakepath(szPath, szDrive, szDir, _T("cluadmin"), _T(".hlp"));
  96. free((void *) m_pszHelpFilePath);
  97. BOOL bEnable;
  98. bEnable = AfxEnableMemoryTracking(FALSE);
  99. m_pszHelpFilePath = _tcsdup(szPath);
  100. AfxEnableMemoryTracking(bEnable);
  101. } // Construct the help path
  102. _Module.Init( ObjectMap, m_hInstance );
  103. return CWinApp::InitInstance();
  104. } //*** CClNetResApp::InitInstance()
  105. /////////////////////////////////////////////////////////////////////////////
  106. //++
  107. //
  108. // CClNetResApp::ExitInstance
  109. //
  110. // Description:
  111. // Deinitialize this instance of the application.
  112. //
  113. // Arguments:
  114. // None.
  115. //
  116. // Return Value:
  117. // Any return codes from CWinApp::ExitInstance().
  118. //
  119. //--
  120. /////////////////////////////////////////////////////////////////////////////
  121. int CClNetResApp::ExitInstance( void )
  122. {
  123. _Module.Term();
  124. return CWinApp::ExitInstance();
  125. } //*** CClNetResApp::ExitInstance()
  126. /////////////////////////////////////////////////////////////////////////////
  127. //++
  128. //
  129. // FormatError
  130. //
  131. // Description:
  132. // Format an error.
  133. //
  134. // Arguments:
  135. // rstrError [OUT] String in which to return the error message.
  136. // dwError [IN] Error code to format.
  137. //
  138. // Return Value:
  139. // None.
  140. //
  141. //--
  142. /////////////////////////////////////////////////////////////////////////////
  143. void FormatError( CString & rstrError, DWORD dwError )
  144. {
  145. DWORD _cch;
  146. TCHAR _szError[ 512 ];
  147. _cch = ::FormatMessage(
  148. FORMAT_MESSAGE_FROM_SYSTEM,
  149. NULL,
  150. dwError,
  151. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  152. _szError,
  153. sizeof( _szError ) / sizeof( TCHAR ),
  154. 0
  155. );
  156. if ( _cch == 0 )
  157. {
  158. // Format the NT status code from NTDLL since this hasn't been
  159. // integrated into the system yet.
  160. _cch = ::FormatMessage(
  161. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  162. ::GetModuleHandle( _T("NTDLL.DLL") ),
  163. dwError,
  164. MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ),
  165. _szError,
  166. sizeof( _szError ) / sizeof( TCHAR ),
  167. 0
  168. );
  169. } // if: error formatting status code from system
  170. if ( _cch != 0 )
  171. {
  172. rstrError = _szError;
  173. } // if: error occurred
  174. else
  175. {
  176. #ifdef _DEBUG
  177. DWORD _sc = GetLastError();
  178. TRACE( _T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), _sc, dwError );
  179. #endif
  180. rstrError.Format( _T("Error 0x%08.8x"), dwError );
  181. } // else: error formatting the message
  182. } //*** FormatError()
  183. /////////////////////////////////////////////////////////////////////////////
  184. // Used to determine whether the DLL can be unloaded by OLE
  185. STDAPI DllCanUnloadNow( void )
  186. {
  187. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  188. return ( AfxDllCanUnloadNow() && _Module.GetLockCount() == 0 ) ? S_OK : S_FALSE;
  189. } //*** DllCanUnloadNow()
  190. /////////////////////////////////////////////////////////////////////////////
  191. // Returns a class factory to create an object of the requested type
  192. STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID * ppv )
  193. {
  194. return _Module.GetClassObject( rclsid, riid, ppv );
  195. } //*** DllGetClassObject()
  196. /////////////////////////////////////////////////////////////////////////////
  197. // DllRegisterServer - Adds entries to the system registry
  198. STDAPI DllRegisterServer( void )
  199. {
  200. HRESULT hRes = S_OK;
  201. // registers object, typelib and all interfaces in typelib
  202. hRes = _Module.RegisterServer( FALSE /*bRegTypeLib*/ );
  203. return hRes;
  204. } //*** DllRegisterServer()
  205. /////////////////////////////////////////////////////////////////////////////
  206. // DllUnregisterServer - Removes entries from the system registry
  207. STDAPI DllUnregisterServer( void )
  208. {
  209. HRESULT hRes = S_OK;
  210. _Module.UnregisterServer();
  211. return hRes;
  212. } //*** DllUnregisterServer()
  213. /////////////////////////////////////////////////////////////////////////////
  214. //++
  215. //
  216. // DllRegisterCluAdminExtension
  217. //
  218. // Description:
  219. // Register the extension with the cluster database.
  220. //
  221. // Arguments:
  222. // hCluster [IN] Handle to the cluster to modify.
  223. //
  224. // Return Value:
  225. // S_OK Extension registered successfully.
  226. // Win32 error code if another failure occurred.
  227. //
  228. //--
  229. /////////////////////////////////////////////////////////////////////////////
  230. STDAPI DllRegisterCluAdminExtension( IN HCLUSTER hCluster )
  231. {
  232. HRESULT hr;
  233. HRESULT hrReturn = S_OK;
  234. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  235. while ( *pwszResTypes != L'\0' )
  236. {
  237. wprintf( L" %s\n", pwszResTypes );
  238. hr = RegisterCluAdminResourceTypeExtension(
  239. hCluster,
  240. pwszResTypes,
  241. &CLSID_CoClNetResEx
  242. );
  243. if ( hr != S_OK )
  244. {
  245. hrReturn = hr;
  246. } // if: error registering the extension
  247. pwszResTypes += lstrlenW( pwszResTypes ) + 1;
  248. } // while: more resource types
  249. return hrReturn;
  250. } //*** DllRegisterCluAdminExtension()
  251. /////////////////////////////////////////////////////////////////////////////
  252. //++
  253. //
  254. // DllUnregisterCluAdminExtension
  255. //
  256. // Description:
  257. // Unregister the extension with the cluster database.
  258. //
  259. // Arguments:
  260. // hCluster [IN] Handle to the cluster to modify.
  261. //
  262. // Return Value:
  263. // S_OK Extension unregistered successfully.
  264. // Win32 error code if another failure occurred.
  265. //
  266. //--
  267. /////////////////////////////////////////////////////////////////////////////
  268. STDAPI DllUnregisterCluAdminExtension( IN HCLUSTER hCluster )
  269. {
  270. HRESULT hr;
  271. HRESULT hrReturn = S_OK;
  272. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  273. while ( *pwszResTypes != L'\0' )
  274. {
  275. wprintf( L" %s\n", pwszResTypes );
  276. hr = UnregisterCluAdminResourceTypeExtension(
  277. hCluster,
  278. pwszResTypes,
  279. &CLSID_CoClNetResEx
  280. );
  281. if ( hr != S_OK )
  282. {
  283. hrReturn = hr;
  284. } // if: error unregistering the extension
  285. pwszResTypes += lstrlenW( pwszResTypes ) + 1;
  286. } // while: more resource types
  287. return hrReturn;
  288. } //*** DllUnregisterCluAdminExtension()