[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

vc++: navigating to a url with parameters, Shellexecute doesnt work

Posted on 2004-11-08
9
Medium Priority
?
1,148 Views
Last Modified: 2008-02-01
I have a link in my dialog which looks something like : "http://www.xyz.com?arg1=val1&arg2=val2" etc.
When I use Shellexecute it works well when the url is only "http://www.xyz.com". But when I make the get request with the parameters as in line 1, the website throws a page moved or expired page. Meanwhile when I paste the same url in the browser and go, it works fine, taking me to the next page.
I have tried using IWebbrowser2.navigate(url, null,null,null,null) also but same result. Please advise.
0
Comment
Question by:swapnil001
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 12530636
Please post your code.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12531506
Well I've just tried...

--------8<--------
#include "windows.h"
#pragma comment(lib,"shell32.lib")
int main(int argc,const char* argv[])
{
      if (argc > 1)
            ShellExecute(NULL, "open", *++argv, NULL, NULL, SW_SHOWNORMAL);
}
--------8<--------

And it fires up Mozilla nicely on my system, when I run the program with the parameter "http://search.experts-exchange.com/search.jsp?query=shellexecute&searchType=all&Submit.x=24&Submit.y=9&restrictToTA=on¤tTAID=84"

What do you get with this?
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 750 total points
ID: 12531828
>> IWebbrowser2.navigate

You need to use Navigate2 (http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/methods/navigate2.asp)

I have used this with querystrings no problem.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12532612
You have to enclose your url between double quotes before calling shellexecute

0
 

Author Comment

by:swapnil001
ID: 12536615
my code :
      HRESULT hr;
      IWebBrowser2* pWebBrowser = NULL;
      HRESULT comInit = CoInitializeEx(NULL,COINIT_MULTITHREADED);
      hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (LPVOID*)&pWebBrowser);
      if (SUCCEEDED (hr) && (pWebBrowser != NULL))
      {
            m_pWebBrowser = pWebBrowser;
            m_pWebBrowser->put_Visible (VARIANT_TRUE);
      }
      else
      {
            if (pWebBrowser)
                  pWebBrowser->Release ();
      }
      BSTR x = url.AllocSysString();
      COleVariant noArg;
      m_pWebBrowser->Navigate(x,&noArg,&noArg,&noArg,&noArg);
      SysFreeString (x);

 rstaveley, what does *++argv stand for ??? is that the url somehow?
mrwad if i use navigate2, do i need to specify any of the other arguments in the function??
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 12537558
>> mrwad if i use navigate2, do i need to specify any of the other arguments in the function??

No.
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12537985
>  rstaveley, what does *++argv stand for ??? is that the url somehow?

argv points to an array of character pointers, which has the command line arguments. The ++ increments the pointer and * dereferences it. It would have been more legible if I'd written argv[1] - *++argv is a quirky old habit :-)

--------8<--------
#include "windows.h"
#pragma comment(lib,"shell32.lib")
int main(int argc,const char* argv[])
{
     if (argc > 1)
          ShellExecute(NULL, "open", argv[1], NULL, NULL, SW_SHOWNORMAL);
}
--------8<--------

This is a command line program. Run it with the command line parameter "http://search.experts-exchange.com/search.jsp?query=shellexecute&searchType=all&Submit.x=24&Submit.y=9&restrictToTA=on¤tTAID=84"
0
 

Author Comment

by:swapnil001
ID: 12582755
thanks mrwad navigate2 worked out just fine for me.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 12583339
Glad to help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

872 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