Board index » cppbuilder » Save a global value to memory

Save a global value to memory


2004-11-22 03:37:27 PM
cppbuilder41
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?
 
 

Re:Save a global value to memory

akuma wrote:
Quote
Is there any more simple way to save the share value to memory?
Each DLL is load from os in a virtual memory.. and two applications
don't have a share area. Try with another solution.. pipe, ipc, socket,
named pipe (not available in 9x) or file, or register...
bye
antonio
 

Re:Save a global value to memory

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
Quote
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?
 

{smallsort}

Re:Save a global value to memory

Quote
>Each DLL is load from os in a virtual memory.. and two applications
>don't have a share area. Try with another solution.. pipe, ipc, socket,
>named pipe (not available in 9x) or file, or register...
I don't want to use file or registry due to security reason, how to do it
under Windows 9x
if process 2 request a value input by process 1 after process 1 terminated?
Quote
>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?
This code is for Win32.
 

Re:Save a global value to memory

akuma wrote:
Quote
I don't want to use file or registry due to security reason, how to
do it
under Windows 9x
if process 2 request a value input by process 1 after process 1 terminated?
Process 2 require a input value to a dead process??
You must store the value input ... build another process that contain
input value
Antonio
 

Re:Save a global value to memory

On Mon, 22 Nov 2004 15:37:27 +0800, "akuma" < XXXX@XXXXX.COM >wrote:
Quote
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:
<snip>
Use memory mapped files. That should work fine.
HTH,
Jeff Kish