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.

146 lines
4.3 KiB

  1. /*****************************************************************************
  2. * Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  3. *
  4. * All Rights Reserved
  5. *
  6. * This software is furnished under a license and may be used and copied
  7. * only in accordance with the terms of such license and with the inclusion
  8. * of the above copyright notice. This software or any other copies thereof
  9. * may not be provided or otherwise made available to any other person. No
  10. * title to and ownership of the software is hereby transferred.
  11. *****************************************************************************/
  12. //============================================================================
  13. //
  14. // CGlobal.h -- Global declarations
  15. //
  16. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  17. //
  18. // Revisions: 6/26/98 a-kevhu Created
  19. //
  20. //============================================================================
  21. #ifndef __CGLOBAL_H__
  22. #define __CGLOBAL_H__
  23. #include <windows.h>
  24. #include <process.h>
  25. #include <winerror.h>
  26. #include <stdio.h>
  27. #include <brodcast.h>
  28. #include <dllutils.h>
  29. #define ERR_LOG_FILE _T("c:\\temp\\test.txt")
  30. // forward class declarations to make the compiler happy...
  31. class CWaitableObject;
  32. class CWaitableCollection;
  33. class CKernel;
  34. class CMutex;
  35. class CSemaphore;
  36. class CEvent;
  37. class CThread;
  38. class CCriticalSec;
  39. class CAutoLock;
  40. class CMonitor;
  41. class CSharedMemory;
  42. class CMailbox;
  43. // defined symbol determines if CThrowError throws exceptions
  44. // or just prints debug error messages...
  45. #ifndef __C_THROW_EXCEPTIONS__
  46. #define __C_THROW_EXCEPTIONS__ TRUE
  47. #endif
  48. // for higher level objects which might have to check internal
  49. // object status when exceptions are disabled, these macros can be useful...
  50. // PTR is the smart pointer to check for NULL,
  51. // STATUS is the variable in which to store an error code if an error is detected...
  52. #if __C_THROW_EXCEPTIONS__
  53. #define C_CHECK_AUTOPTR_OBJECT(PTR,STATUS) if ((PTR).IsNull()) { /*CThrowError(ERROR_OUTOFMEMORY);*/ LogMessage2(L"CAutoLock Error: %d", ERROR_OUTOFMEMORY); }
  54. #else
  55. #define C_CHECK_AUTOPTR_OBJECT(PTR,STATUS) if ((PTR).IsNull()) { (STATUS) = ERROR_OUTOFMEMORY; return; }
  56. #endif
  57. // SCODE is the return value to check,
  58. // STATUS is the variable in which to store an error code if an error is detected...
  59. #if __C_THROW_EXCEPTIONS__
  60. #define C_CHECK_CREATION_STATUS(SCODE,STATUS) {}
  61. #else
  62. #define C_CHECK_CREATION_STATUS(SCODE,STATUS) if (((SCODE)!=NO_ERROR)&&((SCODE)!=ERROR_ALREADY_EXISTS)) { STATUS = (SCODE); return; }
  63. #endif
  64. //// error handling macro and function...
  65. //#define CThrowError(dwStatus) CInternalThrowError((dwStatus), __FILE__, __LINE__)
  66. //extern void CInternalThrowError( DWORD dwStatus, LPCWSTR lpFilename, int line);
  67. // check handle for NULL and INVALID_HANDLE
  68. inline BOOL CIsValidHandle( HANDLE hHandle) {
  69. return ((hHandle != NULL) && (hHandle != INVALID_HANDLE_VALUE));
  70. }
  71. // validate wait return codes...
  72. inline BOOL CWaitSucceeded( DWORD dwWaitResult, DWORD dwHandleCount) {
  73. return (dwWaitResult < WAIT_OBJECT_0 + dwHandleCount);
  74. }
  75. inline BOOL CWaitAbandoned( DWORD dwWaitResult, DWORD dwHandleCount) {
  76. return ((dwWaitResult >= WAIT_ABANDONED_0) &&
  77. (dwWaitResult < WAIT_ABANDONED_0 + dwHandleCount));
  78. }
  79. inline BOOL CWaitTimeout( DWORD dwWaitResult) {
  80. return (dwWaitResult == WAIT_TIMEOUT);
  81. }
  82. inline BOOL CWaitFailed( DWORD dwWaitResult) {
  83. return (dwWaitResult == WAIT_FAILED);
  84. }
  85. // compute object indices for waits...
  86. inline DWORD CWaitSucceededIndex( DWORD dwWaitResult) {
  87. return (dwWaitResult - WAIT_OBJECT_0);
  88. }
  89. inline DWORD CWaitAbandonedIndex( DWORD dwWaitResult) {
  90. return (dwWaitResult - WAIT_ABANDONED_0);
  91. }
  92. // Log messages
  93. inline DWORD LogMsg(LPCTSTR szMsg, LPCTSTR szFileName = ERR_LOG_FILE)
  94. {
  95. SYSTEMTIME systime;
  96. GetSystemTime(&systime);
  97. {
  98. TCHAR szTime[64];
  99. ZeroMemory(szTime,sizeof(szTime));
  100. wsprintf(szTime,_T("(%02d:%02d:%02d.%04d) "),systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);
  101. LogMessage3((LPCWSTR)TOBSTRT(_T("%s%s")), TOBSTRT(szTime), TOBSTRT(szMsg));
  102. }
  103. return 1;
  104. }
  105. #endif