I am trying to share a global variable between my_exe.exe
and my_dll.dll
. I would expect changes to my_var
made inside of my_exe.cpp
to be reflected in my_dll.cpp
at runtime. I expect the exe to have the dll loaded into it's address space and therefore making my_var
shared between the 2. However changes made to my_var
are not being reflected on either side. I am adding mydll.lib to the linker inputs for the my_exe project.
my_exe.cpp
extern __declspec(dllimport) float my_var;
typedef void (*called_from_exe)();
int main()
{
HMODULE my_dll = LoadLibraryW("my_dll.dll");
called_from_exe = (called_from_exe_t)GetProcAddress(my_dll, "called_from_exe");
my_var = 7.f;
called_from_exe();
}
my_dll.cpp
__declspec(dllexport) float my_var = 2.f;
extern "C" __declspec(dllexport) void called_from_exe()
{
print(my_var) // prints 0.00 instead of 7.00
}