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;
}