Static Variables in DLL

Is it possible to use them?

In my DLL, I have a static vector defined in the global scope, and whenever I call a function that uses the vector the program crashes because the size of the vector is 0 when the function is called. The vector has had a value pushed onto it before, and I've even had a MessageBox come up to show what the size of the vector is after the call to push_back(), and it gave me a size of one. At no point am I ever calling any pop_ functions.

I also copied the code into a Win32 Console application project, and after removing all of the __declspecs, I ran a test. It didn't crash, and it gave me all of the values it was expected to. So are static variables to blame in this case? I'd rather not post the code since it's 150+ lines and would look bulky.
Last edited on
your dll might be loading and when you are done it my be unloading. now when you call it next time all your variables will be unset as the dll may load again. this might be the cause. I think you use loadlibrary and then unload the dll when you are done. i think this may work. are you able to debug the dll and see whats going on?
Is the global variable exported?
writetonsharma: I'm able to use the Visual Studio debugger to see where the program is crashing, but it was only able to show me that the vector is being emptied at some point. I've also tried having it a static member of a class, no difference. So I'm guessing that it's not because it's constantly being loaded and unloaded. Plus, it was working before. I added a couple of new arguments to make the function more customizable, but I didn't do anything else before it began to crash.

kbw: The static variable is only used within the DLL. I don't think it needs to be exported.
You're correct. Is it possible that it's being accessed thru inline functions in a header file?
I'm using a vector from the Standard Template Library. You tell me. :P

Other than the Vector class, I'm not using any other inline classes/functions. Not even my own. But why does that matter?

If I need to, I'll post the source. I just get annoyed when I see 5 people post the same 200-line piece of code with only a few changes to it.
Last edited on
yes.. please post the exe and dll code. i will debug.. :D
Alright, give me a while. For some reason it's giving me errors now whenever I compile. >.>

EDIT: Well, since god hates me, my classes aren't recognizing each other any more and I get errors whenever I try to compile. I'll post again when I have it working... er, well, compiling.
Last edited on
ok.. no problem. post it when its fine or i can help you in correcting the compiling errors also.. :D
I have a feeling that the whole problem is just because I accidentally removed a function or forgot a semicolon. The whole thing worked fine until I added the arguments to that one function... >.>
Topic archived. No new replies allowed.