[PATCH 1/3] mmdevapi: Add class factory, try 2

Maarten Lankhorst m.b.lankhorst at gmail.com
Tue Dec 15 08:35:18 CST 2009


diff --git a/dlls/mmdevapi/Makefile.in b/dlls/mmdevapi/Makefile.in
index 2f9db6c..fd43434 100644
--- a/dlls/mmdevapi/Makefile.in
+++ b/dlls/mmdevapi/Makefile.in
@@ -6,6 +6,7 @@ MODULE    = mmdevapi.dll
 IMPORTS   = ole32 user32 advapi32 kernel32 ntdll
 
 C_SRCS = \
+	devenum.c \
 	main.c \
 	regsvr.c
 
diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c
new file mode 100644
index 0000000..e34c824
--- /dev/null
+++ b/dlls/mmdevapi/devenum.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2009 Maarten Lankhorst
+ *
+ * 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 <stdarg.h>
+
+#define CINTERFACE
+#define COBJMACROS
+#include "windef.h"
+#include "winbase.h"
+#include "wine/debug.h"
+
+#include "ole2.h"
+#include "mmdeviceapi.h"
+
+#include "mmdevapi.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
+
+HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
+{
+    FIXME("stub\n");
+    return CLASS_E_CLASSNOTAVAILABLE;
+}
diff --git a/dlls/mmdevapi/main.c b/dlls/mmdevapi/main.c
index af200dc..f33a0a1 100644
--- a/dlls/mmdevapi/main.c
+++ b/dlls/mmdevapi/main.c
@@ -20,6 +20,8 @@
 
 #include <stdarg.h>
 
+#define CINTERFACE
+#define COBJMACROS
 #include "windef.h"
 #include "winbase.h"
 #include "wine/debug.h"
@@ -28,6 +30,8 @@
 #include "ole2.h"
 #include "mmdeviceapi.h"
 
+#include "mmdevapi.h"
+
 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
 
 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
@@ -52,8 +56,115 @@ HRESULT WINAPI DllCanUnloadNow(void)
     return S_FALSE;
 }
 
-HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
+typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
+
+typedef struct {
+    const IClassFactoryVtbl *lpVtbl;
+    REFCLSID rclsid;
+    FnCreateInstance pfnCreateInstance;
+} IClassFactoryImpl;
+
+static HRESULT WINAPI
+MMCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
 {
-    FIXME("stub\n");
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
+    if (ppobj == NULL)
+        return E_POINTER;
+    if (IsEqualIID(riid, &IID_IUnknown) ||
+        IsEqualIID(riid, &IID_IClassFactory))
+    {
+        *ppobj = iface;
+        IUnknown_AddRef(iface);
+        return S_OK;
+    }
+    *ppobj = NULL;
     return E_NOINTERFACE;
 }
+
+static ULONG WINAPI MMCF_AddRef(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p)\n", This);
+    return 2;
+}
+
+static ULONG WINAPI MMCF_Release(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p)\n", This);
+    /* static class, won't be freed */
+    return 1;
+}
+
+static HRESULT WINAPI MMCF_CreateInstance(
+    LPCLASSFACTORY iface,
+    LPUNKNOWN pOuter,
+    REFIID riid,
+    LPVOID *ppobj)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
+
+    if (pOuter)
+        return CLASS_E_NOAGGREGATION;
+
+    if (ppobj == NULL) {
+        WARN("invalid parameter\n");
+        return E_POINTER;
+    }
+    *ppobj = NULL;
+    return This->pfnCreateInstance(riid, ppobj);
+}
+
+static HRESULT WINAPI MMCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    FIXME("(%p, %d) stub!\n", This, dolock);
+    return S_OK;
+}
+
+static const IClassFactoryVtbl MMCF_Vtbl = {
+    MMCF_QueryInterface,
+    MMCF_AddRef,
+    MMCF_Release,
+    MMCF_CreateInstance,
+    MMCF_LockServer
+};
+
+static IClassFactoryImpl MMDEVAPI_CF[] = {
+    { &MMCF_Vtbl, &CLSID_MMDeviceEnumerator, (FnCreateInstance)MMDevEnum_Create }
+};
+
+HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
+{
+    int i = 0;
+    TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
+
+    if (ppv == NULL) {
+        WARN("invalid parameter\n");
+        return E_INVALIDARG;
+    }
+
+    *ppv = NULL;
+
+    if (!IsEqualIID(riid, &IID_IClassFactory) &&
+        !IsEqualIID(riid, &IID_IUnknown)) {
+        WARN("no interface for %s\n", debugstr_guid(riid));
+        return E_NOINTERFACE;
+    }
+
+    for (i = 0; i < sizeof(MMDEVAPI_CF)/sizeof(MMDEVAPI_CF[0]); ++i)
+    {
+        if (IsEqualGUID(rclsid, MMDEVAPI_CF[i].rclsid)) {
+            IUnknown_AddRef((IClassFactory*) &MMDEVAPI_CF[i]);
+            *ppv = &MMDEVAPI_CF[i];
+            return S_OK;
+        }
+        i++;
+    }
+
+    WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
+         debugstr_guid(riid), ppv);
+    return CLASS_E_CLASSNOTAVAILABLE;
+}
diff --git a/dlls/mmdevapi/mmdevapi.h b/dlls/mmdevapi/mmdevapi.h
new file mode 100644
index 0000000..e6b878a
--- /dev/null
+++ b/dlls/mmdevapi/mmdevapi.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2009 Maarten Lankhorst
+ *
+ * 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
+ */
+
+extern HRESULT MMDevEnum_Create(REFIID riid, void **ppv);
-- 
1.6.5.4




More information about the wine-patches mailing list