I have the following code in a DLL:
#pragma data_seg("ABC")
__declspec (dllexport) char abc[2000] = { 0 };
#pragma data_seg()
#pragma comment(linker, "-section:ABC,rws")
I have the following code in an executable:
extern "C" __declspec(dllimport) char abc[];
char *abcPtr = abc;
#define iVar0 (*(long *)(abcPtr))
int main()
{
printf("Value: %d %p\n", iVar0, &iVar0);
iVar0 = 66;
printf("Value: %d %p\n", iVar0, &iVar0);
char buffer[256];
scanf_s("%s", buffer, 256);
}
When I run the first instance of the program I get:
Value: 0 0FC2A000
Value: 66 0FC2A000
If I run a second instance I get the following because they are using the same shared section:
Value: 66 0FC2A000 <- Notice the value here is set
Value: 66 0FC2A000
However if I change the value in the first instance using Visual Studio debugger, I can see that it changed in the memory location; however, I cannot see the value change if I rerun the second instance.
Why is the debugger not able to write the actual shared (memory) section?
I got the same result as yours:
My understanding is that certain value was not shared in the shared memory during debugging.
https://blogs.msdn.microsoft.com/oldnewthing/20040804-00/?p=38253/