C++ Problem beim Debuggen

CodeCrafterCpp

Erfahrenes Mitglied
Hallo,
Wenn ich in OpenGL ein Code schreibe oder mir ein Runterlade(nur zur Probe) bekomme ich immer die beiden Fehler:
Code:
Fehler	1	error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_WinMain@16" in Funktion "___tmainCRTStartup".	C:\Users\**********\Documents\Visual Studio 2010\Projects\opengl25\opengl25\MSVCRTD.lib(crtexew.obj)



Fehler	2	error LNK1120: 1 nicht aufgelöste externe Verweise.	C:\Users\*******\Documents\Visual Studio 2010\Projects\opengl25\Debug\opengl25.exe	1



Der Code kann auch nur so kurz sein :

Code:
#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")


HDC hDC = 0;
HGLRC hRC = 0;
HWND hWND = 0;

HINSTANCE hINSTANCE;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
RECT windows;


bool keys[256];
bool active = true;
bool fullscreen = false;

bool InitGl();



Was mache ich falsch?
 
Du hast keine Main-Funktion mit der Funktions-Definition

C:
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);

Du bräuchtest für eine Windows-Exe mindest eine WinMain-Funktion, sowie du für eine Konsolen-Exe eine main()-Funktion brauchst. Außer natürlich, du willst eine DLL erstellen. Dann brauchst du IMHO eine DllMain()-Funktion.
 
Ok hab ich vllt. ein bisschen doof erklärt wenn ich ein Code habe wie diesen:
Code:
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

HDC hDC = 0;
HGLRC hRC = 0;
HWND hWnd = 0;
HINSTANCE hInstance;		
LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	
RECT window;

bool keys[256];
bool active = true;
bool fullscreen = false;

bool InitGL();
void ReSizeGLScene(unsigned int width, unsigned int height);
bool DrawGLScene();
bool KillGLWindow();
bool CreateGLWindow(LPCWSTR title, int width, int height, int bits, bool fullscreenflag);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR nlpCmdLine, int nCmdShow);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR nlpCmdLine, int nCmdShow)
{
	MSG	msg;									
	bool done = false;								

	if(MessageBox(0, L"Im Vollbildmodus starten?", L"Vollbild?", MB_YESNO | MB_ICONQUESTION) == IDYES)
	{
		fullscreen = true;							
	}

	if(!CreateGLWindow(L"OpenGL", 640, 480, 16, fullscreen))
	{
		return 0;								
	}

	while(!done)								
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))	
		{
			if(msg.message == WM_QUIT)				
			{
				done = true;							
			}
			else									
			{
				TranslateMessage(&msg);				
				DispatchMessage(&msg);			
			}
		}
		else										
		{
			if((active && !DrawGLScene()) || keys[VK_ESCAPE])	
			{
				done = true;							
			}
			else									
			{
				SwapBuffers(hDC);					
			}
		}	
	}

	KillGLWindow();	

	return (msg.wParam);						
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)									
	{
		case WM_ACTIVATE:							
		{
			if(!HIWORD(wParam))					
			{
				active = true;						
			}
			else
			{
				active = false;						
			}

			return 0;								
		}

		case WM_SYSCOMMAND:							
		{
			switch(wParam)							
			{
				case SC_SCREENSAVE:					
				case SC_MONITORPOWER:				
				return 0;							
			}

			break;									
		}

		case WM_KEYDOWN:							
		{
			keys[wParam] = true;

			return 0;								
		}

		case WM_KEYUP:								
		{
			keys[wParam] = false;	

			return 0;							
		}

		case WM_SIZE:								
		{
			ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));  

			return 0;							
		}
	}

	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

