>From 6d826135256529afffecc5521b1b91bbdd098b93 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Fri, 13 Jan 2012 00:14:14 +0300
Subject: [PATCH 2/2] Rearrange code to avoid forward declarations

---
 dlls/shell32/shlfsbind.c |  169 +++++++++++++++++++++------------------------
 1 files changed, 79 insertions(+), 90 deletions(-)

diff --git a/dlls/shell32/shlfsbind.c b/dlls/shell32/shlfsbind.c
index 5988290..53a1d3b 100644
--- a/dlls/shell32/shlfsbind.c
+++ b/dlls/shell32/shlfsbind.c
@@ -44,86 +44,31 @@ typedef struct
     IFileSystemBindData IFileSystemBindData_iface;
     LONG ref;
     WIN32_FIND_DATAW findFile;
-} IFileSystemBindDataImpl;
+} FileSystemBindData;
 
-static inline IFileSystemBindDataImpl *impl_from_IFileSystemBindData(IFileSystemBindData *iface)
+static inline FileSystemBindData *impl_from_IFileSystemBindData(IFileSystemBindData *iface)
 {
-    return CONTAINING_RECORD(iface, IFileSystemBindDataImpl, IFileSystemBindData_iface);
+    return CONTAINING_RECORD(iface, FileSystemBindData, IFileSystemBindData_iface);
 }
 
-static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
-static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
-static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
-static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
-static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
-
-static const IFileSystemBindDataVtbl sbvt =
-{
-    IFileSystemBindData_fnQueryInterface,
-    IFileSystemBindData_fnAddRef,
-    IFileSystemBindData_fnRelease,
-    IFileSystemBindData_fnSetFindData,
-    IFileSystemBindData_fnGetFindData,
-};
-
-static const WCHAR wFileSystemBindData[] = {
-    'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
-
-HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
+static HRESULT WINAPI FileSystemBindData_QueryInterface(
+                IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
 {
-    IFileSystemBindDataImpl *sb;
-    HRESULT ret = E_OUTOFMEMORY;
-
-    TRACE("%p, %p\n", pfd, ppV);
+    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
 
-    if (!ppV)
-       return E_INVALIDARG;
+    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppV);
 
     *ppV = NULL;
 
-    sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
-    if (!sb)
-        return ret;
-
-    sb->IFileSystemBindData_iface.lpVtbl = &sbvt;
-    sb->ref = 1;
-    IFileSystemBindData_fnSetFindData(&sb->IFileSystemBindData_iface, pfd);
-
-    ret = CreateBindCtx(0, ppV);
-    if (SUCCEEDED(ret))
+    if (IsEqualIID(riid, &IID_IUnknown) ||
+        IsEqualIID(riid, &IID_IFileSystemBindData))
     {
-        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, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
-
-        IFileSystemBindData_Release(&sb->IFileSystemBindData_iface);
+        *ppV = &This->IFileSystemBindData_iface;
     }
-    else
-        HeapFree(GetProcessHeap(), 0, sb);
-    return ret;
-}
-
-static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
-                IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
-{
-    IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
-    TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
-
-    *ppV = NULL;
-
-    if (IsEqualIID(riid, &IID_IUnknown))
-        *ppV = This;
-    else if (IsEqualIID(riid, &IID_IFileSystemBindData))
-        *ppV = This;
 
     if (*ppV)
     {
-        IUnknown_AddRef((IUnknown*)(*ppV));
+        IFileSystemBindData_AddRef(iface);
         TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
         return S_OK;
     }
@@ -131,36 +76,32 @@ static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
+static ULONG WINAPI FileSystemBindData_AddRef(IFileSystemBindData *iface)
 {
-    IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
-    ULONG refCount = InterlockedIncrement(&This->ref);
-
-    TRACE("(%p)->(count=%i)\n", This, refCount - 1);
-
-    return refCount;
+    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
+    ULONG ref = InterlockedIncrement(&This->ref);
+    TRACE("(%p)->(%u)\n", This, ref);
+    return ref;
 }
 
-static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
+static ULONG WINAPI FileSystemBindData_Release(IFileSystemBindData *iface)
 {
-    IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
-    ULONG refCount = InterlockedDecrement(&This->ref);
+    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p)->(count=%i)\n", This, refCount + 1);
+    TRACE("(%p)->(%u)\n", This, ref);
 
-    if (!refCount)
-    {
-        TRACE(" destroying ISFBindPidl(%p)\n",This);
+    if (!ref)
         HeapFree(GetProcessHeap(), 0, This);
-    }
-    return refCount;
+
+    return ref;
 }
 
-static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
-               IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
+static HRESULT WINAPI FileSystemBindData_GetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
 {
-    IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
-    TRACE("(%p), %p\n", This, pfd);
+    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
+
+    TRACE("(%p)->(%p)\n", This, pfd);
 
     if (!pfd)
         return E_INVALIDARG;
@@ -169,11 +110,11 @@ static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
     return S_OK;
 }
 
-static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
-               IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
+static HRESULT WINAPI FileSystemBindData_SetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
 {
-    IFileSystemBindDataImpl *This = impl_from_IFileSystemBindData(iface);
-    TRACE("(%p), %p\n", This, pfd);
+    FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
+
+    TRACE("(%p)->(%p)\n", This, pfd);
 
     if (pfd)
         This->findFile = *pfd;
@@ -181,3 +122,51 @@ static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
         memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
     return S_OK;
 }
+
+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;
+}
-- 
1.5.6.5

