CreateProcessW

I am working on a program that opens a browser window and loads the appropriate URL when the user enters a URL in the text box. What is the easiest way to convert the URL from String to LPCSTR?
Try this:

(LPSTR) string.c_str()

It's what I used for createprocess variables - but the types baffle me to be honest.
Thanks, I ended up using this:
1
2
LPCTSTR x;
 x = static_cast<LPCTSTR>(const_cast<void*>(static_cast<const void*>(System::Runtime::InteropServices::Marshal::StringToHGlobalAuto(inbox->Text))));
Last edited on
ACK!

omg no no no no no.

Read this: http://www.cplusplus.com/forum/articles/16820/

LPCTSTR is const TCHAR*

If you have a string of chars, YOU CANNOT CAST TO LPCTSTR. TCHARs are not chars all of the time. They might be wchar_t's.

If you have chars, use CreateProcessA()
If you have wchar_ts, use CreateProcessW()
If you have TCHARs, use CreateProcess()

As for how to get a char/wchar_t/TCHAR array from a String (which looks like it's part of some .NET stuff I'm not familiar with), I don't have a clue. But there's got to be some kind of c_str() or similar function that returns a pointer to the null terminated string data. From there you just have to figure out what type it is and call the appropriate function.
Topic archived. No new replies allowed.