www.digitalmars.com         C & C++   DMDScript  

c++.windows.16-bits - WINIO Shutdown Hangup

reply Mark Evans <mevans zyvex.com> writes:
I have a problem closing WINIO windows at application shutdown time.  When I
quit, WINIO
"hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid of
it.  Windows
98 also issues a number of warning messages.

The structure of my application main loop is very simple.  It's an infinite
loop with a
global flag signaling "stop."  Here is the pseudo-code:

BOOL    appClosing = FALSE;

int main(int argc, char *argv[])
{
    App_Setup(); // open windows, init world

    while (! appClosing) // loop "forever"
    {
        if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
        {
            wmhandler_yield();  // WINIO library call
            continue;
        }
        if (appClosing) break; // safety

        // Do my stuff next....could open more windows
        // or close some, could set appClosing TRUE from
        // program code
    }

    App_Cleanup(); // close windows (???), shutdown

    return 0;
}

I have one main window (the usual __hMainWnd) and other windows open.  The user
can close
or exit from any of them.

The problem is that only the main window is willing to close properly.  Even
winio_closeall() does not get rid of the others.

I've tried several variations of wmhandler_set for WM_CLOSE, winio_onclose,
etc.  I've
used message handlers galore.  It seems overly difficult to set things up so
that the
WINIO windows all close properly when the user selects "Exit" from the file
menu.

Given the application structure shown, could someone please demonstrate the
"approved"
method for shutting down all WINIO windows, and offer an explanation of why one
of them
would "hang" at shutdown.

(I do have a WM_TIMER proc running on the main window and that could contribute
to my
problem.)

Thanks,

Mark
Jul 18 2001
next sibling parent reply Andrew Schulman <undoc sonic.net> writes:
Sorry Mark, I have no idea. It's been years since I've looked at or used WINIO.
Once I could
do Win32 Console apps, I pretty much stopped using WINIO, even though obviously
I did miss
clickable lines and so on.

Regards,
Andrew

--
Andrew Schulman
Software litigation consultant
Chief Researcher, Workplace Surveillance Project, Privacy Foundation, US
http://www.undoc.com
undoc sonic.net
http://www.privacyfoundation.org/workplace

Mark Evans wrote:

 I have a problem closing WINIO windows at application shutdown time.  When I
quit, WINIO
 "hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid of
it.  Windows
 98 also issues a number of warning messages.

 The structure of my application main loop is very simple.  It's an infinite
loop with a
 global flag signaling "stop."  Here is the pseudo-code:

 BOOL    appClosing = FALSE;

 int main(int argc, char *argv[])
 {
     App_Setup(); // open windows, init world

     while (! appClosing) // loop "forever"
     {
         if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
         {
             wmhandler_yield();  // WINIO library call
             continue;
         }
         if (appClosing) break; // safety

         // Do my stuff next....could open more windows
         // or close some, could set appClosing TRUE from
         // program code
     }

     App_Cleanup(); // close windows (???), shutdown

     return 0;
 }

 I have one main window (the usual __hMainWnd) and other windows open.  The
user can close
 or exit from any of them.

 The problem is that only the main window is willing to close properly.  Even
 winio_closeall() does not get rid of the others.

 I've tried several variations of wmhandler_set for WM_CLOSE, winio_onclose,
etc.  I've
 used message handlers galore.  It seems overly difficult to set things up so
that the
 WINIO windows all close properly when the user selects "Exit" from the file
menu.

 Given the application structure shown, could someone please demonstrate the
"approved"
 method for shutting down all WINIO windows, and offer an explanation of why
one of them
 would "hang" at shutdown.

 (I do have a WM_TIMER proc running on the main window and that could
contribute to my
 problem.)

 Thanks,

 Mark

Jul 18 2001
next sibling parent reply Mark Evans <mevans zyvex.com> writes:
Andrew,

Fine then, has the source code been released to the public domain?

I'm not interested in fancy features of winio like clickable lines.  The whole
reason I'm using it is to avoid GUI hassles.

