Jump to content
  • Advertisement
Sign in to follow this  
TrevorPeyton

DX11 Win32 C++ error

This topic is 2137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm new here so if this isn't in the right place sorry. I put it in the DirectX section because I'm following this book:

 

http://www.amazon.com/Beginning-DirectX-11-Game-Programming/dp/1435458958

 

I am on the second chapter and well the first thing it does is teaches you how to display a window using WinApi. I have some knowledge but I'm not very familiar with this and don't know how to fix this error.

 

Here is the code:

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

	MSG msg = {0};

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

	return static_cast<int>(msg.wParam);

}

And the error:

1>------ Build started: Project: BlankWindow, Configuration: Debug Win32 ------
1>  main.cpp
1>  LINK : c:\users\trevor peyton\documents\visual studio 2010\Projects\DXBook\BlankWindow\Debug\BlankWindow.exe not found or not built by the last incremental link; performing full link
1>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
1>c:\users\trevor peyton\documents\visual studio 2010\Projects\DXBook\BlankWindow\Debug\BlankWindow.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I got two things from this.

 

1. It obviously has something to do with:

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

and

    wndClass.lpfnWndProc = WndProc;

2. (I think) that it is a linking error... and I'm not really sure what it's linking. biggrin.png new to C++ (more of a C# guy).

 

Any help is much appreciated, thanks.

Share this post


Link to post
Share on other sites
Advertisement

Unresolved external symbol means the linker cannot find the definition of the mentioned symbol. In this case, it cannot find the definition for WndProc because you haven't supplied the code for it.

Share this post


Link to post
Share on other sites

No, that line simply tells the compiler that there is a function called WndProc that has set of parameters and a return type. It does not know what the function is though, only that is (should) exist somewhere. Look up the difference between declaration and definition; that line is a declaration, but the linker is looking for the definition of the function. The function is missing the code that is actually executed when the function is called.

Share this post


Link to post
Share on other sites

Alright thanks, the book isn't very clear on that part. Also from the looks of it it's not defined in the book, I found it in the books source on there website.

Share this post


Link to post
Share on other sites

 

Does this not define it?

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

To be perfectly clear on the terminology, that line of code declares the function, and the function body is what defines it.

Share this post


Link to post
Share on other sites

And another thing, as a C# developer to a C# developer. In C++, it actually matters where you declare your functions and classes.

You need declarations in order to compile, and definitions in order to link. Declarations must go before usage (unlike C# and most modern languages).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!