- Unlock GDI objects by pointer, not by handle.
- Fix a few invalid lock cases.
- Add support for shared GDI object locks and use it for locking surfaces.
Modified: trunk/reactos/include/win32k/bitmaps.h
Modified: trunk/reactos/include/win32k/brush.h
Modified: trunk/reactos/include/win32k/dc.h
Modified: trunk/reactos/include/win32k/gdiobj.h
Modified: trunk/reactos/include/win32k/pen.h
Modified: trunk/reactos/include/win32k/region.h
Modified: trunk/reactos/include/win32k/text.h
Modified: trunk/reactos/subsys/win32k/eng/bitblt.c
Modified: trunk/reactos/subsys/win32k/eng/misc.c
Modified: trunk/reactos/subsys/win32k/eng/surface.c
Modified: trunk/reactos/subsys/win32k/eng/window.c
Modified: trunk/reactos/subsys/win32k/eng/xlate.c
Modified: trunk/reactos/subsys/win32k/include/dce.h
Modified: trunk/reactos/subsys/win32k/include/palette.h
Modified: trunk/reactos/subsys/win32k/ntddraw/ddraw.c
Modified: trunk/reactos/subsys/win32k/ntuser/cursoricon.c
Modified: trunk/reactos/subsys/win32k/ntuser/desktop.c
Modified: trunk/reactos/subsys/win32k/ntuser/input.c
Modified: trunk/reactos/subsys/win32k/ntuser/metric.c
Modified: trunk/reactos/subsys/win32k/ntuser/misc.c
Modified: trunk/reactos/subsys/win32k/ntuser/monitor.c
Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
Modified: trunk/reactos/subsys/win32k/ntuser/windc.c
Modified: trunk/reactos/subsys/win32k/ntuser/window.c
Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
Modified: trunk/reactos/subsys/win32k/objects/bitmaps.c
Modified: trunk/reactos/subsys/win32k/objects/brush.c
Modified: trunk/reactos/subsys/win32k/objects/cliprgn.c
Modified: trunk/reactos/subsys/win32k/objects/color.c
Modified: trunk/reactos/subsys/win32k/objects/coord.c
Modified: trunk/reactos/subsys/win32k/objects/dc.c
Modified: trunk/reactos/subsys/win32k/objects/dib.c
Modified: trunk/reactos/subsys/win32k/objects/fillshap.c
Modified: trunk/reactos/subsys/win32k/objects/gdiobj.c
Modified: trunk/reactos/subsys/win32k/objects/line.c
Modified: trunk/reactos/subsys/win32k/objects/palette.c
Modified: trunk/reactos/subsys/win32k/objects/path.c
Modified: trunk/reactos/subsys/win32k/objects/pen.c
Modified: trunk/reactos/subsys/win32k/objects/print.c
Modified: trunk/reactos/subsys/win32k/objects/region.c
Modified: trunk/reactos/subsys/win32k/objects/text.c

Modified: trunk/reactos/include/win32k/bitmaps.h
--- trunk/reactos/include/win32k/bitmaps.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/bitmaps.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -29,8 +29,9 @@
   ((HBITMAP) GDIOBJ_AllocObj (GDI_OBJECT_TYPE_BITMAP))
 #define  BITMAPOBJ_FreeBitmap(hBMObj)  \
   GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP)
-#define  BITMAPOBJ_LockBitmap(hBMObj) GDIOBJ_LockObj((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP)
-#define  BITMAPOBJ_UnlockBitmap(hBMObj) GDIOBJ_UnlockObj((HGDIOBJ) hBMObj)
+/* NOTE: Use shared locks! */
+#define  BITMAPOBJ_LockBitmap(hBMObj) (PBITMAPOBJ)EngLockSurface((HSURF)hBMObj)
+#define  BITMAPOBJ_UnlockBitmap(pBMObj) EngUnlockSurface(&pBMObj->SurfObj)
 BOOL INTERNAL_CALL BITMAP_Cleanup(PVOID ObjectBody);
 
 INT     FASTCALL BITMAPOBJ_GetWidthBytes (INT bmWidth, INT bpp);

Modified: trunk/reactos/include/win32k/brush.h
--- trunk/reactos/include/win32k/brush.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/brush.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -71,7 +71,7 @@
 #define  BRUSHOBJ_AllocBrush() ((HBRUSH) GDIOBJ_AllocObj (GDI_OBJECT_TYPE_BRUSH))
 #define  BRUSHOBJ_FreeBrush(hBrush) GDIOBJ_FreeObj((HGDIOBJ)hBrush, GDI_OBJECT_TYPE_BRUSH)
 #define  BRUSHOBJ_LockBrush(hBrush) ((PGDIBRUSHOBJ)GDIOBJ_LockObj((HGDIOBJ)hBrush, GDI_OBJECT_TYPE_BRUSH))
-#define  BRUSHOBJ_UnlockBrush(hBrush) GDIOBJ_UnlockObj((HGDIOBJ)hBrush)
+#define  BRUSHOBJ_UnlockBrush(pBrush) GDIOBJ_UnlockObjByPtr(pBrush)
 BOOL INTERNAL_CALL BRUSH_Cleanup(PVOID ObjectBody);
 
 #ifdef __USE_W32API

