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