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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scoping question

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
0
0
US
Hi,

I wrote two DLLs. One is called by a single application and the other is called by multiple DLLs. For simplicity, here's how they are named.

prg.exe - Application
a.dll - DLL that I wrote, called by prg.exe
b.dll - DLL that I wrote, called by prg.exe and a.dll

b.dll contains five cpp files. One of the cpp files (call it z.cpp) has a function (not exported) that reads a file and stores an integer into a variable that is defined as global to z.cpp. b.dll also has an exported function, but I don't think it's related to the problem.

I wrote two programs that test a.dll and b.dll. The program that calls b.dll works fine, but the program that calls a.dll, which then calls b.dll doesn't work. Here's what appears to be happening in the case that doesn't work.

prg.exe loads a.dll and runs a.dll's initialization procedure, which reads file x and stores an int into a variable (named dbg) that is defined as global to a cpp in a.dll. prg.exe then loads b.dll and runs its initialization procedure, which also reads file x and stores an int into a variable named dbg, which is defined as global to a cpp file in b.dll. The contents of dbg are fine at this point. prg.exe later calls b.dll to run another function in the same cpp file where dbg is defined as global. When b.dll runs this time, dbg contains the value 0 instead of the value that was previously stored.

I tried using different variable names in a.dll and b.dll, such as dbg1 and dbg2 thinking that the compiler was confusing the two variables. That didn't fix the problem, nor did I really think it would because the compiler should be able to keep track of two different variables with the same name that are used in different programs, that also don't have the same scope.

Can anyone help me figure out what the problem is with this? I would be happy to post code if that will help understand the problem.

Thank you very much!

dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top