943,733 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1695
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 21st, 2009
0

ShellExecute() problem

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evilguyme is offline Offline
70 posts
since Sep 2009
Sep 21st, 2009
0

Re: ShellExecute() problem

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:

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009
Sep 21st, 2009
0

Re: ShellExecute() problem

Click to Expand / Collapse  Quote originally posted by JasonHippy ...
Ok.
As you're using a std::string
No, he is using managed C++.NET and the .NET String!!!
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Sep 21st, 2009
0

Re: ShellExecute() problem

he's right, it's .NET string

which is

system::string...

need help plz :O
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evilguyme is offline Offline
70 posts
since Sep 2009
Sep 21st, 2009
0

Re: ShellExecute() problem

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....

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009
Sep 21st, 2009
0

Re: ShellExecute() problem

thnx. lemme try that and get back to you

i keep getting :

C++ Syntax (Toggle Plain Text)
  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...


C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evilguyme is offline Offline
70 posts
since Sep 2009
Sep 22nd, 2009
0

Re: ShellExecute() problem

bump!

i really need help on this
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evilguyme is offline Offline
70 posts
since Sep 2009
Sep 22nd, 2009
0

Re: ShellExecute() problem

Here's a thread on the conversion. Can't test it because I don't use managed code.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Sep 22nd, 2009
0

Re: ShellExecute() problem

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
evilguyme is offline Offline
70 posts
since Sep 2009
Sep 22nd, 2009
0

Re: ShellExecute() problem

Click to Expand / Collapse  Quote originally posted by evilguyme ...
mind PMing me ur MSN?
Yes, actually I do mind. Keep the discussion in the forum.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need help with custom widget in QT
Next Thread in C++ Forum Timeline: .WAV data upsampling





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC