Solved

Program remains in memory after ShellExecute

Posted on 1998-07-01
9
564 Views
Last Modified: 2013-12-03
My program launches the default Web browser and quits itself when the users press a button.

::ShellExecute(NULL, NULL, lpszUrl, NULL, NULL, SW_SHOWNORMAL);
this->PostMessage(WM_CLOSE);  // I am using MFC, this is the frame window, the only window.

I tested it on Windows 95 with IE 4.01 sp1.

With the Browse in a new process setting of IE enabled:

If there is no IE browser running, pressing the button starts the browser, everything is fine. If there is an IE browser running, pressing the button switches to it with the specified URL, everything is fine except that my program remains in memory (it is there when I press Ctrl-Alt-Del) until I restart the system.

With the Browse in a new process setting of IE disabled:

My program remains in memory from the second time the button is pressed.

On Windows NT, the problem does not exist.

Any ideas how to solve this problem?
0
Comment
Question by:chensu
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1409073
Why is your program still in memory?  Does the close message get posted?  Does it get received?  Does the window get destroyed?  Where does the this break down?
0
 
LVL 1

Expert Comment

by:sergem
ID: 1409074
You shoul to send WM_QUIT message
PostAppMessage(WM_QUIT)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409075
I think chensu is expecting the application to post the quite message (PostQuitMessage() when it closes the main window.  That is the way most applications work.  That is why I'm wondering if the main window closes.
0
 
LVL 23

Author Comment

by:chensu
ID: 1409076
>Why is your program still in memory?
If I knew, I would not have asked this question.

>Does the close message get posted?
Yes.

>Does it get received?
Yes.

>Does the window get destroyed?
Yes.

>Where does the this break down?
The this window is a frame window. It does not exist anymore while the program is still in memory.

Please note that the problem occurs only in some cases. If I remove ShellExecute, everything is OK.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 23

Author Comment

by:chensu
ID: 1409077
After ShellExecute, the system sends my window the WM_DDE_INITIATE messages and sends another window (don't know where) the WM_DDE_ACK message (On Windows NT, no this message). At this point, if my main window has been closed, the problem comes out. The workaround is to delay for a while after ShellExecute. And only on Windows 95, there is always a First-chance exception in KERNEL32.DLL after the WM_DDE_ACK message no matter whether my main window is closed at that time.

The PostAppMessage function is obsolete in Win32. Win32-based applications should use the PostThreadMessage function. As nietod said, the application posts the WM_QUIT message (PostQuitMessage) when it closes the main window. The application does not receive the WM_QUIT message even if I send it explicitly when the problem described above is there.
0
 
LVL 23

Author Comment

by:chensu
ID: 1409078
To demo the problem, I write a very simple program. Compile and try it. The program does not quit properly without ::Sleep(700). Is it a known problem on Windows 95?

#include <afxwin.h>


class CMyApp : public CWinApp
{
    public:
        virtual BOOL InitInstance();
};

class CMyWnd : public CFrameWnd
{
    protected:
        afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
         
        DECLARE_MESSAGE_MAP()
};

CMyApp theApp;


BOOL CMyApp::InitInstance()
{
    CMyWnd *pWnd = new CMyWnd;
    if (!pWnd->Create(NULL,
                      _T("My Window"),
                      WS_POPUP,
                      CRect(0, 0, 100, 100)))
        return FALSE;

    pWnd->ShowWindow(SW_SHOW);
     
    m_pMainWnd = pWnd;
     
    return TRUE;
}

BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
      ::ShellExecute(NULL, NULL, _T("http://www.experts-exchange.com"),
                           NULL, NULL, SW_SHOWNORMAL);

      //::Sleep(700);

      this->PostMessage(WM_CLOSE);
}

0
 
LVL 2

Accepted Solution

by:
abesoft earned 200 total points
ID: 1409079
The problem is that IE is opening up a DDE conversation with you, but you are exiting before finishing it.  Try using ShellExecuteEx with the SEE_MASK_FLAG_DDEWAIT flag, which causes the ShellExecute routine to wait until the DDE conversation has finished.

Hope this helps.
0
 
LVL 2

Expert Comment

by:abesoft
ID: 1409080
Sorry.  I meant to say that you were opening a DDE conversation with IE, but then going away before the conversation is finished.
0
 
LVL 23

Author Comment

by:chensu
ID: 1409081
Excellent! Thank you very much.

By the way, you must supply a valid window handle for the hwnd member of the SHELLEXECUTEINFO structure in this case.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now