Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variable in DLL not visible

Status
Not open for further replies.

whothathandel

Programmer
Jul 31, 2002
1
DE
I wrote an application and a DLL that is called by it in C (Visual Studio 6). The application and the DLL each declare a global variable, but when the code of the application is processed, only the applications global variable is visible, and while in the DLL only the Dll's global variable is there.
From what I've found in the documentation, it ought to work when I declare these variables "__declspec(dllexport)" on one side and "__declspec(dllimport)" on the other, but it doesn't.
What do I have to do to get access to both variables at the same time? Have you sample code that works?
 
The thing is, since you create a local copy with the same name in your program, that variable will overshadow the one in the Dll. What you should do is declare it as extern in your program, that means that it is only declared there but will be defined (given a value) somewhere else, the linker will probably find it in you dll and you will be able to access it from your program.

I have no experience coding with dll:s on win, but that's the way it works with different o-files in *NIX.

Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top