conversion from const char * to LPCWSTR

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachin30
    New Member
    • Dec 2007
    • 21

    #1

    conversion from const char * to LPCWSTR

    How do i convert const char * to LPCWSTR?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This can be done several ways:

    [code=cpp]
    const char* c = "Hello";
    LPCWSTR str = TEXT("Hello");
    LPCWSTR str1 = L"Hello";
    LPCWSTR str2 = _T("Hello");
    WCHAR str3[6];
    MultiByteToWide Char( 0,0, c, 5, str3, 6);
    LPCWSTR cstr4 = str3;
    [/code]

    Read this:


    http://msdn.microsoft. com/en-us/library/cc500362.aspx

    Comment

    • sachin30
      New Member
      • Dec 2007
      • 21

      #3
      Originally posted by weaknessforcats
      This can be done several ways:

      [code=cpp]
      const char* c = "Hello";
      LPCWSTR str = TEXT("Hello");
      LPCWSTR str1 = L"Hello";
      LPCWSTR str2 = _T("Hello");
      WCHAR str3[6];
      MultiByteToWide Char( 0,0, c, 5, str3, 6);
      LPCWSTR cstr4 = str3;
      [/code]

      Read this:


      http://msdn.microsoft. com/en-us/library/cc500362.aspx

      Thanks for help it work properly

      Comment

      • kubano
        New Member
        • Nov 2009
        • 1

        #4
        Hi.

        I'm developing a small aplication for pocket pc and I have the same exception :

        "cannot convert parameter 1 from 'const char *' to 'LPCWSTR' "

        But i can't solve in this way.

        I should know how to solve it... but i'm beginer in the language...

        I can't use the functions... because i have the string in a variable (var)


        Somebody can help me??

        Comment

        • MindStalker
          New Member
          • Apr 2010
          • 1

          #5
          Simple Solution

          I'm assuming your using Visual Studio.
          The easiest solution to this problem is to change your solution settings from Unicode to Multi-btye.
          VS sets windows applications to default to unicode. While unicode "may" be better, it certainly is more difficult for beginning programming and requires explicit conversions.

          Right click on your Project, select Properties. Configuration Properties/General
          And Character Set to Multi-Byte.

          Comment

          • Jonptech
            New Member
            • May 2010
            • 1

            #6
            Thank you!

            your solution for altering the character set to Multi-Byte worked marvelously! Much thanks !
            Last edited by Jonptech; May 3 '10, 08:12 AM. Reason: typo

            Comment

            Working...