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.

351 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1997 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // IISClEx4.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 "IISClEx4.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. #include <atlimpl.cpp>
  36. BEGIN_OBJECT_MAP(ObjectMap)
  37. OBJECT_ENTRY(CLSID_CoIISClEx4, CExtObject)
  38. END_OBJECT_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Global Function Prototypes
  41. /////////////////////////////////////////////////////////////////////////////
  42. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
  43. STDAPI DllCanUnloadNow(void);
  44. STDAPI DllRegisterServer(void);
  45. STDAPI DllUnregisterServer(void);
  46. HRESULT HrDeleteKey(IN const CString & rstrKey);
  47. STDAPI DllGetCluAdminExtensionCaps(
  48. OUT DWORD * pdwCaps,
  49. OUT CLSID * pclsid,
  50. OUT LPWSTR pwszResTypeNames,
  51. IN OUT DWORD * pcchResTypeNames
  52. );
  53. /////////////////////////////////////////////////////////////////////////////
  54. // class CIISCluExApp
  55. /////////////////////////////////////////////////////////////////////////////
  56. class CIISCluExApp : public CWinApp
  57. {
  58. public:
  59. virtual BOOL InitInstance();
  60. virtual int ExitInstance();
  61. private:
  62. TCHAR szHelpPath[MAX_PATH+1];
  63. };
  64. CIISCluExApp theApp;
  65. BOOL CIISCluExApp::InitInstance()
  66. {
  67. _Module.Init(ObjectMap, m_hInstance);
  68. //
  69. // Setup the help file
  70. //
  71. if (GetWindowsDirectory(szHelpPath, MAX_PATH))
  72. {
  73. lstrcat(szHelpPath,_T("\\help\\iishelp\\iis\\winhelp\\iisclex4.hlp"));
  74. m_pszHelpFilePath = szHelpPath;
  75. }
  76. return CWinApp::InitInstance();
  77. }
  78. int CIISCluExApp::ExitInstance()
  79. {
  80. m_pszHelpFilePath = NULL;
  81. _Module.Term();
  82. return CWinApp::ExitInstance();
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Used to determine whether the DLL can be unloaded by OLE
  86. STDAPI DllCanUnloadNow(void)
  87. {
  88. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  89. return (AfxDllCanUnloadNow() && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // Returns a class factory to create an object of the requested type
  93. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  94. {
  95. return _Module.GetClassObject(rclsid, riid, ppv);
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // DllRegisterServer - Adds entries to the system registry
  99. STDAPI DllRegisterServer(void)
  100. {
  101. HRESULT hRes = S_OK;
  102. // registers object, typelib and all interfaces in typelib
  103. hRes = _Module.RegisterServer(FALSE /*bRegTypeLib*/);
  104. return hRes;
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // DllUnregisterServer - Adds entries to the system registry
  108. STDAPI DllUnregisterServer(void)
  109. {
  110. HRESULT hRes = S_OK;
  111. _Module.UnregisterServer();
  112. return hRes;
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. //++
  116. //
  117. // FormatError
  118. //
  119. // Routine Description:
  120. // Format an error.
  121. //
  122. // Arguments:
  123. // rstrError [OUT] String in which to return the error message.
  124. // dwError [IN] Error code to format.
  125. //
  126. // Return Value:
  127. // None.
  128. //
  129. //--
  130. /////////////////////////////////////////////////////////////////////////////
  131. void FormatError(CString & rstrError, DWORD dwError)
  132. {
  133. DWORD dwResult;
  134. TCHAR szError[256];
  135. dwResult = ::FormatMessage(
  136. FORMAT_MESSAGE_FROM_SYSTEM,
  137. NULL,
  138. dwError,
  139. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  140. szError,
  141. sizeof(szError) / sizeof(TCHAR),
  142. 0
  143. );
  144. if (dwResult == 0)
  145. {
  146. // Format the NT status code from NTDLL since this hasn't been
  147. // integrated into the system yet.
  148. dwResult = ::FormatMessage(
  149. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  150. ::GetModuleHandle(_T("NTDLL.DLL")),
  151. dwError,
  152. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  153. szError,
  154. sizeof(szError) / sizeof(TCHAR),
  155. 0
  156. );
  157. if (dwResult == 0)
  158. {
  159. // Format the NT status code from CLUSAPI. This is necessary
  160. // for the cases where cluster messages haven't been added to
  161. // the system message file yet.
  162. dwResult = ::FormatMessage(
  163. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  164. ::GetModuleHandle(_T("CLUSAPI.DLL")),
  165. dwError,
  166. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  167. szError,
  168. sizeof(szError) / sizeof(TCHAR),
  169. 0
  170. );
  171. } // if: error formatting status code from NTDLL
  172. } // if: error formatting status code from system
  173. if (dwResult != 0)
  174. rstrError = szError;
  175. else
  176. {
  177. TRACE(_T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), dwResult, dwError);
  178. rstrError.Format(_T("Error 0x%08.8x"));
  179. } // else: error formatting the message
  180. } //*** FormatError()
  181. /////////////////////////////////////////////////////////////////////////////
  182. //++
  183. //
  184. // DllGetCluAdminExtensionCaps
  185. //
  186. // Routine Description:
  187. // Returns the CLSID supported by this extension.
  188. //
  189. // Arguments:
  190. // pdwCaps [OUT] DWORD in which to return extension capabilities.
  191. // pclsid [OUT] Place in which to return the CLSID.
  192. // pwszResTypeNames [OUT] Buffer in which to return the resource type
  193. // names supported by this extension. Each name is
  194. // null-terminated. Two nulls follow the last name.
  195. // pcchResTypeNames [IN OUT] On input, contains the number of characters
  196. // available in the output buffer, including the
  197. // null-terminators. On output, contains the
  198. // total number of characters written, not
  199. // including the null-terminator.
  200. //
  201. // Return Value:
  202. // S_OK Capabilities returned successfully.
  203. // E_INVALIDARG Invalid argument specified.
  204. //
  205. //--
  206. /////////////////////////////////////////////////////////////////////////////
  207. STDAPI DllGetCluAdminExtensionCaps(
  208. OUT DWORD * pdwCaps,
  209. OUT CLSID * pclsid,
  210. OUT LPWSTR pwszResTypeNames,
  211. IN OUT DWORD * pcchResTypeNames
  212. )
  213. {
  214. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  215. // Validate arguments.
  216. if ((pdwCaps == NULL)
  217. || (pclsid == NULL)
  218. || (pwszResTypeNames == NULL)
  219. || (pcchResTypeNames == NULL)
  220. || (*pcchResTypeNames < 1)
  221. )
  222. return E_INVALIDARG;
  223. // Set capabilities flags.
  224. *pdwCaps = 0
  225. //| CLUADMEX_CAPS_RESOURCE_PAGES
  226. ;
  227. // Copy the CLSID to the caller's buffer.
  228. CopyMemory(pclsid, &CLSID_CoIISClEx4, sizeof(CLSID));
  229. // Return the resource type names we support.
  230. {
  231. DWORD cchCopy = min(g_cchResourceTypeNames, *pcchResTypeNames);
  232. CopyMemory(pwszResTypeNames, g_wszResourceTypeNames, cchCopy * sizeof(WCHAR));
  233. *pcchResTypeNames = cchCopy;
  234. } // Return he resource type names we support
  235. return S_OK;
  236. } //*** DllGetCluAdminExtensionCaps()
  237. /////////////////////////////////////////////////////////////////////////////
  238. //++
  239. //
  240. // DllRegisterCluAdminExtension
  241. //
  242. // Routine Description:
  243. // Register the extension with the cluster database.
  244. //
  245. // Arguments:
  246. // hCluster [IN] Handle to the cluster to modify.
  247. //
  248. // Return Value:
  249. // S_OK Extension registered successfully.
  250. // Win32 error code if another failure occurred.
  251. //
  252. //--
  253. /////////////////////////////////////////////////////////////////////////////
  254. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hCluster)
  255. {
  256. HRESULT hr = S_OK;
  257. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  258. while (*pwszResTypes != L'\0')
  259. {
  260. hr = RegisterCluAdminResourceTypeExtension(
  261. hCluster,
  262. pwszResTypes,
  263. &CLSID_CoIISClEx4
  264. );
  265. if (hr != S_OK)
  266. break;
  267. wprintf(L" %s\n", pwszResTypes);
  268. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  269. } // while: more resource types
  270. return hr;
  271. } //*** DllRegisterCluAdminExtension()
  272. /////////////////////////////////////////////////////////////////////////////
  273. //++
  274. //
  275. // DllUnregisterCluAdminExtension
  276. //
  277. // Routine Description:
  278. // Unregister the extension with the cluster database.
  279. //
  280. // Arguments:
  281. // hCluster [IN] Handle to the cluster to modify.
  282. //
  283. // Return Value:
  284. // S_OK Extension unregistered successfully.
  285. // Win32 error code if another failure occurred.
  286. //
  287. //--
  288. /////////////////////////////////////////////////////////////////////////////
  289. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hCluster)
  290. {
  291. HRESULT hr = S_OK;
  292. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  293. while (*pwszResTypes != L'\0')
  294. {
  295. wprintf(L" %s\n", pwszResTypes);
  296. hr = UnregisterCluAdminResourceTypeExtension(
  297. hCluster,
  298. pwszResTypes,
  299. &CLSID_CoIISClEx4
  300. );
  301. if (hr != S_OK)
  302. break;
  303. pwszResTypes += lstrlenW(pwszResTypes) + 1;
  304. } // while: more resource types
  305. return hr;
  306. } //*** DllUnregisterCluAdminExtension()