Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Data in a DLL

Status
Not open for further replies.

AndyHollywood

Programmer
Oct 7, 2001
30
GB
I am working on a dll at the mo which needs to be adapted from the original 16 bit version. Now from what i have read i understand that LibMain would only have been called once, where as dllmain is called for each new process, which gets its own memory address space! So to get round this i added a variable that would toggle once the dll had been entered the first time, and therefore avoid being repeated every new process:

#pragma data_seg("SHARDATA")
static HWND hwndMain = NULL;
static int nLineHeight = 0;
int calledonce = 0;
#pragma data_seg()

calledonce would then be used as follows:

case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
if (calledonce == 0)
{
hInstance = hModule;
calledonce = 1;
MessageBox(NULL, "incremented", " DLL Main", MB_OK);
}

HOw ever this dosent work....am i setting the shared data segment incorrectly or have o got the wrong end of the stick with regard to the shared data! The libmain version only had hInstance = hModule; in it and this is all i wish to achieve with the new version.

Can anybody tell me why my code won't work?! and wether it will solve the random painting problem with my app!?

the code is here if your interested or need to look at it to solve the prob or shed any light on it.

Cheers in advance

Andy :)
 
try to create a open a mutex. If theresulted handle is null create it, else the application is running once. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top