![]() |
| | #1 |
| Registered User Join Date: Dec 2008
Posts: 5
| WindowsXP FileMapping problem,help!! When I want to use the shared memory, I got a problem. 1.I wrote a server to create a piece of shared memory. Source is below: // shmsv.cpp HANDLE hMapFile = NULL; LPVOID pVoid = NULL; hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, BUF_SIZE, // 1024 SHM_NAME); pVoid = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE); memset(pVoid, '*', BUF_SIZE); char *szMsg = "Hello shared memory."; CopyMemory(pVoid, szMsg, strlen(szMsg)); 2.I wrote another program to read message from the shared memory. Source is below: // readFrom.cpp HANDLE hFileMap = NULL; LPVOID pVoid = NULL; hFileMap = OpenFileMapping(FILE_MAP_READ, FALSE, SHM_NAME); pVoid = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 8); //BUF_SIZE); printf("message from shared memory is: %s.\n", (char *)pVoid); 3.Here comes the probelm: I only want to output the 8 bytes' info from the shared memory. But the "readFrom" program outputed all the message from the shared memory. 4.If I only want to output the 8 bytes' info from the shared memory, what should I do? regards, yogo |
| wal_sug is offline | |
| | #2 | |
| Registered User Join Date: Jan 2010
Posts: 231
| Quote:
![]() Code: char *szMsg = "Hello shared memory."; CopyMemory(pVoid, szMsg, strlen(szMsg)); You can either copy 8 chars to a new string, or if you don't care about corrupting the original data just insert a NULL at the 9th position. | |
| _Mike is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The C system command with long filenames in windowsXP | esbo | C Programming | 30 | 09-12-2006 07:06 PM |
| windowsxp networking. | xddxogm3 | Tech Board | 10 | 10-05-2004 12:18 PM |
| WindowsXP themes! | compjinx | A Brief History of Cprogramming.com | 11 | 10-31-2002 06:18 AM |
| WindowsXP Look | Crux++ | Windows Programming | 10 | 04-08-2002 04:06 PM |
| WindowsXP Security | Dude101 | A Brief History of Cprogramming.com | 19 | 10-03-2001 01:22 PM |