Hi there!
I''m trying to code a nice DirectDraw class, but I''ve run into some weird problems. I''m still fairly new to C++, but I checked my syntax thoroughly and to me it looks like good code but it simply won''t compile...
Here''s the code...
Graphics.h:
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <windows.h>
#include <ddraw.h>
class ddGraphics
{
public:
ddGraphics(HINSTANCE hInstance, int iCmdShow);
~ddGraphics();
private:
HWND hWnd;
WNDCLASSEX WndClass;
HRESULT ddReturn;
LPDIRECTDRAW7 lpDD;
LPDIRECTDRAWSURFACE7 lpDDSPrimary;
LPDIRECTDRAWSURFACE7 lpDDSBack;
DDSURFACEDESC2 ddSurfDesc;
DDSCAPS2 ddSurfCaps;
HWND CreateDDWindow(HINSTANCE hInstance);
HRESULT CreateDDObject(HWND hWnd);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
};
#endif // GRAPHICS_H
Graphics.c:
#include "Graphics.h"
ddGraphics::ddGraphics(HINSTANCE hInstance, int iCmdShow)
{
ddReturn = CreateDDObject(CreateDDWindow(hInstance, iCmdShow));
}
ddGraphics::~ddGraphics()
{
if (lpDD != NULL)
{
if (lpDDSPrimary != NULL)
{
lpDDSPrimary->Release();
lpDDSPrimary = NULL;
}
if (lpDDSBack != NULL)
{
lpDDSBack->Release();
lpDDSBack = NULL;
}
lpDD->Release();
lpDD = NULL;
}
}
HWND ddGraphics::CreateDDWindow(HINSTANCE hInstance, int iCmdShow)
{
static char szAppName[] = "ddClass";
hWnd = NULL;
WndClass.cbSize = sizeof(WndClass);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WindowProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
RegisterClassEx(&WndClass);
hWnd = CreateWindow(szAppName, szAppName, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
return hWnd;
}
HRESULT ddGraphics::CreateDDObject(hWnd)
{
ddReturn = DirectDrawCreateEx(NULL, (LPVOID*)&lpDD, IID_IDirectDraw7, NULL);
if(ddReturn != DD_OK) return ddReturn;
ddReturn = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if(ddReturn != DD_OK) return ddReturn;
ddReturn = lpDD->SetDisplayMode(640, 480, 16, 0, 0);
if(ddReturn != DD_OK) return ddReturn;
ZeroMemory(&ddSurfDesc, sizeof(ddSurfDesc));
ddSurfDesc.dwSize = sizeof(ddSurfDesc);
ddSurfDesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddSurfDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddSurfDesc.dwBackBufferCount = 1;
ddReturn = lpDD->CreateSurface(&ddSurfDesc, &lpDDSPrimary, NULL);
if(ddReturn != DD_OK) return ddReturn;
ZeroMemory(&ddSurfCaps, sizeof(ddSurfCaps));
ddSurfCaps.dwCaps = DDSCAPS_BACKBUFFER;
ddReturn = lpDDSPrimary->GetAttachedSurface(&ddSurfCaps, &lpDDSBack);
if(ddReturn != DD_OK) return ddReturn;
return DD_OK;
}
LRESULT CALLBACK ddGraphics::WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
Main.c:
#include <windows.h>
#include "Graphics.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow);
{
ddGraphics * cDD = new ddGraphics(hInstance, iCmdShow);
delete cDD;
cDD = NULL;
return 0;
}
And here are the errors:
--------------------Configuration: ddClass - Win32 Debug--------------------
Compiling...
Graphics.c
graphics.h(7) : error C2061: syntax error : identifier ''ddGraphics''
graphics.h(7) : error C2059: syntax error : '';''
graphics.h(8) : error C2449: found ''{'' at file scope (missing function header?)
graphics.h(25) : error C2059: syntax error : ''}''
graphics.c(8) : error C2143: syntax error : missing ''{'' before '':''
graphics.c(8) : error C2059: syntax error : '':''
graphics.c(29) : error C2143: syntax error : missing ''{'' before '':''
graphics.c(29) : error C2059: syntax error : '':''
graphics.c(54) : error C2143: syntax error : missing ''{'' before '':''
graphics.c(54) : error C2059: syntax error : '':''
graphics.c(82) : warning C4229: anachronism used : modifiers on data are ignored
graphics.c(82) : error C2143: syntax error : missing ''{'' before '':''
graphics.c(82) : error C2059: syntax error : '':''
Main.c
graphics.h(7) : error C2061: syntax error : identifier ''ddGraphics''
graphics.h(7) : error C2059: syntax error : '';''
graphics.h(8) : error C2449: found ''{'' at file scope (missing function header?)
graphics.h(25) : error C2059: syntax error : ''}''
main.c(5) : error C2449: found ''{'' at file scope (missing function header?)
main.c(10) : error C2059: syntax error : ''}''
Error executing cl.exe.
ddClass.exe - 18 error(s), 1 warning(s)
Now I know that this is far from complete (there isn''t even a message loop) but the syntax errors are still very weird. Is there something wrong the the class declaration?
Please help me out here...!
Greetz, MainForze
PS: Sorry for the long post.
"It's strange, isn't it? You stand in the middle of a library and go 'AAAAAAAGGHHHH' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"