shlfsbind.c 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * File System Bind Data object to use as parameter for the bind context to
 * IShellFolder_ParseDisplayName
 *
 * Copyright 2003 Rolf Kalbermatter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24 25 26
 *
 */
#include "config.h"
#include "wine/port.h"

#include <stdarg.h>

27 28
#define COBJMACROS

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "shlobj.h"
#include "shell32_main.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(pidl);

/***********************************************************************
 * IFileSystemBindData implementation
 */
typedef struct
{
44 45
    IFileSystemBindData IFileSystemBindData_iface;
    LONG ref;
46
    WIN32_FIND_DATAW findFile;
47
} FileSystemBindData;
48

49
static inline FileSystemBindData *impl_from_IFileSystemBindData(IFileSystemBindData *iface)
50
{
51
    return CONTAINING_RECORD(iface, FileSystemBindData, IFileSystemBindData_iface);
52 53
}

54 55
static HRESULT WINAPI FileSystemBindData_QueryInterface(
                IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
56
{
57
    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
58

59
    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppV);
60 61 62

    *ppV = NULL;

63 64
    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IFileSystemBindData))
65
    {
66
        *ppV = &This->IFileSystemBindData_iface;
67 68 69 70
    }

    if (*ppV)
    {
71
        IFileSystemBindData_AddRef(iface);
72 73 74 75 76
        TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
        return S_OK;
    }
    TRACE("-- Interface: E_NOINTERFACE\n");
    return E_NOINTERFACE;
77 78
}

79
static ULONG WINAPI FileSystemBindData_AddRef(IFileSystemBindData *iface)
80
{
81 82 83 84
    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
    ULONG ref = InterlockedIncrement(&This->ref);
    TRACE("(%p)->(%u)\n", This, ref);
    return ref;
85 86
}

87
static ULONG WINAPI FileSystemBindData_Release(IFileSystemBindData *iface)
88
{
89 90
    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
    ULONG ref = InterlockedDecrement(&This->ref);
91

92
    TRACE("(%p)->(%u)\n", This, ref);
93

94
    if (!ref)
95
        HeapFree(GetProcessHeap(), 0, This);
96 97

    return ref;
98 99
}

100
static HRESULT WINAPI FileSystemBindData_GetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
101
{
102 103 104
    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);

    TRACE("(%p)->(%p)\n", This, pfd);
105

106 107
    if (!pfd)
        return E_INVALIDARG;
108

109
    *pfd = This->findFile;
110
    return S_OK;
111 112
}

113
static HRESULT WINAPI FileSystemBindData_SetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
114
{
115 116 117
    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);

    TRACE("(%p)->(%p)\n", This, pfd);
118 119

    if (pfd)
120
        This->findFile = *pfd;
121 122
    else
        memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
123
    return S_OK;
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

static const IFileSystemBindDataVtbl FileSystemBindDataVtbl = {
    FileSystemBindData_QueryInterface,
    FileSystemBindData_AddRef,
    FileSystemBindData_Release,
    FileSystemBindData_SetFindData,
    FileSystemBindData_GetFindData,
};

HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *find_data, LPBC *ppV)
{
    FileSystemBindData *This;
    HRESULT ret;

    TRACE("(%p %p)\n", find_data, ppV);

    if (!ppV)
       return E_INVALIDARG;

    *ppV = NULL;

    This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
    if (!This) return E_OUTOFMEMORY;

    This->IFileSystemBindData_iface.lpVtbl = &FileSystemBindDataVtbl;
    This->ref = 1;
    IFileSystemBindData_SetFindData(&This->IFileSystemBindData_iface, find_data);

    ret = CreateBindCtx(0, ppV);
    if (SUCCEEDED(ret))
    {
        static const WCHAR nameW[] = {
            'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
        BIND_OPTS bindOpts;

        bindOpts.cbStruct = sizeof(BIND_OPTS);
        bindOpts.grfFlags = 0;
        bindOpts.grfMode = STGM_CREATE;
        bindOpts.dwTickCountDeadline = 0;
        IBindCtx_SetBindOptions(*ppV, &bindOpts);
        IBindCtx_RegisterObjectParam(*ppV, (WCHAR*)nameW, (IUnknown*)&This->IFileSystemBindData_iface);

        IFileSystemBindData_Release(&This->IFileSystemBindData_iface);
    }
    else
        HeapFree(GetProcessHeap(), 0, This);
    return ret;
}