Modified: trunk/reactos/include/win32k/dc.h
--- trunk/reactos/include/win32k/dc.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/dc.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -151,8 +151,8 @@
 
 #define  DC_LockDc(hDC)  \
   ((PDC) GDIOBJ_LockObj ((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC))
-#define  DC_UnlockDc(hDC)  \
-  GDIOBJ_UnlockObj ((HGDIOBJ) hDC)
+#define  DC_UnlockDc(pDC)  \
+  GDIOBJ_UnlockObjByPtr (pDC)
 
 HDC  FASTCALL RetrieveDisplayHDC(VOID);
 HDC  FASTCALL DC_AllocDC(PUNICODE_STRING  Driver);

Modified: trunk/reactos/include/win32k/gdiobj.h
--- trunk/reactos/include/win32k/gdiobj.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/gdiobj.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -81,6 +81,7 @@
 void    INTERNAL_CALL GDIOBJ_SetOwnership(HGDIOBJ ObjectHandle, PEPROCESS Owner);
 void    INTERNAL_CALL GDIOBJ_CopyOwnership(HGDIOBJ CopyFrom, HGDIOBJ CopyTo);
 BOOL    INTERNAL_CALL GDIOBJ_ConvertToStockObj(HGDIOBJ *hObj);
+VOID    INTERNAL_CALL GDIOBJ_UnlockObjByPtr(PGDIOBJ Object);
 
 #define GDIOBJ_GetObjectType(Handle) \
   GDI_HANDLE_GET_TYPE(Handle)
@@ -91,19 +92,18 @@
 #define GDIOBJ_AllocObj(ty) GDIOBJ_AllocObjDbg(__FILE__,__LINE__,ty)
 #define GDIOBJ_FreeObj(obj,ty) GDIOBJ_FreeObjDbg(__FILE__,__LINE__,obj,ty)
 #define GDIOBJ_LockObj(obj,ty) GDIOBJ_LockObjDbg(__FILE__,__LINE__,obj,ty)
-#define GDIOBJ_UnlockObj(obj) GDIOBJ_UnlockObjDbg(__FILE__,__LINE__,obj)
+#define GDIOBJ_ShareLockObj(obj,ty) GDIOBJ_ShareLockObjDbg(__FILE__,__LINE__,obj,ty)
 
 HGDIOBJ INTERNAL_CALL GDIOBJ_AllocObjDbg(const char* file, int line, ULONG ObjectType);
 BOOL    INTERNAL_CALL GDIOBJ_FreeObjDbg (const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
 PGDIOBJ INTERNAL_CALL GDIOBJ_LockObjDbg (const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
-BOOL    INTERNAL_CALL GDIOBJ_UnlockObjDbg (const char* file, int line, HGDIOBJ hObj);
+PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObjDbg (const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
 
 #else /* !GDI_DEBUG */
 
 HGDIOBJ INTERNAL_CALL GDIOBJ_AllocObj(ULONG ObjectType);
 BOOL    INTERNAL_CALL GDIOBJ_FreeObj (HGDIOBJ hObj, DWORD ObjectType);
-PGDIOBJ INTERNAL_CALL GDIOBJ_LockObj (HGDIOBJ hObj, DWORD ObjectType);
-BOOL    INTERNAL_CALL GDIOBJ_UnlockObj (HGDIOBJ hObj);
+PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ObjectType);
 
 #endif /* GDI_DEBUG */
 

Modified: trunk/reactos/include/win32k/pen.h
--- trunk/reactos/include/win32k/pen.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/pen.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -9,7 +9,7 @@
 #define PENOBJ_AllocPen() ((HPEN)GDIOBJ_AllocObj(GDI_OBJECT_TYPE_PEN))
 #define PENOBJ_FreePen(hBMObj) GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_PEN)
 #define PENOBJ_LockPen(hBMObj) ((PGDIBRUSHOBJ)GDIOBJ_LockObj((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_PEN))
-#define PENOBJ_UnlockPen(hBMObj) GDIOBJ_UnlockObj((HGDIOBJ) hBMObj)
+#define PENOBJ_UnlockPen(pPenObj) GDIOBJ_UnlockObjByPtr(pPenObj)
 
 HPEN STDCALL
 NtGdiCreatePen(

Modified: trunk/reactos/include/win32k/region.h
--- trunk/reactos/include/win32k/region.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/region.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -13,7 +13,7 @@
 
 #define  RGNDATA_FreeRgn(hRgn)  GDIOBJ_FreeObj((HGDIOBJ)hRgn, GDI_OBJECT_TYPE_REGION)
 #define  RGNDATA_LockRgn(hRgn) ((PROSRGNDATA)GDIOBJ_LockObj((HGDIOBJ)hRgn, GDI_OBJECT_TYPE_REGION))
-#define  RGNDATA_UnlockRgn(hRgn) GDIOBJ_UnlockObj((HGDIOBJ)hRgn)
+#define  RGNDATA_UnlockRgn(pRgn) GDIOBJ_UnlockObjByPtr(pRgn)
 HRGN FASTCALL RGNDATA_AllocRgn(INT n);
 BOOL INTERNAL_CALL RGNDATA_Cleanup(PVOID ObjectBody);
 

Modified: trunk/reactos/include/win32k/text.h
--- trunk/reactos/include/win32k/text.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/include/win32k/text.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -16,7 +16,7 @@
   ((HFONT) GDIOBJ_AllocObj (GDI_OBJECT_TYPE_FONT))
 #define  TEXTOBJ_FreeText(hBMObj)  GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_FONT)
 #define  TEXTOBJ_LockText(hBMObj) ((PTEXTOBJ) GDIOBJ_LockObj ((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_FONT))
-#define  TEXTOBJ_UnlockText(hBMObj) GDIOBJ_UnlockObj ((HGDIOBJ) hBMObj)
+#define  TEXTOBJ_UnlockText(pBMObj) GDIOBJ_UnlockObjByPtr (pBMObj)
 
 NTSTATUS FASTCALL TextIntRealizeFont(HFONT FontHandle);
 NTSTATUS FASTCALL TextIntCreateFontIndirect(CONST LPLOGFONTW lf, HFONT *NewFont);

Modified: trunk/reactos/subsys/win32k/eng/bitblt.c
--- trunk/reactos/subsys/win32k/eng/bitblt.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/eng/bitblt.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -89,7 +89,6 @@
    static BYTE maskbit[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
    /* Pattern brushes */
    PGDIBRUSHINST GdiBrush = NULL;
-   HBITMAP PatternSurface = NULL;
    SURFOBJ *PatternObj = NULL;
    PBITMAPOBJ PatternBitmap;
    ULONG PatternWidth = 0, PatternHeight = 0, PatternY = 0;
@@ -109,7 +108,6 @@
          GDIBRUSHINST,
          BrushObject);
 
-      PatternSurface = GdiBrush->GdiBrushObject->hbmPattern;
       PatternBitmap = BITMAPOBJ_LockBitmap(GdiBrush->GdiBrushObject->hbmPattern);
       if(PatternBitmap != NULL)
       {
@@ -157,7 +155,7 @@
    }
 
    if (PatternBitmap != NULL)
-      BITMAPOBJ_UnlockBitmap(PatternSurface);
+      BITMAPOBJ_UnlockBitmap(PatternBitmap);
 
    return TRUE;
 }
@@ -245,7 +243,7 @@
    /* Pattern brush */
    if (bmPattern != NULL)
    {
-      BITMAPOBJ_UnlockBitmap(BltInfo.PatternSurface->hsurf);
+      BITMAPOBJ_UnlockBitmap(bmPattern);
    }
 
    return Result;

Modified: trunk/reactos/subsys/win32k/eng/misc.c
--- trunk/reactos/subsys/win32k/eng/misc.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/eng/misc.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -106,6 +106,7 @@
       {
       EngDeleteClip(EnterLeave->TrivialClipObj);
       EngFreeMem((*OutputObj)->pvBits);
+      EngUnlockSurface(*OutputObj);
       EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
       return FALSE;
       }

Modified: trunk/reactos/subsys/win32k/eng/surface.c
--- trunk/reactos/subsys/win32k/eng/surface.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/eng/surface.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -281,7 +281,7 @@
             }
           if (SurfObj->pvBits == NULL)
             {
-              BITMAPOBJ_UnlockBitmap(NewBitmap);
+              BITMAPOBJ_UnlockBitmap(BitmapObj);
               BITMAPOBJ_FreeBitmap(NewBitmap);
               return 0;
             }
@@ -315,7 +315,7 @@
   BitmapObj->dimension.cy = 0;
   BitmapObj->dib = NULL;
 
-  BITMAPOBJ_UnlockBitmap(NewBitmap);
+  BITMAPOBJ_UnlockBitmap(BitmapObj);
 
   return NewBitmap;
 }
@@ -372,7 +372,7 @@
 
   BitmapObj->flHooks = 0;
 
-  BITMAPOBJ_UnlockBitmap(NewSurface);
+  BITMAPOBJ_UnlockBitmap(BitmapObj);
 
   return NewSurface;
 }
