Source code for child.cpp
1: #define WIN32_LEAN_AND_MEAN
2: #include <windows.h>
3: #include <stdio.h>
4: #include <stdlib.h>
5: #include "sharedmem.h"
6:
7: #define MEM_NAME "ParentChildSharedMemory"
8:
9: typedef struct _DATA {
10: int value;
11: char sText[ 50 ];
12: } DATA, *PDATA;
13:
14:
15: void main( void )
16: {
17: SharedMem sm;
18:
19: if ( !sm.Create( sizeof( DATA ), MEM_NAME ) ) {
20: printf( "Unable to create shared memory buffer! Error#: %d\n",
21: sm.ErrorNumber() );
22: exit( EXIT_FAILURE );
23: }
24:
25: PDATA pdata = (PDATA) sm.GetMem();
26:
27: // put some random number and some text in shared memory
28: srand( GetTickCount() );
29: pdata->value = rand();
30: strcpy( pdata->sText, "Hi, dad!" );
31:
32: printf( "Child put the following in shared memory:\n"
33: "Value: %d\nText: %s\n\n", pdata->value,
34: pdata->sText );
35: }
36:
37: