wxWidgets-3.0.2 : cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR' in Visual Studio 2015

364 views
Skip to first unread message

Abhijith Sugunan

unread,
Sep 6, 2016, 10:50:57 AM9/6/16
to wx-users
Am new to these stuffs so i need so explanation on what is the reason why i gets cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR' type of error.? And also how to i recover from this sort of error?
I found a lot of things in different forums that order of includes and defining unicode and _unicode am using wxWidgets 3.0.2



// ERROR

2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): error C2664: 'HWND CreateDialogParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): error C2664: 'HFONT CreateFontW(int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR)': cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): error C2664: 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): error C2664: 'HMENU LoadMenuW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): error C2664: 'HICON LoadIconW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): error C2664: 'HBITMAP LoadBitmapW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Kenneth Porter

unread,
Sep 6, 2016, 11:03:26 AM9/6/16
to wx-u...@googlegroups.com
On 9/6/2016 3:46 AM, Abhijith Sugunan wrote:
> Am new to these stuffs so i need so explanation on what is the reason
> why i gets cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR' type
> of error.?

Your compiler settings specify Unicode but you're passing an 8-bit char
pointer.

Start with this explanation of the issues:

http://docs.wxwidgets.org/trunk/overview_unicode.html

Abhijith Sugunan

unread,
Sep 7, 2016, 2:17:38 AM9/7/16
to wx-users
Unicode is already disabled in my compiler settings

Igor Korot

unread,
Sep 7, 2016, 7:54:46 AM9/7/16
to wx-u...@googlegroups.com
Hi,

On Wed, Sep 7, 2016 at 2:17 AM, Abhijith Sugunan <abije...@gmail.com> wrote:
> Unicode is already disabled in my compiler settings

Is there a reason you did disable Unicode?

Thank you.
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Abhijith Sugunan

unread,
Sep 7, 2016, 8:05:53 AM9/7/16
to wx-users
Initially, Unicode was enabled and am getting that error and i have no idea about that error.So a part of testing i disabled it.

Igor Korot

unread,
Sep 7, 2016, 10:12:51 AM9/7/16
to wx-u...@googlegroups.com
Hi,

On Wed, Sep 7, 2016 at 8:05 AM, Abhijith Sugunan <abije...@gmail.com> wrote:
> Initially, Unicode was enabled and am getting that error and i have no idea
> about that error.So a part of testing i disabled it.

You are working with the international character set.
You are trying to work with official wxWidgets build.

Let's enable the UNICODE and fix the error.

Can you show the code which gave you that error message?

Thank you.

Abhijith Sugunan

unread,
Sep 8, 2016, 2:40:06 AM9/8/16
to wx-users
I also test after enabling unicode but still i gets the same error

C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): error C2664: 'HWND CreateDialogParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
 C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast`
C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): error C2664: 'HFONT CreateFontW(int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR)': cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR'
  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): error C2664: 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): error C2664: 'HMENU LoadMenuW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): error C2664: 'HICON LoadIconW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): error C2664: 'HBITMAP LoadBitmapW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
  C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Eric Jensen

unread,
Sep 8, 2016, 2:55:38 AM9/8/16
to Abhijith Sugunan
Hello Abhijith,

Thursday, September 8, 2016, 8:40:06 AM, you wrote:

AS> I also test after enabling unicode but still i gets the same error


AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): error C2664:
AS> 'HWND CreateDialogParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM)':
AS> cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(38): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast`
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): error C2664:
AS> 'HFONT
AS> CreateFontW(int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR)':
AS> cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(69): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): error C2664:
AS> 'HWND
AS> CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)':
AS> cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(95): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): error C2664:
AS> 'HMENU LoadMenuW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(111): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): error C2664:
AS> 'HICON LoadIconW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(311): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): error C2664:
AS> 'HBITMAP LoadBitmapW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
AS> C:\wxWidgets-3.0.2\include\wx/msw/winundef.h(324): note: Types
AS> pointed to are unrelated; conversion requires reinterpret_cast,
AS> C-style cast or function-style cast

Do you get these errors when building wxWidgets or your own
application?

Eric

Message has been deleted

Abhijith Sugunan

unread,
Sep 8, 2016, 4:49:53 AM9/8/16
to wx-users, m...@j-dev.de
Yes i do got these errors

Abhijith Sugunan

