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.

487 lines
19 KiB

  1. /*++
  2. Copyright (C) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. GLOBALS.H
  5. Abstract:
  6. Utility functions and global variables for the Performance Logs and
  7. Alerts MMC snap-in.
  8. --*/
  9. #ifndef __GLOBALS_H_
  10. #define __GLOBALS_H_
  11. #include <pdh.h>
  12. #include "DataObj.h"
  13. #include "common.h"
  14. #include <compuuid.h> // for MyComputer guids
  15. // global strings that don't need to be localized
  16. const LPWSTR szEmptyString = _T("");
  17. extern HINSTANCE g_hinst;
  18. extern CRITICAL_SECTION g_critsectInstallDefaultQueries;
  19. //---------------------------------------------------------------------------
  20. // Property change stuff
  21. //
  22. #define PROPCHANGE_ATTRIBUTE 1
  23. #define PROPCHANGE_FILENAME 2
  24. #define PROPCHANGE_COMMENT 3
  25. #define PROPCHANGE_TIMESTAMP 4
  26. //#define __SHOW_TRACES
  27. #ifdef __SHOW_TRACES
  28. #undef __SHOW_TRACES
  29. #endif
  30. #ifdef __SHOW_TRACES
  31. #define LOCALTRACE ATLTRACE
  32. #else
  33. #define LOCALTRACE
  34. #endif
  35. typedef struct tag_PROPCHANGE_DATA
  36. {
  37. ULONG fAttr2Change; // Which attribute we're changing
  38. ULONG nDataLength; // Length of the new data
  39. VOID* pData2Change; // The new data
  40. }PROPCHANGE_DATA;
  41. //---------------------------------------------------------------------------
  42. // Menu IDs
  43. //
  44. #define IDM_NEW_QUERY 40001
  45. #define IDM_NEW_QUERY_FROM 40002
  46. #define IDM_START_QUERY 40003
  47. #define IDM_STOP_QUERY 40004
  48. #define IDM_SAVE_QUERY_AS 40005
  49. // Custom clipboard formats
  50. #define CF_MMC_SNAPIN_MACHINE_NAME _T("MMC_SNAPIN_MACHINE_NAME")
  51. #define CF_INTERNAL _T("SYSMON_LOG_INTERNAL_DATA")
  52. #define MEM_UNINITIALIZED -1
  53. // Constants
  54. const UINT uiSmLogGuidStringBufLen = 39;
  55. // Generated with uuidgen. Each node must have a GUID associated with it.
  56. const GUID GUID_SnapInExt = /* {7478EF65-8C46-11d1-8D99-00A0C913CAD4} */
  57. {
  58. 0x7478eF65,
  59. 0x8c46,
  60. 0x11d1,
  61. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  62. };
  63. // This one is for the main root node.
  64. const GUID GUID_RootNode = /* {7478EF63-8C46-11d1-8D99-00A0C913CAD4} */
  65. {
  66. 0x7478ef63,
  67. 0x8c46,
  68. 0x11d1,
  69. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  70. };
  71. // These are the children nodes of the main root node
  72. const GUID GUID_CounterMainNode = /* {7478EF66-8C46-11d1-8D99-00A0C913CAD4} */
  73. {
  74. 0x7478ef66,
  75. 0x8c46,
  76. 0x11d1,
  77. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  78. };
  79. const GUID GUID_TraceMainNode = /* {7478EF67-8C46-11d1-8D99-00A0C913CAD4} */
  80. {
  81. 0x7478ef67,
  82. 0x8c46,
  83. 0x11d1,
  84. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  85. };
  86. const GUID GUID_AlertMainNode = /* {7478EF68-8C46-11d1-8D99-00A0C913CAD4} */
  87. {
  88. 0x7478ef68,
  89. 0x8c46,
  90. 0x11d1,
  91. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  92. };
  93. // Obsolete after Beta 3:
  94. const GUID GUID_MainNode = /* {7478EF64-8C46-11d1-8D99-00A0C913CAD4} */
  95. {
  96. 0x7478ef64,
  97. 0x8c46,
  98. 0x11d1,
  99. { 0x8d, 0x99, 0x0, 0xa0, 0xc9, 0x13, 0xca, 0xd4 }
  100. };
  101. extern "C" {
  102. extern WCHAR GUIDSTR_TypeLibrary[];
  103. extern WCHAR GUIDSTR_ComponentData[];
  104. extern WCHAR GUIDSTR_Component[];
  105. extern WCHAR GUIDSTR_RootNode[];
  106. extern WCHAR GUIDSTR_MainNode[]; // Obsolete after Beta 3
  107. extern WCHAR GUIDSTR_SnapInExt[];
  108. extern WCHAR GUIDSTR_CounterMainNode[];
  109. extern WCHAR GUIDSTR_TraceMainNode[];
  110. extern WCHAR GUIDSTR_AlertMainNode[];
  111. extern WCHAR GUIDSTR_PerformanceAbout[];
  112. };
  113. extern "C" {
  114. typedef struct _COMBO_BOX_DATA_MAP {
  115. UINT nData;
  116. UINT nResId;
  117. } COMBO_BOX_DATA_MAP, *PCOMBO_BOX_DATA_MAP;
  118. }
  119. extern const COMBO_BOX_DATA_MAP TimeUnitCombo[];
  120. extern const DWORD dwTimeUnitComboEntries;
  121. //---------------------------------------------------------------------------
  122. // Global function defines
  123. //
  124. #define MsgBox(wszMsg, wszTitle) ::MessageBox(NULL, wszMsg, wszTitle, MB_OK)
  125. int DebugMsg( LPWSTR wszMsg, LPWSTR wszTitle );
  126. DWORD __stdcall CreateSampleFileName (
  127. const CString& rstrQueryName,
  128. const CString& rstrMachineName,
  129. const CString& rstrFolderName,
  130. const CString& rstrInputBaseName,
  131. const CString& rstrSqlName,
  132. DWORD dwSuffixFormat,
  133. DWORD dwLogFileTypeValue,
  134. DWORD dwCurrentSerialNumber,
  135. CString& rstrReturnName );
  136. DWORD __stdcall IsDirPathValid (
  137. CString& csPath,
  138. BOOL bLastNameIsDirectory,
  139. BOOL bCreateMissingDirs,
  140. BOOL& rbIsValid);
  141. DWORD __stdcall ProcessDirPath (
  142. CString& rstrPath,
  143. const CString& rstrLogName,
  144. CWnd* pwndParent,
  145. BOOL& rbIsValid,
  146. BOOL bOnFilesPage);
  147. INT __stdcall BrowseCommandFilename ( CWnd* pwndParent, CString& rstrFilename );
  148. DWORD __stdcall FormatSmLogCfgMessage ( CString& rstrMessage,HINSTANCE hResourceHandle, UINT uiMessageId, ... );
  149. BOOL _stdcall FileRead ( HANDLE hFile, void* lpMemory, DWORD nAmtToRead );
  150. BOOL _stdcall FileWrite ( HANDLE hFile, void* lpMemory, DWORD nAmtToWrite );
  151. // Pdh counter paths - return status
  152. #define SMCFG_DUPL_NONE ERROR_SUCCESS
  153. #define SMCFG_DUPL_SINGLE_PATH ((DWORD)0x00000001)
  154. #define SMCFG_DUPL_FIRST_IS_WILD ((DWORD)0x00000002)
  155. #define SMCFG_DUPL_SECOND_IS_WILD ((DWORD)0x00000003)
  156. DWORD _stdcall
  157. CheckDuplicateCounterPaths (
  158. PDH_COUNTER_PATH_ELEMENTS* pFirst,
  159. PDH_COUNTER_PATH_ELEMENTS* pSecond );
  160. LPTSTR _stdcall
  161. ExtractFileName ( LPTSTR pFileSpec );
  162. //---------------------------------------------------------------------------
  163. template<class TYPE>
  164. inline void SAFE_RELEASE( TYPE*& pObj )
  165. {
  166. if( NULL != pObj )
  167. {
  168. pObj->Release();
  169. pObj = NULL;
  170. }
  171. else
  172. {
  173. LOCALTRACE( _T("Release called on NULL interface ptr\n") );
  174. }
  175. } // end SAFE_RELEASE()
  176. /////////////////////////////////////////////////////////////////////////////
  177. // We need a few functions to help work with dataobjects and
  178. // clipboard formats
  179. //
  180. HRESULT ExtractFromDataObject(LPDATAOBJECT lpDataObject,UINT cf,ULONG cb,HGLOBAL *phGlobal);
  181. CDataObject* ExtractOwnDataObject(LPDATAOBJECT lpDataObject);
  182. VOID DisplayError( LONG nErrorCode, LPWSTR wszDlgTitle );
  183. VOID DisplayError( LONG nErrorCode, UINT nTitleString );
  184. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType );
  185. HRESULT ExtractMachineName( IDataObject* piDataObject, CString& rstrMachineName );
  186. class ResourceStateManager
  187. {
  188. public:
  189. ResourceStateManager();
  190. ~ResourceStateManager();
  191. private:
  192. HINSTANCE m_hResInstance;
  193. };
  194. static const COMBO_BOX_DATA_MAP FileNameSuffixCombo[] =
  195. {
  196. {SLF_NAME_NNNNNN, IDS_FS_NNNNNN},
  197. {SLF_NAME_MMDDHH, IDS_FS_MMDDHH},
  198. {SLF_NAME_MMDDHHMM, IDS_FS_MMDDHHMM},
  199. {SLF_NAME_YYYYDDD, IDS_FS_YYYYDDD},
  200. {SLF_NAME_YYYYMM, IDS_FS_YYYYMM},
  201. {SLF_NAME_YYYYMMDD, IDS_FS_YYYYMMDD},
  202. {SLF_NAME_YYYYMMDDHH, IDS_FS_YYYYMMDDHH}
  203. };
  204. static const DWORD dwFileNameSuffixComboEntries = sizeof(FileNameSuffixCombo)/sizeof(FileNameSuffixCombo[0]);
  205. static const COMBO_BOX_DATA_MAP FileTypeCombo[] =
  206. {
  207. {SLF_CSV_FILE, IDS_FT_CSV},
  208. {SLF_TSV_FILE, IDS_FT_TSV},
  209. {SLF_BIN_FILE, IDS_FT_BINARY},
  210. {SLF_BIN_CIRC_FILE, IDS_FT_BINARY_CIRCULAR},
  211. {SLF_SQL_LOG, IDS_FT_SQL}
  212. };
  213. static const DWORD dwFileTypeComboEntries = sizeof(FileTypeCombo)/sizeof(FileTypeCombo[0]);
  214. static const COMBO_BOX_DATA_MAP TraceFileTypeCombo[] =
  215. {
  216. {SLF_CIRC_TRACE_FILE, IDS_FT_CIRCULAR_TRACE},
  217. {SLF_SEQ_TRACE_FILE, IDS_FT_SEQUENTIAL_TRACE}
  218. };
  219. static const DWORD dwTraceFileTypeComboEntries = sizeof(TraceFileTypeCombo)/sizeof(TraceFileTypeCombo[0]);
  220. /////////////////////////////////////////////////////////////////////////////
  221. // We need a few functions to help work with dataobjects and
  222. // clipboard formats
  223. //
  224. // Exception handling macros from snapin\corecopy\macros.h
  225. //____________________________________________________________________________
  226. //
  227. // Macro: EXCEPTION HANDLING MACROS
  228. //
  229. // Purpose: Provide standard macros for exception-handling in
  230. // OLE servers.
  231. //
  232. // History: 7/23/1996 JonN Created
  233. //
  234. // Notes: Declare USE_HANDLE_MACROS("Component name") in each source
  235. // file before these are used.
  236. //
  237. // These macros can only be used in function calls which return
  238. // type HRESULT.
  239. //
  240. // Bracket routines which can generate exceptions
  241. // with STANDARD_TRY and STANDARD_CATCH.
  242. //
  243. // Where these routines are COM methods requiring MFC
  244. // support, use MFC_TRY and MFC_CATCH instead.
  245. //____________________________________________________________________________
  246. //
  247. #define USE_HANDLE_MACROS(component) \
  248. static TCHAR* You_forgot_to_declare_USE_HANDLE_MACROS = _T(component);
  249. #define STANDARD_TRY \
  250. try {
  251. #define MFC_TRY \
  252. AFX_MANAGE_STATE(AfxGetStaticModuleState( )); \
  253. STANDARD_TRY
  254. //
  255. // CODEWORK don't quite have ENDMETHOD_READBLOCK working yet
  256. //
  257. #ifdef DEBUG
  258. #define ENDMETHOD_STRING \
  259. "%s: The unexpected error can be identified as \"%s\" context %n\n"
  260. #define ENDMETHOD_READBLOCK \
  261. { \
  262. TCHAR szError[MAX_PATH]; \
  263. UINT nHelpContext = 0; \
  264. if ( e->GetErrorMessage( szError, MAX_PATH, &nHelpContext ) ) \
  265. { \
  266. TRACE( ENDMETHOD_STRING, \
  267. You_forgot_to_declare_USE_HANDLE_MACROS, \
  268. szError, \
  269. nHelpContext ); \
  270. } \
  271. }
  272. #else
  273. #define ENDMETHOD_READBLOCK
  274. #endif
  275. #define ERRSTRING_MEMORY _T("%s: An out-of-memory error occurred\n")
  276. #define ERRSTRING_FILE _T("%s: File error 0x%lx occurred on file \"%s\"\n")
  277. #define ERRSTRING_OLE _T("%s: OLE error 0x%lx occurred\n")
  278. #define ERRSTRING_UNEXPECTED _T("%s: An unexpected error occurred\n")
  279. #define BADPARM_STRING _T("%s: Bad string parameter\n")
  280. #define BADPARM_POINTER _T("%s: Bad pointer parameter\n")
  281. #define TRACEERR(s) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS )
  282. #define TRACEERR1(s,a) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS,a )
  283. #define TRACEERR2(s,a,b) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS,a,b )
  284. // Note that it is important to use "e->Delete();" and not "delete e;"
  285. #define STANDARD_CATCH \
  286. } \
  287. catch (CMemoryException* e) \
  288. { \
  289. TRACEERR( ERRSTRING_MEMORY ); \
  290. ASSERT( FALSE ); \
  291. e->Delete(); \
  292. return E_OUTOFMEMORY; \
  293. } \
  294. catch (COleException* e) \
  295. { \
  296. HRESULT hr = (HRESULT)e->Process(e); \
  297. TRACEERR1( ERRSTRING_OLE, hr ); \
  298. ASSERT( FALSE ); \
  299. e->Delete(); \
  300. ASSERT( FAILED(hr) ); \
  301. return hr; \
  302. } \
  303. catch (CFileException* e) \
  304. { \
  305. HRESULT hr = (HRESULT)e->m_lOsError; \
  306. TRACEERR2( ERRSTRING_FILE, hr, e->m_strFileName ); \
  307. ASSERT( FALSE ); \
  308. e->Delete(); \
  309. ASSERT( FAILED(hr) ); \
  310. return hr; \
  311. } \
  312. catch (CException* e) \
  313. { \
  314. TRACEERR( ERRSTRING_UNEXPECTED ); \
  315. ASSERT( FALSE ); \
  316. e->Delete(); \
  317. return E_UNEXPECTED; \
  318. }
  319. #define MFC_CATCH_HR_RETURN \
  320. STANDARD_CATCH
  321. #define MFC_CATCH_HR \
  322. } \
  323. catch (CMemoryException* e) \
  324. { \
  325. TRACEERR( ERRSTRING_MEMORY ); \
  326. ASSERT( FALSE ); \
  327. e->Delete(); \
  328. hr = E_OUTOFMEMORY; \
  329. } \
  330. catch (COleException* e) \
  331. { \
  332. hr = (HRESULT)e->Process(e); \
  333. TRACEERR1( ERRSTRING_OLE, hr ); \
  334. ASSERT( FALSE ); \
  335. e->Delete(); \
  336. ASSERT( FAILED(hr) ); \
  337. } \
  338. catch (CFileException* e) \
  339. { \
  340. hr = (HRESULT)e->m_lOsError; \
  341. TRACEERR2( ERRSTRING_FILE, hr, e->m_strFileName ); \
  342. ASSERT( FALSE ); \
  343. e->Delete(); \
  344. ASSERT( FAILED(hr) ); \
  345. } \
  346. catch (CException* e) \
  347. { \
  348. TRACEERR( ERRSTRING_UNEXPECTED ); \
  349. ASSERT( FALSE ); \
  350. e->Delete(); \
  351. hr = E_UNEXPECTED; \
  352. }
  353. #define MFC_CATCH_DWSTATUS \
  354. } \
  355. catch (CMemoryException* e) \
  356. { \
  357. dwStatus = ERROR_OUTOFMEMORY; \
  358. TRACEERR( ERRSTRING_MEMORY ); \
  359. ASSERT( FALSE ); \
  360. e->Delete(); \
  361. } \
  362. catch (COleException* e) \
  363. { \
  364. dwStatus = e->Process(e); \
  365. TRACEERR1( ERRSTRING_OLE, dwStatus ); \
  366. ASSERT( ERROR_SUCCESS != dwStatus ); \
  367. e->Delete(); \
  368. } \
  369. catch (CFileException* e) \
  370. { \
  371. dwStatus = e->m_lOsError; \
  372. TRACEERR2( ERRSTRING_FILE, dwStatus, e->m_strFileName ); \
  373. ASSERT( ERROR_SUCCESS != dwStatus ); \
  374. e->Delete(); \
  375. } \
  376. catch (CException* e) \
  377. { \
  378. dwStatus = GetLastError(); \
  379. TRACEERR( ERRSTRING_UNEXPECTED ); \
  380. ASSERT( FALSE ); \
  381. e->Delete(); \
  382. }
  383. #define MFC_CATCH_MINIMUM \
  384. } \
  385. catch ( ... ) \
  386. { \
  387. TRACEERR( ERRSTRING_MEMORY ); \
  388. } \
  389. VOID
  390. InvokeWinHelp(
  391. UINT message,
  392. WPARAM wParam,
  393. LPARAM lParam,
  394. const CString& rstrHelpFileName,
  395. DWORD adwControlIdToHelpIdMap[]);
  396. DWORD __stdcall
  397. IsCommandFilePathValid (
  398. CString& rstrPath );
  399. BOOL
  400. FileNameIsValid(
  401. CString* pstrFileName );
  402. DWORD _stdcall
  403. FormatSystemMessage (
  404. DWORD dwMessageId,
  405. CString& rstrSystemMessage );
  406. #endif // __GLOBALS_H_