Variable not same across process in DLL
-
I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.
-
I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.
-
I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll) Also the application calls the other.dll as well. Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions. At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set. I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables? How can I solve it to ensure that the variable in other.dll is the same across the process? I forget to mention that I'm using the windows api etc.
You wont be able to access anything in other.dll declared in such a way from Run.dll because they will have different instance handles. The only thing preventing a big crash in try to do so will be MFC's safe pointers because it is an access violation to allow it. There are two ways around the problem provide a function that returns the status on a standard DLL interface function something like
int OtherDLLStatus (void) {
return (OtherDLLStaticVar);
};Then publish it on the DLL interface and get the static variable status via that call. I think that is probably all you need. However Option 2 is use shared memory mapping http://msdn.microsoft.com/en-us/library/ms810613.aspx[^]
In vino veritas