The destructor is called right away because this line
AutoNotify( dlg->m_hWnd );
creates a temporary object that gets deleted right away.
This line creates a non-temporary object:
AutoNotify guard( dlg->m_hWnd );
Now the destructor will be called only when the guard
object goes out of scope.