diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c
index 3175cfa1f08bcc0224a1a35749cb757811a7a56d..94e6691130d2f7af3d186ce805a9380aade5f60f 100644
--- a/dlls/shell32/shlexec.c
+++ b/dlls/shell32/shlexec.c
@@ -540,8 +540,9 @@ static unsigned dde_connect(WCHAR* key, WCHAR* start, WCHAR* ddeexec,
         if (!hConv)
         {
             TRACE("Couldn't connect. ret=%d\n", ret);
-            ret = 30; /* whatever */
-            goto error;
+            DdeUninitialize(ddeInst);
+            SetLastError(ERROR_DDE_FAIL);
+            return 30; /* whatever */
         }
         strcpyW(endkey, wIfexec);
         ifexeclen = sizeof(ifexec)/sizeof(WCHAR);