unread,
Sep 8, 2016, 7:25:57 AM9/8/16
to wx-users, m...@j-dev.de
If the UNICODE and _UNICODE is enabled in the project then LPCTSTR will be equivalent to LPCWSTR right.? so if i call LoadStringW() in winuser.h it is expecting a LPCWSTR. So is there anyway that i can pass LPCTSTR and which get implicitly converted to LPCWSTR.?

Igor Korot

unread,
Sep 8, 2016, 7:46:25 AM9/8/16
to wx-u...@googlegroups.com
Hi,

On Thu, Sep 8, 2016 at 7:25 AM, Abhijith Sugunan <abije...@gmail.com> wrote:
> If the UNICODE and _UNICODE is enabled in the project then LPCTSTR will be
> equivalent to LPCWSTR right.? so if i call LoadStringW() in winuser.h it is
> expecting a LPCWSTR. So is there anyway that i can pass LPCTSTR and which
> get implicitly converted to LPCWSTR.?

Why do you want to pass Windows-specific type?
Just use normal wxString...

Thank you.

Eric Jensen

unread,
Sep 8, 2016, 7:47:16 AM9/8/16
to Abhijith Sugunan
Hello Abhijith,

you still haven't answered one question:

Do you get these errors while building wxWidgets itself?

Or do you get these errors when building your own project that uses
wxWidgets?


AS> If the UNICODE and _UNICODE is enabled in the project then
AS> LPCTSTR will be equivalent to LPCWSTR right.? so if i call
AS> LoadStringW() in winuser.h it is expecting a LPCWSTR. So is there
AS> anyway that i can pass LPCTSTR and which get implicitly converted to LPCWSTR.?

No.

Eric



AS> On Thursday, September 8, 2016 at 2:19:53 PM UTC+5:30, Abhijith Sugunan wrote:
AS> Yes i do got these errors

AS> On Thursday, September 8, 2016 at 12:25:38 PM UTC+5:30, Eric Jensen wrote:
AS> Hello Abhijith,
AS>
AS> Thursday, September 8, 2016, 8:40:06 AM, you wrote:
AS>
AS>> I also test after enabling unicode but still i gets the same error
AS>
AS>
AS>
AS> Do you get these errors when building wxWidgets or your own
AS> application?
AS>
AS> Eric
AS>





--

Abhijith Sugunan

unread,
Sep 8, 2016, 7:58:44 AM9/8/16
to wx-users, m...@j-dev.de
Eric : I get those errors while building project that uses wxWidgets

Fabian Cenedese

unread,
Sep 8, 2016, 8:03:19 AM9/8/16
to wx-u...@googlegroups.com
At 13:25 08.09.2016, you wrote:

>If the UNICODE and _UNICODE is enabled in the project then LPCTSTR will be equivalent to LPCWSTR right.? so if i call LoadStringW() in winuser.h it is expecting a LPCWSTR. So is there anyway that i can pass LPCTSTR and which get implicitly converted to LPCWSTR.?

No. And even if there were you would just feed garbage in. If the function
expects wide string you can't feed in an ascii string, even if the pointer
type could be changed. If you're programming in unicode you also need
to use the unicode types (or TCHAR which gets converted to the needed
type).

>Yes i do got these errors

The question was WHAT you are compiling, the library or your application.
You need to compile both with the same settings. Check your projects that
both wxWidgets and your application use the same settings.

Try (and compare) also the wxWidgets samples, whether they work or not,
and if they do work, what they are doing (differently).

Start off with a simple project and make it work.

bye Fabi

Eric Jensen

unread,
Sep 8, 2016, 8:22:08 AM9/8/16
to Abhijith Sugunan
Hello Abhijith,

Thursday, September 8, 2016, 1:58:43 PM, you wrote:

AS> Eric : I get those errors while building project that uses wxWidgets

Ok. Often this is caused by a wrong order of include files if you
include some Windows specific headers in addition to wxWidgets
headers.

Try including all wxWidgets header files first, then all others.

If that doesn't work, include <wx/msw/winundef.h> after the Windows
headers, then the wxWidgets headers.

https://wiki.wxwidgets.org/WxMSW_Issues#The_windows.h_Header_File.2C_Macros_and_Compiling_Errors

Eric


