• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 972
  • Last Modified:

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.
0
JonMny
Asked:
JonMny
  • 2
1 Solution
 
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 OlivaresCommented:
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
 
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
 
JonMnyAuthor Commented:
Thanks, I see what I was doing wrong. I usally use c# and I was not intilizing the string correctly.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now