Reputation: 485
Consider, I have two Windows stand alone GUI applications. Whenever I press a command button in the first GUI, other GUI should capture the status of the button and should display ON or OFF in the text box in it. How can I do this with the use of shared memory.
PS: I am using VC++ 2008.
Upvotes: 3
Views: 16273
Reputation: 13984
Take a look: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551%28v=vs.85%29.aspx
In process 1 :
CreateFileMapping()
: It will create the Shared Memory Block, with the name provided in last parameter, if it is not already present and returns back a handle (you may call it a pointer), if successful.
MapViewOfFile()
: It maps (includes) this shared block in the process address space and returns a handle (again u can say a pointer).
With this pointer returned by MapViewOfFile() only you can access that shared block.
In process 2 :
OpenFileMapping()
: If the shared memory block is successfully created by CreateFileMapping(), you can use it with the same name (name used to create the shared memory block).
UnmapViewOfFile()
: It will unmap (you can remove the shared memory block from that process address space). When you are done using the shared memory (i.e. access, modification etc) call this function .
Closehandle()
: finally to detach the shared memory block from process , call this with argument,handle returned by OpenFileMapping() or CreateFileMapping().
Upvotes: 6