@@ -414,7 +414,7 @@
   /* Hook up specified functions */
   BitmapObj->flHooks = Hooks;
 
-  BITMAPOBJ_UnlockBitmap(Surface);
+  BITMAPOBJ_UnlockBitmap(BitmapObj);
 
   return TRUE;
 }
@@ -481,19 +481,21 @@
   return FillSolid(Surface, Rect, iColor);
 }
 
+#define GDIBdyToHdr(body)                                                      \
+  ((PGDIOBJHDR)(body) - 1)
+
 /*
  * @implemented
  */
 SURFOBJ * STDCALL
 EngLockSurface(IN HSURF Surface)
 {
-  BITMAPOBJ *bmp = (BITMAPOBJ*)BITMAPOBJ_LockBitmap(Surface);
-  if(bmp != NULL)
-  {
-    return &bmp->SurfObj;
-  }
+   BITMAPOBJ *bmp = GDIOBJ_ShareLockObj(Surface, GDI_OBJECT_TYPE_BITMAP);
 
-  return NULL;
+   if (bmp != NULL)
+      return &bmp->SurfObj;
+
+   return NULL;
 }
 
 /*
@@ -502,7 +504,7 @@
 VOID STDCALL
 EngUnlockSurface(IN SURFOBJ *Surface)
 {
-  ASSERT (Surface);
-  BITMAPOBJ_UnlockBitmap (Surface->hsurf);
+   if (Surface != NULL)
+      GDIOBJ_UnlockObjByPtr(Surface);
 }
 /* EOF */

Modified: trunk/reactos/subsys/win32k/eng/window.c
--- trunk/reactos/subsys/win32k/eng/window.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/eng/window.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -104,7 +104,7 @@
           }
         }
       }
-      RGNDATA_UnlockRgn(hVisRgn);
+      RGNDATA_UnlockRgn(visRgn);
     }
     else
     {

Modified: trunk/reactos/subsys/win32k/eng/xlate.c
--- trunk/reactos/subsys/win32k/eng/xlate.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/eng/xlate.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -272,9 +272,9 @@
 
 end:
    if (PaletteSource != NULL)
-      PALETTE_UnlockPalette(PaletteSource);
+      PALETTE_UnlockPalette(SourcePalGDI);
    if (PaletteDest != NULL && PaletteDest != PaletteSource)
-      PALETTE_UnlockPalette(PaletteDest);
+      PALETTE_UnlockPalette(DestPalGDI);
    return XlateObj;
 }
 
@@ -337,7 +337,7 @@
          break;
    }
 
-   PALETTE_UnlockPalette(PaletteSource);
+   PALETTE_UnlockPalette(SourcePalGDI);
 
    return XlateObj;
 }
@@ -358,7 +358,7 @@
    XlateGDI = EngAllocMem(0, sizeof(XLATEGDI), TAG_XLATEOBJ);
    if (XlateGDI == NULL)
    {
-      PALETTE_UnlockPalette(PaletteDest);
+      PALETTE_UnlockPalette(DestPalGDI);
       DPRINT1("Failed to allocate memory for a XLATE structure!\n");
       return NULL;
    }
@@ -367,7 +367,7 @@
    XlateGDI->translationTable = EngAllocMem(0, sizeof(ULONG) * 2, 0);
    if (XlateGDI->translationTable == NULL)
    {
-      PALETTE_UnlockPalette(PaletteDest);
+      PALETTE_UnlockPalette(DestPalGDI);
       EngFreeMem(XlateGDI);
       return NULL;
    }
@@ -407,7 +407,7 @@
                            DestPalGDI->NumColors);
    }
 
-   PALETTE_UnlockPalette(PaletteDest);
+   PALETTE_UnlockPalette(DestPalGDI);
 
    return XlateObj;
 }
@@ -498,7 +498,7 @@
       {
          /* Return closest match for the given color. */
          Closest = ClosestColorMatch(XlateGDI, (LPPALETTEENTRY)&Color, PalGDI->IndexedColors, PalGDI->NumColors);
-         PALETTE_UnlockPalette(XlateGDI->DestPal);
+         PALETTE_UnlockPalette(PalGDI);
          return Closest;
       }
    }
@@ -538,7 +538,7 @@
        *OutPal = *InPal;
      }
 
-     PALETTE_UnlockPalette(hPalette);
+     PALETTE_UnlockPalette(PalGDI);
 
      return cPal;
    }

Modified: trunk/reactos/subsys/win32k/include/dce.h
--- trunk/reactos/subsys/win32k/include/dce.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/include/dce.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -40,7 +40,7 @@
   ((HDCE) GDIOBJ_AllocObj (GDI_OBJECT_TYPE_DCE))
 #define  DCEOBJ_FreeDCE(hDCE)  GDIOBJ_FreeObj((HGDIOBJ)hDCE, GDI_OBJECT_TYPE_DCE)
 #define  DCEOBJ_LockDCE(hDCE) ((PDCE)GDIOBJ_LockObj((HGDIOBJ)hDCE, GDI_OBJECT_TYPE_DCE))
-#define  DCEOBJ_UnlockDCE(hDCE) GDIOBJ_UnlockObj((HGDIOBJ)hDCE)
+#define  DCEOBJ_UnlockDCE(pDCE) GDIOBJ_UnlockObjByPtr(pDCE)
 BOOL INTERNAL_CALL DCE_Cleanup(PVOID ObjectBody);
 
 PDCE FASTCALL DceAllocDCE(HWND hWnd, DCE_TYPE Type);

Modified: trunk/reactos/subsys/win32k/include/palette.h
--- trunk/reactos/subsys/win32k/include/palette.h	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/include/palette.h	2005-06-07 16:34:07 UTC (rev 15830)
@@ -37,7 +37,7 @@
                                                  CONST RGBQUAD *Colors);
 #define  PALETTE_FreePalette(hPalette)  GDIOBJ_FreeObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE)
 #define  PALETTE_LockPalette(hPalette) ((PPALGDI)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
-#define  PALETTE_UnlockPalette(hPalette) GDIOBJ_UnlockObj((HGDIOBJ)hPalette)
+#define  PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr(pPalette)
 BOOL INTERNAL_CALL PALETTE_Cleanup(PVOID ObjectBody);
 
 HPALETTE FASTCALL PALETTE_Init (VOID);

Modified: trunk/reactos/subsys/win32k/ntddraw/ddraw.c
--- trunk/reactos/subsys/win32k/ntddraw/ddraw.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntddraw/ddraw.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -51,7 +51,7 @@
 	if (!pDC->DriverFunctions.EnableDirectDraw)
 	{
 		// Driver doesn't support DirectDraw
-		DC_UnlockDc(hdc);
+		DC_UnlockDc(pDC);
 		return NULL;
 	}
 
@@ -61,7 +61,7 @@
 	if (!success)
 	{
 		// DirectDraw creation failed
-		DC_UnlockDc(hdc);
+		DC_UnlockDc(pDC);
 		return NULL;
 	}
 
@@ -121,8 +121,8 @@
 	if (palette_callbacks.dwFlags & DDHAL_PALCB32_SETENTRIES)
 		pDirectDraw->DdSetEntries = palette_callbacks.SetEntries;
 
-	GDIOBJ_UnlockObj(hDirectDraw);
-	DC_UnlockDc(hdc);
+	GDIOBJ_UnlockObjByPtr(pDirectDraw);
+	DC_UnlockDc(pDC);
 
 	return hDirectDraw;
 }
@@ -162,7 +162,7 @@
 
 	if (!success)
 	{
-		GDIOBJ_UnlockObj(hDirectDrawLocal);
+		GDIOBJ_UnlockObjByPtr(pDirectDraw);
 		return FALSE;
 	}
 
@@ -189,7 +189,7 @@
 	}
 
 
-	GDIOBJ_UnlockObj(hDirectDrawLocal);
+	GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
 	return TRUE;
 }
@@ -235,8 +235,8 @@
 	// FIXME: figure out how to use this
 	pSurface->bComplete = bComplete;
 
-	GDIOBJ_UnlockObj(hSurface);
-	GDIOBJ_UnlockObj(hDirectDrawLocal);
+	GDIOBJ_UnlockObjByPtr(pSurface);
+	GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
 	return hSurface;
 }
@@ -260,7 +260,7 @@
 	PDD_SURFACE pSurfaceTo = GDIOBJ_LockObj(hSurfaceTo, GDI_OBJECT_TYPE_DD_SURFACE);
 	if (!pSurfaceTo)
 	{
-		GDIOBJ_UnlockObj(hSurfaceFrom);
+		GDIOBJ_UnlockObjByPtr(pSurfaceFrom);
 		return FALSE;
 	}
 
@@ -269,8 +269,8 @@
 		pSurfaceFrom->Local.lpAttachListFrom = pSurfaceFrom->AttachListFrom;
 	}
 
