Advertisement Jump to content


This topic is now archived and is closed to further replies.


Problems with examble from book

This topic is 5821 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

Hi I hope you guys can help me out with a code examble from the book "Opengl Game programming". It´s the second program in chapter 2, where the plan is to make triangle in red spinning on a black background. Im using Visual C++ 6.0, and have installed the Opengl files, but i get this error when trying to link: Compiling... main.cpp Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/main.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have copied the examble from the cd, so there shouldnt be any mistyping, the source-code: #define WIN32_LEAN_AND_MEAN // trim the excess fat from Windows #include <windows.h> // standard Windows app include // the Windows Procedure event handler LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT paintStruct; HDC hDC; // device context char string[] = "Hello, world!"; // text to be displayed switch(message) { case WM_CREATE: // window is being created return 0; break; case WM_CLOSE: // windows is closing PostQuitMessage(0); return 0; break; case WM_PAINT: // window needs updating hDC = BeginPaint(hwnd, &paintStruct); SetTextColor(hDC, COLORREF(0x00FF0000)); // set text color to blue TextOut(hDC, 150, 150, string, sizeof(string)-1); // display text in middle of window EndPaint(hwnd, &paintStruct); return 0; break; default: break; } return (DefWindowProc(hwnd, message, wParam, lParam)); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX windowClass; // window class HWND hwnd; // window handle MSG msg; // message bool done; // flag saying when our app is complete // fill out the window class structure windowClass.cbSize = sizeof(WNDCLASSEX); = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // white background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = "MyClass"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon // register the windows class if (!RegisterClassEx(&windowClass)) return 0; // class registered, so now create our window hwnd = CreateWindowEx(NULL, // extended style "MyClass", // class name "A REAL Windows Application!", // app name WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU, // style 100, 100, // x,y coordinate 400, 400, // width, height NULL, // handle to parent NULL, // handle to menu hInstance, // application instance NULL); // no extra params // check if window creation failed (hwnd would equal NULL) if (!hwnd) return 0; done = false; // intialize the loop condition variable // main message loop while (!done) { PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE); if (msg.message == WM_QUIT) // do we receive a WM_QUIT message? { done = true; // if so, time to quit the application } else { TranslateMessage(&msg); // translate and dispatch to event queue DispatchMessage(&msg); } } return msg.wParam; }

Share this post

Link to post
Share on other sites
I have solved the problem, the guys from #opengl @ quakenet helped me.

There must have been a error in the visual c++ workspace on the cd, because it was made as a console projekt and not a Win 32 api project.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!