1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*
 * PROJECT:     ReactOS API tests
 * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
 * PURPOSE:     Test for IShellFolderViewCB
 * COPYRIGHT:   Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
 */

#include "shelltest.h"
#include <atlsimpcoll.h>
#include <stdio.h>
#include <shellutils.h>
//#include <msgtrace.h>

static DWORD g_WinVersion;
#define WINVER_VISTA   0x0600

#ifndef SFVM_SELECTIONCHANGED
#define SFVM_SELECTIONCHANGED          8 /* undocumented */
#define SFVM_DRAWMENUITEM              9 /* undocumented */
#define SFVM_MEASUREMENUITEM          10 /* undocumented */
#define SFVM_EXITMENULOOP             11 /* undocumented */
#define SFVM_VIEWRELEASE              12 /* undocumented */
#define SFVM_GETNAMELENGTH            13 /* undocumented */
#define SFVM_WINDOWCLOSING            16 /* undocumented */
#define SFVM_LISTREFRESHED            17 /* undocumented */
#define SFVM_WINDOWFOCUSED            18 /* undocumented */
#define SFVM_REGISTERCOPYHOOK         20 /* undocumented */
#define SFVM_COPYHOOKCALLBACK         21 /* undocumented */
#define SFVM_UNMERGEFROMMENU          28 /* undocumented */
#define SFVM_ADDINGOBJECT             29 /* undocumented */
#define SFVM_REMOVINGOBJECT           30 /* undocumented */
#define SFVM_GETCOMMANDDIR            33 /* undocumented */
#define SFVM_GETCOLUMNSTREAM          34 /* undocumented */
#define SFVM_CANSELECTALL             35 /* undocumented */
#define SFVM_ISSTRICTREFRESH          37 /* undocumented */
#define SFVM_ISCHILDOBJECT            38 /* undocumented */
#define SFVM_GETEXTVIEWS              40 /* undocumented */
#define SFVM_GET_CUSTOMVIEWINFO       77 /* undocumented */
#define SFVM_ENUMERATEDITEMS          79 /* undocumented */
#define SFVM_GET_VIEW_DATA            80 /* undocumented */
#define SFVM_GET_WEBVIEW_LAYOUT       82 /* undocumented */
#define SFVM_GET_WEBVIEW_CONTENT      83 /* undocumented */
#define SFVM_GET_WEBVIEW_TASKS        84 /* undocumented */
#define SFVM_GET_WEBVIEW_THEME        86 /* undocumented */
#define SFVM_GETDEFERREDVIEWSETTINGS  92 /* undocumented */
#endif

#define DUM_MSG_GetWindow               400
#define DUM_MSG_ContextSensitiveHelp    401
#define DUM_MSG_InsertMenusSB           402
#define DUM_MSG_SetMenuSB               403
#define DUM_MSG_RemoveMenusSB           404
#define DUM_MSG_SetStatusTextSB         405
#define DUM_MSG_EnableModelessSB        406
#define DUM_MSG_TranslateAcceleratorSB  407
#define DUM_MSG_BrowseObject            408
#define DUM_MSG_GetViewStateStream      409
#define DUM_MSG_GetControlWindow        410
#define DUM_MSG_SendControlMsg          411
#define DUM_MSG_QueryActiveShellView    412
#define DUM_MSG_OnViewWindowActive      413
#define DUM_MSG_SetToolbarItems         414


