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.

310 lines
7.5 KiB

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