-	GDIOBJ_UnlockObj(hSurfaceFrom);
-	GDIOBJ_UnlockObj(hSurfaceTo);
+	GDIOBJ_UnlockObjByPtr(pSurfaceFrom);
+	GDIOBJ_UnlockObjByPtr(pSurfaceTo);
 	return TRUE;
 }
 */
@@ -295,7 +295,7 @@
                  pDirectDraw->Global.dhpdev,(PDD_HALINFO) puGetDriverInfoData,
                  &pdwNumHeaps, pvmList, &pdwNumFourCC, pdwFourCC);
 
-    GDIOBJ_UnlockObj(hDirectDrawLocal);
+    GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
 	return ddRVal;
 }
@@ -314,7 +314,7 @@
 
 	ddRVal = pDirectDraw->DdWaitForVerticalBlank(puWaitForVerticalBlankData);
 
-    GDIOBJ_UnlockObj(hDirectDrawLocal);
+    GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
 	return ddRVal;
 }
@@ -333,7 +333,7 @@
 
 	ddRVal = pDirectDraw->DdCanCreateSurface(puCanCreateSurfaceData);
 
-	GDIOBJ_UnlockObj(hDirectDrawLocal);
+	GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
 	return ddRVal;
 }
@@ -356,7 +356,7 @@
 
  ddRVal = pDirectDraw->DdBlt(puBltData);
 
- GDIOBJ_UnlockObj(hSurfaceDest);
+ GDIOBJ_UnlockObjByPtr(pDirectDraw);
 
  return ddRVal;
 }

Modified: trunk/reactos/subsys/win32k/ntuser/cursoricon.c
--- trunk/reactos/subsys/win32k/ntuser/cursoricon.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/cursoricon.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -50,9 +50,7 @@
 {
   HDC hDC;
   PDC dc;
-  HBITMAP hBitmap;
-  BITMAPOBJ *BitmapObj;
-  SURFOBJ *SurfObj;
+  GDIDEVICE *GDIDevice;
 
 #if 1
   /* FIXME - get the screen dc from the window station or desktop */
@@ -62,17 +60,12 @@
 
   if (!(dc = DC_LockDc(hDC)))
     return FALSE;
+  GDIDevice = (GDIDEVICE *)dc->GDIDevice;
+  DC_UnlockDc(dc);
 
-  hBitmap = dc->w.hBitmap;
-  DC_UnlockDc(hDC);
-  if (!(BitmapObj = BITMAPOBJ_LockBitmap(hBitmap)))
-    return FALSE;
+  loc->x = GDIDevice->Pointer.Pos.x;
+  loc->y = GDIDevice->Pointer.Pos.y;
 
-  SurfObj = &BitmapObj->SurfObj;
-  loc->x = GDIDEV(SurfObj)->Pointer.Pos.x;
-  loc->y = GDIDEV(SurfObj)->Pointer.Pos.y;
-
-  BITMAPOBJ_UnlockBitmap(hBitmap);
   return TRUE;
 }
 
@@ -135,7 +128,7 @@
       }
       dcbmp = dc->w.hBitmap;
       DevInfo = dc->DevInfo;
-      DC_UnlockDc(Screen);
+      DC_UnlockDc(dc);
 
       BitmapObj = BITMAPOBJ_LockBitmap(dcbmp);
       if ( !BitmapObj )
@@ -159,13 +152,13 @@
 
       CurInfo->CurrentCursorObject = NewCursor; /* i.e. CurrentCursorObject = NULL */
       CurInfo->ShowingCursor = 0;
-      BITMAPOBJ_UnlockBitmap(dcbmp);
+      BITMAPOBJ_UnlockBitmap(BitmapObj);
       return Ret;
    }
 
    if (!NewCursor)
    {
-      BITMAPOBJ_UnlockBitmap(dcbmp);
+      BITMAPOBJ_UnlockBitmap(BitmapObj);
       return Ret;
    }
 
@@ -176,11 +169,11 @@
    if (MaskBmpObj)
    {
       const int maskBpp = BitsPerFormat(MaskBmpObj->SurfObj.iBitmapFormat);
-      BITMAPOBJ_UnlockBitmap(NewCursor->IconInfo.hbmMask);
+      BITMAPOBJ_UnlockBitmap(MaskBmpObj);
       if (maskBpp != 1)
       {
          DPRINT1("SetCursor: The Mask bitmap must have 1BPP!\n");
-         BITMAPOBJ_UnlockBitmap(dcbmp);
+         BITMAPOBJ_UnlockBitmap(BitmapObj);
          return Ret;
       }
 
@@ -224,14 +217,14 @@
               NULL);
             if ( !hMask )
             {
-              BITMAPOBJ_UnlockBitmap(NewCursor->IconInfo.hbmMask);
-              BITMAPOBJ_UnlockBitmap(dcbmp);
+              BITMAPOBJ_UnlockBitmap(MaskBmpObj);
+              BITMAPOBJ_UnlockBitmap(BitmapObj);
               return (HCURSOR)0;
             }
             soMask = EngLockSurface((HSURF)hMask);
             EngCopyBits(soMask, &MaskBmpObj->SurfObj, NULL, NULL,
               &DestRect, &SourcePoint);
-            BITMAPOBJ_UnlockBitmap(NewCursor->IconInfo.hbmMask);
+            BITMAPOBJ_UnlockBitmap(MaskBmpObj);
           }
         }
       }
@@ -280,7 +273,7 @@
       GDIDEV(SurfObj)->Pointer.MovePointer = GDIDEVFUNCS(SurfObj).MovePointer;
     }
 
