home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / memory / nmmemcli.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  2KB  |  72 lines

  1. /******************************************************************************\
  2. *       This is a part of the Microsoft Source Code Samples.
  3. *       Copyright (C) 1993-1997 Microsoft Corporation.
  4. *       All rights reserved.
  5. *       This source code is only intended as a supplement to
  6. *       Microsoft Development Tools and/or WinHelp documentation.
  7. *       See these sources for detailed information regarding the
  8. *       Microsoft samples programs.
  9. \******************************************************************************/
  10.  
  11.  
  12. #include <windows.h>
  13. #include "memory.h"
  14.  
  15.  
  16. /************************************************************************
  17.  * void ErrorOut(LPSTR errstring)
  18.  *
  19.  * Purpose: Print out an meainful error code by means of
  20.  *        GetLastError and printf
  21.  *
  22.  * Inputs:  errstring - the action that failed, passed by the
  23.  *                    calling proc.
  24.  *
  25.  * Returns: none
  26.  *
  27.  * Calls:   GetLastError
  28.  *
  29. \************************************************************************/
  30.  
  31.  
  32. void ErrorOut(LPSTR errstring)
  33. {
  34.    DWORD Error;
  35.    char  str[80];
  36.  
  37.    Error= GetLastError();
  38.  
  39.    wsprintf(str, GetStringRes(IDS_ERROR), errstring, Error);
  40.    MessageBox(ghwndMain, str, NULL, MB_OK);
  41. }
  42.  
  43. /*************************************************************************
  44.  * HANDLE OpenMap(LPSTR MapName)
  45.  *
  46.  * Purpose: Open the mapping object pointed to by MapName
  47.  *
  48.  * Inputs: none
  49.  *
  50.  * Returns: handle to mapped object or NULL if failure
  51.  *
  52.  * Calls: OpenFileMapping, ErrorOut
  53.  *
  54. \*************************************************************************/
  55.  
  56. HANDLE OpenMap( LPSTR MapName)
  57. {
  58.    HANDLE hAMap;
  59.  
  60.    hAMap= OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
  61.                           TRUE,
  62.                           MapName);
  63.  
  64.    if (hAMap == NULL)
  65.    {
  66.       ErrorOut("OpenFileMapping");
  67.       return(NULL);
  68.    }
  69.    else
  70.       return(hAMap);
  71. }
  72.