#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.
newbie here, code doesnt compile
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..
Your WinMain function is declared wrong, it takes specific arguments and has a specific return type.
See this MSDN page for details on how to declare it and what each parameter represents.
See this MSDN page for details on how to declare it and what each parameter represents.
shouldn't winmain look more like:
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.
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.
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?
#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?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement