-sync user32_winetest with wine 1.1.32
[reactos.git] / rostests / winetests / user32 / dde.c
index eb875e3..202bb41 100755 (executable)
@@ -73,6 +73,12 @@ static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
     assert(*hwnd);
 }
 
+static void destroy_dde_window(HWND *hwnd, LPCSTR name)
+{
+    DestroyWindow(*hwnd);
+    UnregisterClass(name, GetModuleHandleA(0));
+}
+
 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
     UINT_PTR lo, hi;
@@ -154,7 +160,7 @@ static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPA
         lstrcpyA((LPSTR)data->Value, str);
         GlobalUnlock(hglobal);
 
-        lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
+        lparam = PackDDElParam(WM_DDE_ACK, (UINT_PTR)hglobal, HIWORD(lparam));
         PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
 
         break;
@@ -178,8 +184,10 @@ static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPA
         ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
 
         if (msg_index == 5)
-            ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
-               "Expected 'poke data\\r\\n', got %s\n", poke->Value);
+        {
+            size = GlobalSize((HGLOBAL)lo);
+            ok(size == 4, "got %d\n", size);
+        }
         else
             ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
                "Expected 'poke data\\r\\n', got %s\n", poke->Value);
@@ -203,7 +211,7 @@ static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPA
 
         executed = TRUE;
 
-        lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
+        lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, lparam);
         PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
 
         break;
@@ -227,20 +235,21 @@ static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPA
     return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
-static void test_msg_server(HANDLE hproc)
+static void test_msg_server(HANDLE hproc, HANDLE hthread)
 {
     MSG msg;
     HWND hwnd;
     DWORD res;
 
     create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
+    ResumeThread( hthread );
 
     while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
     {
         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
     }
 
-    DestroyWindow(hwnd);
+    destroy_dde_window(&hwnd, "dde_server");
     GetExitCodeProcess( hproc, &res );
     ok( !res, "client failed with %u error(s)\n", res );
 }
@@ -288,11 +297,8 @@ static void test_ddeml_client(void)
     DdeGetLastError(client_pid);
     hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
     ret = DdeGetLastError(client_pid);
-    ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
-    todo_wine
-    {
-        ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", res);
-    }
+    ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
+    ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %08x\n", res);
     if (hdata == NULL)
         ok(FALSE, "hdata is NULL\n");
     else
@@ -310,11 +316,9 @@ static void test_ddeml_client(void)
     DdeGetLastError(client_pid);
     hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
     ret = DdeGetLastError(client_pid);
-    todo_wine
-    {
-        ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
-        ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
-    }
+    ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
+todo_wine
+    ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
     if (hdata == NULL)
         ok(FALSE, "hdata is NULL\n");
     else
@@ -333,10 +337,7 @@ static void test_ddeml_client(void)
     hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
     ret = DdeGetLastError(client_pid);
     ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
-    todo_wine
-    {
-        ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
-    }
+    ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
     if (hdata == NULL)
         ok(FALSE, "hdata is NULL\n");
     else
@@ -426,10 +427,7 @@ static void test_ddeml_client(void)
     ret = DdeGetLastError(client_pid);
     ok(op == NULL, "Expected NULL, got %p\n", op);
     ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
-    todo_wine
-    {
-        ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
-    }
+    ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
 
     /* XTYP_EXECUTE, no data, -1 size */
     res = 0xdeadbeef;
@@ -438,10 +436,7 @@ static void test_ddeml_client(void)
     ret = DdeGetLastError(client_pid);
     ok(op == NULL, "Expected NULL, got %p\n", op);
     ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
-    todo_wine
-    {
-        ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
-    }
+    ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
 
     DdeFreeStringHandle(client_pid, topic);
     DdeFreeDataHandle(hdata);
@@ -454,10 +449,7 @@ static void test_ddeml_client(void)
     hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
     ret = DdeGetLastError(client_pid);
     ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
-    todo_wine
-    {
-        ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
-    }
+    ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
     if (hdata == NULL)
         ok(FALSE, "hdata is NULL\n");
     else
@@ -567,7 +559,7 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
                                                ULONG_PTR dwData1, ULONG_PTR dwData2)
 {
     char str[MAX_PATH], *ptr;
-    HDDEDATA ret;
+    HDDEDATA ret = NULL;
     DWORD size;
 
     static int msg_index = 0;
@@ -593,7 +585,7 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
         size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
         ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
         ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
-        ok(size == 25, "Expected 25, got %d\n", size);
+        ok(size == 17 + 2*sizeof(ULONG_PTR), "Got size %d for %s\n", size, str);
 
         return (HDDEDATA)TRUE;
     }
