Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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…
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 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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 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