-    BITMAPOBJ_UnlockBitmap(dcbmp);
+    BITMAPOBJ_UnlockBitmap(BitmapObj);
     if(hMask)
     {
       EngUnlockSurface(soMask);
@@ -617,7 +610,7 @@
         {
           CurIconObject->Size.cx = bmp->SurfObj.sizlBitmap.cx;
           CurIconObject->Size.cy = bmp->SurfObj.sizlBitmap.cy;
-          BITMAPOBJ_UnlockBitmap(CurIconObject->IconInfo.hbmColor);
+          BITMAPOBJ_UnlockBitmap(bmp);
           GDIOBJ_SetOwnership(CurIconObject->IconInfo.hbmColor, NULL);
         }
         if(CurIconObject->IconInfo.hbmMask &&
@@ -628,7 +621,7 @@
             CurIconObject->Size.cx = bmp->SurfObj.sizlBitmap.cx;
             CurIconObject->Size.cy = bmp->SurfObj.sizlBitmap.cy / 2;
           }
-          BITMAPOBJ_UnlockBitmap(CurIconObject->IconInfo.hbmMask);
+          BITMAPOBJ_UnlockBitmap(bmp);
           GDIOBJ_SetOwnership(CurIconObject->IconInfo.hbmMask, NULL);
         }
       }
@@ -749,7 +742,7 @@
     else
       SetLastNtError(Status);
 
-    BITMAPOBJ_UnlockBitmap(CurIconObject->IconInfo.hbmColor);
+    BITMAPOBJ_UnlockBitmap(bmp);
 
     done:
     IntReleaseCurIconObject(CurIconObject);
@@ -1109,7 +1102,7 @@
     {
       CurIconObject->Size.cx = bmp->SurfObj.sizlBitmap.cx;
       CurIconObject->Size.cy = bmp->SurfObj.sizlBitmap.cy;
-      BITMAPOBJ_UnlockBitmap(CurIconObject->IconInfo.hbmColor);
+      BITMAPOBJ_UnlockBitmap(bmp);
       GDIOBJ_SetOwnership(CurIconObject->IconInfo.hbmColor, NULL);
     }
     else
@@ -1121,7 +1114,7 @@
       CurIconObject->Size.cx = bmp->SurfObj.sizlBitmap.cx;
       CurIconObject->Size.cy = bmp->SurfObj.sizlBitmap.cy / 2;
 
-      BITMAPOBJ_UnlockBitmap(CurIconObject->IconInfo.hbmMask);
+      BITMAPOBJ_UnlockBitmap(bmp);
       GDIOBJ_SetOwnership(CurIconObject->IconInfo.hbmMask, NULL);
     }
 

Modified: trunk/reactos/subsys/win32k/ntuser/desktop.c
--- trunk/reactos/subsys/win32k/ntuser/desktop.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/desktop.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -349,9 +349,9 @@
     {
       Ret->right = BitmapObj->SurfObj.sizlBitmap.cx;
       Ret->bottom = BitmapObj->SurfObj.sizlBitmap.cy;
-      BITMAPOBJ_UnlockBitmap(dc->w.hBitmap);
+      BITMAPOBJ_UnlockBitmap(BitmapObj);
     }
-    DC_UnlockDc(ScreenDeviceContext);
+    DC_UnlockDc(dc);
   }
 
   if(Rect)

Modified: trunk/reactos/subsys/win32k/ntuser/input.c
--- trunk/reactos/subsys/win32k/ntuser/input.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/input.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -952,7 +952,7 @@
     if (dc)
     {
       hBitmap = dc->w.hBitmap;
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(dc);
 
       BitmapObj = BITMAPOBJ_LockBitmap(hBitmap);
       if (BitmapObj)
@@ -970,7 +970,7 @@
 	GDIDEV(SurfObj)->Pointer.Pos.x = MousePos.x;
 	GDIDEV(SurfObj)->Pointer.Pos.y = MousePos.y;
 
-        BITMAPOBJ_UnlockBitmap(hBitmap);
+        BITMAPOBJ_UnlockBitmap(BitmapObj);
       }
     }
   }

Modified: trunk/reactos/subsys/win32k/ntuser/metric.c
--- trunk/reactos/subsys/win32k/ntuser/metric.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/metric.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -169,7 +169,7 @@
 	{
 	  Width = ScreenDC->GDIInfo->ulHorzRes;
 	  Height = ScreenDC->GDIInfo->ulVertRes;
-	  DC_UnlockDc(ScreenDCHandle);
+	  DC_UnlockDc(ScreenDC);
 	}
 	NtGdiDeleteDC(ScreenDCHandle);
       }

Modified: trunk/reactos/subsys/win32k/ntuser/misc.c
--- trunk/reactos/subsys/win32k/ntuser/misc.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/misc.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -841,7 +841,7 @@
             WinStaObject->cxWallpaper = bmp->SurfObj.sizlBitmap.cx;
             WinStaObject->cyWallpaper = bmp->SurfObj.sizlBitmap.cy;
 
-            BITMAPOBJ_UnlockBitmap(hNewBitmap);
+            BITMAPOBJ_UnlockBitmap(bmp);
 
             /* change the bitmap's ownership */
             GDIOBJ_SetOwnership(hNewBitmap, NULL);

Modified: trunk/reactos/subsys/win32k/ntuser/monitor.c
--- trunk/reactos/subsys/win32k/ntuser/monitor.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/monitor.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -506,7 +506,7 @@
 			return -1;
 		}
 		dcVisRgn = dc->w.hVisRgn;
-		DC_UnlockDc(hDC);
+		DC_UnlockDc(dc);
 
 		regionType = NtGdiGetRgnBox(dcVisRgn, &dcRect);
 		if (regionType == 0)

Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
--- trunk/reactos/subsys/win32k/ntuser/painting.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/painting.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -743,7 +743,7 @@
       if (NULL != Rgn)
       {
          UnsafeIntGetRgnBox(Rgn, &Ps.rcPaint);
-         RGNDATA_UnlockRgn(Window->UpdateRegion);
+         RGNDATA_UnlockRgn(Rgn);
          IntGdiOffsetRect(&Ps.rcPaint,
                           Window->WindowRect.left - Window->ClientRect.left,
                           Window->WindowRect.top - Window->ClientRect.top);
@@ -933,7 +933,7 @@
       ASSERT(RgnData != NULL);
       RegionType = UnsafeIntGetRgnBox(RgnData, &Rect);
       ASSERT(RegionType != ERROR);
-      RGNDATA_UnlockRgn(Window->UpdateRegion);
+      RGNDATA_UnlockRgn(RgnData);
    }
    AlwaysPaint = (Window->Flags & WINDOWOBJECT_NEED_NCPAINT) ||
                  (Window->Flags & WINDOWOBJECT_NEED_INTERNALPAINT);
@@ -1062,7 +1062,7 @@
       IntGdiOffsetRect(&rSrc_lp, offset.left - offset.right, offset.top - offset.bottom);
       IntDPtoLP(DC, (LPPOINT)&rDst_lp, 2);
       IntDPtoLP(DC, (LPPOINT)&rSrc_lp, 2);
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(DC);
 
       if (!NtGdiBitBlt(hDC, rDst_lp.left, rDst_lp.top, rDst_lp.right - rDst_lp.left,
                        rDst_lp.bottom - rDst_lp.top, hDC, rSrc_lp.left, rSrc_lp.top,
@@ -1071,7 +1071,7 @@
    }
    else
    {
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(DC);
    }
 
    /*

Modified: trunk/reactos/subsys/win32k/ntuser/windc.c
--- trunk/reactos/subsys/win32k/ntuser/windc.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/windc.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -130,7 +130,7 @@
 
   Dce = DCEOBJ_LockDCE(DceHandle);
   /* No real locking, just get the pointer */
-  DCEOBJ_UnlockDCE(DceHandle);
+  DCEOBJ_UnlockDCE(Dce);
   Dce->Self = DceHandle;
   Dce->hDC = IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE);
   if (NULL == defaultDCstate)
@@ -200,7 +200,7 @@
 	  dc->w.DCOrgY = WindowObject->ClientRect.top;
 	}
     }
-  DC_UnlockDc(hDC);
+  DC_UnlockDc(dc);
 }
 
 
@@ -855,7 +855,7 @@
                   NtGdiOffsetRgn(pDCE->hClipRgn, DeltaX, DeltaY);
                 }
             }
-          DC_UnlockDc(pDCE->hDC);
+          DC_UnlockDc(dc);
 
           DceUpdateVisRgn(pDCE, CurrentWindow, pDCE->DCXFlags);
 

Modified: trunk/reactos/subsys/win32k/ntuser/window.c
--- trunk/reactos/subsys/win32k/ntuser/window.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/window.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -3918,7 +3918,7 @@
   if((pRgn = RGNDATA_LockRgn(hRgn)))
   {
     Ret = pRgn->rdh.iType;
-    RGNDATA_UnlockRgn(hRgn);
+    RGNDATA_UnlockRgn(pRgn);
   }
   else
     Ret = ERROR;
@@ -3959,7 +3959,7 @@
   {
     Ret = pRgn->rdh.iType;
     *Rect = pRgn->rdh.rcBound;
-    RGNDATA_UnlockRgn(VisRgn);
+    RGNDATA_UnlockRgn(pRgn);
   }
   else
     Ret = ERROR;

Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
--- trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -853,13 +853,13 @@
          if (VisBefore != NULL && (VisRgn = (PROSRGNDATA)RGNDATA_LockRgn(VisBefore)) &&
              UnsafeIntGetRgnBox(VisRgn, &TempRect) == NULLREGION)
          {
-            RGNDATA_UnlockRgn(VisBefore);
+            RGNDATA_UnlockRgn(VisRgn);
             NtGdiDeleteObject(VisBefore);
             VisBefore = NULL;
          }
          else if(VisRgn)
          {
-            RGNDATA_UnlockRgn(VisBefore);
+            RGNDATA_UnlockRgn(VisRgn);
          }
       }
    }
@@ -988,13 +988,13 @@
       if (VisAfter != NULL && (VisRgn = (PROSRGNDATA)RGNDATA_LockRgn(VisAfter)) &&
           UnsafeIntGetRgnBox(VisRgn, &TempRect) == NULLREGION)
       {
-         RGNDATA_UnlockRgn(VisAfter);
+         RGNDATA_UnlockRgn(VisRgn);
          NtGdiDeleteObject(VisAfter);
          VisAfter = NULL;
       }
       else if(VisRgn)
       {
-         RGNDATA_UnlockRgn(VisAfter);
+         RGNDATA_UnlockRgn(VisRgn);
       }
 
       /*
@@ -1048,7 +1048,7 @@
              UnsafeIntGetRgnBox(VisRgn, &CopyRect) == NULLREGION)
          {
             /* Nothing to copy, clean up */
-            RGNDATA_UnlockRgn(CopyRgn);
+            RGNDATA_UnlockRgn(VisRgn);
             NtGdiDeleteObject(CopyRgn);
             CopyRgn = NULL;
          }
@@ -1057,7 +1057,7 @@
          {
             if(VisRgn)
             {
-               RGNDATA_UnlockRgn(CopyRgn);
+               RGNDATA_UnlockRgn(VisRgn);
             }
             /*
              * Small trick here: there is no function to bitblt a region. So
@@ -1083,7 +1083,7 @@
          }
          else if(VisRgn)
          {
-            RGNDATA_UnlockRgn(CopyRgn);
+            RGNDATA_UnlockRgn(VisRgn);
          }
       }
       else

Modified: trunk/reactos/subsys/win32k/objects/bitmaps.c
--- trunk/reactos/subsys/win32k/objects/bitmaps.c	2005-06-07 16:26:14 UTC (rev 15829)
+++ trunk/reactos/subsys/win32k/objects/bitmaps.c	2005-06-07 16:34:07 UTC (rev 15830)
@@ -61,7 +61,7 @@
 	}
 	if (DCDest->IsIC)
 	{
-		DC_UnlockDc(hDCDest);
+		DC_UnlockDc(DCDest);
 		/* Yes, Windows really returns TRUE in this case */
 		return TRUE;
 	}
