atexit() and DLLs

Discussion in 'C++' started by Andreas Schmitt, Mar 9, 2007.

  1. Hi,

    I'm using a phoenix singleton template in a DLL for windows which is using
    the atexit()
    function to call the objects destructor in case
    the object had to be recreated with placement new after destruction.

    Now.. how does the atexit() function work in this case? If atexit() is
    called from within the DLL, will the secified
    functions be called when the DLL is unloaded? (good)
    Will they be called when the progam terminates? (bad)
    Will this not work at all an crash for sure? (worse)

    I'm using VC++ in case that makes a difference.

    Thanks
     
    Andreas Schmitt, Mar 9, 2007
    #1
    1. Advertising

  2. On 2007-03-09 10:23, Andreas Schmitt wrote:
    > Hi,
    >
    > I'm using a phoenix singleton template in a DLL for windows which is using
    > the atexit()
    > function to call the objects destructor in case
    > the object had to be recreated with placement new after destruction.
    >
    > Now.. how does the atexit() function work in this case? If atexit() is
    > called from within the DLL, will the secified
    > functions be called when the DLL is unloaded? (good)
    > Will they be called when the progam terminates? (bad)
    > Will this not work at all an crash for sure? (worse)
    >
    > I'm using VC++ in case that makes a difference.


    No, it does not because this is off topic here, where we discuss only
    the C++ language itself. Your question is better asked in a win32-
    programming group, perhaps you can find one in
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9


    To answer your question: I don't think atexit() is the right function to
    use, better would be to use DllMain(), pay special attention to the
    fdwReason argument. More details can be found here
    http://msdn2.microsoft.com/en-us/library/ms682583.aspx

    --
    Erik Wikström
     
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Mar 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Serve Laurijssen

    atexit and global destructors

    Serve Laurijssen, Jan 15, 2004, in forum: C++
    Replies:
    3
    Views:
    7,044
    tom_usenet
    Jan 15, 2004
  2. MathWizard

    atexit problems and questions....

    MathWizard, Jul 27, 2007, in forum: C++
    Replies:
    9
    Views:
    639
    MathWizard
    Jul 29, 2007
  3. Laurent Deniau

    exit, atexit and scope

    Laurent Deniau, Nov 15, 2007, in forum: C Programming
    Replies:
    22
    Views:
    869
    Laurent Deniau
    Nov 19, 2007
  4. Darren Dale
    Replies:
    8
    Views:
    602
    Darren Dale
    Mar 6, 2009
  5. Carl Banks
    Replies:
    5
    Views:
    296
    Gunter Henriksen
    May 19, 2009
Loading...

Share This Page