Leaked source code of windows server 2003
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.

499 lines
20 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 = L"";
  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 L"MMC_SNAPIN_MACHINE_NAME"
  51. #define CF_INTERNAL L"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& rstrDefault,
  138. CString& csPath,
  139. BOOL bLastNameIsDirectory,
  140. BOOL bCreateMissingDirs,
  141. BOOL& rbIsValid);
  142. DWORD __stdcall ProcessDirPath (
  143. const CString& rstrDefault,
  144. CString& rstrPath,
  145. const CString& rstrLogName,
  146. CWnd* pwndParent,
  147. BOOL& rbIsValid,
  148. BOOL bOnFilesPage);
  149. INT __stdcall BrowseCommandFilename ( CWnd* pwndParent, CString& rstrFilename );
  150. DWORD __stdcall FormatSmLogCfgMessage ( CString& rstrMessage,HINSTANCE hResourceHandle, UINT uiMessageId, ... );
  151. BOOL _stdcall FileRead ( HANDLE hFile, void* lpMemory, DWORD nAmtToRead );
  152. BOOL _stdcall FileWrite ( HANDLE hFile, void* lpMemory, DWORD nAmtToWrite );
  153. // Pdh counter paths - return status
  154. #define SMCFG_DUPL_NONE ERROR_SUCCESS
  155. #define SMCFG_DUPL_SINGLE_PATH ((DWORD)0x00000001)
  156. #define SMCFG_DUPL_FIRST_IS_WILD ((DWORD)0x00000002)
  157. #define SMCFG_DUPL_SECOND_IS_WILD ((DWORD)0x00000003)
  158. DWORD _stdcall
  159. CheckDuplicateCounterPaths (
  160. PDH_COUNTER_PATH_ELEMENTS* pFirst,
  161. PDH_COUNTER_PATH_ELEMENTS* pSecond );
  162. LPWSTR _stdcall
  163. ExtractFileName ( LPWSTR pFileSpec );
  164. //---------------------------------------------------------------------------
  165. template<class TYPE>
  166. inline void SAFE_RELEASE( TYPE*& pObj )
  167. {
  168. if( NULL != pObj )
  169. {
  170. pObj->Release();
  171. pObj = NULL;
  172. }
  173. else
  174. {
  175. LOCALTRACE( L"Release called on NULL interface ptr\n" );
  176. }
  177. } // end SAFE_RELEASE()
  178. /////////////////////////////////////////////////////////////////////////////
  179. // We need a few functions to help work with dataobjects and
  180. // clipboard formats
  181. //
  182. HRESULT ExtractFromDataObject(LPDATAOBJECT lpDataObject,UINT cf,ULONG cb,HGLOBAL *phGlobal);
  183. CDataObject* ExtractOwnDataObject(LPDATAOBJECT lpDataObject);
  184. VOID DisplayError( LONG nErrorCode, LPWSTR wszDlgTitle );
  185. VOID DisplayError( LONG nErrorCode, UINT nTitleString );
  186. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType );
  187. HRESULT ExtractMachineName( IDataObject* piDataObject, CString& rstrMachineName );
  188. class ResourceStateManager
  189. {
  190. public:
  191. ResourceStateManager();
  192. ~ResourceStateManager();
  193. private:
  194. HINSTANCE m_hResInstance;
  195. };
  196. static const COMBO_BOX_DATA_MAP FileNameSuffixCombo[] =
  197. {
  198. {SLF_NAME_NNNNNN, IDS_FS_NNNNNN},
  199. {SLF_NAME_MMDDHH, IDS_FS_MMDDHH},
  200. {SLF_NAME_MMDDHHMM, IDS_FS_MMDDHHMM},
  201. {SLF_NAME_YYYYDDD, IDS_FS_YYYYDDD},
  202. {SLF_NAME_YYYYMM, IDS_FS_YYYYMM},
  203. {SLF_NAME_YYYYMMDD, IDS_FS_YYYYMMDD},
  204. {SLF_NAME_YYYYMMDDHH, IDS_FS_YYYYMMDDHH}
  205. };
  206. static const DWORD dwFileNameSuffixComboEntries = sizeof(FileNameSuffixCombo)/sizeof(FileNameSuffixCombo[0]);
  207. static const COMBO_BOX_DATA_MAP FileTypeCombo[] =
  208. {
  209. {SLF_CSV_FILE, IDS_FT_CSV},
  210. {SLF_TSV_FILE, IDS_FT_TSV},
  211. {SLF_BIN_FILE, IDS_FT_BINARY},
  212. {SLF_BIN_CIRC_FILE, IDS_FT_BINARY_CIRCULAR},
  213. {SLF_SQL_LOG, IDS_FT_SQL}
  214. };
  215. static const DWORD dwFileTypeComboEntries = sizeof(FileTypeCombo)/sizeof(FileTypeCombo[0]);
  216. static const COMBO_BOX_DATA_MAP TraceFileTypeCombo[] =
  217. {
  218. {SLF_CIRC_TRACE_FILE, IDS_FT_CIRCULAR_TRACE},
  219. {SLF_SEQ_TRACE_FILE, IDS_FT_SEQUENTIAL_TRACE}
  220. };
  221. static const DWORD dwTraceFileTypeComboEntries = sizeof(TraceFileTypeCombo)/sizeof(TraceFileTypeCombo[0]);
  222. /////////////////////////////////////////////////////////////////////////////
  223. // We need a few functions to help work with dataobjects and
  224. // clipboard formats
  225. //
  226. // Exception handling macros from snapin\corecopy\macros.h
  227. //____________________________________________________________________________
  228. //
  229. // Macro: EXCEPTION HANDLING MACROS
  230. //
  231. // Purpose: Provide standard macros for exception-handling in
  232. // OLE servers.
  233. //
  234. // History: 7/23/1996 JonN Created
  235. //
  236. // Notes: Declare USE_HANDLE_MACROS("Component name") in each source
  237. // file before these are used.
  238. //
  239. // These macros can only be used in function calls which return
  240. // type HRESULT.
  241. //
  242. // Bracket routines which can generate exceptions
  243. // with STANDARD_TRY and STANDARD_CATCH.
  244. //
  245. // Where these routines are COM methods requiring MFC
  246. // support, use MFC_TRY and MFC_CATCH instead.
  247. //____________________________________________________________________________
  248. //
  249. #define USE_HANDLE_MACROS(component) \
  250. static WCHAR* You_forgot_to_declare_USE_HANDLE_MACROS = L"component";
  251. #define STANDARD_TRY \
  252. try {
  253. #define MFC_TRY \
  254. AFX_MANAGE_STATE(AfxGetStaticModuleState( )); \
  255. STANDARD_TRY
  256. //
  257. // CODEWORK don't quite have ENDMETHOD_READBLOCK working yet
  258. //
  259. #ifdef DEBUG
  260. #define ENDMETHOD_STRING \
  261. "%s: The unexpected error can be identified as \"%s\" context %n\n"
  262. #define ENDMETHOD_READBLOCK \
  263. { \
  264. WCHAR szError[MAX_PATH]; \
  265. UINT nHelpContext = 0; \
  266. if ( e->GetErrorMessage( szError, MAX_PATH, &nHelpContext ) ) \
  267. { \
  268. TRACE( ENDMETHOD_STRING, \
  269. You_forgot_to_declare_USE_HANDLE_MACROS, \
  270. szError, \
  271. nHelpContext ); \
  272. } \
  273. }
  274. #else
  275. #define ENDMETHOD_READBLOCK
  276. #endif
  277. #define ERRSTRING_MEMORY L"%s: An out-of-memory error occurred\n"
  278. #define ERRSTRING_FILE L"%s: File error 0x%lx occurred on file \"%s\"\n"
  279. #define ERRSTRING_OLE L"%s: OLE error 0x%lx occurred\n"
  280. #define ERRSTRING_UNEXPECTED L"%s: An unexpected error occurred\n"
  281. #define BADPARM_STRING L"%s: Bad string parameter\n"
  282. #define BADPARM_POINTER L"%s: Bad pointer parameter\n"
  283. #define TRACEERR(s) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS )
  284. #define TRACEERR1(s,a) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS,a )
  285. #define TRACEERR2(s,a,b) TRACE( s, You_forgot_to_declare_USE_HANDLE_MACROS,a,b )
  286. // Note that it is important to use "e->Delete();" and not "delete e;"
  287. #define STANDARD_CATCH \
  288. } \
  289. catch (CMemoryException* e) \
  290. { \
  291. TRACEERR( ERRSTRING_MEMORY ); \
  292. ASSERT( FALSE ); \
  293. e->Delete(); \
  294. return E_OUTOFMEMORY; \
  295. } \
  296. catch (COleException* e) \
  297. { \
  298. HRESULT hr = (HRESULT)e->Process(e); \
  299. TRACEERR1( ERRSTRING_OLE, hr ); \
  300. ASSERT( FALSE ); \
  301. e->Delete(); \
  302. ASSERT( FAILED(hr) ); \
  303. return hr; \
  304. } \
  305. catch (CFileException* e) \
  306. { \
  307. HRESULT hr = (HRESULT)e->m_lOsError; \
  308. TRACEERR2( ERRSTRING_FILE, hr, e->m_strFileName ); \
  309. ASSERT( FALSE ); \
  310. e->Delete(); \
  311. ASSERT( FAILED(hr) ); \
  312. return hr; \
  313. } \
  314. catch (CException* e) \
  315. { \
  316. TRACEERR( ERRSTRING_UNEXPECTED ); \
  317. ASSERT( FALSE ); \
  318. e->Delete(); \
  319. return E_UNEXPECTED; \
  320. }
  321. #define MFC_CATCH_HR_RETURN \
  322. STANDARD_CATCH
  323. #define MFC_CATCH_HR \
  324. } \
  325. catch (CMemoryException* e) \
  326. { \
  327. TRACEERR( ERRSTRING_MEMORY ); \
  328. ASSERT( FALSE ); \
  329. e->Delete(); \
  330. hr = E_OUTOFMEMORY; \
  331. } \
  332. catch (COleException* e) \
  333. { \
  334. hr = (HRESULT)e->Process(e); \
  335. TRACEERR1( ERRSTRING_OLE, hr ); \
  336. ASSERT( FALSE ); \
  337. e->Delete(); \
  338. ASSERT( FAILED(hr) ); \
  339. } \
  340. catch (CFileException* e) \
  341. { \
  342. hr = (HRESULT)e->m_lOsError; \
  343. TRACEERR2( ERRSTRING_FILE, hr, e->m_strFileName ); \
  344. ASSERT( FALSE ); \
  345. e->Delete(); \
  346. ASSERT( FAILED(hr) ); \
  347. } \
  348. catch (CException* e) \
  349. { \
  350. TRACEERR( ERRSTRING_UNEXPECTED ); \
  351. ASSERT( FALSE ); \
  352. e->Delete(); \
  353. hr = E_UNEXPECTED; \
  354. }
  355. #define MFC_CATCH_DWSTATUS \
  356. } \
  357. catch (CMemoryException* e) \
  358. { \
  359. dwStatus = ERROR_OUTOFMEMORY; \
  360. TRACEERR( ERRSTRING_MEMORY ); \
  361. ASSERT( FALSE ); \
  362. e->Delete(); \
  363. } \
  364. catch (COleException* e) \
  365. { \
  366. dwStatus = e->Process(e); \
  367. TRACEERR1( ERRSTRING_OLE, dwStatus ); \
  368. ASSERT( ERROR_SUCCESS != dwStatus ); \
  369. e->Delete(); \
  370. } \
  371. catch (CFileException* e) \
  372. { \
  373. dwStatus = e->m_lOsError; \
  374. TRACEERR2( ERRSTRING_FILE, dwStatus, e->m_strFileName ); \
  375. ASSERT( ERROR_SUCCESS != dwStatus ); \
  376. e->Delete(); \
  377. } \
  378. catch (CException* e) \
  379. { \
  380. dwStatus = GetLastError(); \
  381. TRACEERR( ERRSTRING_UNEXPECTED ); \
  382. ASSERT( FALSE ); \
  383. e->Delete(); \
  384. }
  385. #define MFC_CATCH_MINIMUM \
  386. } \
  387. catch ( ... ) \
  388. { \
  389. TRACEERR( ERRSTRING_MEMORY ); \
  390. } \
  391. VOID
  392. InvokeWinHelp(
  393. UINT message,
  394. WPARAM wParam,
  395. LPARAM lParam,
  396. const CString& rstrHelpFileName,
  397. DWORD adwControlIdToHelpIdMap[]);
  398. DWORD __stdcall
  399. IsCommandFilePathValid (
  400. CString& rstrPath );
  401. BOOL
  402. FileNameIsValid(
  403. CString* pstrFileName );
  404. DWORD _stdcall
  405. FormatSystemMessage (
  406. DWORD dwMessageId,
  407. CString& rstrSystemMessage );
  408. BOOL _stdcall
  409. wGUIDFromString (
  410. LPCWSTR lpsz,
  411. LPGUID pguid );
  412. void _stdcall
  413. KillString( CString& str );
  414. #endif // __GLOBALS_H_