Expected Initializer before 'Foo()'

This is a discussion on Expected Initializer before 'Foo()' within the C++ Programming forums, part of the General Programming Boards category; When I compile my program it gives me this error Code: |26|error: expected initializer before 'WinMain'| I don't know how ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    Expected Initializer before 'Foo()'

    When I compile my program it gives me this error
    Code:
    |26|error: expected initializer before 'WinMain'|
    I don't know how to fix this.

    Thanks for your time

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,401
    Show your program.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Probably a missing ;

    Maybe even at the end of the class
    Code:
    class Foo {
      // some stuff
    } ;  // <==== THIS ONE
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Ok, here's the code to the GameEngine.cpp file

    Code:
    #include "GameEngine.h"
    
    GameEngine* GameEngine::m_pGameEngine = NULL;
    
    GameEngine::GameEngine(HINSTANCE hInstance, LPSTR szTitle, LPSTR szClassName,WORD wIcon, WORD wIconSm, int Width, int Height)
    {
        m_pGameEngine = this;
    
        hInstance = m_hInstance;
        szTitle = m_szTitle;
        szClassName = m_szClassName;
        wIcon = m_wIcon;
        wIconSm = m_wIconSm;
        Width = m_iWidth;
        Height = m_iHeight;
    }
    
    int WinAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
        MSG msg;
        static int iTickTriger = 0;
        int iTickCount;
    
        if(Initialize(hInstance))
        {
            //initialize game engine
            if(!GameEngine::GetEngine()->Initialize(iCmdShow))
              return FALSE;
    
            while(TRUE)
            {
                if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                {
                    //process the message
                    if(msg.message == WM_QUIT)
                      break;
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
                else
                {
                    if(!GameEngine::GetEngine()->IsInactive())
                    {
                        iTickCount = GetTickCount();
                        if(iTickCount > iTickTriger)
                        {
                            iTickTriger = iTickCount + GameEngine::GetEngine()->GetFrameDelay();
                            GameCycle();
                            HandleKeys();
                        }
                    }
                }
            }
            return (int)msg.wParam
        }
        GameEnd();
    
        return TRUE;
    }
    
    LRESULT CALLBACK WinProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
    }
    
    LRESULT GameEngine::HandleEvent(HWND hWindow,  UINT msg, WPARAM wParam, LPARAM lParam)
    {
            switch(msg)
        {
            case WM_CREATE:
            SetWindow(hWindow);
            GameStart(hWindow);
            break;
    
            case WM_SETFOCUS:
            GameFocus(hWindow);
            SetSleep(FALSE);
            break;
    
            case WM_KILLFOCUS:
            GameNotFocus(hWindow);
            SetSleep(TRUE);
            break;
    
            case WM_DESTROY:
            GameEnd();
            PostQuitMessage(0);
            break;
    
            case WM_LBUTTONDOWN:
            MouseDown(LOWORD(lParam), HIWORD(lParam), TRUE);
            break;
    
            case WM_LBUTTONUP:
            MouseUp(LOWORD(lParam), HIWORD(lParam), TRUE);
            break;
    
            case WM_RBUTTONDOWN:
            MouseDown(LOWORD(lParam), HIWORD(lParam), FALSE);
            break;
    
            case WM_RBUTTONUP:
            MouseUp(LOWORD(lParam), HIWORD(lParam), FALSE);
            break;
    
            case WM_PAINT:
            PAINTSTRUCT ps;
            HDC         hDC;
            hDC = BeginPaint(hWindow, &ps);
    
            GamePaint(hDC);
    
            EndPaint(hWindow, &ps);
            break;
        }
        return DefWindowProc(hWindow, msg, wParam, lParam);
    }
    
    BOOL GameEngine::Initialize(int iCmdShow)
    {
        WNDCLASSEX WndClass;
    
        WndClass.cbSize = sizeof(WNDCLASSEX);
        WndClass.style = 0;
        WndClass.lpfnWndProc = WinProc;
        WndClass.cbClsExtra = 0;
        WndClass.cbWndExtra = 0;
        WndClass.hInstance = m_hInstance;
        WndClass.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(m_wIcon));
        WndClass.hIconSm = LoadIcon(m_hInstance, MAKEINTRESOURCE(m_wIconSm));
        WndClass.lpszMenuName = NULL;
        WndClass.lpszClassName = m_szClassName;
    
        if(!RegisterClassEx(WndClass))
          return FALSE;
    
        m_hWindow = CreateWindowEx(WndClass, m_szClassName, m_szTitle,WS_OVERLAPPEDWINDOW,
                                 CW_USEDEFAULT, CW_USEDEFAULT, m_iWidth, m_iHeight, NULL, NULL,
                                 m_hInstance, NULL);
    
        if(m_hWindow == NULL)
          return FALSE;
    
        ShowWindow(m_hWindow, iCmdShow);
        UpdateWindow(m_hWindow);
    }

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,195
    The "WinAPI" in the definition of WinMain() should be all uppercase.

    The compiler is not complaining about an invalid identifier, because WinAPI is defined as something different from WINAPI.
    Right 98% of the time, and don't care about the other 3%.

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Ok, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Couple of Q's.....
    By oobootsy1 in forum C++ Programming
    Replies: 18
    Last Post: 02-23-2004, 01:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21