1

所以我试图进入一些directX编程,所以我正在关注这本书名为“Beginning DirectX 11 Game Programming”,但我已经被第二个例子困住了。

我花了大约一个小时来寻找这个问题的解决方案,但找不到任何可以帮助我的东西。

所以我得到的错误代码是这样的:

Main.obj : error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function _wWinMain@16

这是代码 - 除了 LRESULT CALLBACK WndProc 之外,完全按照书中的方式编写

#include <Windows.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( WNDCLASSEX );
    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_OVERLAPPEDWINDOW, FALSE );

    HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Blank Win32 Window", 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 );

    return 0;
}
4

4 回答 4

4

如果您不处理任何消息0,则从WndProc回调中返回一个糟糕的主意。所以你可以定义它来自己处理消息,或者简单地使用默认过程:

wndClass.lpfnWndProc = DefWindowProc;

或者:

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { return DefWindowProc(hWnd, msg, wParam, lParam); }

每当您不处理您的消息时,您应该这样做。

于 2012-07-25T22:06:37.313 回答
0

Defining your WndProc as DefWindowProc is not the solution when we're discussing DirectX. Plenty of users run their games in window mode which means you have program the possibility of updating your aspect ratio for your XMMatrixPerspectiveFovLH, changing the resolution of your buffers and updating your viewport if the window becomes resized. Also later on if you want to avoid DirectInput in itself you could just simply use the window messages WM_MOUSEMOVE; WM_LBUTTONDOWN; WM_LBUTTONUP, etc to manage your mouse and keyboard states - as many still detest dinput8.

于 2012-07-29T16:53:57.860 回答
0

你从不定义

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

任何地方。@RomanR。有一个完美的答案,我同意这是一个糟糕的解决方案。回到第一个练习,看看它是否没有实现。

于 2012-07-25T21:57:43.170 回答
0

我在阅读同一本书时也犯了同样的错误,如果您在图 2.4 之后继续阅读,您会注意到它实际上为您回答了问题,并且有一个关于 Windows 回调过程的完整小节。

于 2013-02-12T23:17:19.587 回答