ShellExecute() problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

ShellExecute() problem

 
0
  #1
Sep 21st, 2009
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
  1. String ^URL;
  2.  
  3. 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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 338
Reputation: JasonHippy is just really nice JasonHippy is just really nice JasonHippy is just really nice JasonHippy is just really nice 
Solved Threads: 61
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz

Re: ShellExecute() problem

 
0
  #2
Sep 21st, 2009
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:

  1. 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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: ShellExecute() problem

 
0
  #3
Sep 21st, 2009
Originally Posted by JasonHippy View Post
Ok.
As you're using a std::string
No, he is using managed C++.NET and the .NET String!!!
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: ShellExecute() problem

 
0
  #4
Sep 21st, 2009
he's right, it's .NET string

which is

system::string...

need help plz :O
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 338
Reputation: JasonHippy is just really nice JasonHippy is just really nice JasonHippy is just really nice JasonHippy is just really nice 
Solved Threads: 61
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz

Re: ShellExecute() problem

 
0
  #5
Sep 21st, 2009
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....

  1. String URL;
  2.  
  3. // some code.....Assume URL eventually gets populated with something!
  4.  
  5. // Create a CString to use as a parameter using URL....
  6. CString urlParam(&URL); // don't forget to #include <atlstr.h>
  7.  
  8. // 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!
  9.  
  10. // now call shellexecute passing the CString version of URL (urlParam)..
  11. 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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: ShellExecute() problem

 
0
  #6
Sep 21st, 2009
thnx. lemme try that and get back to you

i keep getting :

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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'
  9. 1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type
  10. 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...


  1. String ^siteURL1;
  2. CString button1URL(&siteURL1);
  3.  
  4. 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]
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: ShellExecute() problem

 
0
  #7
Sep 22nd, 2009
bump!

i really need help on this
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: ShellExecute() problem

 
0
  #8
Sep 22nd, 2009
Here's a thread on the conversion. Can't test it because I don't use managed code.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: ShellExecute() problem

 
0
  #9
Sep 22nd, 2009
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.
Last edited by evilguyme; Sep 22nd, 2009 at 1:49 pm.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: ShellExecute() problem

 
0
  #10
Sep 22nd, 2009
Originally Posted by evilguyme View Post
mind PMing me ur MSN?
Yes, actually I do mind. Keep the discussion in the forum.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC