i have this simple card game i always wanted to program, and i finally decided to look for some info on cards.dll ( the cards drawing library microsoft uses in solitaire, free cell, etc ). i understand it (its pretty simple) and i had it working without any problems. now, suddenly i am getting stack corruption around the class that is drawing the cards when i am lucky, and an ugly blue screen when im not.
i have commented out 90% of my code, and ive narrowed it to the following. its either in the constructor or destructor of my display class.
here is my constructor :
Code:
Display::Display(HWND hW)
{
hCardDLL = LoadLibrary( "cards.dll" );
hWnd = hW;
GetClientRect( hWnd, &client );
// set up the device context
hdc = GetDC( hWnd );
memdc = CreateCompatibleDC( hdc );
bmp = CreateCompatibleBitmap( hdc, client.right, client.bottom );
origBmp = (HBITMAP)SelectObject( memdc, bmp );
// set up the cards.dll function pointers
cdInit = (pfInit) GetProcAddress( hCardDLL, "cdtInit" );
cdDraw = (pfDraw) GetProcAddress( hCardDLL, "cdtDraw" );
cdDrawEx = (pfDrawEx) GetProcAddress( hCardDLL, "cdtDrawEx" );
cdAnimate = (pfAnimate) GetProcAddress( hCardDLL, "cdtAnimate" );
cdTerm = (pfTerm) GetProcAddress( hCardDLL, "cdtTerm" );
cdInit( &cardSizeX, &cardSizeY );
}
and here is my destructor:
Code:
Display::~Display(void)
{
cdTerm();
FreeLibrary( hCardDLL );
SelectObject( memdc, origBmp );
DeleteObject( bmp );
if ( ! DeleteDC( memdc ) )
MessageBox( NULL, "Could Not Delete Memory Device Context", "Error", MB_OK );
ReleaseDC( hWnd, hdc );
}
the only other code of any significance is my draw function, which i have commented down to the following:
Code:
void Display::DrawCards()
{
// paint the background
HBRUSH grn = CreateSolidBrush(RGB(0, 255, 0));
FillRect( memdc, &client, grn );
DeleteObject( grn );
BitBlt( hdc, 0, 0, client.right, client.bottom, memdc, 0, 0, SRCCOPY );
}
and just for the heck of it, here is my message loop in winmain:
Code:
// the display class
Display d( hWnd );
while ( true )
{
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if ( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
d.DrawCards();
}
i cant figure out whats going wrong, and im hoping someone here might be able to pin it down. if you want to help but dont know anything about the cards.dll library, here is some documentation:
http://www.catch22.org.uk/tuts/cardtut.asp
using VS.NET and windows XP.