@@ -662,7 +654,6 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
 
         if (msg_index == 5)
         {
-            todo_wine
             {
                 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
                 ok(size == 1, "Expected 1, got %d\n", size);
@@ -698,16 +689,12 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
 
         ptr = (LPSTR)DdeAccessData(hdata, &size);
         ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
-        todo_wine
-        {
-            ok(size == 14, "Expected 14, got %d\n", size);
-        }
+        ok(size == 12, "Expected 12, got %d\n", size);
         DdeUnaccessData(hdata);
 
         size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
         if (msg_index == 7)
         {
-            todo_wine
             {
                 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
                 ok(size == 1, "Expected 1, got %d\n", size);
@@ -724,7 +711,7 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
 
     case XTYP_EXECUTE:
     {
-        ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
+        ok(msg_index >= 9 && msg_index <= 11, "Expected 9 or 11, got %d\n", msg_index);
         ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
         ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
         ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
@@ -735,29 +722,50 @@ static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hcon
         ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
         ok(size == 12, "Expected 12, got %d\n", size);
 
-        ptr = (LPSTR)DdeAccessData(hdata, &size);
-
-        if (msg_index == 9)
+        if (msg_index == 9 || msg_index == 11)
         {
-            ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
-            ok(size == 15, "Expected 15, got %d\n", size);
-            ret = (HDDEDATA)DDE_FACK;
+            ptr = (LPSTR)DdeAccessData(hdata, &size);
+
+            if (msg_index == 9)
+            {
+                ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
+                ok(size == 15, "Expected 15, got %d\n", size);
+                ret = (HDDEDATA)DDE_FACK;
+            }
+            else
+            {
+                ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
+                ok(size == 18, "Expected 18, got %d\n", size);
+                ret = DDE_FNOTPROCESSED;
+            }
+
+            DdeUnaccessData(hdata);
         }
-        else
+        else if (msg_index == 10)
         {
-            ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
-            ok(size == 18, "Expected 18, got %d\n", size);
-            ret = (HDDEDATA)DDE_FNOTPROCESSED;
-        }
+            DWORD rsize = 0;
+            size = 0;
+
+            size = DdeGetData(hdata, NULL, 0, 0);
+            ok(size == 17, "DdeGetData should have returned 17 not %d\n", size);
+            ptr = HeapAlloc(GetProcessHeap(), 0, size);
+            ok(ptr != NULL,"HeapAlloc should have returned ptr not NULL\n");
+            rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
+            ok(rsize == size, "DdeGetData did not return %d bytes but %d\n", size, rsize);
+
+            ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr);
+            ok(size == 17, "Expected 17, got %d\n", size);
+            ret = (HDDEDATA)DDE_FACK;
 
-        DdeUnaccessData(hdata);
+            HeapFree(GetProcessHeap(), 0, ptr);
+        }
 
         return ret;
     }
 
     case XTYP_DISCONNECT:
     {
-        ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
+        ok(msg_index == 12, "Expected 12, got %d\n", msg_index);
         ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
         ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
         ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
@@ -846,8 +854,8 @@ static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam,
 
     case WM_DDE_ACK:
     {
-        ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
-           "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
+        ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
+           "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
 
         if (msg_index == 2)
         {
@@ -864,7 +872,7 @@ static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam,
             ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
             ok(size == 12, "Expected 12, got %d\n", size);
         }
-        else if (msg_index == 9 || msg_index == 10)
+        else if (msg_index >= 9 && msg_index <= 11)
         {
             ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
 
@@ -882,6 +890,10 @@ static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam,
             {
                 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
                 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
+            } else if (msg_index == 10)
+            {
+                ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
+                ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
             }
             else
             {
@@ -974,13 +986,13 @@ static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam,
     return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
-static HGLOBAL create_poke()
+static HGLOBAL create_poke(void)
 {
     HGLOBAL hglobal;
     DDEPOKE *poke;
     DWORD size;
 
-    size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
+    size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
     hglobal = GlobalAlloc(GMEM_DDESHARE, size);
     ok(hglobal != 0, "Expected non-NULL hglobal\n");
 
@@ -1010,7 +1022,7 @@ static HGLOBAL create_execute(LPCSTR command)
     return hglobal;
 }
 
-static void test_msg_client()
+static void test_msg_client(void)
 {
     HGLOBAL hglobal;
     LPARAM lparam;
@@ -1065,9 +1077,14 @@ static void test_msg_client()
 
     /* WM_DDE_POKE, no ddepoke */
     lparam = PackDDElParam(WM_DDE_POKE, 0, item);
-    PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
+    /* win9x returns 0 here and crashes in PostMessageA */
+    if (lparam) {
+        PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
+        flush_events();
+    }
+    else
+        win_skip("no lparam for WM_DDE_POKE\n");
 
-    flush_events();
 
     /* WM_DDE_POKE, no item */
     lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
@@ -1114,6 +1131,15 @@ static void test_msg_client()
 
     flush_events();
 
+    GlobalFree(execute_hglobal);
+    execute_hglobal = create_execute("[Command-2(Var)]");
+
+    /* WM_DDE_EXECUTE, all params correct */
+    lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
+    PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
+
+    flush_events();
+
     GlobalFree(execute_hglobal);
     execute_hglobal = create_execute("[BadCommand(Var)]");
 
@@ -1123,7 +1149,7 @@ static void test_msg_client()
 
     flush_events();
 
-    DestroyWindow(client_hwnd);
+    destroy_dde_window(&client_hwnd, "dde_client");
 }
 
 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -1162,7 +1188,7 @@ static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LP
             ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
             old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
             trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
-            SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
+            SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
         }
         else
             GlobalDeleteAtom(aService);
@@ -1186,7 +1212,6 @@ static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LP
         ack.fBusy = 0;
 
         cmd = GlobalLock((HGLOBAL)hi);
-
         if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
         {
             trace("ignoring unknown WM_DDE_EXECUTE command\n");
@@ -1319,7 +1344,7 @@ static void test_dde_aw_transaction(void)
 
     dde_inst = 0;
     ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
-    ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
+    ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04x (%x)\n",
        ret, DdeGetLastError(dde_inst));
 
     hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
@@ -1388,6 +1413,53 @@ todo_wine {
     DestroyWindow(hwnd_server);
 }
 
+static void test_initialisation(void)
+{
+    UINT ret;
+    DWORD res;
+    HDDEDATA hdata;
+    HSZ server, topic, item;
+    DWORD client_pid;
+    HCONV conversation;
+
+    /* Initialise without a valid server window. */
+    client_pid = 0;
+    ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
+    ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
+
+
+    server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
+    topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
+
+    DdeGetLastError(client_pid);
+
+    /* There is no server window so no conversation can be extracted */
+    conversation = DdeConnect(client_pid, server, topic, NULL);
+    ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
+    ret = DdeGetLastError(client_pid);
+    ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
+
+    DdeFreeStringHandle(client_pid, server);
+
+    item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
+
+    /* There is no converstation so an invalild parameter results */
+    res = 0xdeadbeef;
+    DdeGetLastError(client_pid);
+    hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
+    ret = DdeGetLastError(client_pid);
+todo_wine
+    ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
+    ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
+
+    DdeFreeStringHandle(client_pid, server);
+    ret = DdeDisconnect(conversation);
+    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
+
+    ret = DdeUninitialize(client_pid);
+    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+}
+
 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
 {
     static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
@@ -1472,41 +1544,69 @@ static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
 static void test_DdeCreateDataHandle(void)
 {
     HDDEDATA hdata;
-    DWORD dde_inst;
+    DWORD dde_inst, dde_inst2;
     DWORD size;
     UINT res, err;
     BOOL ret;
     HSZ item;
     LPBYTE ptr;
+    WCHAR item_str[] = {'i','t','e','m',0};
 
     dde_inst = 0;
+    dde_inst2 = 0;
     res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
     ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
 
+    res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
+    ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
+
+    /* 0 instance id
+     * This block tests an invalid instance Id.  The correct behaviour is that if the instance Id
+     * is invalid then the lastError of all instances is set to the error.  There are two instances
+     * created, lastError is cleared, an error is generated and then both instances are checked to
+     * ensure that they both have the same error set
+     */
+    item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
+    ok(item == NULL, "Expected NULL hsz got %p\n", item);
+    err = DdeGetLastError(dde_inst);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+    err = DdeGetLastError(dde_inst2);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+    item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
+    ok(item == NULL, "Expected NULL hsz got %p\n", item);
+    err = DdeGetLastError(dde_inst);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+    err = DdeGetLastError(dde_inst2);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+
     item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
     ok(item != NULL, "Expected non-NULL hsz\n");
+    item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
+    ok(item != NULL, "Expected non-NULL hsz\n");
 
-    /* invalid instance id */
-    DdeGetLastError(dde_inst);
-    hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
-    err = DdeGetLastError(dde_inst);
-    todo_wine
-    {
-        ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
-        ok(err == DMLERR_INVALIDPARAMETER,
-           "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+    if (0) {
+        /* do not test with an invalid instance id: that crashes on win9x */
+        hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
     }
 
-    /* 0 instance id */
+    /* 0 instance id
+     * This block tests an invalid instance Id.  The correct behaviour is that if the instance Id
+     * is invalid then the lastError of all instances is set to the error.  There are two instances
+     * created, lastError is cleared, an error is generated and then both instances are checked to
+     * ensure that they both have the same error set
+     */
     DdeGetLastError(dde_inst);
+    DdeGetLastError(dde_inst2);
     hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
     err = DdeGetLastError(dde_inst);
-    todo_wine
-    {
-        ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
-        ok(err == DMLERR_INVALIDPARAMETER,
-           "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
-    }
+    ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+    err = DdeGetLastError(dde_inst2);
+    ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
+
+    ret = DdeUninitialize(dde_inst2);
+    ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
+
 
     /* NULL pSrc */
     DdeGetLastError(dde_inst);
@@ -1515,12 +1615,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(size == 260, "Expected 260, got %d\n", size);
@@ -1538,12 +1632,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(size == 0, "Expected 0, got %d\n", size);
@@ -1561,12 +1649,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(size == 262, "Expected 262, got %d\n", size);
@@ -1588,12 +1670,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
@@ -1612,12 +1688,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
@@ -1636,12 +1706,6 @@ static void test_DdeCreateDataHandle(void)
     ok(hdata != NULL, "Expected non-NULL hdata\n");
     ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
 
-    ptr = GlobalLock(hdata);
-    todo_wine
-    {
-        ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
-    }
-
     ptr = DdeAccessData(hdata, &size);
     ok(ptr != NULL, "Expected non-NULL ptr\n");
     ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
@@ -1666,7 +1730,7 @@ static void test_DdeCreateStringHandle(void)
     ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
     {
-        trace("Skipping the DDE test on a Win9x platform\n");
+        win_skip("DdeInitializeW is unimplemented\n");
         return;
     }
 
@@ -1690,7 +1754,7 @@ static void test_FreeDDElParam(void)
     HGLOBAL val, hglobal;
     BOOL ret;
 
-    ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
+    ret = FreeDDElParam(WM_DDE_INITIATE, 0);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
@@ -1702,10 +1766,6 @@ static void test_FreeDDElParam(void)
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    val = GlobalFree(hglobal);
-    ok(val == hglobal, "Expected hglobal, got %p\n", val);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
@@ -1716,18 +1776,10 @@ static void test_FreeDDElParam(void)
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    val = GlobalFree(hglobal);
-    ok(val == hglobal, "Expected hglobal, got %p\n", val);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    val = GlobalFree(hglobal);
-    ok(val == hglobal, "Expected hglobal, got %p\n", val);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
@@ -1738,10 +1790,6 @@ static void test_FreeDDElParam(void)
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    val = GlobalFree(hglobal);
-    ok(val == hglobal, "Expected hglobal, got %p\n", val);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
     ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
@@ -1753,16 +1801,12 @@ static void test_FreeDDElParam(void)
 static void test_PackDDElParam(void)
 {
     UINT_PTR lo, hi, *ptr;
-    HGLOBAL hglobal;
     LPARAM lparam;
     BOOL ret;
 
     lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
-    ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
-    ok(GlobalLock((HGLOBAL)lparam) == NULL,
-       "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+    /* value gets sign-extended despite being an LPARAM */
+    ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
 
     lo = hi = 0;
     ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
@@ -1774,11 +1818,7 @@ static void test_PackDDElParam(void)
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
     lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
-    ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
-    ok(GlobalLock((HGLOBAL)lparam) == NULL,
-       "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+    ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
 
     lo = hi = 0;
     ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
@@ -1790,34 +1830,30 @@ static void test_PackDDElParam(void)
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
     lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
-    ptr = GlobalLock((HGLOBAL)lparam);
-    ok(ptr != NULL, "Expected non-NULL ptr\n");
-    ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
-    ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
+    /* win9x returns 0 here */
+    if (lparam) {
+        ptr = GlobalLock((HGLOBAL)lparam);
+        ok(ptr != NULL, "Expected non-NULL ptr\n");
+        ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
+        ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
 
-    ret = GlobalUnlock((HGLOBAL)lparam);
-    ok(ret == 1, "Expected 1, got %d\n", ret);
+        ret = GlobalUnlock((HGLOBAL)lparam);
+        ok(ret == 1, "Expected 1, got %d\n", ret);
 
-    lo = hi = 0;
-    ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
-    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
-    ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+        lo = hi = 0;
+        ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
+        ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+        ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
+        ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+    }
+    else
+        win_skip("no lparam for WM_DDE_ADVISE\n");
 
     ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
-    hglobal = GlobalFree((HGLOBAL)lparam);
-    ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
-
     lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
-    ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
-    ok(GlobalLock((HGLOBAL)lparam) == NULL,
-       "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+    ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
 
     lo = hi = 0;
     ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
@@ -1829,57 +1865,53 @@ static void test_PackDDElParam(void)
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
     lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
-    ptr = GlobalLock((HGLOBAL)lparam);
-    ok(ptr != NULL, "Expected non-NULL ptr\n");
-    ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
-    ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
+    /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
+    if (lparam != (int)0xbeefcafe) {
+        ptr = GlobalLock((HGLOBAL)lparam);
+        ok(ptr != NULL, "Expected non-NULL ptr\n");
+        ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
+        ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
 
-    ret = GlobalUnlock((HGLOBAL)lparam);
-    ok(ret == 1, "Expected 1, got %d\n", ret);
+        ret = GlobalUnlock((HGLOBAL)lparam);
+        ok(ret == 1, "Expected 1, got %d\n", ret);
 
-    lo = hi = 0;
-    ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
-    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
-    ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
-
-    ret = FreeDDElParam(WM_DDE_ACK, lparam);
-    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+        lo = hi = 0;
+        ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
+        ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+        ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
+        ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
 
-    hglobal = GlobalFree((HGLOBAL)lparam);
-    ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+        ret = FreeDDElParam(WM_DDE_ACK, lparam);
+        ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+    }
+    else
+        win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam);
 
     lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
-    ptr = GlobalLock((HGLOBAL)lparam);
-    ok(ptr != NULL, "Expected non-NULL ptr\n");
-    ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
-    ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
+    /* win9x returns 0 here */
+    if (lparam) {
+        ptr = GlobalLock((HGLOBAL)lparam);
+        ok(ptr != NULL, "Expected non-NULL ptr\n");
+        ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
+        ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
 
-    ret = GlobalUnlock((HGLOBAL)lparam);
-    ok(ret == 1, "Expected 1, got %d\n", ret);
+        ret = GlobalUnlock((HGLOBAL)lparam);
+        ok(ret == 1, "Expected 1, got %d\n", ret);
 
-    lo = hi = 0;
-    ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
-    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
-    ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+        lo = hi = 0;
+        ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
+        ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+        ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
+        ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+    }
+    else
+        win_skip("no lparam for WM_DDE_DATA\n");
 
     ret = FreeDDElParam(WM_DDE_DATA, lparam);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
-    hglobal = GlobalFree((HGLOBAL)lparam);
-    ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
-
     lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
-    ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
-    ok(GlobalLock((HGLOBAL)lparam) == NULL,
-       "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
+    ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
 
     lo = hi = 0;
     ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
@@ -1891,34 +1923,30 @@ static void test_PackDDElParam(void)
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
     lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
-    ptr = GlobalLock((HGLOBAL)lparam);
-    ok(ptr != NULL, "Expected non-NULL ptr\n");
-    ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
-    ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
+    /* win9x returns 0 here */
+    if (lparam) {
+        ptr = GlobalLock((HGLOBAL)lparam);
+        ok(ptr != NULL, "Expected non-NULL ptr\n");
+        ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
+        ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
 
-    ret = GlobalUnlock((HGLOBAL)lparam);
-    ok(ret == 1, "Expected 1, got %d\n", ret);
+        ret = GlobalUnlock((HGLOBAL)lparam);
+        ok(ret == 1, "Expected 1, got %d\n", ret);
 
-    lo = hi = 0;
-    ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
-    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
-    ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
-    ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+        lo = hi = 0;
+        ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
+        ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+        ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
+        ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
+    }
+    else
+        win_skip("no lparam for WM_DDE_POKE\n");
 
     ret = FreeDDElParam(WM_DDE_POKE, lparam);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
 
-    hglobal = GlobalFree((HGLOBAL)lparam);
-    ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
-
     lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
     ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
-    ok(GlobalLock((HGLOBAL)lparam) == NULL,
-       "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
-    ok(GetLastError() == ERROR_INVALID_HANDLE,
-       "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
     lo = hi = 0;
     ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
@@ -1939,7 +1967,7 @@ static void test_UnpackDDElParam(void)
     /* NULL lParam */
     lo = 0xdead;
     hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
+    ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
     ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
     ok(lo == 0, "Expected 0, got %08lx\n", lo);
     ok(hi == 0, "Expected 0, got %08lx\n", hi);
@@ -1976,17 +2004,14 @@ static void test_UnpackDDElParam(void)
 
     lo = 0xdead;
     hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
+    ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
     ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
-    ok(lo == 0, "Expected 0, got %08lx\n", lo);
-    ok(hi == 0, "Expected 0, got %08lx\n", hi);
-
-    lo = 0xdead;
-    hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
-    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
-    ok(lo == 0, "Expected 0, got %08lx\n", lo);
-    ok(hi == 0, "Expected 0, got %08lx\n", hi);
+    ok(lo == 0 ||
+       broken(lo == 0xdead), /* win2k */
+       "Expected 0, got %08lx\n", lo);
+    ok(hi == 0 ||
+       broken(hi == 0xbeef), /* win2k */
+       "Expected 0, got %08lx\n", hi);
 
     hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
     ptr = GlobalLock(hglobal);
@@ -2008,13 +2033,6 @@ static void test_UnpackDDElParam(void)
     ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
     ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
 
-    lo = 0xdead;
-    hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
-    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
-    ok(lo == 0, "Expected 0, got %08lx\n", lo);
-    ok(hi == 0, "Expected 0, got %08lx\n", hi);
-
     lo = 0xdead;
     hi = 0xbeef;
     ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
@@ -2022,13 +2040,6 @@ static void test_UnpackDDElParam(void)
     ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
     ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
 
-    lo = 0xdead;
-    hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
-    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
-    ok(lo == 0, "Expected 0, got %08lx\n", lo);
-    ok(hi == 0, "Expected 0, got %08lx\n", hi);
-
     lo = 0xdead;
     hi = 0xbeef;
     ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
@@ -2043,13 +2054,6 @@ static void test_UnpackDDElParam(void)
     ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
     ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
 
-    lo = 0xdead;
-    hi = 0xbeef;
-    ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
-    ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
-    ok(lo == 0, "Expected 0, got %08lx\n", lo);
-    ok(hi == 0, "Expected 0, got %08lx\n", hi);
-
     lo = 0xdead;
     hi = 0xbeef;
     ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
@@ -2065,6 +2069,277 @@ static void test_UnpackDDElParam(void)
     ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
 }
 
+static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
+                                               HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
+                                               ULONG_PTR dwData1, ULONG_PTR dwData2)
+{
+    DWORD size, rsize;
+    char str[MAX_PATH];
+    static int msg_index = 0;
+    static HCONV conversation = 0;
+    static char test_cmd_w_to_a[] = "test dde command";
+    static char test_cmd_a_to_a[] = "Test dde command";
+    static WCHAR test_cmd_w_to_w[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
+    static WCHAR test_cmd_a_to_w[] = {'T','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
+    static char test_service [] = "TestDDEService";
+    static char test_topic [] = "TestDDETopic";
+
+    msg_index++;
+
+    switch (uType)
+    {
+    case XTYP_REGISTER:
+    {
+        ok(msg_index == 1 || msg_index == 7 || msg_index == 13 || msg_index == 19,
+                             "Expected 1, 7, 13 or 19, got %d\n", msg_index);
+        return (HDDEDATA)TRUE;
+    }
+
+    case XTYP_CONNECT:
+    {
+        ok(msg_index == 2 || msg_index == 8 || msg_index == 14 || msg_index == 20,
+                             "Expected 2, 8, 14 or 20, got %d\n", msg_index);
+        ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
+        ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
+        ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
+        ok(dwData1 != 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
+        ok(dwData2 == FALSE, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2, msg_index);
+
+        size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
+        ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
+                             test_topic, str, msg_index);
+        ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
+
+        size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
+        ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
+                             test_service, str, msg_index);
+        ok(size == 14, "Expected 14, got %d, msg_index=%d\n", size, msg_index);
+
+        return (HDDEDATA) TRUE;
+    }
+    case XTYP_CONNECT_CONFIRM:
+    {
+        ok(msg_index == 3 || msg_index == 9  ||  msg_index == 15 ||  msg_index == 21,
+                             "Expected 3, 9, 15 or 21 got %d\n", msg_index);
+        conversation = hconv;
+        return (HDDEDATA) TRUE;
+    }
+    case XTYP_EXECUTE:
+    {
+        BYTE *buffer = NULL;
+
+        ok(msg_index == 4 || msg_index == 5 || msg_index == 10 || msg_index == 11 ||
+           msg_index == 16 || msg_index == 17 || msg_index == 22 || msg_index == 23,
+           "Expected 4, 5, 10, 11, 16, 17, 22 or 23, got %d\n", msg_index);
+        ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
+        ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
+                             hconv, msg_index);
+        ok(dwData1 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
+        ok(dwData2 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2, msg_index);
+        ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
+        size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
+        ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
+                             test_topic, str, msg_index);
+        ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
+        ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
+
+        size = DdeGetData(hdata, NULL, 0, 0);
+        if (msg_index == 10 || msg_index ==11 || msg_index == 16 || msg_index ==17)
+          if (msg_index == 10 || msg_index == 16)
+          todo_wine
+            ok(size == 34, "Expected that size should be 34 not %d, msg_index=%d\n",
+                             size, msg_index);
+          else
+            ok(size == 34, "Expected that size should be 34 not %d, msg_index=%d\n",
+                             size, msg_index);
+        else
+        if (msg_index ==22)
+            ok(size == 8 || size == 9, "Expected that size should be 8 or 9 not %d, msg_index=%d\n",
+                             size, msg_index);
+        else
+          if (msg_index == 5)
+          todo_wine
+            ok(size == 17, "Expected that size should be 17 not %d, msg_index=%d\n",
+                             size, msg_index);
+          else
+            ok(size == 17, "Expected that size should be 17 not %d, msg_index=%d\n",
+                             size, msg_index);
+        ok((buffer = HeapAlloc(GetProcessHeap(), 0, size)) != NULL, "should not be null\n");
+        rsize = DdeGetData(hdata, buffer, size, 0);
+        if (msg_index == 10 || msg_index == 11 || msg_index == 16 || msg_index ==17)
+        {
+            ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
+                             size, rsize, msg_index);
+          if (msg_index == 10 || msg_index == 16)
+          todo_wine {
+            ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
+                             "Expected \"Test dde command\", msg_index=%d\n",
+                             msg_index);
+            ok(size == 34, "Expected 34, got %d, msg_index=%d\n", size, msg_index);
+          } else
+          {
+            ok(!lstrcmpW((WCHAR*)buffer, test_cmd_w_to_w),
+                             "Expected \"test dde command\", msg_index=%d\n",
+                             msg_index);
+            ok(size == 34, "Expected 34, got %d, msg_index=%d\n", size, msg_index);
+          }
+        }else if (msg_index == 22)
+        {
+            ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
+                             size, rsize, msg_index);
+        } else
+        {
+            ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
+                             size, rsize, msg_index);
+          if (msg_index == 5)
+          todo_wine {
+            ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
+                             test_cmd_w_to_a, buffer, msg_index);
+            ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
+          }
+          else if (msg_index == 23)
+          {
+            ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
+                             test_cmd_w_to_a, buffer, msg_index);
+            ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
+          }
+            else
+            {
+              ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
+                               test_cmd_a_to_a, buffer, msg_index);
+              ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
+            }
+
+        }
+
+        return (HDDEDATA) DDE_FACK;
+    }
+    case XTYP_DISCONNECT:
+        return (HDDEDATA) TRUE;
+
+    default:
+        ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
+    }
+
+    return NULL;
+}
+
+static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
+                                               HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
+                                               ULONG_PTR dwData1, ULONG_PTR dwData2)
+{
+    switch (uType)
+    {
+    case XTYP_DISCONNECT:
+        return (HDDEDATA) TRUE;
+
+    default:
+        ok(FALSE, "Unhandled msg: %08x\n", uType);
+    }
+
+    return NULL;
+}
+
+static void test_end_to_end_client(BOOL type_a)
+{
+    DWORD  ret, err;
+    DWORD client_pid = 0;
+    HSZ server, topic;
+    HCONV hconv;
+    HDDEDATA hdata;
+    static char test_cmd[] = "Test dde command";
+    static WCHAR test_cmd_w[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
+    static char test_service[] = "TestDDEService";
+    static WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
+    static char test_topic[] = "TestDDETopic";
+    static WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
+
+    trace("Start end to end client %s\n", type_a ? "ASCII" : "UNICODE");
+
+    if (type_a)
+        ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
+    else
+        ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
+    ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
+
+    if (type_a)
+    {
+        server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
+        topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
+    }
+    else {
+        server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
+        topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
+    }
+
+    DdeGetLastError(client_pid);
+    hconv = DdeConnect(client_pid, server, topic, NULL);
+    ok(hconv != NULL, "Expected non-NULL conversation\n");
+    ret = DdeGetLastError(client_pid);
+    ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
+    DdeFreeStringHandle(client_pid, server);
+
+    /* Test both A and W data being passed to DdeClientTransaction */
+    hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1,
+            hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
+    ok(hdata != NULL, "DdeClientTransaction failed\n");
+    ok(ret == DDE_FACK, "wrong status code %x\n", ret);
+    err = DdeGetLastError(client_pid);
+    ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
+
+    hdata = DdeClientTransaction((LPBYTE)test_cmd_w, lstrlenW(test_cmd_w) * sizeof(WCHAR) + 2,
+            hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
+    ok(hdata != NULL, "DdeClientTransaction failed\n");
+    ok(ret == DDE_FACK, "wrong status code %x\n", ret);
+    err = DdeGetLastError(client_pid);
+    ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
+
+    DdeFreeStringHandle(client_pid, topic);
+    ret = DdeDisconnect(hconv);
+    ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
+
+    ret = DdeUninitialize(client_pid);
+    ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
+
+}
+
+static void test_end_to_end_server(HANDLE hproc, HANDLE hthread, BOOL type_a)
+{
+    MSG msg;
+    HSZ server;
+    BOOL ret;
+    DWORD res;
+    HDDEDATA hdata;
+    static CHAR test_service[] = "TestDDEService";
+
+    trace("start end to end server %s\n", type_a ? "ASCII" : "UNICODE");
+    server_pid = 0;
+
+    if (type_a)
+        res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
+    else
+        res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
+    ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
+
+    server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
+    ok(server != NULL, "Expected non-NULL string handle\n");
+
+    hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
+    ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
+    ResumeThread( hthread );
+
+
+    while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
+    {
+        while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    }
+
+    ret = DdeUninitialize(server_pid);
+    ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
+    GetExitCodeProcess( hproc, &res );
+    ok( !res, "client failed with %u error(s)\n", res );
+}
+
 START_TEST(dde)
 {
     int argc;
@@ -2080,10 +2355,16 @@ START_TEST(dde)
             test_ddeml_client();
         else if (!lstrcmpA(argv[2], "msg"))
             test_msg_client();
+        else if (!lstrcmpA(argv[2], "enda"))
+            test_end_to_end_client(TRUE);
+        else if (!lstrcmpA(argv[2], "endw"))
+            test_end_to_end_client(FALSE);
 
         return;
     }
 
+    test_initialisation();
+
     ZeroMemory(&startup, sizeof(STARTUPINFO));
     sprintf(buffer, "%s dde ddeml", argv[0]);
     startup.cb = sizeof(startup);
@@ -2091,9 +2372,9 @@ START_TEST(dde)
     startup.wShowWindow = SW_SHOWNORMAL;
 
     CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
-                   0, NULL, NULL, &startup, &proc);
+                   CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
 
-    test_msg_server(proc.hProcess);
+    test_msg_server(proc.hProcess, proc.hThread);
 
     sprintf(buffer, "%s dde msg", argv[0]);
     CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
@@ -2101,6 +2382,42 @@ START_TEST(dde)
 
     test_ddeml_server(proc.hProcess);
 
+    /* Test the combinations of A and W interfaces with A and W data
+       end to end to ensure that data conversions are accurate */
+    sprintf(buffer, "%s dde enda", argv[0]);
+    CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
+                   CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
+
+    test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
+
+    /* Don't bother testing W interfaces on Win9x/WinMe */
+    SetLastError(0xdeadbeef);
+    lstrcmpW(NULL, NULL);
+    if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
+    {
+        win_skip("Skipping W-interface tests\n");
+    }
+    else
+    {
+        sprintf(buffer, "%s dde endw", argv[0]);
+        CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
+                       CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
+
+        test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
+
+        sprintf(buffer, "%s dde enda", argv[0]);
+        CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
+                       CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
+
+        test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
+
+        sprintf(buffer, "%s dde endw", argv[0]);
+        CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
+                       CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
+
+        test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
+    }
+
     test_dde_aw_transaction();
 
     test_DdeCreateDataHandle();