CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #1
    Join Date
    Aug 2004
    Posts
    29

    Unhappy A Newbie's Problems w/ DLLs

    I have a "Model" abstract class with several concrete derived classes. Originally,
    I had test cases to create the various different classes. For instance:

    If (...)
    modelPtr = new Model1;
    else
    modelPtr = new Model2;

    I then call various members functions such as Model1.printParams(paramList), where paramList is a map of name strings with values.

    The declaration of printParams looks something like:
    void printParams(paramList& parameters);

    I wanted to change my implementation so that I could input in the name of a dll file and it would dynamically load the correct concrete model. To do so, I created a DLL for each model and an accompanying interface function that returned a new instance of the specific model. So instead of the above, I simply called:

    getModel(&modelPtr);

    After I had successfully grabbed the "getModel" interface function from whatever DLL I wanted to use. Each DLL basically was a seperate concrete class for Model and an interface function that looked like:

    int getModel(Model** model)
    {
    if (*model == NULL)
    return -1;
    else
    *model= new Model1;
    return 0;
    }

    Unfortunately, now when I attempt to call my printParams function from the newly created Model1, I get a access violation trying to iterate through the list of parameters. Whereas before it would print out each one, now it gives me an exception after printing the first one. The implementation of the printParams function is identical to the one previous; it just got moved along with the rest of the definition of the Model1 to a seperate project and then made into a DLL. Likewise, the definition of paramList is identical between the client code and the DLL model code. I test to verify that I have correctly opened the library, grabbed the function pointer, and gotten a non-NULL model** back after the getModel call.

    I don't understand how this could happen -- especially since I am passing in a reference to the parameters, and both the client code and the DLL code have the same header / source defining what a parameter list is. Any help would be greatly appreciated. Am I just missing something obvious that I should understand about DLL's? Is my interface function create poorly?
    Last edited by liquidroyl; August 26th, 2004 at 06:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured