strmbase: Define STRMBASE_DllMain.
[wine] / dlls / qcap / dllsetup.c
1 /*
2  * DirectX DLL registration and unregistration
3  *
4  * Copyright (C) 2005 Rolf Kalbermatter
5 *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include "config.h"
21
22 #include <stdarg.h>
23 #include <assert.h>
24
25 #define COBJMACROS
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "winreg.h"
34 #include "objbase.h"
35 #include "uuids.h"
36
37 #include "strmif.h"
38 #include "wine/strmbase.h"
39 #include "dllsetup.h"
40
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
45
46 /*
47  * defines and constants
48  */
49 #define MAX_KEY_LEN  260
50
51 static WCHAR const clsid_keyname[6] =
52 {'C','L','S','I','D',0 };
53 static WCHAR const ips32_keyname[15] =
54 {'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
55 static WCHAR const tmodel_keyname[15] =
56 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
57 static WCHAR const tmodel_both[] =
58 {'B','o','t','h',0};
59
60 /*
61  * SetupRegisterClass()
62  */
63 static HRESULT SetupRegisterClass(HKEY clsid, LPCWSTR szCLSID,
64                                   LPCWSTR szDescription,
65                                   LPCWSTR szFileName,
66                                   LPCWSTR szServerType,
67                                   LPCWSTR szThreadingModel)
68 {
69     HKEY hkey, hsubkey = NULL;
70     LONG ret = RegCreateKeyW(clsid, szCLSID, &hkey);
71     if (ERROR_SUCCESS != ret)
72         return HRESULT_FROM_WIN32(ret);
73
74     /* set description string */
75     ret = RegSetValueW(hkey, NULL, REG_SZ, szDescription,
76                        sizeof(WCHAR) * (lstrlenW(szDescription) + 1));
77     if (ERROR_SUCCESS != ret)
78         goto err_out;
79
80     /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
81        passed back by last call to RegCreateKeyW(). */
82     ret = RegCreateKeyW(hkey,  szServerType, &hsubkey);
83     if (ERROR_SUCCESS != ret)
84         goto err_out;
85
86     /* set server path */
87     ret = RegSetValueW(hsubkey, NULL, REG_SZ, szFileName,
88                        sizeof(WCHAR) * (lstrlenW(szFileName) + 1));
89     if (ERROR_SUCCESS != ret)
90         goto err_out;
91
92     /* set threading model */
93     ret = RegSetValueExW(hsubkey, tmodel_keyname, 0L, REG_SZ,
94                          (const BYTE*)szThreadingModel, 
95                          sizeof(WCHAR) * (lstrlenW(szThreadingModel) + 1));
96 err_out:
97     if (hsubkey)
98         RegCloseKey(hsubkey);
99     RegCloseKey(hkey);
100     return HRESULT_FROM_WIN32(ret);
101 }
102
103 /*
104  * RegisterAllClasses()
105  */
106 static HRESULT SetupRegisterAllClasses(const FactoryTemplate * pList, int num,
107                                        LPCWSTR szFileName, BOOL bRegister)
108 {
109     HRESULT hr = NOERROR;
110     HKEY hkey;
111     OLECHAR szCLSID[CHARS_IN_GUID];
112     LONG i, ret = RegCreateKeyW(HKEY_CLASSES_ROOT, clsid_keyname, &hkey);
113     if (ERROR_SUCCESS != ret)
114         return HRESULT_FROM_WIN32(ret);
115
116     for (i = 0; i < num; i++, pList++)
117     {
118         /* (un)register CLSID and InprocServer32 */
119         hr = StringFromGUID2(pList->m_ClsID, szCLSID, CHARS_IN_GUID);
120         if (SUCCEEDED(hr))
121         {
122             if (bRegister )
123                 hr = SetupRegisterClass(hkey, szCLSID,
124                                         pList->m_Name, szFileName,
125                                         ips32_keyname, tmodel_both);
126             else
127                 hr = RegDeleteTreeW(hkey, szCLSID);
128         }
129     }
130     RegCloseKey(hkey);
131     return hr;
132 }
133
134
135 /****************************************************************************
136  * SetupRegisterServers
137  *
138  * This function is table driven using the static members of the
139  * CFactoryTemplate class defined in the Dll.
140  *
141  * It registers the Dll as the InprocServer32 for all the classes in
142  * CFactoryTemplate
143  *
144  ****************************************************************************/
145 HRESULT SetupRegisterServers(const FactoryTemplate * pList, int num,
146                              BOOL bRegister)
147 {
148     static const WCHAR szFileName[] = {'q','c','a','p','.','d','l','l',0};
149     HRESULT hr = NOERROR;
150
151     /* first register all server classes, just to make sure */
152     if (bRegister)
153         hr = SetupRegisterAllClasses(pList, num, szFileName, TRUE );
154
155     hr = AMovieDllRegisterServer2(bRegister);
156
157     /* if unregistering, unregister all OLE servers */
158     if (SUCCEEDED(hr) && !bRegister)
159         hr = SetupRegisterAllClasses(pList, num, szFileName, FALSE);
160     return hr;
161 }