change in Variable Value

  • Thread starter Thread starter Varadha
  • Start date Start date
V

Varadha

Hi,
I am declaring a variable
static char Version_No = '1' in header file header.h
In a application "app.exe", i am changing the value of the
variable in to '2'

In the same application i am calling an function fun1()
which is in another dll, MYDll.dll(which is linked
implicitly to the exe) which includes the same header file
header.h

When i use the variable Version_No in this function fun1(),
the change i made in the executable is not reflected in the
dll function.
i.e. when i access the variable Version_No in the function
fun1(), i am getting a value of '1' inshead of '2' . can u
help me in solving this problem.

If i want the change in the variable value to be reflected
in the application what is the change i need to do.

-Thanks in Advance
Varadha
 
Varadha said:
Hi,
I am declaring a variable
static char Version_No = '1' in header file header.h
In a application "app.exe", i am changing the value of the
variable in to '2'

In the same application i am calling an function fun1()
which is in another dll, MYDll.dll(which is linked
implicitly to the exe) which includes the same header file
header.h

When i use the variable Version_No in this function fun1(),
the change i made in the executable is not reflected in the
dll function.
i.e. when i access the variable Version_No in the function
fun1(), i am getting a value of '1' inshead of '2' . can u
help me in solving this problem.

If i want the change in the variable value to be reflected
in the application what is the change i need to do.

You have two variables named Version_No - one in the EXE and one in the DLL.
Indeed, since you declare the variable as static, you may have many copies
of the variable - a distinct copy in each translation unit (.c or .cpp file)
that includes the header file.

While it's possible to share data between an EXE and a DLL, it's generally
not a good design. Better to rely on exported functions to access/modify
the shared data.

-cd
 
Back
Top