const char* msg2str(UINT uMsg)
{
    static char buf[2][50];
    static int index = 0;
    index ^= 1;

    switch (uMsg)
    {
    case SFVM_MERGEMENU: return "SFVM_MERGEMENU";
    case SFVM_INVOKECOMMAND: return "SFVM_INVOKECOMMAND";
    case SFVM_GETHELPTEXT: return "SFVM_GETHELPTEXT";
    case SFVM_GETTOOLTIPTEXT: return "SFVM_GETTOOLTIPTEXT";
    case SFVM_GETBUTTONINFO: return "SFVM_GETBUTTONINFO";
    case SFVM_GETBUTTONS: return "SFVM_GETBUTTONS";
    case SFVM_INITMENUPOPUP: return "SFVM_INITMENUPOPUP";
    case SFVM_SELECTIONCHANGED: return "SFVM_SELECTIONCHANGED";
    case SFVM_DRAWMENUITEM: return "SFVM_DRAWMENUITEM";
    case SFVM_MEASUREMENUITEM: return "SFVM_MEASUREMENUITEM";
    case SFVM_EXITMENULOOP: return "SFVM_EXITMENULOOP";
    case SFVM_VIEWRELEASE: return "SFVM_VIEWRELEASE";
    case SFVM_GETNAMELENGTH: return "SFVM_GETNAMELENGTH";
    case SFVM_FSNOTIFY: return "SFVM_FSNOTIFY";
    case SFVM_WINDOWCREATED: return "SFVM_WINDOWCREATED";
    case SFVM_WINDOWCLOSING: return "SFVM_WINDOWCLOSING";
    case SFVM_LISTREFRESHED: return "SFVM_LISTREFRESHED";
    case SFVM_WINDOWFOCUSED: return "SFVM_WINDOWFOCUSED";
    case SFVM_REGISTERCOPYHOOK: return "SFVM_REGISTERCOPYHOOK";
    case SFVM_COPYHOOKCALLBACK: return "SFVM_COPYHOOKCALLBACK";
    case SFVM_GETDETAILSOF: return "SFVM_GETDETAILSOF";
    case SFVM_COLUMNCLICK: return "SFVM_COLUMNCLICK";
    case SFVM_QUERYFSNOTIFY: return "SFVM_QUERYFSNOTIFY";
    case SFVM_DEFITEMCOUNT: return "SFVM_DEFITEMCOUNT";
    case SFVM_DEFVIEWMODE: return "SFVM_DEFVIEWMODE";
    case SFVM_UNMERGEFROMMENU: return "SFVM_UNMERGEFROMMENU";
    case SFVM_ADDINGOBJECT: return "SFVM_ADDINGOBJECT";
    case SFVM_REMOVINGOBJECT: return "SFVM_REMOVINGOBJECT";
    case SFVM_UPDATESTATUSBAR: return "SFVM_UPDATESTATUSBAR";
    case SFVM_BACKGROUNDENUM: return "SFVM_BACKGROUNDENUM";
    case SFVM_GETCOMMANDDIR: return "SFVM_GETCOMMANDDIR";
    case SFVM_GETCOLUMNSTREAM: return "SFVM_GETCOLUMNSTREAM";
    case SFVM_CANSELECTALL: return "SFVM_CANSELECTALL";
    case SFVM_DIDDRAGDROP: return "SFVM_DIDDRAGDROP";
    case SFVM_ISSTRICTREFRESH: return "SFVM_ISSTRICTREFRESH";
    case SFVM_ISCHILDOBJECT: return "SFVM_ISCHILDOBJECT";
    case SFVM_SETISFV: return "SFVM_SETISFV";
    case SFVM_GETEXTVIEWS: return "SFVM_GETEXTVIEWS";
    case SFVM_THISIDLIST: return "SFVM_THISIDLIST";
    case SFVM_ADDPROPERTYPAGES: return "SFVM_ADDPROPERTYPAGES";
    case SFVM_BACKGROUNDENUMDONE: return "SFVM_BACKGROUNDENUMDONE";
    case SFVM_GETNOTIFY: return "SFVM_GETNOTIFY";
    case SFVM_GETSORTDEFAULTS: return "SFVM_GETSORTDEFAULTS";
    case SFVM_SIZE: return "SFVM_SIZE";
    case SFVM_GETZONE: return "SFVM_GETZONE";
    case SFVM_GETPANE: return "SFVM_GETPANE";
    case SFVM_GETHELPTOPIC: return "SFVM_GETHELPTOPIC";
    case SFVM_GETANIMATION: return "SFVM_GETANIMATION";
    case SFVM_GET_CUSTOMVIEWINFO: return "SFVM_GET_CUSTOMVIEWINFO";
    case SFVM_ENUMERATEDITEMS: return "SFVM_ENUMERATEDITEMS";
    case SFVM_GET_VIEW_DATA: return "SFVM_GET_VIEW_DATA";
    case SFVM_GET_WEBVIEW_LAYOUT: return "SFVM_GET_WEBVIEW_LAYOUT";
    case SFVM_GET_WEBVIEW_CONTENT: return "SFVM_GET_WEBVIEW_CONTENT";
    case SFVM_GET_WEBVIEW_TASKS: return "SFVM_GET_WEBVIEW_TASKS";
    case SFVM_GET_WEBVIEW_THEME: return "SFVM_GET_WEBVIEW_THEME";
    case SFVM_GETDEFERREDVIEWSETTINGS: return "SFVM_GET_WEBVIEW_THEME";

    case DUM_MSG_GetWindow: return "|GetWindow|";
    case DUM_MSG_ContextSensitiveHelp: return "|ContextSensitiveHelp|";
    case DUM_MSG_InsertMenusSB: return "|InsertMenusSB|";
    case DUM_MSG_SetMenuSB: return "|SetMenuSB|";
    case DUM_MSG_RemoveMenusSB: return "|RemoveMenusSB|";
    case DUM_MSG_SetStatusTextSB: return "|SetStatusTextSB|";
    case DUM_MSG_EnableModelessSB: return "|EnableModelessSB|";
    case DUM_MSG_TranslateAcceleratorSB: return "|TranslateAcceleratorSB|";
    case DUM_MSG_BrowseObject: return "|BrowseObject|";
    case DUM_MSG_GetViewStateStream: return "|GetViewStateStream|";
    case DUM_MSG_GetControlWindow: return "|GetControlWindow|";
    case DUM_MSG_SendControlMsg: return "|SendControlMsg|";
    case DUM_MSG_QueryActiveShellView: return "|QueryActiveShellView|";
    case DUM_MSG_OnViewWindowActive: return "|OnViewWindowActive|";
    case DUM_MSG_SetToolbarItems: return "|SetToolbarItems|";
    default:
        sprintf(buf[index], "[%u]", uMsg);
        return buf[index];
    }
}


