Annotation of mstools/samples/memory/nmmemsrv.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
1.1       root       12: #include <stdio.h>
                     13: #include <stdlib.h>
                     14: #include <stdarg.h>
                     15: #include <windows.h>
                     16: #include <string.h>
                     17: #include <winbase.h>
                     18: 
                     19: extern ErrorOut();
                     20: 
                     21: HANDLE CreateMapFile (char *MapFileName);
                     22: HANDLE CreateMap     (HANDLE *FileToBeMapped, char MapName[30]);
1.1.1.3 ! root       23: LPVOID MapView       (HANDLE *hMap);
1.1       root       24: 
                     25: /**************************************************************************
                     26:  * HANDLE CreateMapFile(char *MapFileName)
                     27:  *
                     28:  * Purpose: Create a Map file to map named share memory
                     29:  *
                     30:  * Inputs:  none
                     31:  *
                     32:  * Returns: MapFileHandle - a handle to the file
1.1.1.3 ! root       33:  *                        or NULL if failure
1.1       root       34:  *
                     35:  * Calls:   CreateFile, ErrorOut
                     36:  *
                     37: \**************************************************************************/
                     38: HANDLE CreateMapFile(char *MapFileName)
                     39: {
                     40: //char MapFileName[30]="MapFile.001";
                     41: HANDLE MapFileHandle;
                     42: 
                     43: MapFileHandle= CreateFile(MapFileName,
                     44:                           GENERIC_READ | GENERIC_WRITE,
                     45:                           FILE_SHARE_READ | FILE_SHARE_WRITE,
                     46:                           NULL,
                     47:                           CREATE_ALWAYS,
                     48:                           FILE_ATTRIBUTE_NORMAL /* | STANDARD_RIGHTS_REQUIRED |
                     49:                           FILE_MAP_WRITE | FILE_MAP_READ */,
                     50:                           NULL);
                     51: 
                     52: if (MapFileHandle == (HANDLE)-1)
                     53:   {
                     54:   ErrorOut("CreateFile");
                     55:   return(NULL);
                     56:   }
                     57: else
                     58:   return(MapFileHandle);
                     59: 
                     60: }
                     61: 
                     62: /**************************************************************************
                     63:  * HANDLE CreateMap(HANDLE *FileToBeMapped, char MapName[30] )
                     64:  *
                     65:  * Purpose: Create File Mapping object using the open file handle
                     66:  *
                     67:  * Inputs:  *FileToBeMapped - pointer to the file handle
                     68:  *
                     69:  * Returns: MapHandle - handle to the file mapping object
1.1.1.3 ! root       70:  *                    or NULL if failure
1.1       root       71:  *
                     72:  * Calls:   CreateFileMapping, ErrorOut
                     73:  *
                     74:  * History:
1.1.1.2   root       75:  * 09-13-91 Pete Gray   Created.
1.1       root       76:  *
                     77: \**************************************************************************/
                     78: 
                     79: HANDLE CreateMap(HANDLE *FileToBeMapped, char MapName[30])
                     80: {
                     81: //char MapNameH[30]="MapName1";
                     82: HANDLE MapHandle;
                     83: 
                     84: MapHandle= CreateFileMapping(*FileToBeMapped,
                     85:                              NULL,
                     86:                              PAGE_READWRITE,
                     87:                              0,
                     88:                              4096,
1.1.1.3 ! root       89:                              MapName);
1.1       root       90: 
                     91: if (MapHandle == NULL)
                     92:   {
                     93:   ErrorOut("CreateFileMapping");
                     94:   return(NULL);
                     95:   }
                     96: else
                     97:   return(MapHandle);
                     98: 
                     99: }
                    100: 
                    101: 
                    102: /**************************************************************************
                    103:  * LPVOID MapView(HANDLE *hMap)
                    104:  *
                    105:  * Purpose: Map the file mapping object into address space
                    106:  *
                    107:  * Inputs:  *hMap - pointer to the mapping object
                    108:  *
                    109:  * Returns: MappedPointer - pointer to the address space that the
1.1.1.3 ! root      110:  *                        object is mapped into
        !           111:  *                        or NULL if failure
1.1       root      112:  *
                    113:  * Calls:   MapViewOfFile, ErrorOut
                    114:  *
                    115:  * History:
1.1.1.2   root      116:  * 09-13-91 Pete Gray   Created.
1.1       root      117:  *
                    118: \**************************************************************************/
                    119: 
                    120: LPVOID MapView(HANDLE *hMap)
                    121: {
                    122: LPVOID MappedPointer;
                    123: 
                    124: MappedPointer= MapViewOfFile(*hMap,
                    125:                              FILE_MAP_WRITE | FILE_MAP_READ,
                    126:                              0,
                    127:                              0,
                    128:                              4096);
                    129: if (MappedPointer == NULL)
                    130:   {
                    131:   ErrorOut("MapViewOfFile");
                    132:   return(NULL);
                    133:   }
                    134: else
                    135:   return(MappedPointer);
                    136: 
                    137: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.