Skip to main content
gamedev.net
🔒 Locked

some compiler errors (VC++6) [SOLVED]

Started by u235 10 replies 1.5k views
Original Post
u235
u235
Well, at the moment I am forced to use VC++6 because I don't have a web connection on my computer so I can't install VC++ 2005 Express. Anyway, on to the problem. Maybe it's just that using Managed code has made me complacent, but I'm getting a few errors when trying to setup a basic OpenGL app (from "Beginning OpenGL Game Programming" by Dave Astle and Kevin Hawkins). Here are the errors:

c:\dev-cpp\beginogl.cpp(6) : error C2143: syntax error : missing ';' before 'PCH creation point'
c:\dev-cpp\beginogl.cpp(66) : error C2360: initialization of 'pfd' is skipped by 'case' label
        c:\dev-cpp\beginogl.cpp(40) : see declaration of 'pfd'
c:\dev-cpp\beginogl.cpp(67) : error C2360: initialization of 'pfd' is skipped by 'case' label
        c:\dev-cpp\beginogl.cpp(40) : see declaration of 'pfd'
c:\dev-cpp\beginogl.cpp(68) : error C2360: initialization of 'pfd' is skipped by 'case' label
        c:\dev-cpp\beginogl.cpp(40) : see declaration of 'pfd'
c:\dev-cpp\beginogl.cpp(74) : error C2360: initialization of 'pfd' is skipped by 'case' label
        c:\dev-cpp\beginogl.cpp(40) : see declaration of 'pfd'
c:\dev-cpp\beginogl.cpp(80) : error C2360: initialization of 'pfd' is skipped by 'case' label
        c:\dev-cpp\beginogl.cpp(40) : see declaration of 'pfd'
CGfxOpenGL.cpp
c:\dev-cpp\cgfxopengl.cpp(10) : error C2143: syntax error : missing ';' before 'PCH creation point'



The first and last one make no sense to me because the first one is just for a variable declaration and the last one is just a constructor definition in another class. Here is the code for the first and last ones respectively (note: these are just partials, containing only the line on which the error occured and some of the surrounding lines):

//First error
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "CGfxOpenGL.h"

HGLRC hRC;  //<--Error is on this line
HDC hDC;
CGfxOpenGL *g_glRender;


//Second error (from CGfxOpenGL.cpp)
#ifdef _WINDOWS
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>
#include "CGfxOpenGL.h"

CGfxOpenGL::CGfxOpenGL()  //<--Error is on this line
{
}



And the middle five obviously mean there is something wrong with my switch block, but I can't figure out what it is:

switch(msg)
    {
        case WM_CREATE:
             hDC = GetDC(hWnd);
             int pixelFormat;
             PIXELFORMATDESCRIPTOR pfd = 
             {
                 sizeof(PIXELFORMATDESCRIPTOR),
                 1,
                 PFD_SUPPORT_OPENGL |
                 PFD_DRAW_TO_WINDOW |
                 PFD_DOUBLEBUFFER,
                 PFD_TYPE_RGBA,
                 32,
                 0, 0, 0, 0, 0, 0,
                 0,
                 0,
                 0,
                 0, 0, 0, 0,
                 16,
                 0,
                 0,
                 PFD_MAIN_PLANE,
                 0,
                 0, 0, 0};
             
             pixelFormat = ChoosePixelFormat(hDC, &pfd);
             SetPixelFormat(hDC, pixelFormat, &pfd);
             hRC = wglCreateContext(hDC);
             wglMakeCurrent(hDC, hRC);
             break;
        case WM_DESTROY:  //<--Error 2
        case WM_QUIT:  //<--Error 3
        case WM_CLOSE: //<--Error 4
            wglMakeCurrent(hDC, NULL);
            wglDeleteContext(hRC);
            PostQuitMessage(0);
            return 0;
            break;
        case WM_SIZE:  //<--Error 5
	    height = HIWORD(lParam);
	    width = LOWORD(lParam);

	    g_glRender->SetupProjection(width, height);
	    break;
        case WM_KEYUP:  //<--Error 6
            switch (wParam)
            {
                case VK_ESCAPE:
                    //User has pressed the escape key, so quit
                    DestroyWindow(hWnd);
                    return 0;
                break;
            }
            break;
    }



That was very long, I know and I apologize. But if I can get this licked, hopefully I can get on with learning OpenGL. Thanks very much for the help. -AJ [Edited by - u235 on April 3, 2006 10:29:26 PM]
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
KulSeran
KulSeran
It looks like you made a project that has "precompiled header file"(PCH) turned on.
I moved onto 2003.NET, so I don't know were exactly in the project settings
the option is to turn that off. But that should be all you have to do.

