Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c	(revision 42003)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c	(revision 42023)
@@ -287,8 +287,23 @@
 }
 
+
+static HRESULT vboxExtWndCleanup();
+
 static HRESULT vboxExtTerm()
 {
-    HRESULT hr = VBoxExtWorkerDestroy(&g_VBoxExtGlobal.Worker);
-    return hr;
+    HRESULT hr = vboxExtWndCleanup();
+    if (!SUCCEEDED(hr))
+    {
+        ERR("vboxExtWndCleanup failed, hr %d", hr);
+        return hr;
+    }
+
+    hr = VBoxExtWorkerDestroy(&g_VBoxExtGlobal.Worker);
+    if (!SUCCEEDED(hr))
+    {
+        ERR("VBoxExtWorkerDestroy failed, hr %d", hr);
+        return hr;
+    }
+    return S_OK;
 }
 
@@ -465,5 +480,22 @@
 #define VBOXEXTWND_NAME "VboxDispD3DWineWnd"
 
-HRESULT vboxExtWndDoCreate(DWORD w, DWORD h, HWND *phWnd, HDC *phDC)
+static HRESULT vboxExtWndDoCleanup()
+{
+    HRESULT hr = S_OK;
+    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
+    WNDCLASS wc;
+    if (GetClassInfo(hInstance, VBOXEXTWND_NAME, &wc))
+    {
+        if (!UnregisterClass(VBOXEXTWND_NAME, hInstance))
+        {
+            DWORD winEr = GetLastError();
+            ERR("UnregisterClass failed, winErr(%d)\n", winEr);
+            hr = E_FAIL;
+        }
+    }
+    return hr;
+}
+
+static HRESULT vboxExtWndDoCreate(DWORD w, DWORD h, HWND *phWnd, HDC *phDC)
 {
     HRESULT hr = S_OK;
@@ -557,5 +589,10 @@
 } VBOXEXTWND_DESTROY_INFO;
 
-DECLCALLBACK(void) vboxExtWndDestroyWorker(void *pvUser)
+typedef struct VBOXEXTWND_CLEANUP_INFO
+{
+    int hr;
+} VBOXEXTWND_CLEANUP_INFO;
+
+static DECLCALLBACK(void) vboxExtWndDestroyWorker(void *pvUser)
 {
     VBOXEXTWND_DESTROY_INFO *pInfo = (VBOXEXTWND_DESTROY_INFO*)pvUser;
@@ -564,9 +601,15 @@
 }
 
-DECLCALLBACK(void) vboxExtWndCreateWorker(void *pvUser)
+static DECLCALLBACK(void) vboxExtWndCreateWorker(void *pvUser)
 {
     VBOXEXTWND_CREATE_INFO *pInfo = (VBOXEXTWND_CREATE_INFO*)pvUser;
     pInfo->hr = vboxExtWndDoCreate(pInfo->width, pInfo->height, &pInfo->hWnd, &pInfo->hDC);
     Assert(pInfo->hr == S_OK);
+}
+
+static DECLCALLBACK(void) vboxExtWndCleanupWorker(void *pvUser)
+{
+    VBOXEXTWND_CLEANUP_INFO *pInfo = (VBOXEXTWND_CLEANUP_INFO*)pvUser;
+    pInfo-> hr = vboxExtWndDoCleanup();
 }
 
@@ -579,11 +622,17 @@
     Info.hDC = hDC;
     hr = VBoxExtDwSubmitProcSync(vboxExtWndDestroyWorker, &Info);
-    Assert(hr == S_OK);
-    if (hr == S_OK)
-    {
-        Assert(Info.hr == S_OK);
+    if (!SUCCEEDED(hr))
+    {
+        ERR("VBoxExtDwSubmitProcSync-vboxExtWndDestroyWorker failed hr %d", hr);
+        return hr;
+    }
+
+    if (!SUCCEEDED(Info.hr))
+    {
+        ERR("vboxExtWndDestroyWorker failed hr %d", Info.hr);
         return Info.hr;
     }
-    return hr;
+
+    return S_OK;
 }
 
@@ -596,15 +645,40 @@
     Info.height = height;
     hr = VBoxExtDwSubmitProcSync(vboxExtWndCreateWorker, &Info);
-    Assert(hr == S_OK);
-    if (hr == S_OK)
-    {
-        Assert(Info.hr == S_OK);
-        if (Info.hr == S_OK)
-        {
-            *phWnd = Info.hWnd;
-            *phDC = Info.hDC;
-        }
+    if (!SUCCEEDED(hr))
+    {
+        ERR("VBoxExtDwSubmitProcSync-vboxExtWndCreateWorker failed hr %d", hr);
+        return hr;
+    }
+
+    Assert(Info.hr == S_OK);
+    if (!SUCCEEDED(Info.hr))
+    {
+        ERR("vboxExtWndCreateWorker failed hr %d", Info.hr);
         return Info.hr;
     }
-    return hr;
-}
+
+    *phWnd = Info.hWnd;
+    *phDC = Info.hDC;
+    return S_OK;
+}
+
+static HRESULT vboxExtWndCleanup()
+{
+    HRESULT hr;
+    VBOXEXTWND_CLEANUP_INFO Info;
+    Info.hr = E_FAIL;
+    hr = VBoxExtDwSubmitProcSync(vboxExtWndCleanupWorker, &Info);
+    if (!SUCCEEDED(hr))
+    {
+        ERR("VBoxExtDwSubmitProcSync-vboxExtWndCleanupWorker failed hr %d", hr);
+        return hr;
+    }
+
+    if (!SUCCEEDED(Info.hr))
+    {
+        ERR("vboxExtWndCleanupWorker failed hr %d", Info.hr);
+        return Info.hr;
+    }
+
+    return S_OK;
+}
