|
|
1.1 ! 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: ! 12: /******************************************************************************\ ! 13: * ! 14: * PROGRAM: readdata.C ! 15: * Part of: BPointer sample application ! 16: * ! 17: \******************************************************************************/ ! 18: #include <windows.h> ! 19: #include <stdio.h> ! 20: #include "shrstuff.h" ! 21: ! 22: ! 23: ! 24: ! 25: int main(void) ! 26: { HANDLE hFileMapping; ! 27: char cInput; ! 28: ! 29: // Set up the shared memory. By using MapViewOfFileEx(), we force the ! 30: // memory onto a specific location. This is just to show how based ! 31: // pointers work for memory that is mapped differenctly in two processes. ! 32: // In this process, the mapped file must already exist unless in chgdata ! 33: // where it must not exist yet. ! 34: ! 35: ! 36: hFileMapping = CreateFileMapping((HANDLE)0xffffffff,NULL,PAGE_READONLY,0,4096, ! 37: "DemoMapObject"); ! 38: if (GetLastError() != ERROR_ALREADY_EXISTS) ! 39: { printf("Please run chgdata before readdata!"); ! 40: return(0); ! 41: }; ! 42: if (!hFileMapping) ! 43: { printf ("Failed on CreateFileMapping..."); ! 44: return(0); ! 45: }; ! 46: clBasePt = (CHAINLIST *)MapViewOfFileEx(hFileMapping,FILE_MAP_READ,0,0,0, ! 47: (PVOID)0x50000000); ! 48: if (clBasePt == 0) ! 49: { printf("Error in MapViewOfFile: %d",GetLastError()); ! 50: scanf("%c",&cInput); ! 51: return(0); ! 52: }; ! 53: ! 54: // This loop continuously traverses the linkes list, dereferencing the ! 55: // link pointers through the base implicitly. ! 56: ! 57: printf("Press q to quit, anything else to display list: "); ! 58: scanf("%c",&cInput); ! 59: while (cInput != 'q') ! 60: { ! 61: clRunning = 0; ! 62: printf("Base address of file mapping in this process: 0x%x\n",(int)clBasePt); ! 63: while (clRunning->clNext != 0) ! 64: { printf ("Next Element in chain: %d\n",clRunning->iElement); ! 65: clRunning = clRunning->clNext; ! 66: }; ! 67: printf("Press q to quit, anything else to continue: "); ! 68: scanf("%c",&cInput); ! 69: }; ! 70: ! 71: // user didn't want any more dumps, so clean up. ! 72: ! 73: UnmapViewOfFile(clBasePt); ! 74: CloseHandle(hFileMapping); ! 75: return(0); ! 76: } ! 77: ! 78: ! 79: ! 80: ! 81: ! 82:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.