All I care about are crash messages at shutdown -- and sometimes the stray
WINIO task loop will not terminate even with several CTRL-ALT-DEL 
operations.

If I had the source I could figure it out for myself.....

Mark


On Wed, 18 Jul 2001 12:01:18 -0700, Andrew Schulman <undoc sonic.net> wrote:
 Sorry Mark, I have no idea. It's been years since I've looked at or used
WINIO. Once I could
 do Win32 Console apps, I pretty much stopped using WINIO, even though
obviously I did miss
 clickable lines and so on.
 
 Regards,
 Andrew
 
 --
 Andrew Schulman
 Software litigation consultant
 Chief Researcher, Workplace Surveillance Project, Privacy Foundation, US
 http://www.undoc.com
 undoc sonic.net
 http://www.privacyfoundation.org/workplace
 
 Mark Evans wrote:
 
 I have a problem closing WINIO windows at application shutdown time.  When I
quit, WINIO
 "hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid of
it.  Windows
 98 also issues a number of warning messages.

 The structure of my application main loop is very simple.  It's an infinite
loop with a
 global flag signaling "stop."  Here is the pseudo-code:

 BOOL    appClosing = FALSE;

 int main(int argc, char *argv[])
 {
     App_Setup(); // open windows, init world

     while (! appClosing) // loop "forever"
     {
         if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
         {
             wmhandler_yield();  // WINIO library call
             continue;
         }
         if (appClosing) break; // safety

         // Do my stuff next....could open more windows
         // or close some, could set appClosing TRUE from
         // program code
     }

     App_Cleanup(); // close windows (???), shutdown

     return 0;
 }

 I have one main window (the usual __hMainWnd) and other windows open.  The
user can close
 or exit from any of them.

 The problem is that only the main window is willing to close properly.  Even
 winio_closeall() does not get rid of the others.

 I've tried several variations of wmhandler_set for WM_CLOSE, winio_onclose,
etc.  I've
 used message handlers galore.  It seems overly difficult to set things up so
that the
 WINIO windows all close properly when the user selects "Exit" from the file
menu.

 Given the application structure shown, could someone please demonstrate the
"approved"
 method for shutting down all WINIO windows, and offer an explanation of why
one of them
 would "hang" at shutdown.

 (I do have a WM_TIMER proc running on the main window and that could
contribute to my
 problem.)

 Thanks,

 Mark


Jul 18 2001
parent reply Mark Evans <mevans zyvex.com> writes:
Ah, there it is in the Digital Mars folder....thank you Digital Mars.

Mark


On Wed, 18 Jul 2001 21:13:51 GMT, Mark Evans <mevans zyvex.com> wrote:
 Andrew,
 
 Fine then, has the source code been released to the public domain?
 

Jul 18 2001
parent "Walter" <walter digitalmars.com> writes:
Special thanks should go to Andrew Schulman, who graciously has allowed
Digital Mars to distribute his work.

Mark Evans wrote in message <1103_995495695 evans>...
Ah, there it is in the Digital Mars folder....thank you Digital Mars.

Mark


On Wed, 18 Jul 2001 21:13:51 GMT, Mark Evans <mevans zyvex.com> wrote:
 Andrew,

 Fine then, has the source code been released to the public domain?


Jul 18 2001
prev sibling parent "Kar Gay Lim" <kagay kimay.net> writes:
WOW!!!!

Walter wrote the compiler and Andrew Schulman is also reading this news
group....
This is programmer's heaven.

Ron Burk should be in I think.

Now, let us see if we can get Petzold in as well one...


Kar Gay Lim

Andrew Schulman <undoc sonic.net> wrote in message
news:3B55DCFE.70895AD3 sonic.net...
 Sorry Mark, I have no idea. It's been years since I've looked at or used
WINIO. Once I

 do Win32 Console apps, I pretty much stopped using WINIO, even though