@@ -73,15 +73,15 @@
 			DCSrc = DC_LockDc(hDCSrc);
 			if (NULL == DCSrc)
 			{
-				DC_UnlockDc(hDCDest);
+				DC_UnlockDc(DCDest);
 				DPRINT1("Invalid source dc handle (0x%08x) passed to NtGdiBitBlt\n", hDCSrc);
 				SetLastWin32Error(ERROR_INVALID_HANDLE);
 				return FALSE;
 			}
 			if (DCSrc->IsIC)
 			{
-				DC_UnlockDc(hDCSrc);
-				DC_UnlockDc(hDCDest);
+				DC_UnlockDc(DCSrc);
+				DC_UnlockDc(DCDest);
 				/* Yes, Windows really returns TRUE in this case */
 				return TRUE;
 			}
@@ -137,17 +137,17 @@
 		{
 			if (UsesSource && hDCSrc != hDCDest)
 			{
-				DC_UnlockDc(hDCSrc);
+				DC_UnlockDc(DCSrc);
 			}
 			if(BitmapDest != NULL)
 			{
-                                BITMAPOBJ_UnlockBitmap(DCDest->w.hBitmap);
+                                BITMAPOBJ_UnlockBitmap(BitmapDest);
 			}
 			if(BitmapSrc != NULL && BitmapSrc != BitmapDest)
 			{
-                                BITMAPOBJ_UnlockBitmap(DCSrc->w.hBitmap);
+                                BITMAPOBJ_UnlockBitmap(BitmapSrc);
 			}
-			DC_UnlockDc(hDCDest);
+			DC_UnlockDc(DCDest);
 			SetLastWin32Error(ERROR_INVALID_HANDLE);
 			return FALSE;
 		}
@@ -191,20 +191,20 @@
 			{
 				if (UsesSource && hDCSrc != hDCDest)
 				{
-					DC_UnlockDc(hDCSrc);
+					DC_UnlockDc(DCSrc);
 				}
-				DC_UnlockDc(hDCDest);
+				DC_UnlockDc(DCDest);
 				if(BitmapDest != NULL)
 				{
-                                	BITMAPOBJ_UnlockBitmap(DCDest->w.hBitmap);
+                                	BITMAPOBJ_UnlockBitmap(BitmapDest);
 				}
 				if(BitmapSrc != NULL && BitmapSrc != BitmapDest)
 				{
-                                	BITMAPOBJ_UnlockBitmap(DCSrc->w.hBitmap);
+                                	BITMAPOBJ_UnlockBitmap(BitmapSrc);
 				}
 				if(BrushObj != NULL)
 				{
-                                        BRUSHOBJ_UnlockBrush(DCDest->w.hBrush);
+                                        BRUSHOBJ_UnlockBrush(BrushObj);
 				}
 				SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
 				return FALSE;
@@ -222,21 +222,21 @@
 
         if(BitmapDest != NULL)
         {
-                BITMAPOBJ_UnlockBitmap(DCDest->w.hBitmap);
+                BITMAPOBJ_UnlockBitmap(BitmapDest);
         }
 	if (UsesSource && BitmapSrc != BitmapDest)
 	{
-		BITMAPOBJ_UnlockBitmap(DCSrc->w.hBitmap);
+		BITMAPOBJ_UnlockBitmap(BitmapSrc);
 	}
 	if (BrushObj != NULL)
 	{
-		BRUSHOBJ_UnlockBrush(DCDest->w.hBrush);
+		BRUSHOBJ_UnlockBrush(BrushObj);
 	}
 	if (UsesSource && hDCSrc != hDCDest)
 	{
-		DC_UnlockDc(hDCSrc);
+		DC_UnlockDc(DCSrc);
 	}
-	DC_UnlockDc(hDCDest);
+	DC_UnlockDc(DCDest);
 
 	return Status;
 }
@@ -273,14 +273,14 @@
   }
   if (DCDest->IsIC)
   {
-    DC_UnlockDc(hdcDst);
+    DC_UnlockDc(DCDest);
     /* Yes, Windows really returns TRUE in this case */
     return TRUE;
   }
 
   if((hdcDst != hdcSrc) && !(DCSrc = DC_LockDc(hdcSrc)))
   {
-    DC_UnlockDc(hdcDst);
+    DC_UnlockDc(DCDest);
     DPRINT1("Invalid source dc handle (0x%08x) passed to NtGdiTransparentBlt\n", hdcSrc);
     SetLastWin32Error(ERROR_INVALID_HANDLE);
     return FALSE;
@@ -291,10 +291,10 @@
   }
   if (DCSrc->IsIC)
   {
-    DC_UnlockDc(hdcSrc);
+    DC_UnlockDc(DCSrc);
     if(hdcDst != hdcSrc)
     {
-      DC_UnlockDc(hdcDst);
+      DC_UnlockDc(DCDest);
     }
     /* Yes, Windows really returns TRUE in this case */
     return TRUE;
@@ -314,16 +314,16 @@
 
   if(!(PalSourceGDI = PALETTE_LockPalette(SourcePalette)))
   {
-    DC_UnlockDc(hdcSrc);
-    DC_UnlockDc(hdcDst);
+    DC_UnlockDc(DCSrc);
+    DC_UnlockDc(DCDest);
     SetLastWin32Error(ERROR_INVALID_HANDLE);
[truncated at 1000 lines; 3758 more skipped]