none
Convert char * to LPCTSTR

    Question

  • How I can convert char * to LPCTSTR.

    I reading msdn but I don't know nothing sensible to do.

     

    Thx for all hepl.

    Sunday, December 16, 2007 1:10 PM

Answers

  • I use "String Conversion Macros":

     

    LPCTSTR pszCharacterString = CA2W(pChar);

     

    where

     

    pChar is type char *

     

    and everything working fine

     

    Maybe this solution will help someone.

    Sunday, December 16, 2007 9:55 PM

All replies

  • http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=136598&SiteID=1

    maybe this will help, it worked for me.
    Sunday, December 16, 2007 8:05 PM
  • I use "String Conversion Macros":

     

    LPCTSTR pszCharacterString = CA2W(pChar);

     

    where

     

    pChar is type char *

     

    and everything working fine

     

    Maybe this solution will help someone.

    Sunday, December 16, 2007 9:55 PM
  • If your program is not using Unicode as the default, then "char *" is the same thing as LPCTSTR; the compiler will see the same thing, the only difference is that the preprocessor replaces LPCTSTR with "char *".

     

    Your program however is probably using Unicode as the default. If so, then you need to convert the non-Unicode "char *" string to a Unicode string. There are many ways to do that and the most convenient solution for you depends on what your program is already using. If your program is using MFC then there is a MFC solution. If your program is using the CLI (.Net) then there is a different solution using that. If your program uses the C++ standard classes (std namespace) then there is a solution using that. There is also a solution using the C runtime and anotehr using the Windows SDK.

    Monday, December 17, 2007 2:18 AM
  • What are the differences between these two function CA2W and A2W?

    Wednesday, April 29, 2015 4:32 AM
  • What are the differences between these two function CA2W and A2W?

    It is not usually a good practice to attach a question to an old post, especially if that post is (supposedly) answered.

    A2W is form the old ATL 3.0 conversion facility; you should use CA2W from ATL 7.0. See

    https://msdn.microsoft.com/en-us/library/87zae4a3.aspx?f=255&MSPPError=-2147217396

    Note that the "answer"

    LPCTSTR pszCharacterString = CA2W(pChar);

    given in this thread is an incorrect usage of CA2W, because the temporary CA2W object is destroyed. This is explained in the above link.


    David Wilkinson | Visual C++ MVP

    Wednesday, April 29, 2015 8:54 AM
  • You can try this function: MultiByteToWideChar()

    Wednesday, April 29, 2015 1:54 PM