Search code examples
c++urlshellexecute

C++ ShellExecute a URL


Tried googling for a few hours, testing different solutions for hours but still just cannot get this to work.

I need a const url base (Ex. http://www.google.com) Then I need a string input from the user (ex. Mountain Dew) and then combine them. I've tried making the URL a LPCWSTR, wstring, wchar_t, doing a function to convert them and combine them but I cannot get it to work at all.

std::string baseUrl = "http://www.google.com/";
std::string userAdd;
getline(std::cin, userAdd)
ShellExecute(NULL, TEXT("open"), baseUrl + userAdd, NULL, NULL, SW_SHOWNORMAL);

Solution

  • There's no automatic conversion from std::string to const char*.

    Try this: (baseUrl + userAdd).c_str()

    and try using ShellExecuteA