locked
'char *' into 'LPTSTR'

    Question

  • how to convert 'char *' into  'LPTSTR' ?
    Saturday, June 03, 2006 11:57 AM

Answers

  • It depends what you are trying to do. 

    Go to the Visual C++ 2005 Help | Index and search for "wide characters".  That page and others will give you information about moving between wide characters and narrow (single-byte) characters.

    If you know that you are doing Unicode, then use L"..." strings and L'...' characters.  To make storage and arrays of such characters, use wchar_t instead of char.

    The problem with LPTSTR is that it is either char* or wchar_t* depending on compiler settings.  If you do a web search on LPTSTR Unicode there will be a number of web-page articles on how to use these special macros to match up all character usages properly. 

    There is also information about Tchar.h at http://msdn2.microsoft.com/en-us/library/c426s321.aspx

    One way to write code that compiles properly in either Unicode or single-byte characters is to use the TCHAR rules in your program.  Look up TCHAR type in the VC++ Help | Index.

     - Dennis

    Saturday, June 03, 2006 3:49 PM

All replies

  • It depends what you are trying to do. 

    Go to the Visual C++ 2005 Help | Index and search for "wide characters".  That page and others will give you information about moving between wide characters and narrow (single-byte) characters.

    If you know that you are doing Unicode, then use L"..." strings and L'...' characters.  To make storage and arrays of such characters, use wchar_t instead of char.

    The problem with LPTSTR is that it is either char* or wchar_t* depending on compiler settings.  If you do a web search on LPTSTR Unicode there will be a number of web-page articles on how to use these special macros to match up all character usages properly. 

    There is also information about Tchar.h at http://msdn2.microsoft.com/en-us/library/c426s321.aspx

    One way to write code that compiles properly in either Unicode or single-byte characters is to use the TCHAR rules in your program.  Look up TCHAR type in the VC++ Help | Index.

     - Dennis

    Saturday, June 03, 2006 3:49 PM
  • your answer is excellent.

    Tuesday, October 31, 2006 9:05 AM
  • Just replace L before the char*, and it will work

    Thursday, July 07, 2011 10:37 AM