LPCSTR and LPCWSTR

This is a discussion on LPCSTR and LPCWSTR within the C Programming forums, part of the General Programming Boards category; Hello everyone, I think when UNICODE or _UNICODE is defined, when using _T, it could convert characters to wide character. ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    LPCSTR and LPCWSTR

    Hello everyone,


    I think when UNICODE or _UNICODE is defined, when using _T, it could convert characters to wide character.

    And I also think LPCSTR should be defined to pointer to wide character when UNICODE or _UNICODE is defined, and LPCSTR should be defined to pointer to multibyte character when UNICODE and _UNICODE are not defined.

    But it seems I am wrong for all points. Could anyone explain to me why I get such warnings in Visual Studio 2003?

    Code:
    #include <windows.h>
    #include <TCHAR.h>
    
    #define UNICODE
    #define _UNICODE
    
    int main (int argc, char** argv)
    {
            WCHAR* p = _T("hello");
            LPCSTR p1 = p;
            LPCWSTR p2 = p;
    }
    warning messages,

    warning C4133: 'initializing' : incompatible types - from 'char [6]' to 'WCHAR *'
    warning C4133: 'initializing' : incompatible types - from 'WCHAR *' to 'LPCSTR'


    thanks in advance,
    George

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    You should be using the portability type _TCHAR (see my answer to your other post)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Just read the acronyms:
    LPCSTR = Long Pointer to a Const String.
    LPCWSTR = Long Pointer to a Const Wide String.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LPCSTR to LPCWSTR
    By stanlvw in forum Windows Programming
    Replies: 7
    Last Post: 07-20-2008, 09:58 AM
  2. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM

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