Solved

Pausing ShellExecuteEx

Posted on 2003-11-17
4
269 Views
Last Modified: 2010-04-02
Why does this routine fail to wait?

The ShellExecuteEx manages to open a web page, but the WaitForSingleObjectEx shows the error message Invalid handle.

Testing on windows 98.

Any clues?

Sorry about low points, been sick latley. I will add more points later and/or give the answerer a freebee question. I always grant an A.

RJSoft


      // TODO: Add extra validation here
      DWORD Error;
      char Start[1000];
      m_EditBox.GetWindowText(Start,999);

      SHELLEXECUTEINFO si;
      memset(&si, 0, sizeof(si));
      si.cbSize = sizeof(si);
      si.hwnd = this->m_hWnd;
      si.lpVerb = "open";
      si.lpFile=Start;
      si.nShow = SW_NORMAL;
      si.fMask = SEE_MASK_NOCLOSEPROCESS;

      bool res = ShellExecuteEx(&si);
      
      if(res<=0)MessageBox("Shell failed");
      
      else
      {
      DWORD Flag=WaitForSingleObjectEx(si.hProcess,INFINITE,0);
      
            if(Flag==WAIT_FAILED)
            {
            LPVOID lpMsgBuf;
            FormatMessage(
                  FORMAT_MESSAGE_ALLOCATE_BUFFER |
                  FORMAT_MESSAGE_FROM_SYSTEM |
                  FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL,
                  GetLastError(),
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                  (LPTSTR) &lpMsgBuf,
                  0,
                  NULL
                  );
            // Process any inserts in lpMsgBuf.
            // ...
            // Display the string.
            ::MessageBox( NULL, (LPCTSTR)lpMsgBuf, "WAIT_FAILED", MB_OK | MB_ICONINFORMATION );
            // Free the buffer.
            LocalFree( lpMsgBuf );
       
      }//endelse


      MessageBox("Shell good");
      }
      
0
Comment
Question by:RJSoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 25 total points
ID: 9769449
Try this:
Set the lpFile parameter to "IExplorer.com" and set the lpParameters parm to the full URL.
-- Dan
0
 
LVL 3

Author Comment

by:RJSoft
ID: 9792475
Dan the man.
Thanks again.

RJ
0
 
LVL 3

Author Comment

by:RJSoft
ID: 9792520
Just for documentation I used iexplore.exe not com.
RJ
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9792650
Thanks for the points.    Yes, the EXE would tend to be a better choice :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 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