gpt4 book ai didi

c++ - "const wchar_t *"类型的值不能用于初始化 "LPCSTR"类型的实体

转载 作者:行者123 更新时间:2023-12-05 09:20:40 30 4
gpt4 key购买 nike

我正在学习 C++ Direct X 编程。我在 directx 编程教程的第一个教程中(我将在评论中发布链接..)。由于某种原因,我在设置 Chilli DirectX 框架时遇到了问题。

错误

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

我从 Window.cpp 中猜测它的目标行 90 和 126 很多所以这里是 Window.cpp 的完整代码:

错误行

第 90 行 Window.cpp:

   WNDCLASSEX wc = { sizeof( WNDCLASSEX ),CS_CLASSDC,MsgProc,0,0,
GetModuleHandle( NULL ),NULL,NULL,NULL,NULL,
L"Chili DirectX Framework Window",NULL };

第 125 行 Window.cpp:UnregisterClass(L"Chili DirectX Framework Window",wc.hInstance );

错误图片

代表 visual studio 问题的图片:第 126 行:http://i.imgur.com/LrHHr9o.png

第 90 行:http://i.imgur.com/5dXSvFS.png

仅Window.cpp的完整代码

完整代码窗口.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;
}

启用 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

最佳答案

LPCSTR 被定义为 const char*,而不是 const wchar_t*。使用定义了 UNICODE 的 LPCWSTR 或 LPCTSTR。

关于c++ - "const wchar_t *"类型的值不能用于初始化 "LPCSTR"类型的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36990723/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com