|
|
1.1 root 1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <stdarg.h>
4: #include <windows.h>
5: #include <string.h>
6: #include <winbase.h>
7:
8: extern ErrorOut();
9:
10: HANDLE CreateMapFile (char *MapFileName);
11: HANDLE CreateMap (HANDLE *FileToBeMapped, char MapName[30]);
12: LPVOID MapView (HANDLE *hMap);
13:
14: /**************************************************************************
15: * HANDLE CreateMapFile(char *MapFileName)
16: *
17: * Purpose: Create a Map file to map named share memory
18: *
19: * Inputs: none
20: *
21: * Returns: MapFileHandle - a handle to the file
22: * or NULL if failure
23: *
24: * Calls: CreateFile, ErrorOut
25: *
26: * History:
27: * 09-13-91 Peteg Created.
28: *
29: \**************************************************************************/
30: HANDLE CreateMapFile(char *MapFileName)
31: {
32: //char MapFileName[30]="MapFile.001";
33: HANDLE MapFileHandle;
34:
35: MapFileHandle= CreateFile(MapFileName,
36: GENERIC_READ | GENERIC_WRITE,
37: FILE_SHARE_READ | FILE_SHARE_WRITE,
38: NULL,
39: CREATE_ALWAYS,
40: FILE_ATTRIBUTE_NORMAL /* | STANDARD_RIGHTS_REQUIRED |
41: FILE_MAP_WRITE | FILE_MAP_READ */,
42: NULL);
43:
44: if (MapFileHandle == (HANDLE)-1)
45: {
46: ErrorOut("CreateFile");
47: return(NULL);
48: }
49: else
50: return(MapFileHandle);
51:
52: }
53:
54: /**************************************************************************
55: * HANDLE CreateMap(HANDLE *FileToBeMapped, char MapName[30] )
56: *
57: * Purpose: Create File Mapping object using the open file handle
58: *
59: * Inputs: *FileToBeMapped - pointer to the file handle
60: *
61: * Returns: MapHandle - handle to the file mapping object
62: * or NULL if failure
63: *
64: * Calls: CreateFileMapping, ErrorOut
65: *
66: * History:
67: * 09-13-91 Peteg Created.
68: *
69: \**************************************************************************/
70:
71: HANDLE CreateMap(HANDLE *FileToBeMapped, char MapName[30])
72: {
73: //char MapNameH[30]="MapName1";
74: HANDLE MapHandle;
75:
76: MapHandle= CreateFileMapping(*FileToBeMapped,
77: NULL,
78: PAGE_READWRITE,
79: 0,
80: 4096,
81: MapName);
82:
83: if (MapHandle == NULL)
84: {
85: ErrorOut("CreateFileMapping");
86: return(NULL);
87: }
88: else
89: return(MapHandle);
90:
91: }
92:
93:
94: /**************************************************************************
95: * LPVOID MapView(HANDLE *hMap)
96: *
97: * Purpose: Map the file mapping object into address space
98: *
99: * Inputs: *hMap - pointer to the mapping object
100: *
101: * Returns: MappedPointer - pointer to the address space that the
102: * object is mapped into
103: * or NULL if failure
104: *
105: * Calls: MapViewOfFile, ErrorOut
106: *
107: * History:
108: * 09-13-91 Peteg Created.
109: *
110: \**************************************************************************/
111:
112: LPVOID MapView(HANDLE *hMap)
113: {
114: LPVOID MappedPointer;
115:
116: MappedPointer= MapViewOfFile(*hMap,
117: FILE_MAP_WRITE | FILE_MAP_READ,
118: 0,
119: 0,
120: 4096);
121: if (MappedPointer == NULL)
122: {
123: ErrorOut("MapViewOfFile");
124: return(NULL);
125: }
126: else
127: return(MappedPointer);
128:
129: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.