Solved

Pausing ShellExecuteEx

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

617 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