run-time dll linking - getting a variable
-
Hi, my scenario is like this: I link a dll at run-time by calling LoadLibrary() and then I call GetProcAddress to get the location of a function within that DLL so i can call it. This works fine. But now I wanted to get the location of a variable, and address that, but it doesn't work. In my DLL I have a declaration as follows:
extern "C" { char * szLogFile = "C:\\log.txt"; }
So I try to address the variable from my program as follows:
char * test = (char*)GetProcAddress(hinstDLL, "szLogFile");
But when I then try to show the variable test using a messagebox I just get garbage so the pointer must be wrong. Any ideas whats wrong? Kuniva --------------------------------------------
-
Hi, my scenario is like this: I link a dll at run-time by calling LoadLibrary() and then I call GetProcAddress to get the location of a function within that DLL so i can call it. This works fine. But now I wanted to get the location of a variable, and address that, but it doesn't work. In my DLL I have a declaration as follows:
extern "C" { char * szLogFile = "C:\\log.txt"; }
So I try to address the variable from my program as follows:
char * test = (char*)GetProcAddress(hinstDLL, "szLogFile");
But when I then try to show the variable test using a messagebox I just get garbage so the pointer must be wrong. Any ideas whats wrong? Kuniva --------------------------------------------
I've seen this same problem. I can't recall why now. I suggest you add a set/get function to the DLL and use that to access the variable instead. BTW global variables are evil. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
-
I've seen this same problem. I can't recall why now. I suggest you add a set/get function to the DLL and use that to access the variable instead. BTW global variables are evil. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
Heh, damn, I was kinda hoping for an explanation, I hate having to have to avoid the problem. But I guess I don't have much choice so thank you for your reply anyway. And as for the global variables are evil thing, so they keep telling me.. I don't see any reason why they should be evil in very small programs though :P And generally I believe it to be said by people who can't make sense of their own programs after a while ;) Also, no stack operations means more speed, weee. So, in short, global variables are evil, but fun! lol.. just messing. Kuniva --------------------------------------------