strmbase: Implement OLE registration in AMovieDllRegisterServer2.
diff --git a/dlls/qcap/Makefile.in b/dlls/qcap/Makefile.in
index d4762bd..3abc295 100644
--- a/dlls/qcap/Makefile.in
+++ b/dlls/qcap/Makefile.in
@@ -3,7 +3,6 @@
 
 C_SRCS = \
 	capturegraph.c \
-	dllsetup.c \
 	enummedia.c \
 	qcap_main.c \
 	v4l.c \
diff --git a/dlls/qcap/dllsetup.c b/dlls/qcap/dllsetup.c
deleted file mode 100644
index 0791749..0000000
--- a/dlls/qcap/dllsetup.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * DirectX DLL registration and unregistration
- *
- * Copyright (C) 2005 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
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-#include "config.h"
-
-#include <stdarg.h>
-#include <assert.h>
-
-#define COBJMACROS
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winerror.h"
-#include "winreg.h"
-#include "objbase.h"
-#include "uuids.h"
-
-#include "strmif.h"
-#include "wine/strmbase.h"
-#include "dllsetup.h"
-
-#include "wine/unicode.h"
-#include "wine/debug.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(qcap);
-
-/*
- * defines and constants
- */
-#define MAX_KEY_LEN  260
-
-static WCHAR const clsid_keyname[6] =
-{'C','L','S','I','D',0 };
-static WCHAR const ips32_keyname[15] =
-{'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
-static WCHAR const tmodel_keyname[15] =
-{'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
-static WCHAR const tmodel_both[] =
-{'B','o','t','h',0};
-
-/*
- * SetupRegisterClass()
- */
-static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
-                                  LPCWSTR szDescription,
-                                  LPCWSTR szFileName,
-                                  LPCWSTR szServerType,
-                                  LPCWSTR szThreadingModel)
-{
-    HKEY hkey, hsubkey = NULL;
-    LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey);
-    if (ERROR_SUCCESS != ret)
-        return HRESULT_FROM_WIN32(ret);
-
-    /* set description string */
-    ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription,
-                       sizeof(WCHAR) * (lstrlenW(szDescription) + 1));
-    if (ERROR_SUCCESS != ret)
-        goto err_out;
-
-    /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
-       passed back by last call to RegCreateKeyW(). */
-    ret = RegCreateKeyW(hkey,  szServerType, &hsubkey);
-    if (ERROR_SUCCESS != ret)
-        goto err_out;
-
-    /* set server path */
-    ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
-                       sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
-    if (ERROR_SUCCESS != ret)
-        goto err_out;
-
-    /* set threading model */
-    ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
-                         (const BYTE*)szThreadingModel, 
-                         sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
-err_out:
-    if (hsubkey)
-        RegCloseKey(hsubkey);
-    RegCloseKey(hkey);
-    return HRESULT_FROM_WIN32(ret);
-}
-
-/*
- * RegisterAllClasses()
- */
-static HRESULT SetupRegisterAllClasses(const FactoryTemplate * pList, int num,
-                                       LPCWSTR szFileName, BOOL bRegister)
-{
-    HRESULT hr = NOERROR;
-    HKEY hkey;
-    OLECHAR szCLSID[CHARS_IN_GUID];
-    LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
-    if (ERROR_SUCCESS != ret)
-        return HRESULT_FROM_WIN32(ret);
-
-    for (i = 0; i < num; i++, pList++)
-    {
-        /* (un)register CLSID and InprocServer32 */
-        hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
-        if (SUCCEEDED(hr))
-        {
-            if (bRegister )
-                hr = SetupRegisterClass(hkey, szCLSID,
-                                        pList->m_Name, szFileName,
-                                        ips32_keyname, tmodel_both);
-            else
-                hr = RegDeleteTreeW(hkey, szCLSID);
-        }
-    }
-    RegCloseKey(hkey);
-    return hr;
-}
-
-
-/****************************************************************************
- * SetupRegisterServers
- *
- * This function is table driven using the static members of the
- * CFactoryTemplate class defined in the Dll.
- *
- * It registers the Dll as the InprocServer32 for all the classes in
- * CFactoryTemplate
- *
- ****************************************************************************/
-HRESULT SetupRegisterServers(const FactoryTemplate * pList, int num,
-                             BOOL bRegister)
-{
-    static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
-    HRESULT hr = NOERROR;
-
-    /* first register all server classes, just to make sure */
-    if (bRegister)
-        hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );
-
-    hr = AMovieDllRegisterServer2(bRegister);
-
-    /* if unregistering, unregister all OLE servers */
-    if (SUCCEEDED(hr) && !bRegister)
-        hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
-    return hr;
-}
diff --git a/dlls/qcap/dllsetup.h b/dlls/qcap/dllsetup.h
deleted file mode 100644
index 43950d8..0000000
--- a/dlls/qcap/dllsetup.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * DirectX DLL registration and unregistration
- *
- * Copyright (C) 2005 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
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef _QCAP_DLLSETUP_H_DEFINED
-#define _QCAP_DLLSETUP_H_DEFINED
-
-#define COBJMACROS
-
-/****************************************************************************
- * SetupRegisterServers
- *
- * This function is table driven using the static members of the
- * CFactoryTemplate class defined in the Dll.
- *
- * It registers the Dll as the InprocServer32 for all the classes in
- * CFactoryTemplate
- *
- ****************************************************************************/
-extern HRESULT SetupRegisterServers(const FactoryTemplate * pList, int num, BOOL bRegister);
-
-#endif /* _QCAP_DLLSETUP_H_DEFINED */
diff --git a/dlls/qcap/qcap_main.c b/dlls/qcap/qcap_main.c
index 7465bb4..fdfc214 100644
--- a/dlls/qcap/qcap_main.c
+++ b/dlls/qcap/qcap_main.c
@@ -37,7 +37,6 @@
 #include "strmif.h"
 
 #include "qcap_main.h"
