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.

177 lines
5.0 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. StdAfx.cpp
  5. Abstract:
  6. Precompiled header root.
  7. Author:
  8. Rohde Wakefield [rohde] 20-Feb-1998
  9. Revision History:
  10. --*/
  11. #ifndef RECALL_STDAFX_H
  12. #define RECALL_STDAFX_H
  13. #pragma once
  14. //#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
  15. #include <afxwin.h>
  16. #include <afxext.h>
  17. #include <afxcmn.h>
  18. #include <afxtempl.h>
  19. #include <atlbase.h>
  20. extern CComModule _Module;
  21. #include <atlcom.h>
  22. #include <statreg.h>
  23. //{{AFX_INSERT_LOCATION}}
  24. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  25. //}}AFX
  26. #include "RsTrace.h"
  27. #include "resource.h"
  28. #include "rsutil.h"
  29. #include "fsaint.h"
  30. #include "RsRecall.h"
  31. #include "clientob.h"
  32. #include "note.h"
  33. // Don't do module state tracking if just an exe
  34. #ifndef _USRDLL
  35. #undef AFX_MANAGE_STATE
  36. #define AFX_MANAGE_STATE(a)
  37. #endif
  38. #define RecDebugOut CRsFuncTrace::Trace
  39. #define RecAssert(cond, hr) if (!(cond)) RecThrow(hr)
  40. #define RecThrow(hr) throw( CRecThrowContext( __FILE__, __LINE__, hr ) );
  41. #define RecAffirm(cond, hr) if (!(cond)) RecThrow(hr)
  42. #define RecAffirmHr(hr) \
  43. { \
  44. HRESULT lHr; \
  45. lHr = (hr); \
  46. RecAffirm(SUCCEEDED(lHr), lHr); \
  47. }
  48. #define RecAffirmHrOk(hr) \
  49. { \
  50. HRESULT lHr; \
  51. lHr = (hr); \
  52. RecAffirm(S_OK == lHr, lHr); \
  53. }
  54. #define RecAssertHr(hr) \
  55. { \
  56. HRESULT lHr; \
  57. lHr = (hr); \
  58. RecAssert(SUCCEEDED(lHr), lHr); \
  59. }
  60. #define RecAssertStatus(status) \
  61. { \
  62. BOOL bStatus; \
  63. bStatus = (status); \
  64. if (!bStatus) { \
  65. DWORD dwErr = GetLastError(); \
  66. HRESULT lHr = HRESULT_FROM_WIN32(dwErr); \
  67. RecAssert(SUCCEEDED(lHr), lHr); \
  68. } \
  69. }
  70. #define RecAssertHandle(hndl) \
  71. { \
  72. HANDLE hHndl; \
  73. hHndl = (hndl); \
  74. if (hHndl == INVALID_HANDLE_VALUE) { \
  75. DWORD dwErr = GetLastError(); \
  76. HRESULT lHr = HRESULT_FROM_WIN32(dwErr); \
  77. RecAssert(SUCCEEDED(lHr), lHr); \
  78. } \
  79. }
  80. #define RecAssertPointer( ptr ) \
  81. { \
  82. RecAssert( ptr != 0, E_POINTER);\
  83. }
  84. #define RecAffirmStatus(status) \
  85. { \
  86. BOOL bStatus; \
  87. bStatus = (status); \
  88. if (!bStatus) { \
  89. DWORD dwErr = GetLastError(); \
  90. HRESULT lHr = HRESULT_FROM_WIN32(dwErr); \
  91. RecAffirm(SUCCEEDED(lHr), lHr); \
  92. } \
  93. }
  94. #define RecAffirmHandle(hndl) \
  95. { \
  96. HANDLE hHndl; \
  97. hHndl = (hndl); \
  98. if (hHndl == INVALID_HANDLE_VALUE) { \
  99. DWORD dwErr = GetLastError(); \
  100. HRESULT lHr = HRESULT_FROM_WIN32(dwErr); \
  101. RecAffirm(SUCCEEDED(lHr), lHr); \
  102. } \
  103. }
  104. #define RecAffirmPointer( ptr ) \
  105. { \
  106. RecAffirm( ptr != 0, E_POINTER);\
  107. }
  108. #define RecCatchAndDo(hr, code) \
  109. catch(CRecThrowContext context) { \
  110. hr = context.m_Hr; \
  111. TRACE( _T("Throw <0x%p> on line [%ld] of %hs"), context.m_Hr, (long)context.m_Line, context.m_File); \
  112. { code } \
  113. }
  114. // Turn on In-Your-Trace error messages for debugging.
  115. class CRecThrowContext {
  116. public:
  117. CRecThrowContext( char * File, long Line, HRESULT Hr ) :
  118. m_File(File), m_Line(Line), m_Hr(Hr) { }
  119. char * m_File;
  120. long m_Line;
  121. HRESULT m_Hr;
  122. };
  123. #define RecCatch(hr) \
  124. catch(CRecThrowContext context) { \
  125. hr = context.m_Hr; \
  126. TRACE( _T("Throw <0x%p> on line [%ld] of %hs"), context.m_Hr, (long)context.m_Line, context.m_File); \
  127. }
  128. class RecComString {
  129. public:
  130. RecComString( ) : m_sz( 0 ) { }
  131. RecComString( const OLECHAR * sz ) { m_sz = (OLECHAR*)CoTaskMemAlloc( ( wcslen( sz ) + 1 ) * sizeof( OLECHAR ) ); }
  132. ~RecComString( ) { Free( ); }
  133. void Free( ) { if( m_sz ) CoTaskMemFree( m_sz ); }
  134. operator OLECHAR * () { return( m_sz ); }
  135. OLECHAR** operator &() { return( &m_sz ); }
  136. private:
  137. OLECHAR * m_sz;
  138. };
  139. #endif