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

  1. /*
  2.  *  LocalFree
  3.  *
  4.  *  This program demonstrates the use of the function LocalFree.  It
  5.  *  allocates a block of memory, using LocalAlloc, and then simply
  6.  *  frees the block.
  7.  */
  8.  
  9. #include <windows.h>
  10.  
  11. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  12.  
  13. HANDLE  hInstance, hPrevInstance;
  14. LPSTR    lpszCmdLine;
  15. int    cmdShow;
  16.   {
  17.   HANDLE    hMemBlock;      /*  The memory block    */
  18.   WORD    Flags;          /*  Return Value from function  */
  19.  
  20. /*  Allocate 40 bytes of moveable, discardable memory and initialize
  21.     *  all of the bytes to 0.
  22.     */
  23.   hMemBlock = LocalAlloc (LMEM_ZEROINIT | LMEM_MOVEABLE | LMEM_DISCARDABLE,
  24.       (WORD) 40);
  25.  
  26.   hMemBlock = LocalFree (hMemBlock);  /* Free the block of memory
  27.                                              * and put the return code into
  28.                                             * hMemBlock.
  29.                                                */
  30.  
  31.   if (hMemBlock == NULL)
  32.     MessageBox (NULL, (LPSTR)"LocalFree function Successful",
  33.         (LPSTR)"OK", MB_OK);
  34. /*  Tells user if successful  */
  35.   else
  36.     MessageBox (NULL, (LPSTR)"LocalFree function Unsuccessful",
  37.         (LPSTR)"OK", MB_OK);
  38. /*  Tells user if not successful  */
  39.  
  40.   return 0;
  41.   }
  42.