home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / palfx / gmem.h < prev    next >
Text File  |  1991-09-17  |  3KB  |  73 lines

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