Reputation: 1
I tried opening a url in my program but I keep getting errors from "shellapi.h", how can I fix it?
ShellExecuteA(NULL, NULL , "chrome.exe", this->photo.c_str(), NULL, SW_SHOWMAXIMIZED);
Upvotes: 0
Views: 1613
Reputation: 375
For a cross-platform solution, you can set this header:
#ifdef _WIN32
static int platform = 1;
#elif _WIN64
static int platform= 1;
#elif __linux__
static int platform = 2;
#elif __APPLE__
static int platform = 3;
#else
static int platform = 0;
#endif
and then create a method to open the URL, with the code below:
std::string str;
switch(platform) {
case 1:
str = "explorer";
break;
case 2:
str = "xdg-open";
break;
case 3:
str = "open";
break;
default:
std::cout << "Should never happen on the 3 defined platforms" << std::endl;
}
str.append(" " + url);
std::system(str.data());
Remember to provide a URL string, in this case a const std::string& url
.
Upvotes: 0
Reputation: 6050
Probably better to just use the default browser, like this:
// assumes photo.c_str() is valid URL ...
ShellExecuteA(0, NULL, photo.c_str(), NULL, NULL, SW_SHOWDEFAULT);
Upvotes: 1
Reputation: 11
There are a number of c++ library available for this, and here you can find something.
I have used the following:
Upvotes: 1