Thread: LPCTSTR to LPWSTR

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    6

    LPCTSTR to LPWSTR

    hi, how to convert LPCSTR to LPWSTR if UNICODE is #defined?

    Thanks.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Depends on what you want to do.
    Do you simply want to pass a string literal such as "Hello, this is my string"?
    If so, append L: L"Hello, this is my string".
    If you want to do a conversion, it's slightly more difficult. Let me know what you want to do.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    or you can use TEXT macro - so your string literals will be converted automatically to the correct type depending on the defined/not defined UNICODE macro (or _UNICODE - I do not remember which...)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you're not talking about a string literal......

    Well, your subject says "LPCTSTR to LPWSTR" and your post says "LPCSTR to LPWSTR" - so I'll awnser both.

    "LPCSTR to LPWSTR"
    MultiByteToWideChar() or mbstowcs()

    "LPCTSTR to LPWSTR"
    Code:
        LPCTSTR tsz;
        LPWSTR wsz;
    #if defined(UNICODE) || defined(_UNICODE)
        wsz = tsz; // or lstrcpyW() or wcscpy()
    #else
        // MultiByteToWideChar() or mbstowcs()
    #endif
    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LPCTSTR and HRESULT
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-27-2007, 02:17 AM
  2. ofstream << LPCTSTR
    By lefnire in forum C++ Programming
    Replies: 3
    Last Post: 08-02-2006, 02:50 PM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. Convert Char To LPCTSTR
    By cloudy in forum C Programming
    Replies: 2
    Last Post: 01-15-2006, 08:33 AM
  5. Autorun - How?
    By nouneim in forum C++ Programming
    Replies: 30
    Last Post: 06-23-2004, 06:15 PM