Subj : Re: Save a global value to memory To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Mon Nov 22 2004 08:17 am There are elements in that message and the code it contains which suggests it is for 16 bit and other elements which suggest it is for 32 bit. Is this code for 16 bit Windows 3.1x or for Win32? .. Ed >akuma wrote: >I want to record the input value from one program >and put these value to the dll and let the other >program get this value. However, this is not sucess. >It seems that the varialbe is localized to one process >and private to the other process. Also, after all the >process terimated, the dll was automatically unloaded >even if FreeLibray function was not called. It is easy >to save these value to an ini file or registy, but due >to security reason, I want some method to store the >value to memory. I hope someone can help me to solve >the problem. The following is the non-working code: > >//Shared dll >int nGlobalValue; > >BOOL WINAPI DllEntryPoint(HINSTANCE hinst, DWORD >dwReason, LPVOID reserved) >{ > return 1; >} > >void FAR PASCAL _export SetGlobalValue(int nValue) >{ > nGlobalValue = nValue; >} > > >void FAR PASCAL _export GetGlobalValue(int *nValue) >{ > *nValue = nGlobalValue; >} > > >//process 1: > >void (FAR PASCAL *SetGlobalValue)(int) > > >void main() >{ > HINSTANCE hlib = LoadLibrary("Shareddll"); > if(hlib) > { > (FARPROC)SetGlobalValue = > GetProcAddress(hlib, "SetGlobalValue"); > SetGlobalValue("123456"); > } > > for(;;); //infine loop to stay process 1 and dll > in memory >} > > >//process 2: >//run when process 1 still running > >void (FAR PASCAL *GetGlobalValue)(int*) > >void main() >{ >int nGlobalValue; > > HINSTANCE hlib = LoadLibrary("Shareddll"); > if(hlib) > { > (FARPROC)GetGlobalValue = GetProcAddress(hlib, "GetGlobalValue"); > GetGlobalValue(&nGlobalValue); //always gets 0 > //How to share this global value??? > } >} > >After process 1 and process 2 both exited. The Dll >was freed automatically. Is there any way to keep >the dll in memory without import from any process? > >I have tried another method which was compile the >dll from to an exe file to let it share the functions. >However, the result is worser than before. Calling >the SetGlobalValue function to set the value will >generate "Access Viloation" exception. > >Is there any more simple way to save the share value >to memory? .