|
|
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: chgdata.C ! 15: * Part of: BPointer sample application ! 16: * ! 17: \******************************************************************************/ ! 18: ! 19: #include <windows.h> ! 20: #include <stdio.h> ! 21: #include "shrstuff.h" ! 22: ! 23: ! 24: void InsertElement(int iValue) ! 25: { ! 26: clRunning->iElement = iValue; ! 27: clRunning->clNext = clRunning + 1; ! 28: clRunning += 1; ! 29: } ! 30: ! 31: ! 32: int main(void) ! 33: { HANDLE hFileMapping; ! 34: int iCounter; ! 35: int iNextElement; ! 36: int iInternalCounter = 0; ! 37: ! 38: // Set up the shared memory. By using MapViewOfFileEx(), we force the ! 39: // memory onto a specific location. This is just to show how based ! 40: // pointers work for memory that is mapped differenctly in two processes. ! 41: ! 42: hFileMapping = CreateFileMapping((HANDLE)0xffffffff,NULL,PAGE_READWRITE,0,4096, ! 43: "DemoMapObject"); ! 44: if (GetLastError() == ERROR_ALREADY_EXISTS) ! 45: { printf("Please close readdata before running this application!"); ! 46: return(0); ! 47: }; ! 48: if (!hFileMapping) ! 49: { printf ("Failed on CreateFileMapping..."); ! 50: return(0); ! 51: }; ! 52: clBasePt = (CHAINLIST *)MapViewOfFileEx(hFileMapping,FILE_MAP_ALL_ACCESS,0,0,0, ! 53: (PVOID)0x40000000); ! 54: ! 55: // Now the memory is set up. The following loops prompts the user for new ! 56: // elements until a 0 is hit. The memory is displayed so that we see that ! 57: // the offsets are entered into the link fields, ignoring the based ! 58: // pointers. ! 59: ! 60: printf("Base address of file mapping in this process: 0x%x\n",(int)clBasePt); ! 61: printf("Enter element to insert; 0 terminates: "); ! 62: scanf("%d",&iNextElement); ! 63: while (iNextElement != 0) ! 64: { InsertElement(iNextElement); ! 65: iInternalCounter+= sizeof(CHAINLIST); ! 66: printf ("Now displaying raw data at address: 0x%x\n",(int)clBasePt); ! 67: printf ("You might want to run readdata.exe now.\n"); ! 68: for (iCounter = 0; iCounter<=iInternalCounter;iCounter++) ! 69: printf("%2x ",((char *)clBasePt)[iCounter]); ! 70: printf("\n"); ! 71: printf("Enter next element to insert; 0 terminates: "); ! 72: scanf("%d",&iNextElement); ! 73: }; ! 74: ! 75: // user has entered 0 -- now clean up. ! 76: ! 77: UnmapViewOfFile(clBasePt); ! 78: CloseHandle(hFileMapping); ! 79: return(0); ! 80: } ! 81: ! 82: ! 83: ! 84: ! 85: ! 86: ! 87: ! 88: ! 89: ! 90: ! 91: ! 92: ! 93:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.