How to LPCTSTR Convert to char *

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 14
Reputation: rxgmoral is an unknown quantity at this point 
Solved Threads: 0
rxgmoral rxgmoral is offline Offline
Newbie Poster

How to LPCTSTR Convert to char *

 
0
  #1
Dec 5th, 2006
How to LPCTSTR Convert to char *
thank
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: How to LPCTSTR Convert to char *

 
0
  #2
Dec 5th, 2006
What are you trying to do with it? The C in LPCTSTR stands for Constant. So you are maybe better off without changing it's permissions.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: How to LPCTSTR Convert to char *

 
0
  #3
Dec 5th, 2006
I think you need to use _tcscpy() to do the conversion.

Hope this helps
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to LPCTSTR Convert to char *

 
0
  #4
Dec 6th, 2006
Originally Posted by joeprogrammer View Post
I think you need to use _tcscpy() to do the conversion.

Hope this helps
No. LPCTSTR is defined as const char *. No conversion needed except typecasting to remove the const attribute. Depending upon what is going to be done this may or may not be a good idea.

Example:
  1. int main()
  2. {
  3. LPCTSTR s = "Hello";
  4. char *p = const_cast<char*>(s);
  5. return 0;
  6. }
Last edited by Ancient Dragon; Dec 6th, 2006 at 12:14 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: How to LPCTSTR Convert to char *

 
0
  #5
Dec 6th, 2006
:o...

Tells you how much I know about Windows programming. :cheesy:
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to LPCTSTR Convert to char *

 
0
  #6
Dec 6th, 2006
Originally Posted by joeprogrammer View Post
:o...

Tells you how much I know about Windows programming. :cheesy:
No problem -- all of us (except maybe Narue) makes mistakes.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 14
Reputation: rxgmoral is an unknown quantity at this point 
Solved Threads: 0
rxgmoral rxgmoral is offline Offline
Newbie Poster

Re: How to LPCTSTR Convert to char *

 
0
  #7
Dec 6th, 2006
Originally Posted by Ancient Dragon View Post
No. LPCTSTR is defined as const char *. No conversion needed except typecasting to remove the const attribute. Depending upon what is going to be done this may or may not be a good idea.

Example:
  1. int main()
  2. {
  3. LPCTSTR s = "Hello";
  4. char *p = const_cast<char*>(s);
  5. return 0;
  6. }
thank you ,i write your cord ....

LPCTSTR s = _T("Hello");
char *p = const_cast<char*>(s);

error C2440: 'const_cast' : cannot convert from 'LPCTSTR' to 'char *'

help me ,thank you
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to LPCTSTR Convert to char *

 
0
  #8
Dec 6th, 2006
are you compiling for UNICODE. If you are using VC++ 2005 that is the default.

If yes, then typecasting won't work. you have to use a conversion function to convert from wchar_t* to char*
Last edited by Ancient Dragon; Dec 6th, 2006 at 1:06 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC