home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / rleapp / gmem.h < prev    next >
Text File  |  1992-09-12  |  2KB  |  62 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.  *      GAlloc(ulBytes)          allocate a SELECTOR ulBytes in size
  23.  *      GAllocPtr(ulBytes)          allocate a POINTER ulBytes in size
  24.  *
  25.  *      GReAlloc(sel,ulBytes)    re-alloc a SELECTOR
  26.  *      GReAllocPtr(lp,ulBytes)     re-alloc a POINTER
  27.  *
  28.  *      GSize(sel)               return the size in bytes of a SELECTOR
  29.  *
  30.  *      GLock(sel)               convert a SELECTOR into a POINTER
  31.  *      GUnlock(sel)             does nothing
  32.  *
  33.  *      GFree(sel)               free a SELECTOR
  34.  *      GFreePtr(lp)                free a POINTER
  35.  *
  36.  */
  37.  
  38. HANDLE __H;
  39.  
  40. #define MAKEP(sel,off)              ((LPVOID)MAKELONG(off,sel))
  41. #define SelPtr(sel)                 MAKEP(sel,0)
  42.  
  43. #define GHandle(sel)                ((HANDLE)(sel))  /* GlobalHandle? */
  44. #define GSelector(h)                (HIWORD((DWORD)GlobalLock(h)))
  45.  
  46. #define GAllocF(f,ulBytes)          ((__H=GlobalAlloc(f,(LONG)(ulBytes))) ? GSelector(__H) : NULL )
  47. #define GAllocPtrF(f,ulBytes)       MAKEP(GAllocF(f,ulBytes),0)
  48.  
  49. #define GAllocPtr(ulBytes)          GAllocPtrF(GMEM_MOVEABLE,ulBytes)
  50. #define GAlloc(ulBytes)             GAllocF(GMEM_MOVEABLE,ulBytes)
  51.  
  52. #define GReAlloc(sel,ulBytes)       ((__H=GlobalReAlloc((HANDLE)(sel),(LONG)(ulBytes),0)) ? GSelector(__H) : NULL )
  53. #define GReAllocPtr(lp,ulBytes)     MAKEP(GReAlloc(HIWORD((DWORD)(lp)),ulBytes),0)
  54.  
  55. #define GSize(sel)                  GlobalSize((HANDLE)(sel))
  56.  
  57. #define GLock(sel)                  MAKEP(sel,0)
  58. #define GUnlock(sel)                /* nothing */
  59.  
  60. #define GFree(sel)                  (GlobalUnlock(GHandle(sel)),GlobalFree(GHandle(sel)))
  61. #define GFreePtr(lp)                GFree(HIWORD((DWORD)(lp)))
  62.