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

  1. /*
  2.  *  LocalLock
  3.  *
  4.  *  This program demonstrates the use of the function LocalLock.  It
  5.  *  allocates a block of memory, using LocalAlloc, Locks it, copies a string
  6.  *  into it and displays it in a message box.
  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        wFlags;       /*  Return Value from function  */
  19.   char NEAR *    pBuffer;      /*  Pointer to locked buffer    */
  20.   char *    strcpy();      /*  Tell compiler that it returns
  21.                    *  a pointer to a char
  22.                    */
  23.  
  24.   hMemBlock = LocalAlloc( LMEM_ZEROINIT | LMEM_MOVEABLE ,
  25.              (WORD) 80 );
  26.  
  27.        /*  Allocate 80 bytes of moveable memory and initialize
  28.     *  all of the bytes to 0
  29.     */
  30.  
  31.   pBuffer = LocalLock ( hMemBlock );
  32.        /*  Lock it and return the pointer  */
  33.  
  34.   if ( pBuffer != NULL )
  35.     {
  36.     strcpy ( pBuffer , "LocalLock was Successfull" );
  37.     MessageBox( NULL , (LPSTR) pBuffer , (LPSTR) "OK" , MB_OK );
  38.        /*  Display the message that all is OK  */
  39.     }
  40.   else
  41.     MessageBox( NULL , (LPSTR)"LocalLock was not Successfull" ,
  42.         (LPSTR)"OK" , MB_OK );
  43.  
  44.   return 0;
  45.   }
  46.