C - shared memory for the structure

I need to finish a C program, but I'm stuck in the shared memory part of a task.

Basically this is what I should do: MapViewOfFilereturns a pointer to voidwhich you can overlay on anything. I suggest you create a structure that represents the structure that you would like to have in your memory and put a return pointer on that structure.

I call a function MapViewOffFile, but I don’t understand how I should point to the structure of it. The code:

typedef struct {
        LARGE_INTEGER start;
        LARGE_INTEGER end;
        LARGE_INTEGER frq;
} TimeOfSharing;

TimeOfSharing timing;

HANDLE fileView;
fileView = MapViewOfFile(fileHandle, FILE_MAP_READ | FILE_MAP_WRITE,PAGE_READONLY, 0, 0);

So how do I point fileViewto my structure? (I need to get the structure from another process)

Hope I was clear enough! Many thanks!

+3
source share
1 answer

MapViewOfFile void, HANDLE.

:

TimeOfSharing *timing = (TimeOfSharing *)MapViewOfFile(...);

// Then access as you see fit, e.g.:
LARGE_INTEGER length;

length.QuadPart = timing->end.QuadPart - timing->start.QuadPart;

/ , :

TimeOfSharing my_copy = *(TimeOfSharing *)MapViewOfFile(...);
+1

All Articles