obviously I did

 clickable lines and so on.

 Regards,
 Andrew

 --
 Andrew Schulman
 Software litigation consultant
 Chief Researcher, Workplace Surveillance Project, Privacy Foundation, US
 http://www.undoc.com
 undoc sonic.net
 http://www.privacyfoundation.org/workplace

 Mark Evans wrote:

 I have a problem closing WINIO windows at application shutdown time.  When I
quit,


 "hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid of
it.


 98 also issues a number of warning messages.

 The structure of my application main loop is very simple.  It's an infinite
loop with


 global flag signaling "stop."  Here is the pseudo-code:

 BOOL    appClosing = FALSE;

 int main(int argc, char *argv[])
 {
     App_Setup(); // open windows, init world

     while (! appClosing) // loop "forever"
     {
         if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
         {
             wmhandler_yield();  // WINIO library call
             continue;
         }
         if (appClosing) break; // safety

         // Do my stuff next....could open more windows
         // or close some, could set appClosing TRUE from
         // program code
     }

     App_Cleanup(); // close windows (???), shutdown

     return 0;
 }

 I have one main window (the usual __hMainWnd) and other windows open.  The
user can


 or exit from any of them.

 The problem is that only the main window is willing to close properly.  Even
 winio_closeall() does not get rid of the others.

 I've tried several variations of wmhandler_set for WM_CLOSE, winio_onclose,
etc.  I've
 used message handlers galore.  It seems overly difficult to set things up so
that the
 WINIO windows all close properly when the user selects "Exit" from the file
menu.

 Given the application structure shown, could someone please demonstrate the
"approved"
 method for shutting down all WINIO windows, and offer an explanation of why
one of


 would "hang" at shutdown.

 (I do have a WM_TIMER proc running on the main window and that could
contribute to my
 problem.)

 Thanks,

 Mark


Jul 21 2001
prev sibling parent reply Mark Evans <mevans zyvex.com> writes:
I'm happy to report that I have solved the problems with WINIO.

Using the WINIO source and the lovely DM line number/object address listing
file, I was able to track down the General Protection Faults fairly 
easily (without even using a debugger).

I had to tweak the WINIO source a little bit to deal with my app closure issues
properly, but all is well now.

One of the things I don't like about WINIO is the assumption that every window
is somehow going to be closed by the destruction of the main 
window.  That is not the case.  Independent windows must be destroyed by hand.

Mark


On Wed, 18 Jul 2001 17:20:46 GMT, Mark Evans <mevans zyvex.com> wrote:
 I have a problem closing WINIO windows at application shutdown time.  When I
quit, WINIO
 "hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid of
it.  Windows
 98 also issues a number of warning messages.
 
 The structure of my application main loop is very simple.  It's an infinite
loop with a
 global flag signaling "stop."  Here is the pseudo-code:
 
 BOOL    appClosing = FALSE;
 
 int main(int argc, char *argv[])
 {
     App_Setup(); // open windows, init world
 
     while (! appClosing) // loop "forever"
     {
         if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
         {
             wmhandler_yield();  // WINIO library call
             continue;
         }
         if (appClosing) break; // safety
 
         // Do my stuff next....could open more windows
         // or close some, could set appClosing TRUE from
         // program code
     }
 
     App_Cleanup(); // close windows (???), shutdown
 
     return 0;
 }
 
 I have one main window (the usual __hMainWnd) and other windows open.  The
user can close
 or exit from any of them.
 
 The problem is that only the main window is willing to close properly.  Even
 winio_closeall() does not get rid of the others.
 
 I've tried several variations of wmhandler_set for WM_CLOSE, winio_onclose,
etc.  I've
 used message handlers galore.  It seems overly difficult to set things up so
that the
 WINIO windows all close properly when the user selects "Exit" from the file
menu.
 
 Given the application structure shown, could someone please demonstrate the
"approved"
 method for shutting down all WINIO windows, and offer an explanation of why
one of them
 would "hang" at shutdown.
 
 (I do have a WM_TIMER proc running on the main window and that could
contribute to my
 problem.)
 
 Thanks,
 
 Mark
 
 
 

