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

  1. /*
  2.  *  LocalUnlock
  3.  *
  4.  *  This program demonstrates the use of the LocalUnlock function.  It
  5.  *  will allocate a block of memory using LocalAlloc, lock the
  6.  *  memory with LocalLock, copy a string to it and display it with
  7.  *  the MessageBox function, and then unlock the memory block with the
  8.  *  local Unlock function.
  9.  */
  10.  
  11. #include <windows.h>
  12.  
  13. int PASCAL WinMain ( hInstance , hPrevInstance, lpszCmdLine, cmdShow )
  14.  
  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 NEAR *    pBuffer;      /*  Pointer to locked buffer    */
  22.   char *    strcpy();      /*  Tell compiler that it returns
  23.                    *  a pointer to a char
  24.                    */
  25.  
  26.   hMemBlock = LocalAlloc( LMEM_ZEROINIT | LMEM_MOVEABLE ,
  27.              (WORD) 80 );
  28.  
  29.        /*  Allocate 80 bytes of moveable memory and initialize
  30.     *  all of the bytes to 0
  31.     */
  32.  
  33.   pBuffer = LocalLock ( hMemBlock );
  34.        /*  Lock it and return the pointer to the locked block  */
  35.  
  36.   if ( pBuffer != NULL )  /*  Make sure that it was locked
  37.                *  Returns NULL if it wasn't
  38.                */
  39.     {
  40.     strcpy ( pBuffer , "LocalLock was Successfull" );
  41.        /*  Place the string into the block  */
  42.  
  43.     MessageBox( NULL , (LPSTR) pBuffer , (LPSTR) "OK" , MB_OK );
  44.        /*  Display the message that all is OK  */
  45.  
  46.     LocalUnlock( hMemBlock );
  47.        /*  Unlock Memory Block    */
  48.     }
  49.   else
  50.     MessageBox( NULL , (LPSTR)"LocalLock was not Successfull" ,
  51.         (LPSTR)"ERROR!!!" , MB_OK );
  52.  
  53.   return 0;
  54.   }
  55.