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.

68 lines
1.1 KiB

  1. #if !defined(FUSION_INC_FUSIONLASTWIN32ERROR_H_INCLUDED_)
  2. #define FUSION_INC_FUSIONLASTWIN32ERROR_H_INCLUDED_
  3. #pragma once
  4. #include <nt.h>
  5. #include <ntrtl.h>
  6. #include <nturtl.h>
  7. #include <windows.h>
  8. #if defined(_M_IX86)
  9. inline DWORD FusionpGetLastWin32Error(void)
  10. /* This works fine. */
  11. {
  12. __asm
  13. {
  14. mov eax, fs:[0] _TEB.LastErrorValue
  15. }
  16. }
  17. inline void FusionpGetLastWin32Error(
  18. DWORD *pdwLastError
  19. )
  20. {
  21. *pdwLastError = ::FusionpGetLastWin32Error();
  22. }
  23. /* This works pretty ok. */
  24. __forceinline VOID FusionpSetLastWin32Error(DWORD dw)
  25. {
  26. NtCurrentTeb()->LastErrorValue = dw;
  27. }
  28. inline void FusionpClearLastWin32Error(void)
  29. {
  30. __asm
  31. {
  32. mov fs:[0] _TEB.LastErrorValue, 0
  33. }
  34. }
  35. #else
  36. inline DWORD FusionpGetLastWin32Error(void)
  37. {
  38. return ::GetLastError();
  39. }
  40. inline void FusionpGetLastWin32Error(
  41. DWORD *pdwLastError
  42. )
  43. {
  44. *pdwLastError = ::GetLastError();
  45. }
  46. inline VOID FusionpSetLastWin32Error(DWORD dw)
  47. {
  48. ::SetLastError(dw);
  49. }
  50. inline void FusionpClearLastWin32Error(void)
  51. {
  52. ::SetLastError(ERROR_SUCCESS);
  53. }
  54. #endif
  55. #endif