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.

312 lines
7.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DebugEx.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CDebugexApp class and DLL initialization
  10. // routines.
  11. //
  12. // Author:
  13. // David Potter (davidp) September 19, 1996
  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 "DebugEx.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_CoDebugEx, 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 CDebugexApp
  54. /////////////////////////////////////////////////////////////////////////////
  55. class CDebugexApp : public CWinApp
  56. {
  57. public:
  58. virtual BOOL InitInstance();
  59. virtual int ExitInstance();
  60. };
  61. /////////////////////////////////////////////////////////////////////////////
  62. // The one and only CDebugexApp object
  63. CDebugexApp theApp;
  64. /////////////////////////////////////////////////////////////////////////////
  65. //++
  66. //
  67. // CDebugexApp::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 CDebugexApp::InitInstance(void)
  81. {
  82. _Module.Init(ObjectMap, m_hInstance);
  83. // Construct the help path.
  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. } //*** CDebugexApp::InitInstance()
  107. /////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // CDebugexApp::ExitInstance
  111. //
  112. // Routine Description:
  113. // Deinitialize this instance of the application.
  114. //
  115. // Arguments:
  116. // None.
  117. //
  118. // Return Value:
  119. // Any return codes from CWinApp::ExitInstance().
  120. //
  121. //--
  122. /////////////////////////////////////////////////////////////////////////////
  123. int CDebugexApp::ExitInstance(void)
  124. {
  125. _Module.Term();
  126. return CWinApp::ExitInstance();
  127. } //*** CDebugexApp::ExitInstance()
  128. /////////////////////////////////////////////////////////////////////////////
  129. //++
  130. //
  131. // FormatError
  132. //
  133. // Routine Description:
  134. // Format an error.
  135. //
  136. // Arguments:
  137. // rstrError [OUT] String in which to return the error message.
  138. // dwError [IN] Error code to format.
  139. //
  140. // Return Value:
  141. // None.
  142. //
  143. //--
  144. /////////////////////////////////////////////////////////////////////////////
  145. void FormatError(CString & rstrError, DWORD dwError)
  146. {
  147. DWORD _cch;
  148. TCHAR _szError[512];
  149. _cch = FormatMessage(
  150. FORMAT_MESSAGE_FROM_SYSTEM,
  151. NULL,
  152. dwError,
  153. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  154. _szError,
  155. sizeof(_szError) / sizeof(TCHAR),
  156. 0
  157. );
  158. if (_cch == 0)
  159. {
  160. // Format the NT status code from NTDLL since this hasn't been
  161. // integrated into the system yet.
  162. _cch = FormatMessage(
  163. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  164. ::GetModuleHandle(_T("NTDLL.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 system
  172. if (_cch > 0)
  173. {
  174. rstrError = _szError;
  175. } // if: no error
  176. else
  177. {
  178. #ifdef _DEBUG
  179. DWORD _sc = GetLastError();
  180. TRACE(_T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), _sc, dwError);
  181. #endif
  182. rstrError.Format(_T("Error 0x%08.8x"), dwError);
  183. } // else: error formatting the message
  184. } //*** FormatError()
  185. /////////////////////////////////////////////////////////////////////////////
  186. // Used to determine whether the DLL can be unloaded by OLE
  187. STDAPI DllCanUnloadNow(void)
  188. {
  189. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  190. return (AfxDllCanUnloadNow() && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  191. } //*** DllCanUnloadNow()
  192. /////////////////////////////////////////////////////////////////////////////
  193. // Returns a class factory to create an object of the requested type
  194. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  195. {
  196. return _Module.GetClassObject(rclsid, riid, ppv);
  197. } //*** DllGetClassObject()
  198. /////////////////////////////////////////////////////////////////////////////
  199. // DllRegisterServer - Adds entries to the system registry
  200. STDAPI DllRegisterServer(void)
  201. {
  202. HRESULT hRes = S_OK;
  203. // registers object, typelib and all interfaces in typelib
  204. hRes = _Module.RegisterServer(FALSE /*bRegTypeLib*/);
  205. return hRes;
  206. } //*** DllRegisterServer()
  207. /////////////////////////////////////////////////////////////////////////////
  208. // DllUnregisterServer - Adds entries to the system registry
  209. STDAPI DllUnregisterServer(void)
  210. {
  211. HRESULT hRes = S_OK;
  212. _Module.UnregisterServer();
  213. return hRes;
  214. } //*** DllUnregisterServer()
  215. /////////////////////////////////////////////////////////////////////////////
  216. //++
  217. //
  218. // DllRegisterCluAdminExtension
  219. //
  220. // Routine Description:
  221. // Register the extension with the cluster database.
  222. //
  223. // Arguments:
  224. // hCluster [IN] Handle to the cluster to modify.
  225. //
  226. // Return Value:
  227. // S_OK Extension registered successfully.
  228. // Win32 error code if another failure occurred.
  229. //
  230. //--
  231. /////////////////////////////////////////////////////////////////////////////
  232. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hCluster)
  233. {
  234. HRESULT hr;
  235. hr = RegisterCluAdminAllResourcesExtension(hCluster, &CLSID_CoDebugEx);
  236. if (hr == S_OK)
  237. hr = RegisterCluAdminAllResourceTypesExtension(hCluster, &CLSID_CoDebugEx);
  238. return hr;
  239. } //*** DllRegisterCluAdminExtension()
  240. /////////////////////////////////////////////////////////////////////////////
  241. //++
  242. //
  243. // DllUnregisterCluAdminExtension
  244. //
  245. // Routine Description:
  246. // Unregister the extension with the cluster database.
  247. //
  248. // Arguments:
  249. // hCluster [IN] Handle to the cluster to modify.
  250. //
  251. // Return Value:
  252. // S_OK Extension unregistered successfully.
  253. // Win32 error code if another failure occurred.
  254. //
  255. //--
  256. /////////////////////////////////////////////////////////////////////////////
  257. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hCluster)
  258. {
  259. HRESULT hr;
  260. hr = UnregisterCluAdminAllResourcesExtension(hCluster, &CLSID_CoDebugEx);
  261. if (hr == S_OK)
  262. hr = UnregisterCluAdminAllResourceTypesExtension(hCluster, &CLSID_CoDebugEx);
  263. return hr;
  264. } //*** DllUnregisterCluAdminExtension()