int g_Value; // Note that the global is not initialized.
#pragma data_seg()
DLL提供两个接口函数:
int GetValue()
{ return g_Value;
}
void SetValue(int n)
{ g_Value = n;
}
然后启动两个进程A和B,A和B都调用了这个DLL,假如A调用了SetValue(5);
B接着调用int m = GetValue();那么m的值不一定是5,而是一个未定义的值。因为DLL中的全局数据对于每一个调用它的进程而言,是私有的,不能共享的。假如你对g_Value进行了初始化,那么g_Value就一定会被放进MyData段中。换句话说,如果A调用了SetValue(5);
B接着调用int m = GetValue();那么m的值就一定是5!这就实现了跨进程之间的数据通信!