المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem in writing values to shared memory from another process



C++ Programming
07-03-2012, 05:43 PM
I have a Delphi application which Creates a shared memory uses CreateFileMapping, OpenFileMapping, MapViewOfFile functions.

Now I wanted to share the same memory for my MFC application. I used the OpenFileMapping, MapViewOfFile functions.

I created a structure exactly same in size as the Delphi application and mapped the structure object.
sample code:
HANDLE hMapObject2;
hMapObject2 = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, "PP101U3_SHARED");
if( !hMapObject2 )
{
AfxMessageBox("Failed to open Simpack DataBase");
return( 0 );
}
Simpack = ( struct SIMPACKDB *) MapViewOfFile( hMapObject2, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( !Simpack )
{
AfxMessageBox("Failed to create Simpack File Map View");
return(0);
}
Esim->SPV1 = Simpack->SP_Z;I am able to read the values exactly correct for all the member variables in the structure.
But when I try to write value in the shared memory, its not changing. It shows the previous value immediately in the debugger watch ********

The value of Simpack->SP_Z[15] is 0.5010 as read from the shared memory which is got from the Delphi application. i.e., value set by the Delphi application
When I set or write the value of the same variable to the shared memory in my MFC Application using the code:

Simpack->SP_Z[15] = 0.6123;
or
float test = 0.6123;
memcpy( Simpack->SP_Z + 16, &test, sizeof(float));it still shows the previous value 0.5010 which is got from the Delphi Application. But When I change the same variable's value in the Delphi applicationit changes and the changed value can be read here in the MFC application.

Please help me to find why I am unable to write or set value in the shared memory from my MFC Application and suggest me with any code how to write the values in the shared memory from my MFC Application.
Is there anything wrong in the code?
Is this happening because I am sharing the memory that is created by a Delphi Application from a MFC Application? i.e., Sharing memory between Delphi and MFC Application is not allowed.