Shared Variable – Shared variables are those variables which can be shared in multiple instance of the same application. Suppose we are running three instance of an exe, then the value of shared variable will be same in all three instances. If any instance change the value of shared variable then it will be reflect in all instance.
In short shared variable is same as static variable, the only difference is that static variable contain same value for all instance of class and shared variable contains same value for all instance of application.
To declare shared variable in VC++, following code can be use in .cpp file
// shared data
int IsHomePageSet = -1;
#pragma comment(linker, “/section:.SHARED,RWS”)
// end shared data
In above code, IsHomePageSet is declared as a shared variable. This variable will be use as normal variable. Value of this variable will be same in all the instance of application.