oleaut32: Do no check for dispatchable flag on dual interfaces.
[wine] / dlls / shell32 / tests / progman_dde.c
1 /*
2  * Unit test of the Program Manager DDE Interfaces
3  *
4  * Copyright 2009 Mikey Alexander
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /* DDE Program Manager Tests
22  * - Covers basic CreateGroup, ShowGroup, DeleteGroup, AddItem, and DeleteItem
23  *   functionality
24  * - Todo: Handle CommonGroupFlag
25  *         Handle Difference between administrator and non-administrator calls
26  *           as documented
27  *         Better AddItem Tests (Lots of parameters to test)
28  *         Tests for Invalid Characters in Names / Invalid Parameters
29  */
30
31 #include <stdio.h>
32 #include <wine/test.h>
33 #include <winbase.h>
34 #include "dde.h"
35 #include "ddeml.h"
36 #include "winuser.h"
37 #include "shlobj.h"
38
39 /* Timeout on DdeClientTransaction Call */
40 #define MS_TIMEOUT_VAL 1000
41 /* # of times to poll for window creation */
42 #define PDDE_POLL_NUM 50
43 /* time to sleep between polls */
44 #define PDDE_POLL_TIME 200
45
46 /* Call Info */
47 #define DDE_TEST_MISC            0x00010000
48 #define DDE_TEST_CREATEGROUP     0x00020000
49 #define DDE_TEST_DELETEGROUP     0x00030000
50 #define DDE_TEST_SHOWGROUP       0x00040000
51 #define DDE_TEST_ADDITEM         0x00050000
52 #define DDE_TEST_DELETEITEM      0x00060000
53 #define DDE_TEST_COMPOUND        0x00070000
54 #define DDE_TEST_CALLMASK        0x00ff0000
55
56 /* Type of Test (Common, Individual) */
57 #define DDE_TEST_COMMON            0x01000000
58 #define DDE_TEST_INDIVIDUAL        0x02000000
59
60 #define DDE_TEST_NUMMASK           0x0000ffff
61
62 static HDDEDATA CALLBACK DdeCallback(UINT type, UINT format, HCONV hConv, HSZ hsz1, HSZ hsz2,
63                                      HDDEDATA hDDEData, ULONG_PTR data1, ULONG_PTR data2)
64 {
65     trace("Callback: type=%i, format=%i\n", type, format);
66     return NULL;
67 }
68
69 /*
70  * Encoded String for Error Messages so that inner failures can determine
71  * what test is failing.  Format is: [Code:TestNum]
72  */
73 static const char * GetStringFromTestParams(int testParams)
74 {
75     int testNum;
76     static char testParamString[64];
77     const char *callId;
78
79     testNum = testParams & DDE_TEST_NUMMASK;
80     switch (testParams & DDE_TEST_CALLMASK)
81     {
82     default:
83     case DDE_TEST_MISC:
84         callId = "MISC";
85         break;
86     case DDE_TEST_CREATEGROUP:
87         callId = "C_G";
88         break;
89     case DDE_TEST_DELETEGROUP:
90         callId = "D_G";
91         break;
92     case DDE_TEST_SHOWGROUP:
93         callId = "S_G";
94         break;
95     case DDE_TEST_ADDITEM:
96         callId = "A_I";
97         break;
98     case DDE_TEST_DELETEITEM:
99         callId = "D_I";
100         break;
101     case DDE_TEST_COMPOUND:
102         callId = "CPD";
103         break;
104     }
105
106     sprintf(testParamString, "  [%s:%i]", callId, testNum);
107     return testParamString;
108 }
109
110 /* Transfer DMLERR's into text readable strings for Error Messages */
111 #define DMLERR_TO_STR(x) case x: return#x;
112 static const char * GetStringFromError(UINT err)
113 {
114     const char * retstr;
115     switch (err)
116     {
117     DMLERR_TO_STR(DMLERR_NO_ERROR);
118     DMLERR_TO_STR(DMLERR_ADVACKTIMEOUT);
119     DMLERR_TO_STR(DMLERR_BUSY);
120     DMLERR_TO_STR(DMLERR_DATAACKTIMEOUT);
121     DMLERR_TO_STR(DMLERR_DLL_NOT_INITIALIZED);
122     DMLERR_TO_STR(DMLERR_DLL_USAGE);
123     DMLERR_TO_STR(DMLERR_EXECACKTIMEOUT);
124     DMLERR_TO_STR(DMLERR_INVALIDPARAMETER);
125     DMLERR_TO_STR(DMLERR_LOW_MEMORY);
126     DMLERR_TO_STR(DMLERR_MEMORY_ERROR);
127     DMLERR_TO_STR(DMLERR_NOTPROCESSED);
128     DMLERR_TO_STR(DMLERR_NO_CONV_ESTABLISHED);
129     DMLERR_TO_STR(DMLERR_POKEACKTIMEOUT);
130     DMLERR_TO_STR(DMLERR_POSTMSG_FAILED);
131     DMLERR_TO_STR(DMLERR_REENTRANCY);
132     DMLERR_TO_STR(DMLERR_SERVER_DIED);
133     DMLERR_TO_STR(DMLERR_SYS_ERROR);
134     DMLERR_TO_STR(DMLERR_UNADVACKTIMEOUT);
135     DMLERR_TO_STR(DMLERR_UNFOUND_QUEUE_ID);
136     default:
137         retstr = "Unknown DML Error";
138         break;
139     }
140
141     return retstr;
142 }
143
144 /* Helper Function to Transfer DdeGetLastError into a String */
145 static const char * GetDdeLastErrorStr(DWORD instance)
146 {
147     UINT err = DdeGetLastError(instance);
148
149     return GetStringFromError(err);
150 }
151
152 /* Execute a Dde Command and return the error & result */
153 /* Note: Progman DDE always returns a pointer to 0x00000001 on a successful result */
154 static void DdeExecuteCommand(DWORD instance, HCONV hConv, const char *strCmd, HDDEDATA *hData, UINT *err, int testParams)
155 {
156     HDDEDATA command;
157
158     command = DdeCreateDataHandle(instance, (LPBYTE) strCmd, strlen(strCmd)+1, 0, 0L, 0, 0);
159     ok (command != NULL, "DdeCreateDataHandle Error %s.%s\n",
160         GetDdeLastErrorStr(instance), GetStringFromTestParams(testParams));
161     *hData = DdeClientTransaction((void *) command,
162                                   -1,
163                                   hConv,
164                                   0,
165                                   0,
166                                   XTYP_EXECUTE,
167                                   MS_TIMEOUT_VAL,
168                                   NULL);
169
170     /* hData is technically a pointer, but for Program Manager,
171      * it is NULL (error) or 1 (success)
172      * TODO: Check other versions of Windows to verify 1 is returned.
173      * While it is unlikely that anyone is actually testing that the result is 1
174      * if all versions of windows return 1, Wine should also.
175      */
176     if (*hData == NULL)
177     {
178         *err = DdeGetLastError(instance);
179     }
180     else
181     {
182         *err = DMLERR_NO_ERROR;
183         todo_wine
184         {
185             ok(*hData == (HDDEDATA) 1, "Expected HDDEDATA Handle == 1, actually %p.%s\n",
186                *hData, GetStringFromTestParams(testParams));
187         }
188     }
189 }
190
191 /*
192  * Check if Window is onscreen with the appropriate name.
193  *
194  * Windows are not created synchronously.  So we do not know
195  * when and if the window will be created/shown on screen.
196  * This function implements a polling mechanism to determine
197  * creation.
198  * A more complicated method would be to use SetWindowsHookEx.
199  * Since polling worked fine in my testing, no reason to implement
200  * the other.  Comments about other methods of determining when
201  * window creation happened were not encouraging (not including
202  * SetWindowsHookEx).
203  */
204 static void CheckWindowCreated(const char *winName, int closeWindow, int testParams)
205 {
206     HWND window = NULL;
207     int i;
208
209     /* Poll for Window Creation */
210     for (i = 0; window == NULL && i < PDDE_POLL_NUM; i++)
211     {
212         Sleep(PDDE_POLL_TIME);
213         window = FindWindowA(NULL, winName);
214     }
215     ok (window != NULL, "Window \"%s\" was not created in %i seconds - assumed failure.%s\n",
216         winName, PDDE_POLL_NUM*PDDE_POLL_TIME/1000, GetStringFromTestParams(testParams));
217
218     /* Close Window as desired. */
219     if (window != NULL && closeWindow)
220     {
221         SendMessageA(window, WM_SYSCOMMAND, SC_CLOSE, 0);
222     }
223 }
224
225 /* Check for Existence (or non-existence) of a file or group
226  *   When testing for existence of a group, groupName is not needed
227  */
228 static void CheckFileExistsInProgramGroups(const char *nameToCheck, int shouldExist, int isGroup,
229                                            const char *groupName, int testParams)
230 {
231     char *path;
232     int err;
233     DWORD attributes;
234     int len;
235
236     path = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
237     if (path != NULL)
238     {
239         int specialFolder;
240
241         err = FALSE;
242         /* Win 9x doesn't support common */
243         if (testParams & DDE_TEST_COMMON)
244         {
245             specialFolder = CSIDL_COMMON_PROGRAMS;
246             err = SHGetSpecialFolderPath(NULL, path, specialFolder, FALSE);
247             /* Win 9x fails, use CSIDL_PROGRAMS (err == FALSE) */
248         }
249         if (err == FALSE)
250         {
251             specialFolder = CSIDL_PROGRAMS;
252             err = SHGetSpecialFolderPath(NULL, path, specialFolder, FALSE);
253         }
254         len = strlen(path) + strlen(nameToCheck)+1;
255         if (groupName != NULL)
256         {
257             len += strlen(groupName)+1;
258         }
259         ok (len <= MAX_PATH, "Path Too Long.%s\n", GetStringFromTestParams(testParams));
260         if (len <= MAX_PATH)
261         {
262             if (groupName != NULL)
263             {
264                 strcat(path, "\\");
265                 strcat(path, groupName);
266             }
267             strcat(path, "\\");
268             strcat(path, nameToCheck);
269             attributes = GetFileAttributes(path);
270             if (!shouldExist)
271             {
272                 ok (attributes == INVALID_FILE_ATTRIBUTES , "File exists and shouldn't %s.%s\n",
273                     path, GetStringFromTestParams(testParams));
274             } else {
275                 if (attributes == INVALID_FILE_ATTRIBUTES)
276                 {
277                     ok (FALSE, "Created File %s doesn't exist.%s\n", path, GetStringFromTestParams(testParams));
278                 } else if (isGroup) {
279                     ok (attributes & FILE_ATTRIBUTE_DIRECTORY, "%s is not a folder (attr=%x).%s\n",
280                         path, attributes, GetStringFromTestParams(testParams));
281                 } else {
282                     ok (attributes & FILE_ATTRIBUTE_ARCHIVE, "Created File %s has wrong attributes (%x).%s\n",
283                         path, attributes, GetStringFromTestParams(testParams));
284                 }
285             }
286         }
287         HeapFree(GetProcessHeap(), 0, path);
288     }
289     else
290     {
291         ok (FALSE, "Could not Allocate Path Buffer\n");
292     }
293 }
294
295 /* Create Group Test.
296  *   command and expected_result.
297  *   if expected_result is DMLERR_NO_ERROR, test
298  *        1. group was created
299  *        2. window is open
300  */
301 static void CreateGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
302                             const char *groupName, int testParams)
303 {
304     HDDEDATA hData;
305     UINT error;
306
307     /* Execute Command & Check Result */
308     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
309     todo_wine
310     {
311         ok (expected_result == error, "CreateGroup %s: Expected Error %s, received %s.%s\n",
312             groupName, GetStringFromError(expected_result), GetStringFromError(error),
313             GetStringFromTestParams(testParams));
314     }
315
316     /* No Error */
317     if (error == DMLERR_NO_ERROR)
318     {
319
320         /* Check if Group Now Exists */
321         CheckFileExistsInProgramGroups(groupName, TRUE, TRUE, NULL, testParams);
322         /* Check if Window is Open (polling) */
323         CheckWindowCreated(groupName, TRUE, testParams);
324     }
325 }
326
327 /* Show Group Test.
328  *   DDE command, expected_result, and the group name to check for existence
329  *   if expected_result is DMLERR_NO_ERROR, test
330  *        1. window is open
331  */
332 static void ShowGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
333                           const char *groupName, int closeAfterShowing, int testParams)
334 {
335     HDDEDATA hData;
336     UINT error;
337
338     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
339 /* todo_wine...  Is expected to fail, wine stubbed functions DO fail */
340 /* TODO REMOVE THIS CODE!!! */
341     if (expected_result == DMLERR_NOTPROCESSED)
342     {
343         ok (expected_result == error, "ShowGroup %s: Expected Error %s, received %s.%s\n",
344             groupName, GetStringFromError(expected_result), GetStringFromError(error),
345             GetStringFromTestParams(testParams));
346     } else {
347         todo_wine
348         {
349             ok (expected_result == error, "ShowGroup %s: Expected Error %s, received %s.%s\n",
350                 groupName, GetStringFromError(expected_result), GetStringFromError(error),
351                 GetStringFromTestParams(testParams));
352         }
353     }
354
355     if (error == DMLERR_NO_ERROR)
356     {
357         /* Check if Window is Open (polling) */
358         CheckWindowCreated(groupName, closeAfterShowing, testParams);
359     }
360 }
361
362 /* Delete Group Test.
363  *   DDE command, expected_result, and the group name to check for existence
364  *   if expected_result is DMLERR_NO_ERROR, test
365  *        1. group does not exist
366  */
367 static void DeleteGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
368                             const char *groupName, int testParams)
369 {
370     HDDEDATA hData;
371     UINT error;
372
373     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
374     todo_wine
375     {
376         ok (expected_result == error, "DeleteGroup %s: Expected Error %s, received %s.%s\n",
377             groupName, GetStringFromError(expected_result), GetStringFromError(error),
378             GetStringFromTestParams(testParams));
379     }
380
381     if (error == DMLERR_NO_ERROR)
382     {
383         /* Check that Group does not exist */
384         CheckFileExistsInProgramGroups(groupName, FALSE, TRUE, NULL, testParams);
385     }
386 }
387
388 /* Add Item Test
389  *   DDE command, expected result, and group and file name where it should exist.
390  *   checks to make sure error code matches expected error code
391  *   checks to make sure item exists if successful
392  */
393 static void AddItemTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
394                         const char *fileName, const char *groupName, int testParams)
395 {
396     HDDEDATA hData;
397     UINT error;
398
399     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
400     todo_wine
401     {
402         ok (expected_result == error, "AddItem %s: Expected Error %s, received %s.%s\n",
403             fileName, GetStringFromError(expected_result), GetStringFromError(error),
404             GetStringFromTestParams(testParams));
405     }
406
407     if (error == DMLERR_NO_ERROR)
408     {
409         /* Check that File exists */
410         CheckFileExistsInProgramGroups(fileName, TRUE, FALSE, groupName, testParams);
411     }
412 }
413
414 /* Delete Item Test.
415  *   DDE command, expected result, and group and file name where it should exist.
416  *   checks to make sure error code matches expected error code
417  *   checks to make sure item does not exist if successful
418  */
419 static void DeleteItemTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
420                            const char *fileName, const char *groupName, int testParams)
421 {
422     HDDEDATA hData;
423     UINT error;
424
425     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
426     todo_wine
427     {
428         ok (expected_result == error, "DeleteItem %s: Expected Error %s, received %s.%s\n",
429             fileName, GetStringFromError(expected_result), GetStringFromError(error),
430             GetStringFromTestParams(testParams));
431     }
432
433     if (error == DMLERR_NO_ERROR)
434     {
435         /* Check that File does not exist */
436         CheckFileExistsInProgramGroups(fileName, FALSE, FALSE, groupName, testParams);
437     }
438 }
439
440 /* Compound Command Test.
441  *   not really generic, assumes command of the form:
442  *          [CreateGroup ...][AddItem ...][AddItem ...]
443  *   All samples I've seen using Compound were of this form (CreateGroup,
444  *   AddItems) so this covers minimum expected functionality.
445  */
446 static void CompoundCommandTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
447                                 const char *groupName, const char *fileName1,
448                                 const char *fileName2, int testParams)
449 {
450     HDDEDATA hData;
451     UINT error;
452
453     DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
454     todo_wine
455     {
456         ok (expected_result == error, "Compound String %s: Expected Error %s, received %s.%s\n",
457             command, GetStringFromError(expected_result), GetStringFromError(error),
458             GetStringFromTestParams(testParams));
459     }
460
461     if (error == DMLERR_NO_ERROR)
462     {
463         /* Check that File exists */
464         CheckFileExistsInProgramGroups(groupName, TRUE, TRUE, NULL, testParams);
465         CheckWindowCreated(groupName, FALSE, testParams);
466         CheckFileExistsInProgramGroups(fileName1, TRUE, FALSE, groupName, testParams);
467         CheckFileExistsInProgramGroups(fileName2, TRUE, FALSE, groupName, testParams);
468     }
469 }
470
471 /* 1st set of tests */
472 static int DdeTestProgman(DWORD instance, HCONV hConv)
473 {
474     HDDEDATA hData;
475     UINT error;
476     int testnum;
477
478     testnum = 1;
479     /* Invalid Command */
480     DdeExecuteCommand(instance, hConv, "[InvalidCommand()]", &hData, &error, DDE_TEST_MISC|testnum++);
481     ok (error == DMLERR_NOTPROCESSED, "InvalidCommand(), expected error %s, received %s.\n",
482         GetStringFromError(DMLERR_NOTPROCESSED), GetStringFromError(error));
483
484     /* CreateGroup Tests (including AddItem, DeleteItem) */
485     CreateGroupTest(instance, hConv, "[CreateGroup(Group1)]", DMLERR_NO_ERROR, "Group1", DDE_TEST_COMMON|DDE_TEST_CREATEGROUP|testnum++);
486     AddItemTest(instance, hConv, "[AddItem(c:\\f1g1,f1g1Name)]", DMLERR_NO_ERROR, "f1g1Name.lnk", "Group1", DDE_TEST_COMMON|DDE_TEST_ADDITEM|testnum++);
487     AddItemTest(instance, hConv, "[AddItem(c:\\f2g1,f2g1Name)]", DMLERR_NO_ERROR, "f2g1Name.lnk", "Group1", DDE_TEST_COMMON|DDE_TEST_ADDITEM|testnum++);
488     DeleteItemTest(instance, hConv, "[DeleteItem(f2g1Name)]", DMLERR_NO_ERROR, "f2g1Name.lnk", "Group1", DDE_TEST_COMMON|DDE_TEST_DELETEITEM|testnum++);
489     AddItemTest(instance, hConv, "[AddItem(c:\\f3g1,f3g1Name)]", DMLERR_NO_ERROR, "f3g1Name.lnk", "Group1", DDE_TEST_COMMON|DDE_TEST_ADDITEM|testnum++);
490     CreateGroupTest(instance, hConv, "[CreateGroup(Group2)]", DMLERR_NO_ERROR, "Group2", DDE_TEST_COMMON|DDE_TEST_CREATEGROUP|testnum++);
491     /* Create Group that already exists - same instance */
492     CreateGroupTest(instance, hConv, "[CreateGroup(Group1)]", DMLERR_NO_ERROR, "Group1", DDE_TEST_COMMON|DDE_TEST_CREATEGROUP|testnum++);
493
494     /* ShowGroup Tests */
495     ShowGroupTest(instance, hConv, "[ShowGroup(Group1)]", DMLERR_NOTPROCESSED, "Startup", TRUE, DDE_TEST_SHOWGROUP|testnum++);
496     DeleteItemTest(instance, hConv, "[DeleteItem(f3g1Name)]", DMLERR_NO_ERROR, "f3g1Name.lnk", "Group1", DDE_TEST_COMMON|DDE_TEST_DELETEITEM|testnum++);
497     ShowGroupTest(instance, hConv, "[ShowGroup(Startup,0)]", DMLERR_NO_ERROR, "Startup", TRUE, DDE_TEST_SHOWGROUP|testnum++);
498     ShowGroupTest(instance, hConv, "[ShowGroup(Group1,0)]", DMLERR_NO_ERROR, "Group1", FALSE, DDE_TEST_SHOWGROUP|testnum++);
499
500     /* DeleteGroup Test - Note that Window is Open for this test */
501     DeleteGroupTest(instance, hConv, "[DeleteGroup(Group1)]", DMLERR_NO_ERROR, "Group1", DDE_TEST_DELETEGROUP|testnum++);
502
503     /* Compound Execute String Command */
504     CompoundCommandTest(instance, hConv, "[CreateGroup(Group3)][AddItem(c:\\f1g3,f1g3Name)][AddItem(c:\\f2g3,f2g3Name)]", DMLERR_NO_ERROR, "Group3", "f1g3Name.lnk", "f2g3Name.lnk", DDE_TEST_COMMON|DDE_TEST_COMPOUND|testnum++);
505     DeleteGroupTest(instance, hConv, "[DeleteGroup(Group3)]", DMLERR_NO_ERROR, "Group3", DDE_TEST_DELETEGROUP|testnum++);
506
507     /* Full Parameters of Add Item */
508     /* AddItem(CmdLine[,Name[,IconPath[,IconIndex[,xPos,yPos[,DefDir[,HotKey[,fMinimize[fSeparateSpace]]]]]]]) */
509
510     return testnum;
511 }
512
513 /* 2nd set of tests - 2nd connection */
514 static void DdeTestProgman2(DWORD instance, HCONV hConv, int testnum)
515 {
516     /* Create Group that already exists on a separate connection */
517     CreateGroupTest(instance, hConv, "[CreateGroup(Group2)]", DMLERR_NO_ERROR, "Group2", DDE_TEST_COMMON|DDE_TEST_CREATEGROUP|testnum++);
518     DeleteGroupTest(instance, hConv, "[DeleteGroup(Group2)]", DMLERR_NO_ERROR, "Group2", DDE_TEST_COMMON|DDE_TEST_DELETEGROUP|testnum++);
519 }
520
521 START_TEST(progman_dde)
522 {
523     DWORD instance = 0;
524     UINT err;
525     HSZ hszProgman;
526     HCONV hConv;
527     int testnum;
528
529     /* Initialize DDE Instance */
530     err = DdeInitialize(&instance, DdeCallback, APPCMD_CLIENTONLY, 0);
531     ok (err == DMLERR_NO_ERROR, "DdeInitialize Error %s\n", GetStringFromError(err));
532
533     /* Create Connection */
534     hszProgman = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
535     ok (hszProgman != NULL, "DdeCreateStringHandle Error %s\n", GetDdeLastErrorStr(instance));
536     hConv = DdeConnect(instance, hszProgman, hszProgman, NULL);
537     ok (hConv != NULL, "DdeConnect Error %s\n", GetDdeLastErrorStr(instance));
538     ok (DdeFreeStringHandle(instance, hszProgman), "DdeFreeStringHandle failure\n");
539
540     /* Run Tests */
541     testnum = DdeTestProgman(instance, hConv);
542
543     /* Cleanup & Exit */
544     ok (DdeDisconnect(hConv), "DdeDisonnect Error %s\n", GetDdeLastErrorStr(instance));
545     ok (DdeUninitialize(instance), "DdeUninitialize failed\n");
546
547     /* 2nd Instance (Followup Tests) */
548     /* Initialize DDE Instance */
549     instance = 0;
550     err = DdeInitialize(&instance, DdeCallback, APPCMD_CLIENTONLY, 0);
551     ok (err == DMLERR_NO_ERROR, "DdeInitialize Error %s\n", GetStringFromError(err));
552
553     /* Create Connection */
554     hszProgman = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
555     ok (hszProgman != NULL, "DdeCreateStringHandle Error %s\n", GetDdeLastErrorStr(instance));
556     hConv = DdeConnect(instance, hszProgman, hszProgman, NULL);
557     ok (hConv != NULL, "DdeConnect Error %s\n", GetDdeLastErrorStr(instance));
558     ok (DdeFreeStringHandle(instance, hszProgman), "DdeFreeStringHandle failure\n");
559
560     /* Run Tests */
561     DdeTestProgman2(instance, hConv, testnum);
562
563     /* Cleanup & Exit */
564     ok (DdeDisconnect(hConv), "DdeDisonnect Error %s\n", GetDdeLastErrorStr(instance));
565     ok (DdeUninitialize(instance), "DdeUninitialize failed\n");
566 }