-#include "dllsetup.h"
 
 #include "wine/unicode.h"
 #include "wine/debug.h"
@@ -163,8 +162,7 @@
 HRESULT WINAPI DllRegisterServer(void)
 {
     TRACE("()\n");
-
-    return SetupRegisterServers(g_Templates, g_cTemplates, TRUE);
+    return AMovieDllRegisterServer2(TRUE);
 }
 
 /***********************************************************************
@@ -173,8 +171,7 @@
 HRESULT WINAPI DllUnregisterServer(void)
 {
     TRACE("\n");
-
-    return SetupRegisterServers(g_Templates, g_cTemplates, FALSE);
+    return AMovieDllRegisterServer2(FALSE);
 }
 
 /***********************************************************************
diff --git a/dlls/strmbase/dllfunc.c b/dlls/strmbase/dllfunc.c
index cac93b6..c24ec97 100644
--- a/dlls/strmbase/dllfunc.c
+++ b/dlls/strmbase/dllfunc.c
@@ -45,6 +45,96 @@
 extern const int g_cTemplates;
 extern const FactoryTemplate g_Templates[];
 
+static HINSTANCE g_hInst = NULL;
+
+/*
+ * defines and constants
+ */
+#define MAX_KEY_LEN  260
+
+static WCHAR const clsid_keyname[6] =
+{'C','L','S','I','D',0 };
+static WCHAR const ips32_keyname[15] =
+{'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
+static WCHAR const tmodel_keyname[15] =
+{'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
+static WCHAR const tmodel_both[] =
+{'B','o','t','h',0};
+
+/*
+ * SetupRegisterClass()
+ */
+static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
+                                  LPCWSTR szDescription,
+                                  LPCWSTR szFileName,
+                                  LPCWSTR szServerType,
+                                  LPCWSTR szThreadingModel)
+{
+    HKEY hkey, hsubkey = NULL;
+    LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey);
+    if (ERROR_SUCCESS != ret)
+        return HRESULT_FROM_WIN32(ret);
+
+    /* set description string */
+    ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription,
+                       sizeof(WCHAR) * (lstrlenW(szDescription) + 1));
+    if (ERROR_SUCCESS != ret)
+        goto err_out;
+
+    /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
+       passed back by last call to RegCreateKeyW(). */
+    ret = RegCreateKeyW(hkey,  szServerType, &hsubkey);
+    if (ERROR_SUCCESS != ret)
+        goto err_out;
+
+    /* set server path */
+    ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
+                       sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
+    if (ERROR_SUCCESS != ret)
+        goto err_out;
+
+    /* set threading model */
+    ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
+                         (const BYTE*)szThreadingModel,
+                         sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
+err_out:
+    if (hsubkey)
+        RegCloseKey(hsubkey);
+    RegCloseKey(hkey);
+    return HRESULT_FROM_WIN32(ret);
+}
+
+/*
+ * RegisterAllClasses()
+ */
+static HRESULT SetupRegisterAllClasses(const FactoryTemplate * pList, int num,
+                                       LPCWSTR szFileName, BOOL bRegister)
+{
+    HRESULT hr = NOERROR;
+    HKEY hkey;
+    OLECHAR szCLSID[CHARS_IN_GUID];
+    LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
+    if (ERROR_SUCCESS != ret)
+        return HRESULT_FROM_WIN32(ret);
+
+    for (i = 0; i < num; i++, pList++)
+    {
+        /* (un)register CLSID and InprocServer32 */
+        hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
+        if (SUCCEEDED(hr))
+        {
+            if (bRegister )
+                hr = SetupRegisterClass(hkey, szCLSID,
+                                        pList->m_Name, szFileName,
+                                        ips32_keyname, tmodel_both);
+            else
+                hr = RegDeleteTreeW(hkey, szCLSID);
+        }
+    }
+    RegCloseKey(hkey);
+    return hr;
+}
+
 HRESULT WINAPI AMovieSetupRegisterFilter2( const AMOVIESETUP_FILTER const * pFilter, IFilterMapper2  *pIFM2, BOOL  bRegister)
 {
     if (!pFilter)
@@ -71,6 +161,16 @@
     HRESULT hr;
     int i;
     IFilterMapper2 *pIFM2 = NULL;
+    WCHAR szFileName[MAX_PATH];
+
+    if (!GetModuleFileNameW(g_hInst, szFileName, MAX_PATH))
+    {
+        ERR("Failed to get module file name for registration\n");
+        return E_FAIL;
+    }
+
+    if (bRegister)
+        hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, TRUE );
 
     hr = CoInitialize(NULL);
 
@@ -89,6 +189,10 @@
     CoFreeUnusedLibraries();
     CoUninitialize();
 
+    /* if unregistering, unregister all OLE servers */
+    if (SUCCEEDED(hr) && !bRegister)
+        hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, FALSE);
+
     return hr;
 }
 
@@ -119,6 +223,7 @@
     switch (fdwReason)
     {
         case DLL_PROCESS_ATTACH:
+            g_hInst = hInstDLL;
             DisableThreadLibraryCalls(hInstDLL);
             SetupInitializeServers(g_Templates, g_cTemplates, TRUE);
             break;