Solved

Pausing ShellExecuteEx

Posted on 2003-11-17
4
264 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

19 Experts available now in Live!

Get 1:1 Help Now