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.

91 lines
3.0 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. lhport.h
  5. Abstract:
  6. for porting code from longhorn (namespaces, exceptions)
  7. Author:
  8. Jay Krell (JayKrell) August 2001
  9. Revision History:
  10. --*/
  11. #pragma once
  12. #include "debmacro.h"
  13. #include "fusionbuffer.h"
  14. #include "fusionlastwin32error.h"
  15. #include "fusionhandle.h"
  16. #pragma warning(disable:4290) /* exception specifications mostly ignored */
  17. namespace F
  18. {
  19. typedef :: CStringBuffer CStringBuffer;
  20. typedef :: CStringBufferAccessor CStringBufferAccessor;
  21. typedef :: CUnicodeBaseStringBuffer CUnicodeBaseStringBuffer;
  22. typedef :: CBaseStringBuffer CBaseStringBuffer;
  23. typedef :: CTinyStringBuffer CTinyStringBuffer;
  24. typedef :: CDynamicLinkLibrary CDynamicLinkLibrary;
  25. inline BOOL InitializeHeap(HMODULE Module) { return FusionpInitializeHeap(Module); }
  26. inline void UninitializeHeap() { FusionpUninitializeHeap(); }
  27. inline DWORD GetLastWin32Error() { return FusionpGetLastWin32Error(); }
  28. inline void SetLastWin32Error(DWORD dw) { return FusionpSetLastWin32Error(dw); }
  29. class CErr
  30. {
  31. public:
  32. static void ThrowWin32(DWORD dw) {
  33. CErr e; ASSERT_NTC(dw != ERROR_SUCCESS); e.m_Type = eWin32Error; e.m_Win32Error = dw; throw e; }
  34. static void ThrowHresult(HRESULT hr) {
  35. CErr e; ASSERT_NTC(hr != S_OK); e.m_Type = eHresult; e.m_Hresult = hr; throw e; }
  36. bool IsWin32Error(DWORD dw) const {
  37. return (this->m_Type == eWin32Error && this->m_Win32Error == dw)
  38. || (this->m_Type == eHresult && HRESULT_FROM_WIN32(dw) == m_Hresult); }
  39. enum EType { eNtStatus, eHresult, eWin32Error };
  40. EType m_Type;
  41. union
  42. {
  43. LONG m_NtStatus;
  44. HRESULT m_Hresult;
  45. DWORD m_Win32Error;
  46. };
  47. };
  48. class CFnTracerVoidThrow : public ::CFrame
  49. {
  50. public:
  51. CFnTracerVoidThrow(const SXS_STATIC_TRACE_CONTEXT &rsftc) : CFrame(rsftc) { }
  52. ~CFnTracerVoidThrow() { if (g_FusionEnterExitTracingEnabled) ::FusionpTraceCallExit(); }
  53. void MarkInternalError() { this->MarkWin32Failure(ERROR_INTERNAL_ERROR); }
  54. void MarkAllocationFailed() { this->MarkWin32Failure(FUSION_WIN32_ALLOCFAILED_ERROR); }
  55. void MarkWin32LastErrorFailure(){ this->MarkWin32Failure(this->GetLastError()); }
  56. void MarkWin32Failure(DWORD dw) { F::CErr::ThrowWin32(dw); }
  57. void MarkCOMFailure(HRESULT hr) { F::CErr::ThrowHresult(hr); }
  58. void MarkSuccess() { }
  59. void ReturnValue() const { }
  60. private:
  61. void operator=(const CFnTracerVoidThrow&); // intentionally not implemented
  62. CFnTracerVoidThrow(const CFnTracerVoidThrow&); // intentionally not implemented
  63. };
  64. #define FN_PROLOG_VOID_THROW DEFINE_STATIC_FN_TRACE_CONTEXT(); F::CFnTracerVoidThrow __t(__stc); __t.Enter()
  65. #define FN_EPILOG_THROW FN_EPILOG
  66. // These are not right, but ok for "tools".
  67. #define ORIGINATE_COM_FAILURE_AND_EXIT(x, hr) IFCOMFAILED_ORIGINATE_AND_EXIT(hr)
  68. #define ThrResizeBuffer Win32ResizeBuffer
  69. #define ThrAssign Win32Assign
  70. #define ThrFormatAppend Win32FormatAppend
  71. #define ThrAppend Win32Append
  72. }