Jul 18 2001
next sibling parent reply "Walter" <walter digitalmars.com> writes:
Is your solution of general interest, i.e. should it be folded back into the
source?

Mark Evans wrote in message <1103_995505698 evans>...
I'm happy to report that I have solved the problems with WINIO.

Using the WINIO source and the lovely DM line number/object address listing

easily (without even using a debugger).

I had to tweak the WINIO source a little bit to deal with my app closure

One of the things I don't like about WINIO is the assumption that every

window.  That is not the case.  Independent windows must be destroyed by

Mark


On Wed, 18 Jul 2001 17:20:46 GMT, Mark Evans <mevans zyvex.com> wrote:
 I have a problem closing WINIO windows at application shutdown time.


 "hangs" and I need several CTRL-ALT-DEL task manager shutdowns to get rid


 98 also issues a number of warning messages.

 The structure of my application main loop is very simple.  It's an


 global flag signaling "stop."  Here is the pseudo-code:

 BOOL    appClosing = FALSE;

 int main(int argc, char *argv[])
 {
     App_Setup(); // open windows, init world

     while (! appClosing) // loop "forever"
     {
         if ( PeekMessage(&appMessage,(HWND) NULL,0,0,PM_NOREMOVE) )
         {
             wmhandler_yield();  // WINIO library call
             continue;
         }
         if (appClosing) break; // safety

         // Do my stuff next....could open more windows
         // or close some, could set appClosing TRUE from
         // program code
     }

     App_Cleanup(); // close windows (???), shutdown

     return 0;
 }

 I have one main window (the usual __hMainWnd) and other windows open.


 or exit from any of them.

 The problem is that only the main window is willing to close properly.


 winio_closeall() does not get rid of the others.

 I've tried several variations of wmhandler_set for WM_CLOSE,


 used message handlers galore.  It seems overly difficult to set things up


 WINIO windows all close properly when the user selects "Exit" from the


 Given the application structure shown, could someone please demonstrate


 method for shutting down all WINIO windows, and offer an explanation of


 would "hang" at shutdown.

 (I do have a WM_TIMER proc running on the main window and that could


 problem.)

 Thanks,

 Mark


Jul 18 2001
parent Mark Evans <mevans zyvex.com> writes:
Hmm.  Could be.  One thing was to call winio_doexit() explicitly from my code,
after tweaking it to call a cleanup procedure of my own.  I have a second
window called scan_params_window 
which WINIO was failing to close at shutdown.  On this window I call
DestroyWindow from the cleanup proc.

One other thing, maybe the most important:  WINIO by default does not make new
windows children of __hMainWnd.  It only does that if you make the child a
"popup" style window (yuk).  This 
design decision seemed to cause much of the shutdown problem.  I modified
new_window to make all new windows child windows of __hMainWnd.  That way when
__hMainWnd closes, so 
do they.

Mark



void winio_doexit(HWND hwnd, int nID)
{
    // Mark's additions
    App_Cleanup();
    // originally just this:
    DestroyWindow(hMaster);
}


void App_Cleanup()
{
   static didCleaning = FALSE;

   if (didCleaning) return;
   // else:
   didCleaning = TRUE; 
   appClosing = TRUE;
   Connection_Close();
   KillTimer(__hMainWnd,1);
   CircBuf_Destroy(in);
   CircBuf_Destroy(out);
   // WINIO was failing to close this guy
   DestroyWindow(scan_params_window);
   return;
}



