15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


problem when windows system shutdown.

Mao Zhihong -- maozh@geocities.com
Wednesday, January 08, 1997

Environment: VC++ 1.52, VC++ 4.0 with patch, Win3.1, Win 95

Hi, 
  I have a very strange problem: Only when my MFC application is closed
by 
Windows shutdown, it will cause a GP error.  
  In my appilcation, I have 2 document template, one kind of document is 
another's manager. When the manager document close, it will close those 
managed documents, when managed documents close, it will nitify its man-
ager documents. my codes are like these:
    
  class CMyDoc;   
  class CManagerDoc : public CDocument
  {
    ...
    public:
      CManagerDoc();
      ~CManagerDoc();
      CMyDoc *m_pMyDoc;
      
      void NotifyClose(); 
    ...
  };
  
  class CMyDoc : public CDocument
  {   
    ...
    public:
      CManagerDoc *m_pManager;
      
      virtual void OnCloseDocument(); 
    ...  
  };
  
  
  ...
  CManagerDoc::CManagerDoc()
  {
    ...
    m_pMyDoc = NULL;
    ...
  }                 
  
  CManagerDoc::~CManagerDoc()
  {
    ...
    if (m_pMyDoc != NULL) {           
      m_pMyDoc->m_pManager = NULL; // don't let it notify me
      m_pMyDoc->OnCloseDocument();
    }  
    ...
  }                               
  
  CManagerDoc::NotifyClose()
  {
    m_pMyDoc = NULL; 
  }                  
  
  ....
  
  void CMyDoc::OnCloseDocument()
  {
    if (m_pManager != NULL) 
      m_pManager->NotifyClose();
      
    CDocument::OnCloseDocument();
  }
  ...               
  
  every thing is ok when you close this application normally(close by
ALT+F4,
close menu, close icon, or close by windows task manager, etc.). but
when 
windows system shut down, a GP error will occur when my application
close. 
(in windows 95, each kind of shut down will cause this error)
  Do anybody know why and can give me any advise?! Thanks in advance.
  
  							yours
  																			mao zhihong
  

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
          Mao Zhihong     DreamyRainbow Software Studio
                                                        Oooo.
 .oooO    Voc/Fax : 86-25-5408086                       (   )
 (   )    E-Mail  : mailto:maozh@geocities.com           ) /
  \ (               mailto:mao@seu.edu.cn               (_/
   \_)    URL     : http://www.geocities.com/Vienna/2898
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

"We get to create only a few things in this life. We really have 
such a short time here,  some of us just want to make it count."
                                                   - Steven Jobs



Dulepov Dmitry -- dima@ssm6000.samsung.ru
Friday, January 10, 1997

[Mini-digest: 2 responses]

        [Mailer: "Groupware E-Mail". Version 1.02.051]


Handle WM_ENDSESSION to close your application. Use SendMessage(WM_CLOSE) in your CMainFrame. Shutdown process differs in different systems (especially in Win95). I researched it for some time, but to handle WM_ENDSESSION is the easiest way to work around it that I know.


Dmitry A. Dulepov
Samsung Electronics Co., Ltd.
Russian Research Center
Phone: +7 (095) 213-9207
Fax: +7 (095) 213-9196
E-mail: dima@src.samsung.ru
====================================
-----------------------------
>        [From: Mao Zhihong
>        [Address: maozh@geocities.com
>        [To: MFC Board <" mfc-l"@netcom.com>
>        [Date: Fri Jan 10 10:22:59 1997
>Environment: VC++ 1.52, VC++ 4.0 with patch, Win3.1, Win 95
>
>Hi, 
>  I have a very strange problem: Only when my MFC application is closed
>by 
>Windows shutdown, it will cause a GP error.  
>  In my appilcation, I have 2 document template, one kind of document is 
>another's manager. When the manager document close, it will close those 
>managed documents, when managed documents close, it will nitify its man-
>ager documents. my codes are like these:
>    
>  class CMyDoc;   
>  class CManagerDoc : public CDocument
>  {
>    ...
>    public:
>      CManagerDoc();
>      ~CManagerDoc();
>      CMyDoc *m_pMyDoc;
>      
>      void NotifyClose(); 
>    ...
>  };
>  
>  class CMyDoc : public CDocument
>  {   
>    ...
>    public:
>      CManagerDoc *m_pManager;
>      
>      virtual void OnCloseDocument(); 
>    ...  
>  };
>  
>  
>  ...
>  CManagerDoc::CManagerDoc()
>  {
>    ...
>    m_pMyDoc = NULL;
>    ...
>  }                 
>  
>  CManagerDoc::~CManagerDoc()
>  {
>    ...
>    if (m_pMyDoc != NULL) {           
>      m_pMyDoc->m_pManager = NULL; // don't let it notify me
>      m_pMyDoc->OnCloseDocument();
>    }  
>    ...
>  }                               
>  
>  CManagerDoc::NotifyClose()
>  {
>    m_pMyDoc = NULL; 
>  }                  
>  
>  ....
>  
>  void CMyDoc::OnCloseDocument()
>  {
>    if (m_pManager != NULL) 
>      m_pManager->NotifyClose();
>      
>    CDocument::OnCloseDocument();
>  }
>  ...               
>  
>  every thing is ok when you close this application normally(close by
>ALT+F4,
>close menu, close icon, or close by windows task manager, etc.). but
>when 
>windows system shut down, a GP error will occur when my application
>close. 
>(in windows 95, each kind of shut down will cause this error)
>  Do anybody know why and can give me any advise?! Thanks in advance.
>  
>                              yours
>                                                                              mao zhihong
>  
>
>-- 
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>          Mao Zhihong     DreamyRainbow Software Studio
>                                                        Oooo.
> .oooO    Voc/Fax : 86-25-5408086                       (   )
> (   )    E-Mail  : mailto:maozh@geocities.com           ) /
>  \ (               mailto:mao@seu.edu.cn               (_/
>   \_)    URL     : http://www.geocities.com/Vienna/2898
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>"We get to create only a few things in this life. We really have 
>such a short time here,  some of us just want to make it count."
>                                                   - Steven Jobs
-----From: Bob Weidman 

I'm not sure this is related to MFC. I have experienced the same
behavior from Netscape 3.0 when doing a shutdown. (Unless Netscape uses
MFC).

I have seen this with programs written with 4.1, 4.2b MFC doing this
too.


Mao Zhihong wrote:
> 
> Environment: VC++ 1.52, VC++ 4.0 with patch, Win3.1, Win 95
> 
> Hi,
>   I have a very strange problem: Only when my MFC application is closed
> by
> Windows shutdown, it will cause a GP error.
>   In my appilcation, I have 2 document template, one kind of document is
> another's manager. When the manager document close, it will close those
> managed documents, when managed documents close, it will nitify its man-
> ager documents. my codes are like these:
> 
>   class CMyDoc;
>   class CManagerDoc : public CDocument
>   {
>     ...
>     public:
>       CManagerDoc();
>       ~CManagerDoc();
>       CMyDoc *m_pMyDoc;
> 
>       void NotifyClose();
>     ...
>   };
> 
>   class CMyDoc : public CDocument
>   {
>     ...
>     public:
>       CManagerDoc *m_pManager;
> 
>       virtual void OnCloseDocument();
>     ...
>   };
> 
> 
>   ...
>   CManagerDoc::CManagerDoc()
>   {
>     ...
>     m_pMyDoc = NULL;
>     ...
>   }
> 
>   CManagerDoc::~CManagerDoc()
>   {
>     ...
>     if (m_pMyDoc != NULL) {
>       m_pMyDoc->m_pManager = NULL; // don't let it notify me
>       m_pMyDoc->OnCloseDocument();
>     }
>     ...
>   }
> 
>   CManagerDoc::NotifyClose()
>   {
>     m_pMyDoc = NULL;
>   }
> 
>   ....
> 
>   void CMyDoc::OnCloseDocument()
>   {
>     if (m_pManager != NULL)
>       m_pManager->NotifyClose();
> 
>     CDocument::OnCloseDocument();
>   }
>   ...
> 
>   every thing is ok when you close this application normally(close by
> ALT+F4,
> close menu, close icon, or close by windows task manager, etc.). but
> when
> windows system shut down, a GP error will occur when my application
> close.
> (in windows 95, each kind of shut down will cause this error)
>   Do anybody know why and can give me any advise?! Thanks in advance.
> 
>                                                         yours
>                                                                                                                                                         mao zhihong
> 
> 
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>           Mao Zhihong     DreamyRainbow Software Studio
>                                                         Oooo.
>  .oooO    Voc/Fax : 86-25-5408086                       (   )
>  (   )    E-Mail  : mailto:maozh@geocities.com           ) /
>   \ (               mailto:mao@seu.edu.cn               (_/
>    \_)    URL     : http://www.geocities.com/Vienna/2898
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> "We get to create only a few things in this life. We really have
> such a short time here,  some of us just want to make it count."
>                                                    - Steven Jobs



Roger Onslow/Newcastle/Computer Systems Australia/
Monday, January 13, 1997

Environment: VC++ 1.52, VC++ 4.0 with patch, Win3.1, Win 95

Destructors are not called when Windows Shutdown occurs.

This is documented in MSDN (Ask DrGui I think)

============================================================
    Roger Onslow
 Software Development Manager - Quisine Division
   Computer Systems Australia
------------------------------------------------------------
Ph:   +61 49 675266
Fax:   +61 49 675554
Personal  mailto:Roger_Onslow@compsys.com.au
Quisine info mailto:Quisine@compsys.com.au
Visit us at  http://www.compsys.com.au
============================================================
  Quisine - Designing for the Future
============================================================



Hemanta Banerjee -- hemantab@indus.hclt.com
Monday, January 13, 1997

Hi , 
I think its better to handle the WM_QUERYENDSESSION. U can check up whether
u want to actually end windows at that point of time (say middle of a 
processing in ur appllication) and act suitably. Check MSDEV help.

Bye , 
Hemanta Banerjee.
> 
> Handle WM_ENDSESSION to close your application. Use SendMessage(WM_CLOSE) in your CMainFrame. Shutdown process differs in different systems (especially in Win95). I researched it for some time, but to handle WM_ENDSESSION is the easiest way to work around it that I know.
> 
> 



Hemanta Banerjee -- hemantab@indus.hclt.com
Tuesday, January 14, 1997

> 
hi , 

> Environment: VC++ 1.52, VC++ 4.0 with patch, Win3.1, Win 95
> 
> Destructors are not called when Windows Shutdown occurs.
> 
> This is documented in MSDN (Ask DrGui I think)

It will be easier for u to trap the WM_QUERYENDSESSION if u want to 
have a choice whether windows is to actually shut down when ur app is 
running or u can trap WM_ENDSESSION which u will get on windows shutdown.
Here u call call the destructors of the actual objects.

Btw the destructors cannot be called on windows shutdown and that seems 
quite logical and windows does not store a run time object list of all 
object active in the system.

Bye,
Hemanta Banerjee. 



Regards,
Hemanta Banerjee.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Office :- 							Residence :- 
HCL Technologies Limited,			#17, Sriramnagar 1st Cross,
50-53 Greams Road,					Thiruvanmiyur,
Madras - 600 0006.					Madras - 600 041.

Ph :- (91)-(44)-8279140,8279312		(91)-(44)-#######
email :- hemantab@hclt.com			laddo@hotmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




| Вернуться в корень Архива |