#define PTR_VALUE   0xf7f7f7f7

struct message
{
    message(UINT msg, WPARAM wp, LPARAM lp) : uMsg(msg), wParam(wp), lParam(lp) { ; }

    UINT uMsg;
    WPARAM wParam;
    LPARAM lParam;
};

CSimpleArray<message> g_Received;

void clear_list()
{
    g_Received.RemoveAll();
}

void add_msg(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    g_Received.Add(message(uMsg, wParam, lParam));
}

void print_list_(const CSimpleArray<message>& input, const char* file, int line)
{
    trace_(file, line)("Got list:\n");
    for (int n = 0; n < input.GetSize(); ++n)
    {
        const message& msg = input[n];
        trace_(file, line)("msg: %d(%s), wParam:0x%x, lParam:0x%lx\n", msg.uMsg, msg2str(msg.uMsg), msg.wParam, msg.lParam);
    }
    trace_(file, line)("End of list.\n");
}

void compare_list_(const CSimpleArray<message>& input, const message* compare, const char* file, int line)
{
    int input_item = 0;
    int compare_item = 0;
    LONG old_failures = winetest_get_failures();
    while (compare[compare_item].uMsg && input_item < input.GetSize())
    {
        const message& inp = input[input_item];
        const message& cmp = compare[compare_item];
        if (cmp.uMsg == inp.uMsg)
        {
            if (cmp.lParam != (LPARAM)PTR_VALUE)
            {
                ok_(file, line)(cmp.lParam == inp.lParam, "Expected lParam to be 0x%lx, was 0x%lx for %i(%s)\n",
                                cmp.lParam, inp.lParam, compare_item, msg2str(cmp.uMsg));
            }
            else
            {
                ok_(file, line)(inp.lParam != 0, "Expected lParam to be a pointer, was 0 for %i(%s)\n",
                                compare_item, msg2str(cmp.uMsg));
            }
            if (cmp.wParam != PTR_VALUE)
            {
                ok_(file, line)(cmp.wParam == inp.wParam, "Expected wParam to be 0x%x, was 0x%x for %i(%s)\n",
                                cmp.wParam, inp.wParam, compare_item, msg2str(cmp.uMsg));
            }
            else
            {
                ok_(file, line)(inp.wParam != 0, "Expected wParam to be a pointer, was 0 for %i(%s)\n",
                                compare_item, msg2str(cmp.uMsg));
            }
            compare_item++;
        }
        else
        {
            /* We skip unknown items for now */
        }

        input_item++;
    }

    while (compare[compare_item].uMsg)
    {
        ok_(file, line)(0, "Message %i(%s) not found\n", compare_item, msg2str(compare[compare_item].uMsg));
        compare_item++;
    }
    if (old_failures != winetest_get_failures())
    {
        print_list_(input, file, line);
    }
}

