Original Post
I keep getting Unhandled exception in Pong.exe(DDRAW.DLL): 0xC0000005: Access Violation. I assume this is a memory error and has something to do with the way i load an image onto the surface. This happens when I try to BltFast onto the back buffer. this is what I call my_dx.CreateBitmapSurface(sample, "test.bmp" ,128, 128); this is the required functions void cDX::CreateSurface(LPDIRECTDRAWSURFACE7 *lpSource, int xs, int ys) { DDSURFACEDESC2 ddsd2; ZeroMemory(&ddsd2, sizeof(ddsd2)); ddsd2.dwSize = sizeof(ddsd2); ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd2.dwWidth = xs; ddsd2.dwHeight = ys; lpDD->CreateSurface(&ddsd2, lpSource, NULL); } void cDX::CreateBitmapSurface(LPDIRECTDRAWSURFACE7 lpSurface, char *fname, int xs, int ys) { HBITMAP hBitmap; CreateSurface(&lpSurface, xs, ys); hBitmap = (HBITMAP)LoadImage(NULL, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DrawHBitmap(lpSurface, hBitmap, 0, 0, xs, ys); DeleteObject(hBitmap); } void cDX::DrawHBitmap(LPDIRECTDRAWSURFACE7 lpSurface, HBITMAP hBitmap, int x, int y, int width, int height) { HDC hdcImage; HDC hdc; BITMAP bm; if (lpSurface == NULL || hBitmap == NULL) return; lpSurface->Restore(); hdcImage = CreateCompatibleDC(NULL); SelectObject(hdcImage, hBitmap); GetObject(hBitmap, sizeof(bm), &bm); width = width == 0 ? bm.bmWidth : width; height = height == 0 ? bm.bmHeight : height; lpSurface->GetDC(&hdc); BitBlt(hdc, x, y, width, height, hdcImage, 0, 0, SRCCOPY); lpSurface->ReleaseDC(hdc); DeleteDC(hdcImage); } I've tried to learn from several different tutorials including several from this site and I keep getting the same error. Can someone please shed some light so I can get somewhere. :)