Solved

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

Posted on 2008-06-12
4
946 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Combobox, SelectedIndexChanged Get Index 2 21
.NET Error 7 42
crm development 2 36
Getfiles in vb.net 20 0
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now