Re: Sharing a structure between processes with memory mapped files
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:OFQB9F9SIHA.5980@TK2MSFTNGP04.phx.gbl...
"Sean Farrow" <sean.farrow@seanfarrow.co.uk> wrote in message
news:%23bDxA$8SIHA.2000@TK2MSFTNGP05.phx.gbl
Sorry if thisis th wrong group, but I hope somebody can help:
I am currently working on a project within wich I need to shae a
structure between processes.
The structure is defined in a namespace as follows:
struct SATreeviewInfo {
IAccessible* TreeviewAccessible;
[snipped]
};
You cannot share a structure containing pointers between processes. A
pointer only makes sense within a single process' address space. The same
pointer is meaningless in another process.
A "based pointer" is required, so that only relative addresses are stored.
Of course, all the pointers must then refer to other data inside the shared
memory.
http://msdn2.microsoft.com/en-us/library/57a97k4e(VS.71).aspx
Late in the namespace declaration I define a variable of this type:
extern SATreeviewInfo TreeviewInfo;
You want a pointer to SATreeviewInfo instead.
In the main code module after creatin the memory mapped file and
initializing this to th size of the structure, the following code
maps the structure in to the process:
TreeviewInfo =(SATreeviewInfo)MapViewOfFile(HTreeviewMSAAMapFile,
NULL, 0, 0, 0);
Again, you want to cast to SATreeviewInfo*
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925