LNK2019错误;未解决的外部符号| C ++

时间:2018-01-25 05:31:21

标签: c++ visual-studio-2017 directx lnk2019

这是我为学校做的一个项目。我相信该程序应该可行,但我有一个链接器错误,我无法弄清楚。

错误:严重性代码描述项目文件行抑制状态 错误LNK2019未解析的外部符号"长 stdcall WndProc(struct HWND *,unsigned int,unsigned int,long)" (?WndProc @@ YGJPAUHWND __ @@ IIJ @ Z)函数_wWinMain @ 16 Direct X C:\ Visual Studio Programs \ Direct X \ Direct X \ main.obj 1

Main.cpp文件

#include <Windows.h>
#include <memory>
#include "BlankDemo.h"

LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
    WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
    LPWSTR cmdLine, int cmdShow)
{
    UNREFERENCED_PARAMETER(prevInstance);
    UNREFERENCED_PARAMETER(cmdLine);

    WNDCLASSEX wndClass = { 0 };
    wndClass.cbSize = sizeof(WNDCLASS);
    wndClass.style = CS_HREDRAW | CS_VREDRAW;
    wndClass.lpfnWndProc = WndProc;
    wndClass.hInstance = hInstance;
    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = "DX11BookWindowClass";

    if (!RegisterClassEx(&wndClass))
        return -1;

    RECT rc = { 0, 0, 640, 480 };
    AdjustWindowRect(&rc, WS_EX_OVERLAPPEDWINDOW, FALSE);

     HWND hwnd = CreateWindowA("DX11BookWindowClass", "BlankWin32Window",
        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right -      rc.left,
        rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

    if (!hwnd)
        return -1;

    ShowWindow(hwnd, cmdShow);

    std::auto_ptr<Dx11DemoBase> demo(new BlankDemo());

    // Demo Initialize
    bool result = demo->Initialize(hInstance, hwnd);

    // Error reporting if there is an issue
    if (result == false)
        return -1;

    MSG msg = { 0 };

    while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        else
        {
            // Update and Draw
            demo->Update(0.0f);
            demo->Render();
        }
    }
    // Demo Shutdown
    demo->Shutdown();

    return static_cast<int>(msg.wParam);
}

 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM 1Param)
{
    PAINTSTRUCT paintStruct;
    HDC hDC;

    switch (message)
    {
    case WM_PAINT:
        hDC = BeginPaint(hwnd, &paintStruct);
        EndPaint(hwnd, &paintStruct);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    defualt:
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
     return 0;
}

// implementation of the BlankDemo class
BlankDemo::BlankDemo()
{

}

BlankDemo::~BlankDemo()
{

}

bool BlankDemo::LoadContent()
{
    return true;
}

void BlankDemo::UnloadContent()
{

}

void BlankDemo::Update(float dt)
{

}

void BlankDemo::Render()
{
    if (d3dContext_ == 0)
        return;

    float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
    d3dContext_->ClearRenderTargetView(backBufferTarget_, clearColor);

    swapChain_->Present(0, 0);
 }

BlankDemo.h文件:

#pragma once
#ifndef _BLANK_DEMO_H_
#define _BLANK_DEMO_H_
#include "Dx11DemoBase.h"

class BlankDemo : public Dx11DemoBase
{
public:
    BlankDemo();
    virtual ~BlankDemo();

    bool LoadContent();
    void UnloadContent();

    void Update(float dt);
    void Render();
};

#endif // !_BLANK_DEMO_H_

最后,Dx11DemoBase.h文件:

#pragma once
#ifndef _DEMO_BASE_H_
#define _DEMO_BASE_H_

#include <d3d11.h>
#include <D3DX11.h>
#include <DxErr.h>

class Dx11DemoBase
{
public:
    Dx11DemoBase();
    virtual ~Dx11DemoBase();

    bool Initialize(HINSTANCE hInstance, HWND hwnd);
    void Shutdown();

    virtual bool LoadContent();
    virtual void UnloadContent();

    virtual void Update(float dt) = 0;
    virtual void Render() = 0;

protected:

    HINSTANCE hInstance_;

    HWND hwnd_;

    D3D_DRIVER_TYPE driverType_;
    D3D_FEATURE_LEVEL featureLevel_;

    ID3D11Device* d3dDevice_;
    ID3D11DeviceContext* d3dContext_;
    IDXGISwapChain* swapChain_;
    ID3D11RenderTargetView* backBufferTarget_;
};

#endif // !_DEMO_BASE_H_

1 个答案:

答案 0 :(得分:0)

以下是WndProc的定义:

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM 1Param)

1Param定义中的WndProc替换为lParam1Param的前缀为1 (One)而非l (small L)

此外,由于您使用Direct3D API渲染到客户端区域,因此您不需要处理WM_PAINT消息。 Direct3D绘制API调用将您的管道数据呈现到客户区