#define compare_list(cmp)   compare_list_(g_Received, cmp, __FILE__, __LINE__)
#define print_list()        print_list_(g_Received, __FILE__, __LINE__)


LONG g_AddRef = 0;
LONG g_Release = 0;

class CFolderViewCB :
    public IShellFolderViewCB
{
public:
    CFolderViewCB(void) :
        m_RefCount(1)
    {
    }
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void  **ppvObject)
    {
        if (riid == IID_IShellFolderViewCB)
        {
            *ppvObject = static_cast<IShellFolderViewCB*>(this);
            AddRef();
            return S_OK;
        }
        return E_NOINTERFACE;
    }
    virtual ULONG STDMETHODCALLTYPE AddRef(void)
    {
        InterlockedIncrement(&g_AddRef);
        return InterlockedIncrement(&m_RefCount);
    }
    virtual ULONG STDMETHODCALLTYPE Release(void)
    {
        InterlockedIncrement(&g_Release);
        return InterlockedDecrement(&m_RefCount);
    }
    virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        //DbgPrint("MessageSFVCB(uMsg:%s, wParam:%u, lParam:%u\n", msg2str(uMsg), wParam, lParam);
        add_msg(uMsg, wParam, lParam);
        return E_NOTIMPL;
    }
private:
    LONG m_RefCount;
};


static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (msg == WM_DESTROY)
    {
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}


class CDummyShellBrowser : public IShellBrowser
{
public:
    HWND m_hwnd;
    CDummyShellBrowser()
    {
        static const TCHAR* class_name = TEXT("DUMMY_TEST_CLASS");
        WNDCLASSEX wx = {};
        wx.cbSize = sizeof(WNDCLASSEX);
        wx.lpfnWndProc = WndProc;
        wx.hInstance = GetModuleHandle(NULL);
        wx.lpszClassName = class_name;
        wx.style = CS_DBLCLKS;
        RegisterClassEx(&wx);
        m_hwnd = CreateWindowEx(0, class_name, TEXT("dummy_name"), WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
        ShowWindow(m_hwnd, SW_SHOW);
    }

    // *** IUnknown methods ***
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void  **ppvObject)
    {
        if (riid == IID_IShellBrowser || riid == IID_IUnknown)
        {
            *ppvObject = this;
            return S_OK;
        }
        return E_NOINTERFACE;
    }
    virtual ULONG STDMETHODCALLTYPE AddRef(void)
    {
        return 2;
    }
    virtual ULONG STDMETHODCALLTYPE Release(void)
    {
        return 1;
    }

