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

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 :D

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:

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.

Member Avatar for jencas

Ok.
As you're using a std::string

No, he is using managed C++.NET and the .NET String!!!

he's right, it's .NET string

which is

system::string...

need help plz :O

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

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.

thnx. lemme try that and get back to you ;)

i keep getting :

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

String ^siteURL1;
CString button1URL(&siteURL1);

ShellExecute(NULL,"open",button1URL,NULL,NULL,SW_SHOWDEFAULT);

D: now im gna read that article..

bump!

i really need help on this :(

Here's a thread on the conversion. Can't test it because I don't use managed code.

zomg thnx again :)

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

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.

mind PMing me ur MSN? :P

Yes, actually I do mind. Keep the discussion in the forum.

kay then... :P

i need some more help...

how do i add a string in between a text parameter? google doesn't help much :(

something like

string name;

MessageBox(NULL,"Hello,"(name)"sucks",":D",MB_ICONINFORMATION);

i tried that and it keeps giving me errors D:
some help plz ..

Be a part of the DaniWeb community

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