Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I am using ShellExecute to open a web browser with this function:
#include <windows.h>;


void google(string args)
{
    string URL ("http://www.google.com/search?q=");
    URL.append(args);

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


</windows.h>


but I keep on getting the error message :
"error C2664: 'ShellExecuteW' : cannot convert parameter 3 from 'std::string' to 'LPCWSTR'"

does any one know how to change a string to a LPCWSTR or a way around this problem?

thanx
Posted

Here: http://msdn.microsoft.com/en-us/library/dd319072[^]


or you can use: ShellExecuteA
 
Share this answer
 
v2
Convert to const char * first use .c_str(), then char * with static_cast if needed, and finally convert to LPCWSTR if necessary. You also might be able to change the type required by using Multi-Byte Character Set instead of Unicode, and that may modify the type you need to cast to.
 
Share this answer
 
v2
Comments
me773 25-Dec-10 23:42pm    
caused the string to turn into something unrecognizable (01825A50)
me773 25-Dec-10 23:49pm    
I got it! I used ShellExecuteA with .c_str() and it worked! thanx =)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900