Global object inside windows DLL: When gets the DTOR called?

This is a discussion on Global object inside windows DLL: When gets the DTOR called? within the C++ Programming forums, part of the General Programming Boards category; Hi, I compiled this class in a DLL: Code: class DbQuery :boost::noncopyable { DbQuery(); ~DbQuery(); pthread_mutex_t mQueryMutex; public: inline static ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519

    Global object inside windows DLL: When gets the DTOR called?

    Hi,

    I compiled this class in a DLL:

    Code:
    class DbQuery :boost::noncopyable
    {
    	DbQuery();
    	~DbQuery();
    	pthread_mutex_t mQueryMutex;
    
    public:
    
    	inline static DbQuery& instance()
    	{
    		static DbQuery db_query;
    		return db_query;
    	}
    
    [...]
    
    };
    It's used by several processes and encapsulates the access to a database. DB is opened in CTOR and closed in the DTOR. But when does the DTOR gets calles in this case? Never? Or if no process is using it any more in windows decides to unload the DLL (does this mechanism even exist?)?

    Thank You!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure that the destructor is called automatically when the DLL is unloaded (either by the APP requesting it to be unloaded or automatically when the app is exiting).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,666
    Global object constrcutors and destructors are called within the context of DllMain(), so you have to follow allow the rules and restrictions of what you can and can't do inside DllMain().

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Showing a window from inside a DLL
    By Rare177 in forum Windows Programming
    Replies: 0
    Last Post: 10-08-2004, 11:39 AM
  2. Inside a DLL
    By Magos in forum Windows Programming
    Replies: 4
    Last Post: 09-29-2003, 04:25 AM
  3. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  4. Creating object of type HWND from a dll
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-12-2002, 11:40 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21