bool CreateGLWindow(LPCWSTR title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint PixelFormat;			
	WNDCLASS wc;						
	DWORD dwExStyle;				
	DWORD dwStyle;				
	RECT WindowRect;				
	WindowRect.left = 0;			
	WindowRect.right = width;		
	WindowRect.top = 0;				
	WindowRect.bottom = height;		

	fullscreen = fullscreenflag;	

	hInstance			= GetModuleHandle(NULL);				
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	
	wc.lpfnWndProc		= (WNDPROC) WndProc;					
	wc.cbClsExtra		= 0;									
	wc.cbWndExtra		= 0;									
	wc.hInstance		= hInstance;							
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			
	wc.hbrBackground	= NULL;									
	wc.lpszMenuName		= NULL;									
	wc.lpszClassName	= L"OpenGL";								

	if(!RegisterClass(&wc))									
	{
		MessageBox(NULL, L"Window-Class konnte nicht regsitriert werden!", L"ERROR", MB_OK|MB_ICONEXCLAMATION);

		return false;											
	}
	
	if(fullscreen)												
	{
		DEVMODE dmScreenSettings;								
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));	
		dmScreenSettings.dmSize = sizeof(dmScreenSettings);		
		dmScreenSettings.dmPelsWidth = width;				
		dmScreenSettings.dmPelsHeight = height;				
		dmScreenSettings.dmBitsPerPel = bits;					
		dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			if(MessageBox(0, L"Vollbild-Modus wird nicht unterstützt. Window-Mode nutzen?", L"OpenGl - Info", MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
			{
				fullscreen = false;		
			}
			else
			{
				MessageBox(0, L"Programm wird beendet.", L"ERROR", MB_OK|MB_ICONSTOP);

				return false;
			}
		}
	}

	if(fullscreen)												
	{
		dwExStyle = WS_EX_APPWINDOW;								
		dwStyle = WS_POPUP;										
		ShowCursor(FALSE);										
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			
		dwStyle = WS_OVERLAPPEDWINDOW;							
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);	

	if (!(hWnd = CreateWindowEx(dwExStyle, L"OpenGL", (LPCWSTR)title, dwStyle |	WS_CLIPSIBLINGS | WS_CLIPCHILDREN,					
								0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top,	
								NULL, NULL, hInstance, NULL)))								
	{
		KillGLWindow();								
		MessageBox(NULL, L"Fenster konnte nicht erstellt werden!", L"ERROR", MB_OK|MB_ICONEXCLAMATION);

		return false;								
	}

	static PIXELFORMATDESCRIPTOR pfd =				
	{
	    sizeof(PIXELFORMATDESCRIPTOR), 
		1,											
		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA,								
		bits,										
		0, 0, 0, 0, 0, 0,							
		0,											
		0,											
		0,											
		0, 0, 0, 0,									
		16,											
		0,											
		0,											
		PFD_MAIN_PLANE,								
		0,											
		0, 0, 0										
	};
	
	hDC = GetDC(hWnd);					
	PixelFormat = ChoosePixelFormat(hDC, &pfd);	
	SetPixelFormat(hDC, PixelFormat, &pfd);		
	hRC = wglCreateContext(hDC);				
	wglMakeCurrent(hDC, hRC);					
	
	ShowWindow(hWnd, SW_SHOW);						
	SetForegroundWindow(hWnd);						
	SetFocus(hWnd);									
	ReSizeGLScene(width, height);					

	if(!InitGL())									
	{
		KillGLWindow();								
		MessageBox(NULL, L"Initialization Failed.", L"ERROR", MB_OK|MB_ICONEXCLAMATION);

		return false;								
	}

	return true;								
}

bool KillGLWindow()								
{
	if(fullscreen)										
	{
		ChangeDisplaySettings(0, 0);					
		ShowCursor(TRUE);								
	}

	if(hRC)											
	{
		wglMakeCurrent(0, 0);				
		wglDeleteContext(hRC);					
		hRC = 0;									
	}

	ReleaseDC(hWnd, hDC);				

	DestroyWindow(hWnd);					

	UnregisterClass(L"OpenGL", hInstance);	

	return true;
}

bool InitGL()										
{
	//glEnable(GL_TEXTURE_2D);							
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);				
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glClearDepth(1.0);									
	glDepthFunc(GL_LEQUAL);								
	glEnable(GL_DEPTH_TEST);							
	glShadeModel(GL_SMOOTH);							
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	return true;										
}

void ReSizeGLScene(unsigned int width, unsigned int height)		
{
	if(height == 0)										
		height = 1;										

	glViewport(0, 0, width, height);						

	glMatrixMode(GL_PROJECTION);						
	glLoadIdentity();									

	gluPerspective(45.0f, (float)width/(float)height, 0.1f, 500.0f);

	glMatrixMode(GL_MODELVIEW);							
	glLoadIdentity();									
}

bool DrawGLScene()									
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();

	return true;										
}

Bekomme ich die gleichen Fehler....
 
Zurück