Jump to content
  • Advertisement
Sign in to follow this  
ruddj16

newbie here, code doesnt compile

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

Hello been programming console C++ for around a year now... I decided I'll go for a little more of a challenge anyway been looking at code and now stripped some to its bear min... I've tried to be a little too adverntous now and seeking help as to why the following code doesnt compile..



#include <windows.h>		// Header File For Windows
#include <gl\gl.h>		// Header File For The OpenGL32 Library
#include <gl\glu.h>		// Header File For The GLu32 Library
#include <gl\glaux.h>		// Header File For The Glaux Library

HDC		hDC=NULL;	// Private GDI Device Context
HGLRC		hRC=NULL;		// Permanent Rendering Context
HWND		hWnd=NULL;		// Holds Our Window Handle
HINSTANCE	hInstance;		// Holds The Instance Of The Application

WinMain()
{
int a = 0;
if (a ==0)
 {
 MessageBox(NULL,"Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
 }

return 0;
}
For all the soruce codes ive seen none create a WinMain or a main for that fact, so where does the code start to excute? And why doesnt this work? The following errors are generated: c:\Documents and Settings\My Documents\c\test\test.cpp(12): error C2731: 'WinMain' : function cannot be overloaded c:\Documents and Settings\My Documents\c\test\test.cpp(12): warning C4007: 'WinMain' : must be '__stdcall' Thanks John.

Share this post


Link to post
Share on other sites
Advertisement
shouldn't winmain look more like:

int WINAPI WinMain(	HINSTANCE	hInstance,				// Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{


the return type and params are probably why the compiler thinks you are trying to overload winmain. WINAPI probably ensures it uses the stdcall convention.

Just guesses.

Share this post


Link to post
Share on other sites
with the help of msdn and a tad of logic i got this code:


#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library

int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{



MessageBox(NULL,"Error.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);


//return 0;

}

it all compiles and runs correctly ... only question is how does it know when its got to exit code? ie run sucess? In standard c++ you always end your int main() with return 0; since main expects an int to be returned. Here theres no int main but int WINAPI so in theory it needs a return code?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
From MSDN
If the function succeeds, terminating when it receives a WM_QUIT message, it should return the exit value contained in that message's wParam parameter. If the function terminates before entering the message loop, it should return zero.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!