Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ class problem

Options
  • 15-06-2006 1:41pm
    #1
    Registered Users Posts: 250 ✭✭


    Hi

    I am experiencing a problem in a class that I've written and I am not sure why I am getting it. The class is supposed to load the library when it's instantiated and not again until the next reload of the class.

    I wrote a simple class to load an API library which is as follow:

    Class
    class MyClass
    {
    public:
      void LoadLibrary();
    private:
      BOOL bLibLoaded;
    }
    

    Constructor:
    MyClass::MyClass() { bLibLoaded = FALSE; }
    

    Function:
    void MyClass::LoadLibrary()
    {
      HMODULE hModule;
    
       if (bLibLoaded == FALSE)
      {
        hModule = LoadLibrary("mymodule.dll");
    
        bLibLoaded = TRUE;
      }
    }
    

    The problem is that I get an unhandled exception on the IF when it tests whether bLibLoaded is TRUE. I don't understand it. Initially I moved the hModule var declaration into the public/private sections of the class definition but it still doesn't want to work. If I remove the IF the code runs ok.

    This is the error message:
    First-chance exception in testclient.exe (BOCL.DLL): 0xC0000005: Access Violation.
    

    Naturally there is other code embedded aswell but I cannot see that that would effect this specific function.

    Any ideas?


Comments

  • Registered Users Posts: 2,426 ✭✭✭ressem


    Any more information in the stack trace?

    If you drop in more statements before 'bLibLoaded = TRUE;' does the error still occur.

    E.g. if you add in a typical bit of code, following the LoadLibrary

    if (null== hModule){
    //Log Error
    // return/exit/whatever
    }
    else {
    bLibLoaded = TRUE;
    }

    does the exception occur elsewhere, or the same line.


Advertisement