I have the deplorable mission the access a global(!) variable of a .exe from within my .dll (loaded by that .exe).
A header file gives me following declaration of the global variable:
extern Element *ops_TheActiveElement;
Basically, the global variable is a pointer to a class instance which i need to acess.
From what I found on the web, i could use something like this from within the dll:
Element* getTheActiveElement()
{
auto handle = GetModuleHandle(NULL);
if (handle == NULL)
std::cout << "handle" << handle << std::endl;
auto activeElement = GetProcAddress(handle, "ops_TheActiveElement") ;
return (Element*)activeElement;
}
Getting the module handle is fine, but getting the address of the global variable fails. I am not sure, if this is possible at all since i am not familiar with Windows programming. What could be a possible approach? Thank you in advance!