inkobj: Implement IClassFactory

John Klehm xixsimplicityxix at gmail.com
Fri Aug 24 03:06:38 CDT 2007


This patch implements IClassFactory because the book said so.  Also
because wines mshtml and msxml said so too (and this is very similar
to those implementations).

-John Klehm
-------------- next part --------------
From 130ab386dca31ed61e89d35cd0beb482a6471f06 Mon Sep 17 00:00:00 2001
From: John Klehm <xixsimplicityxix at gmail.com>
Date: Fri, 24 Aug 2007 00:45:31 -0500
Subject: inkobj: Implement IClassFactory

---
 dlls/inkobj/Makefile.in           |    3 +-
 dlls/inkobj/inkobj.c              |    1 +
 dlls/inkobj/inkobj_classfactory.c |  115 +++++++++++++++++++++++++++++++++++++
 dlls/inkobj/inkobj_internal.h     |   27 +++++++++
 4 files changed, 145 insertions(+), 1 deletions(-)
 create mode 100644 dlls/inkobj/inkobj_classfactory.c

diff --git a/dlls/inkobj/Makefile.in b/dlls/inkobj/Makefile.in
index ac1ab0a..9f561d6 100644
--- a/dlls/inkobj/Makefile.in
+++ b/dlls/inkobj/Makefile.in
@@ -6,7 +6,8 @@ MODULE    = inkobj.dll
 IMPORTS   = advapi32 kernel32
 
 C_SRCS = \
-	inkobj.c
+	inkobj.c \
+	inkobj_classfactory.c
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/inkobj/inkobj.c b/dlls/inkobj/inkobj.c
index 645e4dc..9f33d8f 100644
--- a/dlls/inkobj/inkobj.c
+++ b/dlls/inkobj/inkobj.c
@@ -15,6 +15,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <initguid.h>             /* trigger GUID definitions. must be first */
 #include "inkobj_internal.h"
 #include "inkobj_registry_keys.h" /* inkobj_registry_keys[][3] */
 
diff --git a/dlls/inkobj/inkobj_classfactory.c b/dlls/inkobj/inkobj_classfactory.c
new file mode 100644
index 0000000..450b9cd
--- /dev/null
+++ b/dlls/inkobj/inkobj_classfactory.c
@@ -0,0 +1,115 @@
+/* Copyright (C) 2007 C John Klehm
+ *
+ * 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 "inkobj_internal.h"
+
+
+WINE_DEFAULT_DEBUG_CHANNEL(inkobj);
+
+
+static HRESULT WINAPI ClassFactory_QueryInterface(
+    IClassFactory* This, REFIID riid, void** ppvObject)
+{
+    *ppvObject = NULL;
+
+    if (IsEqualGUID(riid, &IID_IUnknown) ||
+        IsEqualGUID(riid, &IID_IClassFactory))
+    {
+        IClassFactory_AddRef(This);
+        *ppvObject = This;
+        return S_OK;
+    }
+
+    FIXME("interface %s not implemented\n", debugstr_guid(riid));
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI ClassFactory_AddRef(IClassFactory* This)
+{
+    TRACE("refCount=%i before increment\n", ( (ClassFactory*)This )->refCount);
+
+    return InterlockedIncrement(&( ((ClassFactory*)This)->refCount ));
+}
+
+static ULONG WINAPI ClassFactory_Release(IClassFactory* This)
+{
+    TRACE("refCount=%i before decrement\n", ( (ClassFactory*)This )->refCount);
+
+    if (InterlockedDecrement(&( ((ClassFactory*)This)->refCount )) == 0)
+    {
+        HeapFree(GetProcessHeap(), 0, This);
+        InterlockedDecrement(&INKOBJ_refCount);
+        return 0; /* This->refCount == 0 */
+    }
+
+    return ( (ClassFactory*)This )->refCount;
+}
+
+static HRESULT WINAPI ClassFactory_CreateInstance(
+    IClassFactory* This, IUnknown* pUnkOuter, REFIID riid, void** ppvObject)
+{
+    return ( (ClassFactory*)This )->fnCreateInstance(
+        pUnkOuter, riid, ppvObject);
+}
+
+static HRESULT WINAPI ClassFactory_LockServer(IClassFactory* This, BOOL doLock)
+{
+    TRACE("this=%p, doLock=%x, refCount=%i\n", This, doLock, INKOBJ_refCount);
+
+    if(doLock)
+    {
+        InterlockedIncrement(&INKOBJ_refCount);
+    }
+    else
+    {
+        InterlockedDecrement(&INKOBJ_refCount);
+    }
+
+    return S_OK;
+}
+
+static const IClassFactoryVtbl InkCollectorClassFactoryVtbl =
+{
+    ClassFactory_QueryInterface,
+    ClassFactory_AddRef,
+    ClassFactory_Release,
+    ClassFactory_CreateInstance,
+    ClassFactory_LockServer
+};
+
+HRESULT ClassFactory_Create(REFIID riid, void** ppvObject, CreateInstanceFunc fnCreateInstance)
+{
+    ClassFactory* ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory));
+    HRESULT result = E_NOINTERFACE;
+
+    ret->lpVtbl = &InkCollectorClassFactoryVtbl;
+    ret->refCount = 0;
+    ret->fnCreateInstance = fnCreateInstance;
+
+    result = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppvObject);
+    if (SUCCEEDED(result))
+    {
+        InterlockedIncrement(&INKOBJ_refCount);
+    }
+    else
+    {
+        HeapFree(GetProcessHeap(), 0, ret);
+        *ppvObject = NULL;
+    }
+
+    return result;
+}
diff --git a/dlls/inkobj/inkobj_internal.h b/dlls/inkobj/inkobj_internal.h
index dba3a1d..b59a4cf 100644
--- a/dlls/inkobj/inkobj_internal.h
+++ b/dlls/inkobj/inkobj_internal.h
@@ -19,10 +19,14 @@
 
 #include <stdarg.h>     /* var_arg */
 
+#define COBJMACROS      /* ole2, msinkaut */
+
 #include <windef.h>     /* MUST be before most includes */
 #include <winbase.h>    /* MUST be before most includes */
 #include <winerror.h>   /* MUST be before most includes */
 #include <winreg.h>     /* RegDeleteKey, RegCreateKey, RegSetValue */
+#include <winuser.h>    /* IClassFactory 1 of 2 */
+#include <ole2.h>       /* IClassFactory 2 of 2, IID_IUknown, IID_IClassFactory */
 
 #include <wine/debug.h> /* FIXME, TRACE, WARN, ERR */
 
@@ -39,5 +43,28 @@ extern HINSTANCE INKOBJ_hInstance;
 /*
  * end inkobj.c declarations
  */
+/*
+ * start inkobj_classfactory.c declarations
+ */
+
+/* CreateInstanceFunc - delicious function pointer syntax */
+typedef HRESULT (*CreateInstanceFunc)(IUnknown*,REFIID,void**);
+
+/* ClassFactory object - delcare internal data members here */
+typedef struct tagClassFactory
+{
+    const IClassFactoryVtbl *lpVtbl;
+    /* lpVtbl must be first! */
+
+    LONG refCount;
+    CreateInstanceFunc fnCreateInstance;
+} ClassFactory;
+
+extern HRESULT ClassFactory_Create(
+    REFIID riid, void** ppvObject, CreateInstanceFunc fnCreateInstance);
+
+/*
+ * end inkobj_classfactory.c declarations
+ */
 
 #endif /* INKOBJ_INTERNAL_H */
-- 
1.5.1.6



More information about the wine-patches mailing list