views:

734

answers:

3
A: 

You probably have pointers/references in LtEntity which aren't serialized, too.

Perhaps you can give more information about LtEntity and which data is missing.

DR
+2  A: 

some details are missing

You can say that again. What is the definition of LtEntity?

Does the file mapping contain any embedded pointers? Those won't work, because the shared memory won't necessarily have the same virtual address in each process. And they won't work if they point outside the file mapping, even if the shared memory did happen to have the same virtual address in each process. Instead of pointers, you should store offsets from the beginning of the file mapping.

Are both processes running in the same login session? If not, you need to add the Global\ prefix to the name of the file mapping.

Also, you should use INVALID_HANDLE_VALUE, not (HANDLE)0xFFFFFFFFF. The definition of INVALID_HANDLE_VALUE changed when 64-bit Windows was added.

You can use LtEntity test(pBuf); instead of LtEntity test = LtEntity(pBuf);.

bk1e
+1  A: 

If you have pointers in LtEntity it won't work, as the mapped memory block in each process will typically start at a different address. Try using Boost::interprocess offset pointers, which store relative addresses instead.

Jason S
+1 for recommending Boost::interprocess. Don't fiddle with the low level error prone details if you can use a nice (well tested) abstraction.
lothar