Search code examples
cwinapimingwmingw32

LPCTSTR to LPWSTR conversion is not defined in Mingw32 in winnt.h


I am using mingw32, where I cant find type definition of LPCTSTR to LPCWSTR. But the same is defined in mingw64 as below.

typedef LPCWSTR PCTSTR,LPCTSTR;

But my code works fine in mingw32 without any error even I added LPCTSTR in my code, and if I change the compiler options to mingw64 I am getting lots of errors.

Winnt.h in mingw32:

typedef TCHAR TBYTE,*PTCH,*PTBYTE;
typedef TCHAR *LPTCH,*PTSTR,*LPTSTR,*LP,*PTCHAR;
typedef const TCHAR *LPCTSTR;

winnt.h in mingw64:

typedef LPWSTR LPTCH,PTCH;
typedef LPWSTR PTSTR,LPTSTR;
typedef LPCWSTR PCTSTR,LPCTSTR;
typedef LPUWSTR PUTSTR,LPUTSTR;
typedef LPCUWSTR PCUTSTR,LPCUTSTR;
typedef LPWSTR LP;

How to solve this? why I am not getting any error in mingw32, with UNICODE defined?


Solution

  • LPCTSTR is being defined in mingw32 as:

    typedef const TCHAR *LPCTSTR;
    

    When UNICODE is defined, TCHAR maps to WCHAR, making LPCTSTR equivilent to LPCWSTR.

    When UNICODE is not defined, TCHAR maps to CHAR instead, making LPCTSTR equivilent to LPCSTR.