It is compaining that you dont have #include "stdafx.h" anywhere in your
code, and that is the default precompiled header file. So you could
go that route too, and make a blank stdafx.h and include it.
Doggan
Doggan
Adding brackets will solve your switch statement issues:

switch ( 1 ) {    case 0: {       // do stuff       break;    }}
u235
u235
Many thanks, fellas, but while that made the current errors go away, it gives me 4 new errors. Three of them are on the line: HGLRC hRC;

and they are:

c:\dev-cpp\beginogl.cpp(6) : error C2146: syntax error : missing ';' before identifier 'hRC'c:\dev-cpp\beginogl.cpp(6) : error C2377: 'HGLRC' : redefinition; typedef cannot be overloaded with any other symbol        c:\program files\microsoft visual studio\vc98\include\windef.h(241) : see declaration of 'HGLRC'c:\dev-cpp\beginogl.cpp(6) : fatal error C1004: unexpected end of file found


And the fourth is just telling me that my constructor in CGfxOpenGL.cpp is not allowed a return value when obviously, from looking at the code in the OP, that there is no return type declared for the constructor. I mean seriously, what kind of programmer would I be if I gave my constructor a return type [rolleyes]. Thanks.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Doggan
Doggan
Generally you want to look at the first error. Fix that, and a lot of times the rest of the errors go away. I have had hundreds of errors stemming from a missed semi-colon or bracket.

The error: "error C2146: syntax error : missing ';' before identifier 'hRC'" signifies that the compiler does not recognize the HGLRC data type. It should be defined in windef.h, which is included in windows.h (it compiles fine in my test program with VC++ 2005). The only thing I see here is that you are using VC++ 6.0. I would try placing a #include before the HGLRC line. It is possible (though I doubt it) that windef is not included with the windows.h header file supplied w/ 6.0... Or you are using some strange macro that is ignoring it.

I know you mentioned your connection is too slow to download VC++ 2005... You can always download it on a good connection and burn an iso/img and then install it on your computer.
u235
u235
Ok, so it turns out I do have 2005, I just didn't remember it was there from before. So I tried to compile it in there and now I'm getting all these errors, some the same as before, others new. Now here's something interesting; I switched the position of the HGLRC and HDC declarations and now the same error that was occuring on the HGLRC is now occuring on the HDC and no error on the HGLRC. I added windef.h, but to no avail. Also, since the compiler is not recognizing the HDC, it's treating it as an int (which I guess is to be expected) so everywhere I use hDC, there's an error complaining about converting an int to HDC. So if I get the error on the declaration line fixed, that should solve most my problems. Except the one complaining about the constructor not being allowed a return type. That one is just boggling my mind.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Doggan
Doggan
Try this:

Create a new VC++ 2005 project. This is what my main.cpp looks like:

#include "stdafx.h"#include <windows.h>#include <gl/GL.h>#include <gl/GLU.h>HGLRC hglrc;HDC hDC;int _tmain(int argc, _TCHAR* argv[]){	return 0;}


That should compile fine with no errors. If you are getting errors, your Windows SDK files are not correct. Did you download the latest Platform SDK with VC++ 2005??
u235
u235
I didn't get any errors on the HDC or HGLRC, but I did get an error on the _TCHAR* part, something about a syntax error. My Platform SDK was the latest when I installed it. I don't know what the latest now is, though.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Doggan
Doggan
Ok, if the HGLRC data type is compiling fine in the sample project, I don't see why it wouldn't compile in your main project. I lost you a bit. Could you post the current errors your are experiencing and the code? Are you doing something strange in "CGfxOpenGL.h"? You are including it twice... is it surrounded in #ifndef, #define, #endif?
u235
u235
Sure thing. Ok first here is the main source file, BeginOGL.cpp:

#include <windows.h>#include <gl/GL.h>#include <gl/GLU.h>#include "CGfxOpenGL.h"HDC hDC;HGLRC hRC;CGfxOpenGL *g_glRender;//The windows message handlerLRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){  	int width, height;    switch(msg)    {		case WM_CREATE: {             hDC = GetDC(hWnd);             int pixelFormat;             PIXELFORMATDESCRIPTOR pfd =              {                 sizeof(PIXELFORMATDESCRIPTOR),                 1,                 PFD_SUPPORT_OPENGL |                 PFD_DRAW_TO_WINDOW |                 PFD_DOUBLEBUFFER,                 PFD_TYPE_RGBA,                 32,                 0, 0, 0, 0, 0, 0,                 0,                 0,                 0,                 0, 0, 0, 0,                 16,                 0,                 0,                 PFD_MAIN_PLANE,                 0,                 0, 0, 0};                          pixelFormat = ChoosePixelFormat(hDC, &pfd);             SetPixelFormat(hDC, pixelFormat, &pfd);             hRC = wglCreateContext(hDC);             wglMakeCurrent(hDC, hRC);             break;		}        		case WM_DESTROY:        case WM_QUIT:        case WM_CLOSE: {            wglMakeCurrent(hDC, NULL);            wglDeleteContext(hRC);            PostQuitMessage(0);            return 0;            break;		}        case WM_SIZE: {			height = HIWORD(lParam);			width = LOWORD(lParam);			g_glRender->SetupProjection(width, height);			break;		}        case WM_KEYUP: {            switch (wParam)            {                case VK_ESCAPE:                    //User has pressed the escape key, so quit                    DestroyWindow(hWnd);                    return 0;                break;            }            break;		}    }    return DefWindowProc(hWnd, msg, wParam, lParam);}//Application entry pointINT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT){    MSG msg;    BOOL fMessage;    g_glRender = new CGfxOpenGL;    bool exiting = false;        //Register the window class    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,                     GetModuleHandle(NULL), NULL, NULL, NULL, NULL,                     "OGL Project 1", NULL};    RegisterClassEx(&wc);    //Create the application's window    HWND hWnd = CreateWindow("OGL Project 1", "www.andypike.com: Tutorial 1",                              WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,                              GetDesktopWindow(), NULL, wc.hInstance, NULL);    //Show our window    ShowWindow(hWnd, SW_SHOWDEFAULT);    UpdateWindow(hWnd);        g_glRender->Init();        while (!exiting)    {          g_glRender->Prepare(0.0f);          g_glRender->Render();          SwapBuffers(hDC);              while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))          {              if (!GetMessage(&msg, NULL, 0, 0))              {                  exiting = true;                  break;              }                            TranslateMessage(&msg);              DispatchMessage(&msg);          }    }        delete g_glRender;        UnregisterClass("DX Project 1", wc.hInstance);        return (int)msg.wParam;}


And then CGfxOpenGL.h:

class CGfxOpenGL{      private:          int m_WindowWidth;          int m_WindowHeight;          float m_angle;                public:          CGfxOpenGL();          virtual ~CGfxOpenGL();                    bool Init();          bool Shutdown();                    void SetupProjection(int width, int height);                    void Prepare(float dt);          void Render();}


And finally, CGfxOpenGL.cpp:
#include <windows.h>#include <gl/gl.h>#include <gl/glu.h>#include <math.h>#include "CGfxOpenGL.h"CGfxOpenGL::CGfxOpenGL(){}CGfxOpenGL::~CGfxOpenGL(){}bool CGfxOpenGL::Init(){     glClearColor(0.0, 0.0, 0.0, 0.0);          m_angle = 0.0f;          return true;}bool CGfxOpenGL::Shutdown(){     return true;}void CGfxOpenGL::SetupProjection(int width, int height){     if (height == 0) height = 1;          glViewport(0, 0, width, height);     glMatrixMode(GL_PROJECTION);     glLoadIdentity();          gluPerspective(52.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);     glMatrixMode(GL_MODELVIEW);     glLoadIdentity();          m_WindowWidth = width;     m_WindowHeight = height;}void CGfxOpenGL::Prepare(float dt){     m_angle += 0.1f;}void CGfxOpenGL::Render(){     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     glLoadIdentity();          glTranslatef(0.0, 0.0, -5.0f);     glRotatef(m_angle, 1.0f, 0.0f, 0.0f);     glRotatef(m_angle, 0.0f, 1.0f, 0.0f);     glRotatef(m_angle, 0.0f, 0.0f, 1.0f);          glColor3f(0.7f, 1.0f, 0.3f);          glBegin(GL_TRIANGLES);         glVertex3f(1.0f, -1.0f, 0.0f);         glVertex3f(-1.0f, -1.0f, 0.0f);         glVertex3f(0.0f, 1.0f, 0.0f);     glEnd();}



It's all mostly verbatim from the book, except the stuff that deals with switching between windowed and fullscreen. Have fun and thanks for the help. I have become complacent since switching to predominantly using Managed code.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Doggan
Doggan
First thing, as I said above. CGfxOpenGL.h needs to be changed to the following:

#ifndef _CGfxOpenGL_h_#define _CGfxOpenGL_h_class CGfxOpenGL{      private:          int m_WindowWidth;          int m_WindowHeight;          float m_angle;                public:          CGfxOpenGL();          virtual ~CGfxOpenGL();                    bool Init();          bool Shutdown();                    void SetupProjection(int width, int height);                    void Prepare(float dt);          void Render();};#endif // CGfxOpenGL_h_


You must always wrap your header files in inclusion guards or you will get many errors. Try that for starters.

Edit: You also forgot the semi-colon after the closing } of the class declaration. I have added it above.
u235
u235
You sir and/or ma'am, are a genius. I never really got too good with C++ in the first place and I most certainly never did what you told me to with the headers. Thank you very much and rating up to you.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.