Index: trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h	(revision 3434)
+++ trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h	(revision 3435)
@@ -38,4 +38,7 @@
 {
     uint64_t    lastretval;
+    uint32_t    ulLastError;
+
+    bool        fHasLastError;
 
     uint8_t    *pLastParam;
Index: trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(revision 3434)
+++ trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(revision 3435)
@@ -144,5 +144,5 @@
 void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    HGLRC glrc;
+    HGLRC glrc = 0;
 
     OGL_CMD(DrvCreateContext, 6);
@@ -178,10 +178,7 @@
     uint32_t lasterr = glGetError();
     format = ChoosePixelFormat(pClient->hdc, &pfd);
-    lasterr = glGetError();
     SetPixelFormat(pClient->hdc, format, &pfd);
 
-    lasterr = glGetError();
     glrc = wglCreateContext(pClient->hdc);
-    lasterr = glGetError();
     Assert(glrc);
 #else
@@ -190,11 +187,11 @@
 #endif
 
-    pClient->lastretval = (uint64_t)glrc;
+    pClient->lastretval    = (uint64_t)glrc;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
 void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    BOOL ret;
-
     OGL_CMD(DrvSetContext, 2);
     OGL_PARAM(HDC, hdc);
@@ -203,10 +200,12 @@
     Log(("DrvSetyContext %x %x\n", hdc, hglrc));
 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
-    ret = wglMakeCurrent(pClient->hdc, hglrc);
-    if (!ret)
+    pClient->lastretval = wglMakeCurrent(pClient->hdc, hglrc);
+    if (!pClient->lastretval)
         Log(("wglMakeCurrent failed with %d\n", GetLastError()));
 #else
     AssertFailed();
 #endif
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -221,10 +220,11 @@
     if (!pClient->lastretval)
         Log(("wglCopyContext failed with %d\n", GetLastError()));
+
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
 void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    BOOL ret;
-
     OGL_CMD(DrvReleaseContext, 1);
     OGL_PARAM(HGLRC, hglrc);
@@ -232,25 +232,27 @@
     Log(("DrvReleaseContext %x\n", hglrc));
     /* clear current selection */
-    ret = wglMakeCurrent(pClient->hdc, NULL);
-    if (!ret)
+    pClient->lastretval = wglMakeCurrent(pClient->hdc, NULL);
+    if (!pClient->lastretval)
         Log(("wglMakeCurrent failed with %d\n", GetLastError()));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
 void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    BOOL ret;
-
     OGL_CMD(DrvDeleteContext, 1);
     OGL_PARAM(HGLRC, hglrc);
 
     Log(("DrvDeleteContext %x\n", hglrc));
-    ret = wglDeleteContext(hglrc);
-    if (!ret)
+    pClient->lastretval = wglDeleteContext(hglrc);
+    if (!pClient->lastretval)
         Log(("wglDeleteContext failed with %d\n", GetLastError()));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
 void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    HGLRC glrc;
+    HGLRC glrc = 0;
 
     OGL_CMD(DrvCreateLayerContext, 7);
@@ -295,4 +297,8 @@
     AssertFailed();
 #endif
+
+    pClient->lastretval    = (uint64_t)glrc;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -305,4 +311,6 @@
     Log(("DrvShareLists %x %x\n", hglrc1, hglrc2));
     pClient->lastretval = wglShareLists(hglrc1, hglrc2);
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -316,4 +324,6 @@
     Log(("DrvRealizeLayerPalette %x %d %d\n", hdc, iLayerPlane, bRealize));
     pClient->lastretval = wglRealizeLayerPalette(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, bRealize);
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -325,4 +335,6 @@
     Log(("DrvSwapLayerBuffers %x %d\n", hdc, fuPlanes));
     pClient->lastretval = wglSwapLayerBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), fuPlanes);
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -347,4 +359,6 @@
         pClient->lastretval = 0;
     }
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -360,4 +374,6 @@
 
     /** @todo sync bitmap/screen contents */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -378,4 +394,6 @@
     if (!pClient->lastretval)
         Log(("wglDescribeLayerPlane failed with %d\n", GetLastError()));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -393,4 +411,6 @@
     if (!pClient->lastretval)
         Log(("wglSetLayerPaletteEntries failed with %d\n", GetLastError()));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -412,4 +432,6 @@
     if (!pClient->lastretval)
         Log(("wglGetLayerPaletteEntries failed with %d\n", GetLastError()));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
 }
 
@@ -434,4 +456,7 @@
         Log(("DescribePixelFormat failed with %d\n", GetLastError()));
 
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = GetLastError();
+
     if (!VBOX_OGL_GUEST_TO_HOST_HDC(hdc))
         ReleaseDC(0, pClient->hdc);
Index: trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(revision 3434)
+++ trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(revision 3435)
@@ -114,4 +114,6 @@
     Log(("vboxglFlushBuffer cCommands=%d cbCmdBuffer=%x\n", cCommands, cbCmdBuffer));
 
+    pClient->fHasLastError = false;
+
     for (i=0;i<cCommands;i++)
     {
@@ -135,5 +137,8 @@
 
     *pLastRetVal = pClient->lastretval;
-    *pLastError  = 0; //glGetError();
+    if (pClient->fHasLastError)
+        *pLastError = pClient->ulLastError;
+    else
+        *pLastError = glGetError();
 
 #ifdef DEBUG
