Solved

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

Posted on 2008-06-12
4
952 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
  • 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 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now