Im writing a direct draw wrapper, and well, already running into problems

What I wanted to do was make a DDraw_Manager class, and use that to handle basically everything except drawing text and bitmaps. I want to be able to initlize everything in the constructor, and release everything with the deconstructor. Basically, I wanted it to be as simple as possible.
I'll put my code at the bottom, but heres whats going wrong; First I can initilize everything, set the screen resolution and everything. But then when I go to release it (when I call ->Release on ANYTHING) I get a "this program has performed an illegal operation".
Next, I tried to simply lock and unlock the primary surface, but again, no luck. The program just quits whenever I call either function. I fooled around with the debugger, and it said "access violation" and gave me a hexnumber.
I dont know what it could be, my only guess is Im creating everything wrong, or what Im trying to do cant be done. Any help would be greatly appreciated, as Ive been trying to fix this for a few days and am getting no where.
Thanks, Dave
heres some snippets of the code:
//how I create my DDrawing manager
CDDraw_Manager* DDraw_Manager;
DDraw_Manager = new CDDraw_Manager(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);
//in the main loop
DDraw_Manager->PrepFrame(); // this is where it exits
DDraw_Manager->ReleaseFrame();
//and delete it like this:
delete DDraw_Manager; //this crashed the program if I make it this far by not calling ->PrepFrame and ->ReleaseFrame
// dir_draw_manager.cpp
CDDraw_Manager :: CDDraw_Manager(int width, int height, int bpp)
{
//set all these things to null, just to be safe
LPDIRECTDRAW lpdd = NULL; // dd object
LPDIRECTDRAW4 lpdd4 = NULL; // dd4 object
LPDIRECTDRAWSURFACE4 lpddsprimary = NULL; // dd primary surface
LPDIRECTDRAWSURFACE4 lpddsback = NULL; // dd back surface
LPDIRECTDRAWPALETTE lpddpal = NULL; // a pointer to the created dd palette
LPDIRECTDRAWCLIPPER lpddclipper = NULL; // dd clipper
// first create base IDirectDraw interface
if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
{
// error
} // end if
// now query for IDirectDraw4
if (FAILED(lpdd->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd4)))
{
// error
} // end if
//We should be able to release lpdd now
// set cooperation to full screen
if (FAILED(lpdd4->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN / DDSCL_ALLOWMODEX /
DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT)))
{
// error
} // end if
// set display mode to parm
if (FAILED(lpdd4->SetDisplayMode(width, height, bpp,0,0)))
{
// error
} // end if
// clear ddsd and set size
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
// enable valid fields
ddsd.dwFlags = DDSD_CAPS;
// request primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
// create the primary surface
if (FAILED(lpdd4->CreateSurface(&ddsd, &lpddsprimary, NULL)))
{
// error
} // end if
/////////////////////////////////////////////////////
}
CDDraw_Manager :: ~CDDraw_Manager()
{
// this is used after the game to clean up everything.
// now the primary surface
if (lpddsprimary)
{
lpddsprimary->Release();
lpddsprimary = NULL;
} // end if
// now release the IDirectDraw4 interface
if (lpdd4)
{
lpdd4->Release();
lpdd4 = NULL;
} // end if
}
//////////////////////////////////////
CDDraw_Manager:

repFrame()
{
//////////////////////////////////////////////////////////////////////////////////////
// Purpose: This locks the frame. This should be called before drawing anything. //
// //
// //
//////////////////////////////////////////////////////////////////////////////////////
// this function locks the priamary surface
// and updates the global variables primary_buffer,
and primary_lpitch
DDRAW_INIT_STRUCT(ddsd);
// lock the primary surface
if(lpddsprimary)
{
lpddsprimary->Lock(NULL, &ddsd,
DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT,
NULL);
}
}
Edited by - ratman on 2/12/00 6:02:59 PM