Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

813 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