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.

324 lines
8.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // IISClEx3.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CIISCluExApp 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 <CluAdmEx.h>
  24. #include "IISClEx3.h"
  25. #include "ExtObj.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_CoIISClEx3, CExtObject)
  40. END_OBJECT_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Global Function Prototypes
  43. /////////////////////////////////////////////////////////////////////////////
  44. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
  45. STDAPI DllCanUnloadNow(void);
  46. STDAPI DllRegisterServer(void);
  47. STDAPI DllUnregisterServer(void);
  48. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hcluster);
  49. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hcluster);
  50. /////////////////////////////////////////////////////////////////////////////
  51. // class CIISCluExApp
  52. /////////////////////////////////////////////////////////////////////////////
  53. class CIISCluExApp : public CWinApp
  54. {
  55. public:
  56. virtual BOOL InitInstance();
  57. virtual int ExitInstance();
  58. };
  59. CIISCluExApp theApp;
  60. /////////////////////////////////////////////////////////////////////////////
  61. //++
  62. //
  63. // CIISCluExApp::InitInstance
  64. //
  65. // Routine Description:
  66. // Initialize this instance of the application.
  67. //
  68. // Arguments:
  69. // None.
  70. //
  71. // Return Value:
  72. // TRUE Application initialized successfully.
  73. // FALSE Error initializing application.
  74. //
  75. //--
  76. /////////////////////////////////////////////////////////////////////////////
  77. BOOL CIISCluExApp::InitInstance(void)
  78. {
  79. _Module.Init(ObjectMap, m_hInstance);
  80. // Construct the help path.
  81. // This is only necessary if the name of the help file is different
  82. // than the name of this DLL. Remove this code if the name of the
  83. // help file becomes the same as the name of the DLL.
  84. {
  85. TCHAR szPath[_MAX_PATH];
  86. TCHAR szDrive[_MAX_PATH];
  87. TCHAR szDir[_MAX_DIR];
  88. int cchPath;
  89. VERIFY(::GetSystemWindowsDirectory(szPath, _MAX_PATH));
  90. cchPath = lstrlen(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. lstrcpy(&szPath[cchPath], _T("Help\\"));
  97. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  98. _tmakepath(szPath, szDrive, szDir, _T("cluadmin"), _T(".hlp"));
  99. free((void *) m_pszHelpFilePath);
  100. BOOL bEnable;
  101. bEnable = AfxEnableMemoryTracking(FALSE);
  102. m_pszHelpFilePath = _tcsdup(szPath);
  103. AfxEnableMemoryTracking(bEnable);
  104. } // Construct the help path
  105. return CWinApp::InitInstance();
  106. } //*** CIISCluExApp::InitInstance()
  107. /////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // CIISCluExApp::ExitInstance
  111. //
  112. // Routine Description:
  113. // Cleans up this instance of the application.
  114. //
  115. // Arguments:
  116. // None.
  117. //
  118. // Return Value:
  119. // Application's exit code. 0 indicates no errors.
  120. //
  121. //--
  122. /////////////////////////////////////////////////////////////////////////////
  123. int CIISCluExApp::ExitInstance(void)
  124. {
  125. _Module.Term();
  126. return CWinApp::ExitInstance();
  127. } //*** CIISCluExApp::ExitInstance()
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Used to determine whether the DLL can be unloaded by OLE
  130. STDAPI DllCanUnloadNow(void)
  131. {
  132. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  133. return (AfxDllCanUnloadNow() && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // Returns a class factory to create an object of the requested type
  137. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  138. {
  139. return _Module.GetClassObject(rclsid, riid, ppv);
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllRegisterServer - Adds entries to the system registry
  143. STDAPI DllRegisterServer(void)
  144. {
  145. // registers object, typelib and all interfaces in typelib
  146. return _Module.RegisterServer(FALSE /*bRegTypeLib*/);
  147. }
  148. /////////////////////////////////////////////////////////////////////////////
  149. // DllUnregisterServer - Adds entries to the system registry
  150. STDAPI DllUnregisterServer(void)
  151. {
  152. _Module.UnregisterServer();
  153. return S_OK;
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. //++
  157. //
  158. // FormatError
  159. //
  160. // Routine Description:
  161. // Format an error.
  162. //
  163. // Arguments:
  164. // rstrError [OUT] String in which to return the error message.
  165. // dwError [IN] Error code to format.
  166. //
  167. // Return Value:
  168. // None.
  169. //
  170. //--
  171. /////////////////////////////////////////////////////////////////////////////
  172. void FormatError(CString & rstrError, DWORD dwError)
  173. {
  174. DWORD _cch;
  175. TCHAR _szError[512];
  176. _cch = FormatMessage(
  177. FORMAT_MESSAGE_FROM_SYSTEM,
  178. NULL,
  179. dwError,
  180. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  181. _szError,
  182. sizeof(_szError) / sizeof(TCHAR),
  183. 0
  184. );
  185. if (_cch == 0)
  186. {
  187. // Format the NT status code from NTDLL since this hasn't been
  188. // integrated into the system yet.
  189. _cch = FormatMessage(
  190. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  191. ::GetModuleHandle(_T("NTDLL.DLL")),
  192. dwError,
  193. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  194. _szError,
  195. sizeof(_szError) / sizeof(TCHAR),
  196. 0
  197. );
  198. } // if: error formatting status code from system
  199. if (_cch > 0)
  200. {
  201. rstrError = _szError;
  202. } // if: no error
  203. else
  204. {
  205. #ifdef _DEBUG
  206. DWORD _sc = GetLastError();
  207. TRACE(_T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), _sc, dwError);
  208. #endif
  209. rstrError.Format(_T("Error 0x%08.8x"), dwError);
  210. } // else: error formatting the message
  211. } //*** FormatError()
  212. /////////////////////////////////////////////////////////////////////////////
  213. //++
  214. //
  215. // DllRegisterCluAdminExtension
  216. //
  217. // Routine Description:
  218. // Register the extension with the cluster database.
  219. //
  220. // Arguments:
  221. // hCluster [IN] Handle to the cluster to modify.
  222. //
  223. // Return Value:
  224. // S_OK Extension registered successfully.
  225. // Win32 error code if another failure occurred.
  226. //
  227. //--
  228. /////////////////////////////////////////////////////////////////////////////
  229. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hCluster)
  230. {
  231. HRESULT hr = S_OK;
  232. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  233. while (*pwszResTypes != L'\0')
  234. {
  235. wprintf(L" %s\n", pwszResTypes);
  236. hr = RegisterCluAdminResourceTypeExtension(
  237. hCluster,
  238. pwszResTypes,
  239. &CLSID_CoIISClEx3
  240. );
  241. if (hr != S_OK)
  242. break;
  243. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  244. } // while: more resource types
  245. return hr;
  246. } //*** DllRegisterCluAdminExtension()
  247. /////////////////////////////////////////////////////////////////////////////
  248. //++
  249. //
  250. // DllUnregisterCluAdminExtension
  251. //
  252. // Routine Description:
  253. // Unregister the extension with the cluster database.
  254. //
  255. // Arguments:
  256. // hCluster [IN] Handle to the cluster to modify.
  257. //
  258. // Return Value:
  259. // S_OK Extension unregistered successfully.
  260. // Win32 error code if another failure occurred.
  261. //
  262. //--
  263. /////////////////////////////////////////////////////////////////////////////
  264. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hCluster)
  265. {
  266. HRESULT hr = S_OK;
  267. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  268. while (*pwszResTypes != L'\0')
  269. {
  270. wprintf(L" %s\n", pwszResTypes);
  271. hr = UnregisterCluAdminResourceTypeExtension(
  272. hCluster,
  273. pwszResTypes,
  274. &CLSID_CoIISClEx3
  275. );
  276. if (hr != S_OK)
  277. break;
  278. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  279. } // while: more resource types
  280. return hr;
  281. } //*** DllUnregisterCluAdminExtension()