C++ unresolved external symbol error

Started by
3 comments, last by owiley 14 years, 1 month ago
Hi all, I am new here and have been lurking this forum for a couple months as I get into C++. I am quite new at programming, but I have researched this problem to the nth. I know it has something to do with linking up to libraries, but Visual C++ Express seems to be linked to the libraries that seem to be popping the unresolved external symbol error. Here is the code (from a tutorial at http://www.directxtutorial.com/Tutorial10/A-Win32/dx10A3.aspx):

#include <windows.h>
#include <windowsx.h>

//The WindowProc prototype.

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

//The entry point for any Windows program.


int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nCmdShow)
{
//The handle for the Window, filled by a function.
HWND hWnd;
//This struct holds information for the Window class.
WNDCLASSEX wc;

//Clear out the Window class for use.
ZeroMemory(&wc, sizeof(WNDCLASSEX));

//fill in the struct with the needed information.

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";

//register the window class.
RegisterClassEx(&wc);

//create the window and use the result as a handle.
hWnd = CreateWindowEx(NULL,
					  "WindowClass1", //name of the window class.
					  "Basic Windowed Program", //name of the window title bar.
					  WS_OVERLAPPEDWINDOW, //the window style.
					  300, //x position of the window.
					  300, //y position of the window.
					  500, //width of the window.
					  400, //height of the window.
					  NULL, //No parent window.
					  NULL, //No menus.
					  hInstance, //application handle.
					  NULL); //used with multiple windows.

//show the window on the screen.
ShowWindow(hWnd, nCmdShow);

//enter the main loop:

//this struct holds window event messages.
MSG msg;

//wait for the next message in the queue, store in 'msg'.

while(GetMessage(&msg, NULL, 0, 0))
{
	//translate keystroke messages into the right format.
	TranslateMessage(&msg);

	//send the message to the WindowProc function;
	DispatchMessage(&msg);
}

	//return this part of the WM_QUIT message to Windows.
	return msg.wParam;

}

//this is the main message handler for the program.

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	//sort through and find what code to run for the message given.
	switch(message)
	{
	//this message is read when the windows is closed.
	case WM_DESTROY:
		{
			//close the application entirely.
			PostQuitMessage(0);
			return 0;
		}	break;

	}


//Handle any messages that the switch didn't.

	return DefWindowProc(hWnd, message, wParam, lParam);
}
When I compile, I get the following:

GT_HelloWorldWin32.obj
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__Dispat
chMessageA@4 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__Transl
ateMessage@4 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__GetMes
sageA@16 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__ShowWi
ndow@8 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__Create
WindowExA@48 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__Regist
erClassExA@4 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__LoadCu
rsorA@8 referenced in function _WinMain@16
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__DefWin
dowProcA@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,un
signed int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
GT_HelloWorldWin32.obj : error LNK2019: unresolved external symbol __imp__PostQu
itMessage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,un
signed int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
GT_HelloWorldWin32.exe : fatal error LNK1120: 9 unresolved externals
Could someone please point me in the right direction on this? Thank you for taking the time to look into this. Best Regards, Andrew
Advertisement
If you're using the 2005 version of VC Express, then you need to manually install the Windows SDK (formerly called Platform SDK). If you're using the 2008 version... well, you shouldn't be getting these errors then. Make sure that when you create the project you select the appropriate settings (win32 project, empty... etc).
just download the newest win32sdk usually called platform sdk from msdn(Mircosoft developer network). Next is you have reconfigure the ide to use the new sdk and compiler.
Bring more Pain
Amr0,

Thanks for checking this out. I went ahead and deleted the original project and remade it, making sure to choose the right options. Seems to be working now. I must have checked something wrong when I created it, maybe chose console app vs. win32.

Thanks again,

Andrew
thats possible but it usually complain about not having the correct main() method
Bring more Pain

This topic is closed to new replies.

Advertisement