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.

69 lines
2.6 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. HGLOBAL __H;
  40. #define MAKEP(sel,off) ((LPVOID)MAKELONG(off,sel))
  41. #define GHandle(sel) ((HGLOBAL)(sel)) /* GlobalHandle? */
  42. #define GSelector(h) (HIWORD((DWORD)GlobalLock(h)))
  43. #define GAllocSelF(f,ulBytes) ((__H=GlobalAlloc(f,(LONG)(ulBytes))) ? GSelector(__H) : NULL )
  44. #define GAllocPtrF(f,ulBytes) MAKEP(GAllocSelF(f,ulBytes),0)
  45. #define GAllocF(f,ulBytes) GAllocSelF(f,ulBytes)
  46. #define GAllocSel(ulBytes) GAllocSelF(GMEM_MOVEABLE,ulBytes)
  47. #define GAllocPtr(ulBytes) GAllocPtrF(GMEM_MOVEABLE,ulBytes)
  48. #define GAlloc(ulBytes) GAllocSelF(GMEM_MOVEABLE,ulBytes)
  49. #define GReAllocSel(sel,ulBytes) ((__H=GlobalReAlloc((HGLOBAL)(sel),(LONG)(ulBytes), GMEM_MOVEABLE | GMEM_ZEROINIT)) ? GSelector(__H) : NULL )
  50. #define GReAllocPtr(lp,ulBytes) MAKEP(GReAllocSel(HIWORD((DWORD)(lp)),ulBytes),0)
  51. #define GReAlloc(sel,ulBytes) GReAllocSel(sel,ulBytes)
  52. #define GSizeSel(sel) GlobalSize((HGLOBAL)(sel))
  53. #define GSize(sel) GSizeSel(sel)
  54. #define GLockSel(sel) MAKEP(sel,0)
  55. #define GUnlockSel(sel) /* nothing */
  56. #define GLock(sel) GLockSel(sel)
  57. #define GUnlock(sel) GUnlockSel(sel)
  58. #define GFreeSel(sel) (GlobalUnlock(GHandle(sel)),GlobalFree(GHandle(sel)))
  59. #define GFreePtr(lp) GFreeSel(HIWORD((DWORD)(lp)))
  60. #define GFree(sel) GFreeSel(sel)