    // *** IOleWindow methods ***
    virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *phwnd)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        *phwnd = m_hwnd;
        add_msg(DUM_MSG_GetWindow, NULL, NULL);
        return S_OK;
    }
    virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_ContextSensitiveHelp, NULL, NULL);
        return E_NOTIMPL;
    }

    // *** IShellBrowser methods ***
    virtual HRESULT STDMETHODCALLTYPE InsertMenusSB(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_InsertMenusSB, NULL, NULL);
        return S_OK;
    }
    virtual HRESULT STDMETHODCALLTYPE SetMenuSB(HMENU hmenuShared, HOLEMENU holemenuRes, HWND hwndActiveObject)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_SetMenuSB, NULL, NULL);
        return S_OK;
    }
    virtual HRESULT STDMETHODCALLTYPE RemoveMenusSB(HMENU hmenuShared)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_RemoveMenusSB, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE SetStatusTextSB(LPCWSTR pszStatusText)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_SetStatusTextSB, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE EnableModelessSB(BOOL fEnable)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_EnableModelessSB, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorSB(MSG *pmsg, WORD wID)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_TranslateAcceleratorSB, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE BrowseObject(PCUIDLIST_RELATIVE pidl,UINT wFlags)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_BrowseObject, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE GetViewStateStream(DWORD grfMode,IStream **ppStrm)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_GetViewStateStream, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE GetControlWindow(UINT id,HWND *phwnd)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_GetControlWindow, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE SendControlMsg(UINT id,UINT uMsg,WPARAM wParam,LPARAM lParam,LRESULT *pret)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_SendControlMsg, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE QueryActiveShellView(IShellView **ppshv)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_QueryActiveShellView, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE OnViewWindowActive(IShellView *pshv)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_OnViewWindowActive, NULL, NULL);
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE SetToolbarItems(LPTBBUTTONSB lpButtons,UINT nButtons,UINT uFlags)
    {
        //DbgPrint("%s()\n", __FUNCTION__);
        add_msg(DUM_MSG_SetToolbarItems, NULL, NULL);
        return E_NOTIMPL;
    }
};


