diff --git a/dlls/gdi32/dibdrv/dibdrv.h b/dlls/gdi32/dibdrv/dibdrv.h
index 3e3ab21441ec62ed4c6554da935cf3d990bd0a2c..4068b54e178bd6b0b653a27c24164338279d8cae 100644
--- a/dlls/gdi32/dibdrv/dibdrv.h
+++ b/dlls/gdi32/dibdrv/dibdrv.h
@@ -87,7 +87,7 @@ typedef struct dibdrv_physdev
     DWORD pen_color, pen_and, pen_xor;
     dash_pattern pen_pattern;
     dash_pos dash_pos;
-    BOOL   (* pen_lines)(struct dibdrv_physdev *pdev, int num, POINT *pts);
+    BOOL   (* pen_lines)(struct dibdrv_physdev *pdev, int num, POINT *pts, BOOL close);
 
     /* brush */
     UINT brush_style;
diff --git a/dlls/gdi32/dibdrv/graphics.c b/dlls/gdi32/dibdrv/graphics.c
index d5e4730d46e8ca12683a566780e9a4ac87238688..590a81670185de3dab629234e5950ffb257e059a 100644
--- a/dlls/gdi32/dibdrv/graphics.c
+++ b/dlls/gdi32/dibdrv/graphics.c
@@ -431,7 +431,7 @@ BOOL dibdrv_LineTo( PHYSDEV dev, INT x, INT y )
 
     reset_dash_origin(pdev);
 
-    if(defer_pen(pdev) || !pdev->pen_lines(pdev, 2, pts))
+    if(defer_pen(pdev) || !pdev->pen_lines(pdev, 2, pts, FALSE))
         return next->funcs->pLineTo( next, x, y );
 
     return TRUE;
@@ -528,7 +528,7 @@ BOOL dibdrv_PolyPolyline( PHYSDEV dev, const POINT* pt, const DWORD* counts, DWO
         LPtoDP( dev->hdc, points, counts[i] );
 
         reset_dash_origin( pdev );
-        pdev->pen_lines( pdev, counts[i], points );
+        pdev->pen_lines( pdev, counts[i], points, FALSE );
     }
 
     HeapFree( GetProcessHeap(), 0, points );
@@ -553,7 +553,7 @@ BOOL dibdrv_Polyline( PHYSDEV dev, const POINT* pt, INT count )
     LPtoDP( dev->hdc, points, count );
 
     reset_dash_origin( pdev );
-    pdev->pen_lines( pdev, count, points );
+    pdev->pen_lines( pdev, count, points, FALSE );
 
     HeapFree( GetProcessHeap(), 0, points );
     return TRUE;
@@ -567,7 +567,7 @@ BOOL dibdrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
     PHYSDEV next = GET_NEXT_PHYSDEV( dev, pRectangle );
     dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
     RECT rect = get_device_rect( dev->hdc, left, top, right, bottom, TRUE );
-    POINT pts[5];
+    POINT pts[4];
 
     TRACE("(%p, %d, %d, %d, %d)\n", dev, left, top, right, bottom);
 
@@ -583,9 +583,8 @@ BOOL dibdrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
     pts[0].y = pts[1].y = rect.top;
     pts[1].x = pts[2].x = rect.left;
     pts[2].y = pts[3].y = rect.bottom - 1;
-    pts[4] = pts[0];
 
-    pdev->pen_lines(pdev, 5, pts);
+    pdev->pen_lines(pdev, 4, pts, TRUE);
 
     /* FIXME: Will need updating when we support wide pens */
 
diff --git a/dlls/gdi32/dibdrv/objects.c b/dlls/gdi32/dibdrv/objects.c
index 51e1fdcde1ee59309f8d390a1d4883aa958ef756..0baafdbd9ecabc8bd669f8dbc71439411a0a7324 100644
--- a/dlls/gdi32/dibdrv/objects.c
+++ b/dlls/gdi32/dibdrv/objects.c
@@ -696,7 +696,7 @@ static BOOL solid_pen_line(dibdrv_physdev *pdev, POINT *start, POINT *end)
     return TRUE;
 }
 
-static BOOL solid_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts)
+static BOOL solid_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts, BOOL close)
 {
     int i;
 
@@ -705,6 +705,8 @@ static BOOL solid_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts)
         if (!solid_pen_line( pdev, pts + i, pts + i + 1 ))
             return FALSE;
 
+    if (close) return solid_pen_line( pdev, pts + num - 1, pts );
+
     return TRUE;
 }
 
@@ -996,7 +998,7 @@ static BOOL dashed_pen_line(dibdrv_physdev *pdev, POINT *start, POINT *end)
     return TRUE;
 }
 
-static BOOL dashed_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts)
+static BOOL dashed_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts, BOOL close)
 {
     int i;
 
@@ -1005,10 +1007,12 @@ static BOOL dashed_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts)
         if (!dashed_pen_line( pdev, pts + i, pts + i + 1 ))
             return FALSE;
 
+    if (close) return dashed_pen_line( pdev, pts + num - 1, pts );
+
     return TRUE;
 }
 
-static BOOL null_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts)
+static BOOL null_pen_lines(dibdrv_physdev *pdev, int num, POINT *pts, BOOL close)
 {
     return TRUE;
 }