A value of type "const wchar_t *" cannot be used to initialize an entity of type "LPCSTR"
15,607
LPCSTR is defined as const char*, not const wchar_t*. Use LPCWSTR, or LPCTSTR with UNICODE defined.
Related videos on Youtube
Author by
Johnny Hoirs
Updated on July 13, 2022Comments
-
Johnny Hoirs almost 2 years
im learning C++ Direct X Programming. And im on the first tutorial of directx programming tutorial(I will post link on comments..). I just had trouble setting up Chilli DirectX Framework for some reason..
Errors
Error (active) argument of type "const wchar_t *" is incompatible with parameter of type "LPCSTR" Chilli c:\Users\**NAME**\Documents\DirectXFrameworks\Chili DirectX Framework\Assets\Windows.cpp 126 A value of type "const wchar_t *" cannot be used to initialize an entity of type "LPCSTR" Chilli c:\Users\**NAME**\Documents\DirectXFrameworks\Chili DirectX Framework\Assets\Windows.cpp 90 Error C2440 'initializing': cannot convert from 'const wchar_t [31]' to 'LPCSTR' Chilli c:\users\**NAME**\documents\directxframeworks\chili directx framework\assets\windows.cpp 90 Error C2664 'BOOL UnregisterClassA(LPCSTR,HINSTANCE)': cannot convert argument 1 from 'const wchar_t [31]' to 'LPCSTR' Chilli c:\users\**NAME**\documents\directxframeworks\chili directx framework\assets\windows.cpp 126
I Guess its targeting line 90 and 126 from Window.cpp a lot so here is the full code of Window.cpp :
Error Lines
Line 90 Window.cpp:
WNDCLASSEX wc = { sizeof( WNDCLASSEX ),CS_CLASSDC,MsgProc,0,0, GetModuleHandle( NULL ),NULL,NULL,NULL,NULL, L"Chili DirectX Framework Window",NULL };
Line 125 Window.cpp:
UnregisterClass(L"Chili DirectX Framework Window",wc.hInstance );
Error Pictures
Pictures representing the problem on visual studio : Line 126 : http://i.imgur.com/LrHHr9o.png
Line 90 : http://i.imgur.com/5dXSvFS.png
Full Code of Window.cpp Only
Full Code Window.cpp:
/****************************************************************************************** * Chili DirectX Framework Version 11.12.17 * * Windows.cpp * * Copyright 2011 PlanetChili.net * * * * This file is part of The Chili DirectX Framework. * * * * The Chili DirectX Framework is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * The Chili DirectX Framework is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with The Chili DirectX Framework. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************************/ #include <Windows.h> #include <wchar.h> #include "Game.h" #include "resource.h" static KeyboardServer kServ; LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0; case WM_KEYDOWN: switch( wParam ) { case VK_UP: kServ.OnUpPressed(); break; case VK_DOWN: kServ.OnDownPressed(); break; case VK_LEFT: kServ.OnLeftPressed(); break; case VK_RIGHT: kServ.OnRightPressed(); break; case VK_SPACE: kServ.OnSpacePressed(); break; case VK_RETURN: kServ.OnEnterPressed(); break; } break; case WM_KEYUP: switch( wParam ) { case VK_UP: kServ.OnUpReleased(); break; case VK_DOWN: kServ.OnDownReleased(); break; case VK_LEFT: kServ.OnLeftReleased(); break; case VK_RIGHT: kServ.OnRightReleased(); break; case VK_SPACE: kServ.OnSpaceReleased(); break; case VK_RETURN: kServ.OnEnterReleased(); break; } } return DefWindowProc( hWnd, msg, wParam, lParam ); } int WINAPI wWinMain( HINSTANCE hInst,HINSTANCE,LPWSTR,INT ) { WNDCLASSEX wc = { sizeof( WNDCLASSEX ),CS_CLASSDC,MsgProc,0,0, GetModuleHandle( NULL ),NULL,NULL,NULL,NULL, L"Chili DirectX Framework Window",NULL }; wc.hIconSm = (HICON)LoadImage( hInst,MAKEINTRESOURCE( IDI_APPICON16 ),IMAGE_ICON,16,16,0 ); wc.hIcon = (HICON)LoadImage( hInst,MAKEINTRESOURCE( IDI_APPICON32 ),IMAGE_ICON,32,32,0 ); RegisterClassEx( &wc ); RECT wr; wr.left = 100; wr.right = 800 + wr.left; wr.top = 100; wr.bottom = 600 + wr.top; AdjustWindowRect( &wr,WS_OVERLAPPEDWINDOW,FALSE ); HWND hWnd = CreateWindowW( L"Chili DirectX Framework Window",L"Chili DirectX Framework", WS_OVERLAPPEDWINDOW,wr.left,wr.top,wr.right-wr.left,wr.bottom-wr.top, NULL,NULL,wc.hInstance,NULL ); ShowWindow( hWnd,SW_SHOWDEFAULT ); UpdateWindow( hWnd ); Game theGame( hWnd,kServ ); MSG msg; ZeroMemory( &msg,sizeof( msg ) ); while( msg.message != WM_QUIT ) { if( PeekMessage( &msg,NULL,0,0,PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { theGame.Go(); } } UnregisterClass(L"Chili DirectX Framework Window",wc.hInstance ); return 0; }
Errors after i enable Unicode:
Severity Code Description Project File Line Suppression State Error LNK1120 13 unresolved externals Chilli c:\users\NAME\documents\visual studio 2015\Projects\Chilli\Debug\Chilli.exe 1 Error LNK2019 unresolved external symbol __imp__UpdateWindow@4 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__UnregisterClassW@8 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__TranslateMessage@4 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__ShowWindow@8 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__RegisterClassExW@4 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall MsgProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MsgProc@@YGJPAUHWND__@@IIJ@Z) Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__PeekMessageW@20 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__LoadImageW@24 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__DispatchMessageW@4 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall MsgProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MsgProc@@YGJPAUHWND__@@IIJ@Z) Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__CreateWindowExW@48 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol __imp__AdjustWindowRect@12 referenced in function _wWinMain@16 Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\Windows.obj 1 Error LNK2019 unresolved external symbol _Direct3DCreate9@4 referenced in function "public: __thiscall D3DGraphics::D3DGraphics(struct HWND__ *)" (??0D3DGraphics@@QAE@PAUHWND__@@@Z) Chilli c:\Users\NAME\documents\visual studio 2015\Projects\Chilli\Chilli\D3DGraphics.obj 1
-
MrEricSir about 8 yearsThis looks awfully similar to stackoverflow.com/questions/36989703/…
-
Mark over 6 yearsLooks like the answer has been deleted.
-
Mark over 6 yearsTo overcome the problem I went to project properties and in Configuration Properties->General->Project Defaults->Character Set, change setting from 'Use Multi-Byte Character Set' to 'Use Unicode Character set'
-
-
Johnny Hoirs about 8 yearsOh ok thankyou.. ima look on how to define UNICODE.. but ill update you with results..
-
Johnny Hoirs about 8 yearsAfter i define UniCODE I get a BUNCH Of errors... Ill update the errors i get when i enable unicode
-
Dan Korn about 8 yearsYou need to decide whether you want to use the 8-bit or the Unicode version of the Windows API. Or, you need to append A or W to various Windows API functions in order to specifically call 8-bit or Unicode versions of individual functions.
-
Johnny Hoirs about 8 yearsDan.. that confused me a whole LOT! I can choose whatever you want.. i jsut dont want those nasty errors
-
Dan Korn about 8 yearsI'm not trying to confuse you. I understand that you want the errors to go away, but it's not magic. You either call functions that take const char* parameters, with const char*, or you call functions that take const wchar_t* parameters with const wchar_t*.
-
Dan Korn about 8 yearsReading this might help: msdn.microsoft.com/en-us/library/windows/desktop/…