Topic title is not the best but nvm

I have been looking for this on internet but cant it find anything useful.

#include <windows.h>

void main()
   ShellExecute(NULL, "open", "",
                NULL, NULL, SW_SHOWNORMAL);

This is function which I have found on net to open URL, problem of this function is if I want to open 2 URLs I need to have 2 functions instead of one.

What I need is something like this, but I cant implement it.

void openURL (string& URL){

      ShellExecute(NULL, "open", URL,
                NULL, NULL, SW_SHOWNORMAL);

Since URL is std::string you have to use its c_str() method

void openURL (string& URL){

      ShellExecute(NULL, "open", URL.c_str(),
                NULL, NULL, SW_SHOWNORMAL);

It doesn't work :(

Same compiler error as before

error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'

EDIT: I have tested the same code in DEV and it works, in VS it doesn't.

The problem is that vc++ uses UNICODE strings by default. You have to go to project settings and change it. Select menu Project --> Properties (the last menu item in the list) --> Configuration Properties --> General. Then on the right sice of the screen, near the bottom of the list change "Character Set" to "Not Set".

Thx a lot, it works now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.