I\'d like to share a static/global variable only between a process and a dll that is invoked by the process. The exe and dll are in the same memory address space. I don\'t w
I have seen many answers to this question and since it is a bit tricky and unclear I would like to bring the following scenario. We want to share a global variable between a DLL and a main program, and also allow access to this variable from different modules in the DLL and in the main program.
The variable is a BOOL indicating if the program should continue running or stop. The variable name is ShouldRun;
In the main program we need to put:
__declspec(dllexport) bool ShouldRun;
In the DLL's main module we need to put:
extern "C" BOOL __declspec(dllexport) ShouldRun = TRUE;
In any other module inside the DLL project we will use:
extern "C" BOOL ShouldRun;