[PATCH v2 2/3] uiribbon: Add empty COM implementation

Fabian Maurer dark.shadow4 at web.de
Thu Jul 27 15:24:11 CDT 2017


Code mainly taken and adapted from d3dxof.

Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/uiribbon/Makefile.in          |   5 +-
 dlls/uiribbon/main.c               | 177 +++++++++++++++++++++++++++++++++++++
 dlls/uiribbon/uiribbon.c           | 103 +++++++++++++++++++++
 dlls/uiribbon/uiribbon.spec        |   8 +-
 dlls/uiribbon/uiribbon_classes.idl |  21 +++++
 dlls/uiribbon/uiribbon_private.h   |  32 +++++++
 include/Makefile.in                |   1 +
 include/uiribbon.idl               |  39 ++++++++
 8 files changed, 381 insertions(+), 5 deletions(-)
 create mode 100644 dlls/uiribbon/uiribbon.c
 create mode 100644 dlls/uiribbon/uiribbon_classes.idl
 create mode 100644 dlls/uiribbon/uiribbon_private.h
 create mode 100644 include/uiribbon.idl

diff --git a/dlls/uiribbon/Makefile.in b/dlls/uiribbon/Makefile.in
index 1ac13dfee0..78e6ae00e4 100644
--- a/dlls/uiribbon/Makefile.in
+++ b/dlls/uiribbon/Makefile.in
@@ -2,4 +2,7 @@ MODULE    = uiribbon.dll
 IMPORTS   = uuid ole32
 
 C_SRCS = \
-	main.c
+	main.c \
+	uiribbon.c
+
+IDL_SRCS = uiribbon_classes.idl
\ No newline at end of file
diff --git a/dlls/uiribbon/main.c b/dlls/uiribbon/main.c
index 081e59e6ef..92eef12640 100644
--- a/dlls/uiribbon/main.c
+++ b/dlls/uiribbon/main.c
@@ -26,7 +26,184 @@
 #include "winuser.h"
 #include "winreg.h"
 
+#include "ole2.h"
+#include "rpcproxy.h"
+
+/* Define GUIDs, but only our own */
+#include <unknwn.h>
+#include <propsys.h>
+#include "initguid.h"
+#include "uiribbon_private.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(uiribbon);
+
+static HINSTANCE instance;
+
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
+    switch(fdwReason) {
+        case DLL_PROCESS_ATTACH:
+            instance = hInstDLL;
+            DisableThreadLibraryCalls(hInstDLL);
+            break;
+    }
     return TRUE;
 }
