“const wchar_t *”类型的值不能用于初始化“LPCSTR”类型的实体

问题描述 投票:-2回答:1

即时学习C ++ Direct X编程。我在directx编程教程的第一个教程(我将在评论上发布链接..)。我出于某种原因设置Chilli DirectX Framework时遇到了麻烦。

错误

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 );

错误图片

代表视觉工作室问题的图片:第126行:http://i.imgur.com/LrHHr9o.png

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

仅限Window.cpp的完整代码

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

启用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   
c++
1个回答
3
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.