Problems with examble from the book "Opengl game programming"

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);
windowClass.style = 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;
}

I copied your code from your post. I got a different error - fatal error C1010: unexpected end of file while looking for precompiled header directive.

However, by replacing your:

#include <windows.h>

with:

#include “stdafx.h”

it worked without a problem. If that doesn’t work. Verify whether stdafx.h exists in your project folder. If not change it to <stdafx.h>.

Also, this particual sample has nothing to do with OpenGL. It does not need any OpenGL headers, libs, or DLLs, and calls no OpenGL functions of any kind. I believe they are giving you a quick course in Win32 API programming to give you a framework in which to learn OpenGL programming.

And, if it still isn’t working, start over. You may want to just create a new Win32 application (not console application for this) and copy your code directly over to the new main.cpp

Hope it helps. Good luck.

[This message has been edited by shinpaughp (edited 02-09-2003).]

For the original problem, you created an Win32 Console app (which uses an entry point of main), instead of a Win32 App (which uses an entry point of WinMain.) Since your code has a WinMain instead of a main, but your project is looking for an entry point of main, you run into that problem.

For shinpaughp’s problem, you had your project setup to use pre-compiled headers but dotdkay’s code wasn’t, so he didn’t need to #include “stdafx.h.” You could also have just went to the project settings and disabled pre-compiled headers.