+
+typedef struct {
+    IClassFactory IClassFactory_iface;
+
+    LONG ref;
+    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
+} IClassFactoryImpl;
+
+static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
+{
+    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
+}
+
+struct object_creation_info
+{
+    const CLSID *clsid;
+    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
+};
+
+static const struct object_creation_info object_creation[] =
+{
+    { &CLSID_UIRibbonFramework, UIRibbonFrameworkImpl_Create },
+};
+
+static HRESULT WINAPI XFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppobj)
+{
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+
+    if (IsEqualGUID(riid, &IID_IUnknown)
+        || IsEqualGUID(riid, &IID_IClassFactory))
+    {
+        IClassFactory_AddRef(iface);
+        *ppobj = &This->IClassFactory_iface;
+        return S_OK;
+    }
+
+    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI XFCF_AddRef(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    return InterlockedIncrement(&This->ref);
+}
+
+static ULONG WINAPI XFCF_Release(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    if (ref == 0)
+        HeapFree(GetProcessHeap(), 0, This);
+
+    return ref;
+}
+
+static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
+{
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    HRESULT hres;
+    LPUNKNOWN punk;
+
+    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
+
+    *ppobj = NULL;
+    hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
+    if (SUCCEEDED(hres)) {
+        hres = IUnknown_QueryInterface(punk, riid, ppobj);
+        IUnknown_Release(punk);
+    }
+    return hres;
+}
+
+static HRESULT WINAPI XFCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
+{
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    FIXME("(%p)->(%d), stub!\n",This,dolock);
+    return S_OK;
+}
+
+static const IClassFactoryVtbl XFCF_Vtbl =
+{
+    XFCF_QueryInterface,
+    XFCF_AddRef,
+    XFCF_Release,
+    XFCF_CreateInstance,
+    XFCF_LockServer
+};
+
+/*******************************************************************************
+ * Retrieves class object from a DLL object
+ *
+ * NOTES
+ *    Docs say returns STDAPI
+ *
+ * PARAMS
+ *    rclsid [I] CLSID for the class object
+ *    riid   [I] Reference to identifier of interface for class object
+ *    ppv    [O] Address of variable to receive interface pointer for riid
+ *
+ * RETURNS
+ *    Success: S_OK
+ *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
+ *             E_UNEXPECTED
+ */
+HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
+{
+    unsigned int i;
+    IClassFactoryImpl *factory;
+
+    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
+
+    if ( !IsEqualGUID( &IID_IClassFactory, riid )
+         && ! IsEqualGUID( &IID_IUnknown, riid) )
+        return E_NOINTERFACE;
+
+    for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
+    {
+        if (IsEqualGUID(object_creation[i].clsid, rclsid))
+            break;
+    }
+
+    if (i == sizeof(object_creation)/sizeof(object_creation[0]))
+    {
+        FIXME("%s: no class found.\n", debugstr_guid(rclsid));
+        return CLASS_E_CLASSNOTAVAILABLE;
+    }
+
+    factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
+    if (factory == NULL) return E_OUTOFMEMORY;
+
+    factory->IClassFactory_iface.lpVtbl = &XFCF_Vtbl;
+    factory->ref = 1;
+
+    factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
+
+    *ppv = &(factory->IClassFactory_iface);
+    return S_OK;
+}
+
+HRESULT WINAPI DllCanUnloadNow(void)
+{
+    return S_FALSE;
+}
+
+HRESULT WINAPI DllRegisterServer(void)
+{
+    return __wine_register_resources( instance );
+}
+
+HRESULT WINAPI DllUnregisterServer(void)
+{
+    return __wine_unregister_resources( instance );
+}
diff --git a/dlls/uiribbon/uiribbon.c b/dlls/uiribbon/uiribbon.c
new file mode 100644
index 0000000000..be84b54a65
--- /dev/null
+++ b/dlls/uiribbon/uiribbon.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017 Fabian Maurer
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/debug.h"
+
+#define COBJMACROS
+
+#include "uiribbon_private.h"
+
+#include <stdio.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(uiribbon);
+
+static const struct IUIFrameworkVtbl IUIFramework_Vtbl;
+
+HRESULT UIRibbonFrameworkImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
+{
+    UIRibbonFrameworkImpl* object;
+
+    TRACE("(%p,%p)\n", pUnkOuter, ppObj);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(UIRibbonFrameworkImpl));
+    if (!object)
+        return E_OUTOFMEMORY;
+
+    object->IUIFramework_iface.lpVtbl = &IUIFramework_Vtbl;
+    object->ref = 1;
+
+    *ppObj = &object->IUIFramework_iface;
+
+    return S_OK;
+}
+
+static inline UIRibbonFrameworkImpl *impl_from_IUIFramework(IUIFramework *iface)
+{
+    return CONTAINING_RECORD(iface, UIRibbonFrameworkImpl, IUIFramework_iface);
+}
+
+/*** IUnknown methods ***/
+
+static HRESULT WINAPI UIRibbonFrameworkImpl_QueryInterface(IUIFramework* iface, REFIID riid, void** ppvObject)
+{
+    UIRibbonFrameworkImpl *This = impl_from_IUIFramework(iface);
+
+    TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
+
+    if (IsEqualGUID(riid, &IID_IUnknown)
+        || IsEqualGUID(riid, &IID_IUIFramework))
+    {
+        IUnknown_AddRef(iface);
+        *ppvObject = &This->IUIFramework_iface;
+        return S_OK;
+    }
+
+    ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI UIRibbonFrameworkImpl_AddRef(IUIFramework* iface)
+{
+    UIRibbonFrameworkImpl *This = impl_from_IUIFramework(iface);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->(): new ref %d\n", iface, This, ref);
+
+    return ref;
+}
+
+static ULONG WINAPI UIRibbonFrameworkImpl_Release(IUIFramework* iface)
+{
+    UIRibbonFrameworkImpl *This = impl_from_IUIFramework(iface);
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->(): new ref %d\n", iface, This, ref);
+
+    if (!ref)
+        HeapFree(GetProcessHeap(), 0, This);
+
+    return ref;
+}
+
+static const IUIFrameworkVtbl IUIFramework_Vtbl =
+{
+    UIRibbonFrameworkImpl_QueryInterface,
+    UIRibbonFrameworkImpl_AddRef,
+    UIRibbonFrameworkImpl_Release
+};
diff --git a/dlls/uiribbon/uiribbon.spec b/dlls/uiribbon/uiribbon.spec
index ebb921b887..b16365d0c9 100644
--- a/dlls/uiribbon/uiribbon.spec
+++ b/dlls/uiribbon/uiribbon.spec
@@ -1,4 +1,4 @@
-@ stub -private DllCanUnloadNow()
-@ stub -private DllGetClassObject(ptr ptr ptr)
-@ stub -private DllRegisterServer()
-@ stub -private DllUnregisterServer()
+@ stdcall -private DllCanUnloadNow()
+@ stdcall -private DllGetClassObject(ptr ptr ptr)
+@ stdcall -private DllRegisterServer()
+@ stdcall -private DllUnregisterServer()
diff --git a/dlls/uiribbon/uiribbon_classes.idl b/dlls/uiribbon/uiribbon_classes.idl
new file mode 100644
index 0000000000..bd8bdde6b6
--- /dev/null
+++ b/dlls/uiribbon/uiribbon_classes.idl
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2017 Fabian Maurer
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#pragma makedep register
+
+#include "uiribbon.idl"
diff --git a/dlls/uiribbon/uiribbon_private.h b/dlls/uiribbon/uiribbon_private.h
new file mode 100644
index 0000000000..80ede5fec0
--- /dev/null
+++ b/dlls/uiribbon/uiribbon_private.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Fabian Maurer
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __UIRIBBON_PRIVATE_INCLUDED__
+#define __UIRIBBON_PRIVATE_INCLUDED__
+
+#include "uiribbon.h"
+
+typedef struct {
+    IUIFramework IUIFramework_iface;
+    LONG ref;
+} UIRibbonFrameworkImpl;
+
+HRESULT UIRibbonFrameworkImpl_Create(IUnknown *pUnkOuter, LPVOID *ppObj) DECLSPEC_HIDDEN;
+
+
+#endif /* __UIRIBBON_PRIVATE_INCLUDED__ */
diff --git a/include/Makefile.in b/include/Makefile.in
index 1dd6aafa32..063c4ecd3d 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -161,6 +161,7 @@ IDL_SRCS = \
 	txdtc.idl \
 	uiautomationclient.idl \
 	uiautomationcore.idl \
+	uiribbon.idl \
 	unknwn.idl \
 	urlhist.idl \
 	urlmon.idl \
diff --git a/include/uiribbon.idl b/include/uiribbon.idl
new file mode 100644
index 0000000000..1ac464cb79
--- /dev/null
+++ b/include/uiribbon.idl
@@ -0,0 +1,39 @@
+/*
+ * COM Classes for uiribbon
+ *
+ * Copyright 2017 Fabian Maurer
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+import "unknwn.idl";
+
+[
+    object,
+    uuid(F4F0385D-6872-43a8-AD09-4C339CB3F5C5),
+    local,
+    pointer_default(unique)
+]
+interface IUIFramework : IUnknown
+{
+
+}
+
+[
+    helpstring("UIRibbonFramework Object"),
+    threading(both),
+    uuid(926749fa-2615-4987-8845-c33e65f2b957)
+]
+coclass UIRibbonFramework { interface IUIFramework; }
-- 
2.13.3




More information about the wine-patches mailing list