-1

I'm trying to open a user input url using ShellExecute in my c++ project but am finding difficulty in creating a main function within the project.

Currently I have

#include<Windows.h>
#include<stdlib.h>
#include<shellApi.h>

int findIE(const char*);

int main()
{
    const char* url;
    findIE(url);
    return 0;
}

/**
 * Open the default browser to the specified URL.
 * 
 * \param url     WebAddress to open a browser to.
 *  
 * \returns 
 * If the function succeeds, it returns a value greater than 32.
 * Otherwise,it returns an error code as defined in the ShellExecute   documentation.
 *
 * \remarks 
 * The function uses the headerfiles: windows.h, stdlib.h, shellapi.h.
 * The url is converted into a unicode string before being used.
 **/

int findIE(const char* cUrl)
{
    ShellExecute(NULL, "open", cUrl, NULL, NULL, SW_SHOWDEFAULT);
    return 0;
}

I try going to my executable and running it but nothing is showing up...Can I get some advice on my next steps?

The program should be run:

findIE.exe websitename.com

Then open up the default browser to websitename.com

Thanks for responding!

koala421
  • 786
  • 3
  • 11
  • 27

2 Answers2

2

You need to initialize the variable 'url'.

for example:

int main()
{
const char* url = "www.google.com"
findIE(url);
return 0;
}

And if you want to use user input you will have to take the constness of the char variable away.

TheJavaFan
  • 341
  • 3
  • 15
2

The program should be run:

findIE.exe websitename.com

Ah, then you need to pass command line arguments to main.

At the very least:

int main( int argc, char ** argv )
{
    if ( argc >= 2 )
    {
        findIE( argv[1] );
    }
    return 0;
}
Community
  • 1
  • 1
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180