LPCTSTR to LPWSTR

This is a discussion on LPCTSTR to LPWSTR within the Windows Programming forums, part of the Platform Specific Boards category; hi, how to convert LPCSTR to LPWSTR if UNICODE is #defined? Thanks....

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    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, 10:27 AM
  4. Convert Char To LPCTSTR
    By cloudy in forum C Programming
    Replies: 2
    Last Post: 01-15-2006, 07:33 AM
  5. Autorun - How?
    By nouneim in forum C++ Programming
    Replies: 30
    Last Post: 06-23-2004, 06:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21