home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / memory / global / globunwr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.5 KB  |  50 lines

  1. /*
  2.  *   GlobalUnWire
  3.  *   globwire.c
  4.  *
  5.  *   This program demonstrates the use of the GlobalUnWire function. The
  6.  *   GlobalUnWire function unlocks a block that has been locked into low
  7.  *   memory using the GlobalWire function. GlobalUnWire is called from
  8.  *   WinMain in this sample application.
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. int sprintf();
  15.  
  16. typedef struct {
  17.         char smallstruct[20];
  18.            } SMALLSTRUCT;          /* structure we're going to allocate */
  19.                         /*   space for      */
  20. typedef SMALLSTRUCT far *lpSMALLPtr;  /* pointer to SMALLSTRUCT structure */
  21.  
  22. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  23. HANDLE hInstance, hPrevInstance;
  24. LPSTR lpszCmdLine;
  25. int cmdShow;
  26. {
  27.     HANDLE      hMemBlock;     /* Handle to memory block         */
  28.     lpSMALLPtr         ThisPtr;     /* Pointer to SMALLSTRUCT structure */
  29.     char szBuff[50];         /* buffer for output             */
  30.  
  31. /* Allocate space for SMALLSTRUCT in global heap */
  32.     hMemBlock = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE,
  33.             (long)sizeof(SMALLSTRUCT));
  34. /* if memory allocated properly */
  35.     if (hMemBlock)
  36.     /* GlobalWire the block into low memory */
  37.     ThisPtr = (lpSMALLPtr)GlobalWire(hMemBlock);
  38.  
  39. /******************** GlobalUnwire the block *******************************/
  40.     GlobalUnWire(hMemBlock);
  41.  
  42.     MessageBox(NULL,(LPSTR)"The block has been GlobalUnwire'ed",
  43.             (LPSTR)" ",MB_OK);
  44.  
  45. /* Free the block */
  46.     GlobalFree(hMemBlock);  /* free the block */
  47.  
  48.     return 0;
  49. }
  50.