| | |
ShellExecute() problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
ok so i have used ShellExecute() before but with a specific value eg. "http://www.facebook.com" but now i want this program to be more flexible and allow the user to put the website he wants to.
the thing is i made a string like this
this gives me an error saying cannot convert system::string into LPCSTR.
btw i am using windows forms applications, how can i fix this? D:
thnx
the thing is i made a string like this
C++ Syntax (Toggle Plain Text)
String ^URL; ShellExecute(NULL,"open",URL,NULL,NULL,SW_SHOWDEFAULT)
this gives me an error saying cannot convert system::string into LPCSTR.
btw i am using windows forms applications, how can i fix this? D:
thnx
Ok.
As you're using a std::string to store your URL and ShellExecute is expecting a pointer to a C style string (LPCSTR) as a parameter, you simply need to change your ShellExecute call to:
The c_str() function of the standard library std::string class returns the contents of the string as a C style string...Which is exactly what ShellExecute is expecting as a parameter. That should fix your problem!
Cheers for now,
Jas.
As you're using a std::string to store your URL and ShellExecute is expecting a pointer to a C style string (LPCSTR) as a parameter, you simply need to change your ShellExecute call to:
C++ Syntax (Toggle Plain Text)
ShellExecute(NULL,"open",URL.c_str(),NULL,NULL,SW_SHOWDEFAULT)
The c_str() function of the standard library std::string class returns the contents of the string as a C style string...Which is exactly what ShellExecute is expecting as a parameter. That should fix your problem!
Cheers for now,
Jas.
Last edited by JasonHippy; Sep 21st, 2009 at 10:55 am.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Those who understand binary .....
And those who don't!
Ooops, I didn't notice that at the bottom of the post!
Hmm..It's been quite a while since I did any .NET stuff with C++.
I can't find any of my old managed code, but I know I've had to do similar conversions in the past. I think this may've been one of the ways I've used....
Alternatively, try taking a look at the following article:
http://support.microsoft.com/?id=311259
Cheers for now,
Jas.
Hmm..It's been quite a while since I did any .NET stuff with C++.
I can't find any of my old managed code, but I know I've had to do similar conversions in the past. I think this may've been one of the ways I've used....
C++ Syntax (Toggle Plain Text)
String URL; // some code.....Assume URL eventually gets populated with something! // Create a CString to use as a parameter using URL.... CString urlParam(&URL); // don't forget to #include <atlstr.h> // Above: If memory serves, from VS7 onwards CString can take a pointer to a system::String as a parameter in it's constructor when using the managed extensions... But I could be wrong! // now call shellexecute passing the CString version of URL (urlParam).. ShellExecute(NULL,"open",urlParam,NULL,NULL,SW_SHOWDEFAULT)
Alternatively, try taking a look at the following article:
http://support.microsoft.com/?id=311259
Cheers for now,
Jas.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Those who understand binary .....
And those who don't!
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
thnx. lemme try that and get back to you 
i keep getting :
that error when this is my code...
D: now im gna read that article..

i keep getting :
C++ Syntax (Toggle Plain Text)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(90) : error C3641: 'InterlockedExchangePointer' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(102) : error C3641: 'ATL::_AtlGetConversionACP' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(535) : error C3641: 'AtlA2WHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(554) : error C3641: 'AtlW2AHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(572) : error C3641: 'AtlA2WHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(577) : error C3641: 'AtlW2AHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(530) : error C3641: 'AtlDevModeW2A' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(65) : error C2440: 'default argument' : cannot convert from 'int (__cdecl *)(int,const char *,int,const char *,const char *,...)' to 'ATL::CTrace::fnCrtDbgReport_t' 1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(146) : fatal error C1903: unable to recover from previous error(s); stopping compilation
that error when this is my code...
C++ Syntax (Toggle Plain Text)
String ^siteURL1; CString button1URL(&siteURL1); ShellExecute(NULL,"open",button1URL,NULL,NULL,SW_SHOWDEFAULT);
D: now im gna read that article..
Last edited by evilguyme; Sep 21st, 2009 at 4:03 pm.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
zomg thnx again 
u've helped me a whole bunch.. mind PMing me ur MSN?
oooh i dun understand that whole thing cuz im still learning C++ from a book and was just making these programs to learn...
well the basic idea of that is to convert system::string to a char array yea?
if so then i can refer to that once i learn about char arrays.

u've helped me a whole bunch.. mind PMing me ur MSN?

oooh i dun understand that whole thing cuz im still learning C++ from a book and was just making these programs to learn...
well the basic idea of that is to convert system::string to a char array yea?
if so then i can refer to that once i learn about char arrays.
Last edited by evilguyme; Sep 22nd, 2009 at 1:49 pm.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
![]() |
Similar Threads
- I had problem with onmouse out in div (JavaScript / DHTML / AJAX)
- Using ShellExecute to open a file in a specific program? (Pascal and Delphi)
- Shellexecute problem (C++)
- Can you fix the problem (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Need help with custom widget in QT
- Next Thread: .WAV data upsampling
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