START_TEST(IShellFolderViewCB)
{
    RTL_OSVERSIONINFOEXW rtlinfo = { sizeof(rtlinfo) };
    void (__stdcall* pRtlGetVersion)(RTL_OSVERSIONINFOEXW*);
    pRtlGetVersion = (void (__stdcall*)(RTL_OSVERSIONINFOEXW*))GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
    pRtlGetVersion(&rtlinfo);
    g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;

    CoInitialize(NULL);
    CFolderViewCB cb;

    CComPtr<IShellFolder> desktop;

    HRESULT hr = SHGetDesktopFolder(&desktop);
    ok_hex(hr, S_OK);
    if (!desktop)
        return;

    SFV_CREATE sfvc = { sizeof(sfvc), desktop };
    sfvc.psfvcb = &cb;
    IShellView* psv = NULL;

    g_AddRef = 0;
    g_Release = 0;

    hr = SHCreateShellFolderView(&sfvc, &psv);
    ok_hex(hr, S_OK);
    if (!SUCCEEDED(hr))
        return;

    ok_int(g_AddRef, 1);
    ok_int(g_Release, 0);

    clear_list();

    HWND wnd;
    RECT rc = { 0 };
    FOLDERSETTINGS fs = { FVM_DETAILS, 0 };
    CDummyShellBrowser dum;
    hr = psv->CreateViewWindow(NULL, &fs, &dum, &rc, &wnd);<--- hr is assigned


    static message init_list[] =
    {
        /* ... */
        message(DUM_MSG_GetWindow, 0, 0),
        /* Some unknown messages here, and multiple SFVM_GET_WEBVIEW_THEME + SFVM_GETSORTDEFAULTS + SFVM_GETCOLUMNSTREAM */
        message(SFVM_SIZE, 0, 0),
        /* ... */
        message(DUM_MSG_InsertMenusSB, 0, 0),
        message(SFVM_MERGEMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        /* ... */
        message(SFVM_WINDOWCREATED, PTR_VALUE, 0),
        /* ... */

        message(SFVM_GETBUTTONINFO, 0, PTR_VALUE),
        message(SFVM_GETBUTTONS, PTR_VALUE, PTR_VALUE),
        message(DUM_MSG_SetToolbarItems, 0, 0),

        message(0, 0, 0)
    };


    static message init_list_vista[] =
    {
        /* Some unknown messages here */
        message(DUM_MSG_GetWindow, 0, 0),
        /* Some unknown messages here, and multiple SFVM_GET_WEBVIEW_THEME + SFVM_GETSORTDEFAULTS + SFVM_GETCOLUMNSTREAM */
        message(SFVM_SIZE, 0, 0),
        message(SFVM_WINDOWCREATED, PTR_VALUE, 0),
        /* Some unknown messages here */
        message(DUM_MSG_InsertMenusSB, 0, 0),
        message(SFVM_MERGEMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),

        message(0, 0, 0)
    };

    if (g_WinVersion < WINVER_VISTA)
    {
        compare_list(init_list);
    }
    else
    {
        compare_list(init_list_vista);
    }
    clear_list();

    hr = psv->Refresh();<--- hr is overwritten<--- hr is assigned
    //ok_hex(hr, S_FALSE);

    static message refresh_list[] =
    {
        message(SFVM_LISTREFRESHED, 1, 0),

        message(SFVM_UNMERGEFROMMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        message(DUM_MSG_RemoveMenusSB, 0, 0),
        message(DUM_MSG_InsertMenusSB, 0, 0),
        message(SFVM_MERGEMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),

        message(0, 0, 0)
    };

    static message refresh_list_vista[] =
    {
        message(SFVM_LISTREFRESHED, 1, 0),

        message(SFVM_UNMERGEFROMMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        message(DUM_MSG_RemoveMenusSB, 0, 0),
        message(DUM_MSG_InsertMenusSB, 0, 0),
        message(SFVM_MERGEMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        /* Some messages here, like SFVM_GET_WEBVIEW_THEME, SFVM_GETSORTDEFAULTS, SFVM_GETCOLUMNSTREAM */
        message(SFVM_UNMERGEFROMMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        message(DUM_MSG_RemoveMenusSB, 0, 0),
        message(DUM_MSG_InsertMenusSB, 0, 0),
        message(SFVM_MERGEMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),

        message(0, 0, 0)
    };

    if (g_WinVersion < WINVER_VISTA)
    {
        compare_list(refresh_list);
    }
    else
    {
        compare_list(refresh_list_vista);
    }
    clear_list();

    hr = psv->DestroyViewWindow();<--- hr is overwritten<--- hr is assigned

    static message destroy_list[] =
    {
        message(SFVM_UNMERGEFROMMENU, 0, PTR_VALUE),
        message(DUM_MSG_SetMenuSB, 0, 0),
        message(DUM_MSG_RemoveMenusSB, 0, 0),
        message(SFVM_WINDOWCLOSING, PTR_VALUE, 0),

        message(0, 0, 0)
    };

    compare_list(destroy_list);
    clear_list();

    CComPtr<IShellFolderView> folderView;
    hr = psv->QueryInterface(IID_PPV_ARG(IShellFolderView, &folderView));<--- hr is overwritten
    ok_hex(hr, S_OK);
    if (SUCCEEDED(hr))
    {
        IShellFolderViewCB* oldPtr;

        hr = folderView->SetCallback(NULL, &oldPtr);<--- hr is assigned
        ok_int(g_AddRef, 1);
        ok_int(g_Release, 0);

        /* Last pointer is not optional! */
        IShellFolderViewCB* oldPtr2;
        hr = folderView->SetCallback(oldPtr, &oldPtr2);<--- hr is overwritten
        ok_int(g_AddRef, 2);
        ok_int(g_Release, 0);
    }

    ULONG refCount = psv->Release();
    ok(refCount == 1, "refCount = %lu\n", refCount);

    static message release_list[] =
    {
        message(SFVM_VIEWRELEASE, 0, 0),

        message(0, 0, 0)
    };

    /* Investigate why this fails */
    if (refCount == 0)
    {
        compare_list(release_list);
    }
}