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

  1. /*
  2.  *  LocalFlags
  3.  *
  4.  *  This program demonstrates the use of the LocalFlags function. The
  5.  *  program will allocate some memory using LocalAlloc, and then tell
  6.  *  the user if that memory block has been discarded or if it is marked
  7.  *  as discarded.
  8.  */
  9.  
  10. #include <windows.h>
  11.  
  12. /***************************************************************************/
  13.  
  14. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  15. HANDLE  hInstance, hPrevInstance;
  16. LPSTR    lpszCmdLine;
  17. int    cmdShow;
  18.   {
  19.   HANDLE    hMemBlock;           /*  The memory block */
  20.   WORD        wFlags;            /*  Return Value from function */
  21.   char    szBuffer[80];     /*  Temporary Buffer for a string */
  22.   int   sprintf ();          /*  Tell the compiler what will
  23.                                  *  be returned.
  24.                                    */
  25.  
  26. /*  Allocate 40 bytes of moveable, discardable memory and initialize
  27.     *  all of the bytes to 0.
  28.     */
  29.   hMemBlock = LocalAlloc (LMEM_ZEROINIT | LMEM_MOVEABLE | LMEM_DISCARDABLE,
  30.       (WORD) 40);
  31.  
  32.   wFlags = LocalFlags (hMemBlock);   /*  Get the info from LocalFlags  */
  33.  
  34.   if (wFlags & LMEM_DISCARDED)
  35.     MessageBox (NULL, (LPSTR)"The allocated memory has been discarded.",
  36.         (LPSTR)"Ok", MB_OK);
  37.  
  38.   if (wFlags & LMEM_DISCARDABLE)
  39.     MessageBox (NULL, (LPSTR)"The allocated memory is discardable.",
  40.         (LPSTR)"Ok", MB_OK);
  41.  
  42.   sprintf (szBuffer, "The Reference Count is %d",
  43.       wFlags & LMEM_LOCKCOUNT);
  44. /*  Masking out the lock or reference count  */
  45.  
  46.   MessageBox (NULL, (LPSTR) szBuffer, (LPSTR) "Ok", MB_OK);
  47. /*  Display the lock count via a message box  */
  48.  
  49.   return 0;
  50.   }
  51.