Does my code look alright?

Just wondering if my code is appropriate. Opinions welcome :)

LPDIRECTDRAW7 lpdd = NULL; //DirectDraw 7 Object
LPDIRECTDRAWPALETTE lpddpal = NULL; //DirectDraw Palette
LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; //DirectDraw 7 Surface
PALETTEENTRY Palette[256] ; //Palette::8-Bit
DDSURFACEDESC2 ddsd ; //Primary Surface Structure

void GameInit(void) {
//Create DDraw7 Interface
if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd, IID_IDirectDraw7, NULL))) {
throw Exception(MainWindow, "DirectDrawCreateEx() Failed");
return; }

//Set the cooperative level
if(FAILED(lpdd->SetCooperativeLevel(MainWindow, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) {
throw Exception(MainWindow, "SetCooperativeLevel() Failed");
return; }

//Set display mode
if(FAILED(lpdd->SetDisplayMode(ScreenX, ScreenY, 8, 0, 0))) {
throw Exception(MainWindow, "SetDisplayMode() Failed");
return; }

//--Set-Palette----------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
srand((unsigned)time(NULL));

for(i = 1; i < 255; i++) {
Palette[i].peRed = rand()%256;
Palette[i].peGreen = rand()%256;
Palette[i].peBlue = rand()%256;
Palette[i].peFlags = PC_NOCOLLAPSE; }

Palette[0].peRed = 0;
Palette[0].peGreen = 0;
Palette[0].peBlue = 0;
Palette[0].peFlags = PC_NOCOLLAPSE;

Palette[255].peRed = 255;
Palette[255].peGreen = 255;
Palette[255].peBlue = 255;
Palette[255].peFlags = PC_NOCOLLAPSE;
//--------------

//Create Palette Object
if(FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, Palette, &lpddpal, NULL))) {
throw Exception(MainWindow, "CreatePalette() Failed");
return; }

//--Set-Surface----------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
memset(&ddsd, 0, sizeof(ddsd));

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
//--------------

//Create Surface Object
if(FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) {
throw Exception(MainWindow, "CreateSurface() Failed");
return; }

//Attach palette to surface
if(FAILED(lpddsprimary->SetPalette(lpddpal))) {
throw Exception(MainWindow, "SetPalette() Failed");
return; } }

this too, a couple of macros and functions...

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

inline void DrawPixel(const int& X, const int& Y, const UCHAR& Color,
UCHAR* Surface, const int& Pitch)
{ Surface[X + Y * Pitch] = Color; }

DrawPixel(rand()%6 + (X - 3), ScreenY - i, RandColor, (UCHAR*)ddsd.lpSurface, (int)ddsd.lPitch);

void GameTerminate(void) {
if(lpddpal) {
lpddpal->Release();
lpddpal = NULL; }

if(lpddsprimary) {
lpddsprimary->Release();
lpddsprimary = NULL; }

if(lpdd) {
lpdd->Release();
lpdd = NULL; } }
[3783 byte] By [MrDoomMaster] at [2007-11-18 22:07:34]
# 1 Re: Does my code look alright?
In GameInit(), there isn't any need to have a return statement after a throw statement. When an exception is being thrown, the stack will automatically unwind until your program reaches the respective catch statement that handles the exception.

Beside that, you might like to use a singleton class to contain all your global variables.
Kheun at 2007-11-10 3:51:39 >
# 2 Re: Does my code look alright?
Thank you :D

Could someone please delete this thread now?
MrDoomMaster at 2007-11-10 3:52:48 >