Monday, March 20, 2006
Sharing dll data across multiple processes
Suppose you have a dll and it is loaded by two processes A and B and you want to share some dll data between these two processes.
One of the simplest ways to achieve this is by declaring a shared data segment in the dll. This makes sure that all processes loading this dll will have access to same data. This method provides full access to shared data information, hence no security.
Here is how you declare a shared data segment in the dll (generally at the top of the source file):
One of the simplest ways to achieve this is by declaring a shared data segment in the dll. This makes sure that all processes loading this dll will have access to same data. This method provides full access to shared data information, hence no security.
Here is how you declare a shared data segment in the dll (generally at the top of the source file):
#pragma data_seg("SHARED") // Start of shared data segment.
// Declare variables here
int iSharedData;
#pragma data_seg() // End of shared data segment
// The following statment instructs the linker to generate the shared data segment
#pragma comment(linker, "/section:SHARED,RWS")