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

  1. /*
  2.  *  Function (s) demonstrated in this program: LocalHandle
  3.  *  Description:
  4.  *     This program will demonstrate the use of the LocalHandle function.
  5.  *  It will allocate memory using LocalAlloc, get a pointer to that
  6.  *  memory, and then check to make sure that LocalHandle returns the
  7.  *  same handle that LocalAlloc did.
  8.  *
  9.  */
  10.  
  11. #include <windows.h>
  12.  
  13. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. /***************************************************************************/
  16. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  17. HANDLE      hInstance, hPrevInstance;
  18. LPSTR       lpszCmdLine;
  19. int         nCmdShow;
  20.   {
  21.   HANDLE      hLocalMem;          /*  Handle to Local Memory  */
  22.   HANDLE      hLocalHandleMem;    /*  Will hold returned handle  */
  23.   PSTR        pszLocalMem;       /*  Near Pointer to memory  */
  24.  
  25.   hLocalMem = LocalAlloc (LMEM_MOVEABLE, 40);         /* Allocate memory */
  26.   pszLocalMem = (PSTR) LocalLock (hLocalMem);         /* Get a pointer   */
  27.   hLocalHandleMem = LocalHandle ( (WORD) pszLocalMem);
  28.  
  29. /*  Get the handle to the memory  */
  30.   if (hLocalHandleMem == hLocalMem)
  31.     MessageBox (GetFocus (), (LPSTR)"The two handles match", (LPSTR)"", MB_OK);
  32.   else
  33.     MessageBox (GetFocus (), (LPSTR)"The two handles don't match",
  34.         (LPSTR)"", MB_OK);
  35.  
  36.   LocalUnlock (hLocalMem);                          /* Unlock the memory */
  37.   LocalFree (hLocalMem);                            /* Free the memory   */
  38.  
  39.   return (0L);
  40.   }
  41.