Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-12
4
Medium Priority
?
971 Views
Last Modified: 2010-04-21
I'm trying to convert an variable of LPCTSTR type to System:string. Any help is appreciated.
0
Comment
Question by:JonMny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 21771761
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21771769
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
 
LVL 40

Accepted Solution

by:
evilrix earned 1000 total points
ID: 21772040
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
 
LVL 9

Author Closing Comment

by:JonMny
ID: 31466642
Thanks, I see what I was doing wrong. I usally use c# and I was not intilizing the string correctly.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question