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.

186 lines
6.1 KiB

  1. #if !defined(_BCL_NTCOMMON_H_INCLUDED_)
  2. #define _BCL_NTCOMMON_H_INCLUDED_
  3. #pragma once
  4. #include <windows.h>
  5. #include <bcl_inlinestring.h>
  6. #include <bcl_unicodechartraits.h>
  7. namespace BCL
  8. {
  9. class CNtStringComparisonResult
  10. {
  11. public:
  12. inline void SetLessThan() { m_iComparisonResult = -1; }
  13. inline bool IsLessThan() const { return m_iComparisonResult == -1; }
  14. inline static CNtStringComparisonResult LessThan() { CNtStringComparisonResult cr; cr.m_iComparisonResult = -1; return cr; }
  15. inline void SetEqualTo() { m_iComparisonResult = 0; }
  16. inline bool IsEqualTo() const { return m_iComparisonResult == 0; }
  17. inline static CNtStringComparisonResult EqualTo() { CNtStringComparisonResult cr; cr.m_iComparisonResult = 0; return cr; }
  18. inline void SetGreaterThan() { m_iComparisonResult = 1; }
  19. inline bool IsGreaterThan() const { return m_iComparisonResult == 1; }
  20. inline static CNtStringComparisonResult GreaterThan() { CNtStringComparisonResult cr; cr.m_iComparisonResult = 1; return cr; }
  21. int m_iComparisonResult;
  22. };
  23. class CNtUnicodeToANSIDataIn
  24. {
  25. public:
  26. };
  27. class CNtUnicodeToOEMDataIn
  28. {
  29. public:
  30. };
  31. class CNtUnicodeToANSIDataOut
  32. {
  33. public:
  34. };
  35. class CNtUnicodeToOEMDataOut
  36. {
  37. public:
  38. };
  39. class CNtANSIToUnicodeDataIn
  40. {
  41. public:
  42. };
  43. class CNtOEMToUnicodeDataIn
  44. {
  45. public:
  46. };
  47. class CNtANSIToUnicodeDataOut
  48. {
  49. public:
  50. // Nothing!
  51. };
  52. class CNtOEMToUnicodeDataOut
  53. {
  54. public:
  55. };
  56. class CNtStringComparisonResultOnExitHelper : public CNtStringComparisonResult
  57. {
  58. public:
  59. inline CNtStringComparisonResultOnExitHelper(int &riComparisonResult) : m_riComparisonResult(riComparisonResult) { }
  60. inline ~CNtStringComparisonResultOnExitHelper() { m_riComparisonResult = m_iComparisonResult; }
  61. CNtStringComparisonResultOnExitHelper& operator=(const CNtStringComparisonResultOnExitHelper& o) { if (this != &o) { this->m_iComparisonResult = o.m_iComparisonResult; } return *this; }
  62. protected:
  63. int &m_riComparisonResult;
  64. };
  65. class CNtCallDisposition
  66. {
  67. public:
  68. inline bool DidFail() const { return m_NtStatus != STATUS_SUCCESS; }
  69. inline bool DidSucceed() const { return m_NtStatus == STATUS_SUCCESS; }
  70. inline void SetSuccess() { m_NtStatus = STATUS_SUCCESS; }
  71. inline void SetArithmeticOverflow() { m_NtStatus = STATUS_INTEGER_OVERFLOW; }
  72. inline void SetArithmeticUnderflow() { m_NtStatus = STATUS_INTEGER_OVERFLOW; }
  73. inline void SetInternalError_ObjectLocked() { m_NtStatus = STATUS_INTERNAL_ERROR; }
  74. inline void SetInternalError_RuntimeCheck() { m_NtStatus = STATUS_INTERNAL_ERROR; }
  75. inline void SetInternalError_EpilogSkipped() { m_NtStatus = STATUS_INTERNAL_ERROR; }
  76. inline void SetBadParameter() { m_NtStatus = STATUS_INVALID_PARAMETER; }
  77. inline void SetBufferOverflow() { m_NtStatus = STATUS_BUFFER_OVERFLOW; }
  78. inline void SetOutOfMemory() { m_NtStatus = STATUS_NO_MEMORY; }
  79. inline static CNtCallDisposition Success() { CNtCallDisposition t; t.m_NtStatus = STATUS_SUCCESS; return t; }
  80. inline static CNtCallDisposition ArithmeticOverflow() { CNtCallDisposition t; t.m_NtStatus = STATUS_INTEGER_OVERFLOW; return t; }
  81. inline static CNtCallDisposition ArithmeticUnderflow() { CNtCallDisposition t; t.m_NtStatus = STATUS_INTEGER_OVERFLOW; return t; }
  82. inline static CNtCallDisposition InternalError_ObjectLocked() { CNtCallDisposition t; t.m_NtStatus = STATUS_INTERNAL_ERROR; return t; }
  83. inline static CNtCallDisposition InternalError_RuntimeCheck() { CNtCallDisposition t; t.m_NtStatus = STATUS_INTERNAL_ERROR; return t; }
  84. inline static CNtCallDisposition InternalError_EpilogSkipped() { CNtCallDisposition t; t.m_NtStatus = STATUS_INTERNAL_ERROR; return t; }
  85. inline static CNtCallDisposition BadParameter() { CNtCallDisposition t; t.m_NtStatus = STATUS_INVALID_PARAMETER; return t; }
  86. inline static CNtCallDisposition BufferOverflow() { CNtCallDisposition t; t.m_NtStatus = STATUS_BUFFER_OVERFLOW; return t; }
  87. inline static CNtCallDisposition OutOfMemory() { CNtCallDisposition t; t.m_NtStatus = STATUS_NO_MEMORY; return t; }
  88. inline NTSTATUS OnPublicReturn() const { return m_NtStatus; }
  89. protected:
  90. NTSTATUS m_NtStatus;
  91. };
  92. class CNtPWSTRAllocationHelper
  93. {
  94. typedef CNtCallDisposition TCallDisposition;
  95. public:
  96. CNtPWSTRAllocationHelper() : m_pwstr(NULL) { }
  97. ~CNtPWSTRAllocationHelper() { if (m_pwstr != NULL) { ::RtlFreeHeap(RtlProcessHeap(), 0, m_pwstr); m_pwstr = NULL; } }
  98. CNtCallDisposition Allocate(SIZE_T cch)
  99. {
  100. BCL_MAYFAIL_PROLOG
  101. SIZE_T cb;
  102. if (m_pwstr != NULL)
  103. BCL_ORIGINATE_ERROR(CNtCallDisposition::InternalError_RuntimeCheck());
  104. cb = cch * sizeof(WCHAR);
  105. if ((cb / sizeof(WCHAR)) != cch)
  106. BCL_ORIGINATE_ERROR(CNtCallDisposition::ArithmeticOverflow());
  107. m_pwstr = reinterpret_cast<PWSTR>(::RtlAllocateHeap(RtlProcessHeap(), 0, cb));
  108. if (m_pwstr == NULL)
  109. BCL_ORIGINATE_ERROR(CNtCallDisposition::OutOfMemory());
  110. BCL_MAYFAIL_EPILOG_INTERNAL
  111. }
  112. PWSTR Detach() { PWSTR pszResult = m_pwstr; m_pwstr = NULL; return pszResult; }
  113. operator PWSTR() const { return m_pwstr; }
  114. private:
  115. PWSTR m_pwstr;
  116. };
  117. class CNtPSTRAllocationHelper
  118. {
  119. typedef CNtCallDisposition TCallDisposition;
  120. public:
  121. CNtPSTRAllocationHelper() : m_pstr(NULL) { }
  122. ~CNtPSTRAllocationHelper() { if (m_pstr != NULL) { ::RtlFreeHeap(RtlProcessHeap(), 0, m_pstr); m_pstr = NULL; } }
  123. CNtCallDisposition Allocate(SIZE_T cch /* == cb */)
  124. {
  125. BCL_MAYFAIL_PROLOG
  126. if (m_pstr != NULL)
  127. BCL_ORIGINATE_ERROR(CNtCallDisposition::InternalError_RuntimeCheck());
  128. m_pstr = reinterpret_cast<PSTR>(::RtlAllocateHeap(RtlProcessHeap(), 0, cch));
  129. if (m_pstr == NULL)
  130. BCL_ORIGINATE_ERROR(CNtCallDisposition::OutOfMemory());
  131. BCL_MAYFAIL_EPILOG_INTERNAL
  132. }
  133. PSTR Detach() { PSTR pszResult = m_pstr; m_pstr = NULL; return pszResult; }
  134. operator PSTR() const { return m_pstr; }
  135. private:
  136. PSTR m_pstr;
  137. };
  138. }; // namespace BCL
  139. #endif // !defined(_BCL_NTCOMMON_H_INCLUDED_)