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.

90 lines
3.1 KiB

  1. /*
  2. * GMEM.H - Macros for windows 3.0 memory management in protected mode
  3. *
  4. * because windows 3.0 runs in pmode GlobalLock and GlobalUnlock are
  5. * unnessary. The "Selector" to a memory object will always be the
  6. * same for the life of the memory object.
  7. *
  8. * these macros take advantage of the following win3 memory "facts"
  9. *
  10. * a SELECTOR (to a global object) is a HANDLE
  11. * a HANDLE is *not* a SELECTOR!!!!!!!!
  12. *
  13. * GlobalLock() and GlobalUnlock() do *not* keep lock counts
  14. *
  15. * GlobalLock() is the only way to convert a HANDLE to a SELECTOR
  16. *
  17. * functions:
  18. *
  19. * GHandle(sel) convert a SELECTOR to a HANDLE
  20. * GSelector(h) convert a HANDLE to a SELECTOR
  21. *
  22. * GAllocSel(ulBytes) allocate a SELECTOR ulBytes in size
  23. * GAllocPtr(ulBytes) allocate a POINTER ulBytes in size
  24. *
  25. * GReAllocSel(sel,ulBytes) re-alloc a SELECTOR
  26. * GReAllocPtr(lp,ulBytes) re-alloc a POINTER
  27. *
  28. * GSizeSel(sel) return the size in bytes of a SELECTOR
  29. *
  30. * GLockSel(sel) convert a SELECTOR into a POINTER
  31. * GUnlockSel(sel) does nothing
  32. *
  33. * GFreeSel(sel) free a SELECTOR
  34. * GFreePtr(lp) free a POINTER
  35. *
  36. * 5/31/90 ToddLa
  37. *
  38. */
  39. HANDLE __H;
  40. #ifndef _WIN32
  41. #define MAKEP(sel,off) ((LPVOID)MAKELONG(off,sel))
  42. #define GHandle(sel) ((HANDLE)(sel)) /* GlobalHandle? */
  43. #define GSelector(h) (HIWORD((DWORD)GlobalLock(h)))
  44. #else
  45. #define MAKEP(sel,off) GlobalLock((LPVOID)(sel))
  46. #define GHandle(sel) ((HANDLE)(sel)) /* GlobalHandle? */
  47. #define GSelector(h) (((DWORD)(h)))
  48. #endif // WIN16
  49. #define GAllocSelF(f,ulBytes) ((__H=GlobalAlloc(f,(LONG)(ulBytes))) ? GSelector(__H) : NULL )
  50. #define GAllocPtrF(f,ulBytes) MAKEP(GAllocSelF(f,ulBytes),0)
  51. #define GAllocF(f,ulBytes) GAllocSelF(f,ulBytes)
  52. #define GAllocSel(ulBytes) GAllocSelF(GMEM_MOVEABLE,ulBytes)
  53. #define GAllocPtr(ulBytes) GAllocPtrF(GMEM_MOVEABLE,ulBytes)
  54. #define GAlloc(ulBytes) GAllocSelF(GMEM_MOVEABLE,ulBytes)
  55. #define GReAllocSel(sel,ulBytes) ((__H=GlobalReAlloc((HANDLE)(sel),(LONG)(ulBytes),0)) ? GSelector(__H) : NULL )
  56. #ifndef _WIN32
  57. #define GReAllocPtr(lp,ulBytes) MAKEP(GReAllocSel(HIWORD((DWORD)(lp)),ulBytes),0)
  58. #else
  59. #define GReAllocPtr(lp,ulBytes) MAKEP(GReAllocSel(GlobalHandle(lp),ulBytes),0)
  60. #endif
  61. #define GReAlloc(sel,ulBytes) GReAllocSel(sel,ulBytes)
  62. #define GSizeSel(sel) GlobalSize((HANDLE)(sel))
  63. #define GSize(sel) GSizeSel(sel)
  64. #define GLockSel(sel) MAKEP(sel,0)
  65. #ifndef _WIN32
  66. #define GUnlockSel(sel) /* nothing */
  67. #else
  68. #define GUnlockSel(sel) GlobalUnlock(sel)
  69. #endif
  70. #define GLock(sel) GLockSel(sel)
  71. #define GUnlock(sel) GUnlockSel(sel)
  72. #define GFreeSel(sel) (GlobalUnlock(GHandle(sel)),GlobalFree(GHandle(sel)))
  73. #ifndef _WIN32
  74. #define GFreePtr(lp) GFreeSel(HIWORD((DWORD)(lp)))
  75. #else
  76. #define GFreePtr(lp) GFreeSel(GlobalHandle(lp))
  77. #endif
  78. #define GFree(sel) GFreeSel(sel)