When I compile my program it gives me this error
I don't know how to fix this.Code:|26|error: expected initializer before 'WinMain'|
Thanks for your time
Printable View
When I compile my program it gives me this error
I don't know how to fix this.Code:|26|error: expected initializer before 'WinMain'|
Thanks for your time
Show your program.
Probably a missing ;
Maybe even at the end of the class
Code:class Foo {
// some stuff
} ; // <==== THIS ONE
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);
}
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.
Ok, thanks!