AS> On Thursday, September 8, 2016 at 5:17:16 PM UTC+5:30, Eric Jensen wrote:
AS> Hello Abhijith,
AS>
AS> you still haven't answered one question:
AS>
AS> Do you get these errors while building wxWidgets itself?
AS>
AS> Or do you get these errors when building your own project that uses
AS> wxWidgets?
AS>
AS>
AS>> If the UNICODE and _UNICODE is enabled in the project then
AS>> LPCTSTR will be equivalent to LPCWSTR right.? so if i call
AS>> LoadStringW() in winuser.h it is expecting a LPCWSTR. So is there
AS>> anyway that i can pass LPCTSTR and which get implicitly converted to LPCWSTR.?
AS>
AS> No.
AS>
AS> Eric
AS>
AS>
AS>
AS>
AS>
AS>
AS>
AS>
AS> --
AS>




--

Abhijith Sugunan

unread,
Sep 8, 2016, 8:48:38 AM9/8/16
to wx-users, m...@j-dev.de
Following is a piece of code from winundef.h in wxWidgets

#if defined(CreateDialog)
    #undef CreateDialog

    inline HWND CreateDialog(HINSTANCE hInstance,
                             LPCTSTR pTemplate,
                             HWND hwndParent,
                             DLGPROC pDlgProc)
    {
        #ifdef _UNICODE
            return CreateDialogW(hInstance, pTemplate, hwndParent, pDlgProc);
        #else
            return CreateDialogA(hInstance, pTemplate, hwndParent, pDlgProc);
        #endif
    }
#endif
If UNICODE is defined in my project it gonna pass pTemplate in CreateDialogW and pTemplate is of LPCTSTR why it is defined so.?

Eric Jensen

unread,
Sep 8, 2016, 9:06:25 AM9/8/16
to Abhijith Sugunan
Hello Abhijith,

Thursday, September 8, 2016, 2:48:37 PM, you wrote:

AS> Following is a piece of code from winundef.h in wxWidgets


AS> #if defined(CreateDialog)
AS>     #undef CreateDialog


AS>     inline HWND CreateDialog(HINSTANCE hInstance,
AS>                              LPCTSTR pTemplate,
AS>                              HWND hwndParent,
AS>                              DLGPROC pDlgProc)
AS>     {
AS>         #ifdef _UNICODE
AS>             return CreateDialogW(hInstance, pTemplate, hwndParent, pDlgProc);
AS>         #else
AS>             return CreateDialogA(hInstance, pTemplate, hwndParent, pDlgProc);
AS>         #endif
AS>     }
AS> #endifIf UNICODE is defined in my project it gonna pass pTemplate
AS> in CreateDialogW and pTemplate is of LPCTSTR why it is defined so.?


https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#LPCTSTR

Eric

Igor Korot

unread,
Sep 8, 2016, 9:09:44 AM9/8/16
to wx-u...@googlegroups.com
Hi,

On Thu, Sep 8, 2016 at 8:48 AM, Abhijith Sugunan <abije...@gmail.com> wrote:
> Following is a piece of code from winundef.h in wxWidgets
>
> #if defined(CreateDialog)
> #undef CreateDialog
>
> inline HWND CreateDialog(HINSTANCE hInstance,
> LPCTSTR pTemplate,
> HWND hwndParent,
> DLGPROC pDlgProc)
> {
> #ifdef _UNICODE
> return CreateDialogW(hInstance, pTemplate, hwndParent,
> pDlgProc);
> #else
> return CreateDialogA(hInstance, pTemplate, hwndParent,
> pDlgProc);
> #endif
> }
> #endif
> If UNICODE is defined in my project it gonna pass pTemplate in CreateDialogW
> and pTemplate is of LPCTSTR why it is defined so.?

My question remains un-answered: why do you need Windows-specific stuff?
Just use normal wxString.

Or you want to make a patch for wxWidgets?

Thank you.

David Connet

unread,
Sep 8, 2016, 10:02:49 AM9/8/16
to wx-u...@googlegroups.com
On 9/8/2016 5:48 AM, Abhijith Sugunan wrote:
> If UNICODE is defined in my project it gonna pass pTemplate in
> CreateDialogW and pTemplate is of LPCTSTR why it is defined so.?

How are you defining UNICODE? If you are doing "#define UNICODE" in your
code, that must happen before ANY headers are included. You should just
set "Character Set" to "Use Unicode Character Set" in the project
settings (on the General page).

The fact that your getting errors about LPCTSTR to LPCWSTR mismatch
means you are NOT compiling in UNICODE.

Dave

Abhijith Sugunan

unread,
Sep 8, 2016, 10:17:11 PM9/8/16
to wx-users
I had already set the character set to Use Unicode Character Set and i can clearly see that in my compiler options.
Reply all
Reply to author
Forward
0 new messages