Reputation: 141
So I'm trying to get into some directX programming so I'm following this book called "Beginning DirectX 11 Game Programming", but I'm stuck already at the second example.
I've spend roughly an hour searching for a solution to this problem, but havn't been able to find anything that could help me.
So the error code I'm getting is this.:
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
And here's the code - written exactly as in the book, except for 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;
}
Upvotes: 1
Views: 2030
Reputation: 1
I've just made the same mistake while following this same book, and if you read on after figure 2.4 you'll notice it actually answers the question for you and has a whole sub-section about the windows callback procedure.
Upvotes: 0
Reputation: 18850
Returning 0
from your WndProc
callback IS a terrible idea if you're not handling any messages. So you can either define it to handle messages yourself, or simply use the default procedure:
wndClass.lpfnWndProc = DefWindowProc;
Alternatively:
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { return DefWindowProc(hWnd, msg, wParam, lParam); }
Which you should do whenever you don't handle your messages.
Upvotes: 4
Reputation: 1
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.
Upvotes: 0
Reputation: 343
You never define
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
anywhere. @RomanR. has a perfect answer, and I agree that it is a bad solution. Check back to the first exercise and see if it doesn't have an implementation for it.
Upvotes: 0