DLL Forgetting Values?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bakhil
    New Member
    • Aug 2008
    • 1

    DLL Forgetting Values?

    Sorry if this question has been asked before, but I didn't exactly know how to word my question in the search box to get relevant results.

    The app I'm working on determines what DLL to load based on certain criteria. Each DLL implements the same abstract class such as in the example below:

    Code:
    class MyInterface
    {
    public:
    	void initialize() = 0;
    	void doSomething(int i) = 0;
    	int getSomeVar() = 0;
    }
    
    class MyFirstImplementation: public MyInterface
    {
    public:
    	void initialize();
    	void doSomething(int i);
    	int getSomeVar();
    private:
    	int _someVar;
    	int _anotherVar;
    }
    By setting a pointer to the base class (in this example, MyInterface), the main app can use the same API across all DLLs. The DLLs each read certain files, store the vital contents in member variables and provide a method to get/set these variables (eg. getSomeVar() returns the contents of _someVar in the example above).

    However, I've noticed that the DLLs will "forget" the values in these variables after a while. The first call, immediately after the DLL has loaded the file, everything works. I try and access the variables again at another point in the program (I've made sure that nothing else has accessed the DLL by debugging the program line by line) and the functions begin to return junk values. I've even iterated through every function using for () and found that the second time the functions are called, they begin to return junk (but the first time everything works). No other program is accessing this DLL either.

    Has anyone experienced the same or even similar situation? If so, are there any ways to fix it? Any help wold be appreciated. Thanks!
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Possibly your program is suffering from 'slicing'; slicing can happen when you
    store an object of a derived class in something that can only hold space for the
    base class. The rest or the object will be 'sliced' off.

    This behaviour notably happens when you have a vector<BaseClas s> and you
    want to store DerivedClass objects in it. If this applies to your program better
    use a vector<BaseClas s*> or vector<BaseClas s&> instead.

    kind regards,

    Jos

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Where are your base class virtual functions?

      Without them you have no polymorphism at all.

      Read this: http://bytes.com/forum/thread793836.html.

      Comment

      Working...