/* ---------------------------------------------------------------  */
/* This function is called by winio_window(). It creates the new    */
/* window, and attaches the wmhandler table pointer and the         */
/* pointed to structure.                                            */
/* ---------------------------------------------------------------  */
HWND new_window(LPCREATEPARAMS cp, LPSTR strTitle, WORD wFlags)
    {
    HWND hwnd;
    WINIO_HWND whWnd = (WINIO_HWND) (cp->lpData);

    if (wFlags & WW_HASMENU)
        if (((whWnd->hFileMenu = CreateMenu()) == NULL) ||
            ((whWnd->hMainMenu = CreateMenu()) == NULL) ||
            (!hMaster && ((whWnd->hHelpMenu = CreateMenu()) == NULL)) ||
            (! AppendMenu(whWnd->hFileMenu, MF_STRING | MF_ENABLED,
                ID_SAVE, "&Save Buffer...")) ||
            (! AppendMenu(whWnd->hFileMenu,
                MF_SEPARATOR, NULL, NULL)) ||
            (! AppendMenu(whWnd->hFileMenu,
                MF_STRING | MF_ENABLED,
                ID_EXIT, "E&xit")) ||
            (!hMaster && (! AppendMenu(whWnd->hHelpMenu,
                MF_STRING | MF_ENABLED,
                ID_ABOUT, "&About..."))) ||
            (! AppendMenu(whWnd->hMainMenu,
                MF_STRING | MF_ENABLED | MF_POPUP,
                whWnd->hFileMenu, "&File")) ||
            (!hMaster && (! AppendMenu(whWnd->hMainMenu,
                MF_STRING | MF_ENABLED | MF_POPUP,
                whWnd->hHelpMenu, "&Help"))))
            return FALSE;

/*
    MJE Note
    The original WINIO source made a weird decision about whether
    to create the new window as a child window, we override that
    and make all windows child windows.
*/
    hwnd = CreateWindow((LPSTR) winio_wclass, (LPSTR) strTitle,
        winio_wstyle,
        grectCurr.left, grectCurr.top, grectCurr.right, grectCurr.bottom,
        (wFlags & WW_STAYSONTOP) ? hMaster : NULL,
        whWnd->hMainMenu, __hInst, (LPSTR) cp);
/*
    hwnd = CreateWindow((LPSTR) winio_wclass, (LPSTR) strTitle,
        winio_wstyle,
        grectCurr.left, grectCurr.top, grectCurr.right, grectCurr.bottom,
        hMaster,
        whWnd->hMainMenu, __hInst, (LPSTR) cp);
*/
    if (! hwnd)
        return NULL;

    if (!hMaster) winio_setmenufunc(hwnd, ID_ABOUT, winio_doabout);
    winio_setmenufunc(hwnd, ID_SAVE, winio_dosave);
    winio_setmenufunc(hwnd, ID_EXIT, winio_doexit);
    
    set_font(hwnd, whWnd);
    
    if (! gcxDefFont)
        {
        gcxDefFont = whWnd->cxChar;
        gcyDefFont = whWnd->cyChar;
        }
        
    winio_clear(hwnd);
    
    ShowWindow(hwnd, (hMaster) ? SW_SHOWNORMAL : __nCmdShow);
    UpdateWindow(hwnd);

    if (! hMaster)
        {
        winio_wstyle |= WS_POPUP;
        hMaster = hwnd;
        }
    else
    if (! (wFlags & WW_EXITALLOWED))
        EnableMenuItem(whWnd->hFileMenu, ID_EXIT, MF_DISABLED | MF_GRAYED);
    
    return hwnd;
    }
Jul 23 2001
prev sibling parent Chris Johnson <Chris_member pathlink.com> writes:
In article <1103_995505698 evans>, Mark Evans says...
I'm happy to report that I have solved the problems with WINIO.

A largely unrelated response. I made a port of Andrew Schulman's WINIO for Win32, which worked very successfully for years, and enabled me to write utilities which could function both in a Windows and a Linux environment (with a certain amount of conditional compilation!). I moved away from it by writing an equivalent which used a list box for the display (simpler, and gave cut and paste etc facilities). For my part I am quite happy to make the Win32 WINIO public if Andrew had no objection. I have a feeling that there was a Win32 port available, but it didn't work! It was all a long time ago now. Regards Chris Johnson chrisj_dmars edimatrix.co.uk
Feb 23 2006