Can anyone tell me how to convert LPCTSTR to System::String

I'm trying to convert an variable of LPCTSTR type to System:string. Any help is appreciated.
LVL 9
JonMnyAsked:
Who is Participating?
 
evilrixSenior Software Engineer (Avast)Commented:
The T in LPCTSTR means this type is either wide or narrow depending upon your build settings. Below is a simple example of each.
void wide()
{
	LPCTSTR pStr = L"Hello world";
	System::String ^ s = gcnew System::String(pStr);
}
 
void narrow()
{
	LPCTSTR pStr = "Hello world";
	System::String ^ s = gcnew System::String(pStr);
}

Open in new window

0
 
evilrixSenior Software Engineer (Avast)Commented:
Type LPCTSTR will be either char const * or wchar_t const * depending upon what your build settings are. Either way you should just be able to assign it to a String. Does that not work?
0
 
Jaime OlivaresSoftware ArchitectCommented:
How did you obtained the LPCTSTR pointer?
If it is returned by an unmanaged function, you can do by simply declaring the function correctly.
0
 
JonMnyAuthor Commented:
Thanks, I see what I was doing wrong. I usally use c# and I was not intilizing the string correctly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.