2 * DirectX DLL registration and unregistration
4 * Copyright (C) 2005 Rolf Kalbermatter
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.
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.
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
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(qcap
);
45 * defines and constants
47 #define MAX_KEY_LEN 260
49 static WCHAR
const clsid_keyname
[6] =
50 {'C','L','S','I','D',0 };
51 static WCHAR
const ips32_keyname
[15] =
52 {'I','n','P','r','o','c','S','e','r','v','e','r','3','2',0};
53 static WCHAR
const tmodel_keyname
[15] =
54 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
55 static WCHAR
const tmodel_both
[] =
59 * SetupRegisterClass()
61 static HRESULT
SetupRegisterClass(HKEY clsid
, LPCWSTR szCLSID
,
62 LPCWSTR szDescription
,
65 LPCWSTR szThreadingModel
)
67 HKEY hkey
, hsubkey
= NULL
;
68 LONG ret
= RegCreateKeyW(clsid
, szCLSID
, &hkey
);
69 if (ERROR_SUCCESS
!= ret
)
70 return HRESULT_FROM_WIN32(ret
);
72 /* set description string */
73 ret
= RegSetValueW(hkey
, NULL
, REG_SZ
, szDescription
,
74 sizeof(WCHAR
) * (lstrlenW(szDescription
) + 1));
75 if (ERROR_SUCCESS
!= ret
)
78 /* create CLSID\\{"CLSID"}\\"ServerType" key, using key to CLSID\\{"CLSID"}
79 passed back by last call to RegCreateKeyW(). */
80 ret
= RegCreateKeyW(hkey
, szServerType
, &hsubkey
);
81 if (ERROR_SUCCESS
!= ret
)
85 ret
= RegSetValueW(hsubkey
, NULL
, REG_SZ
, szFileName
,
86 sizeof(WCHAR
) * (lstrlenW(szFileName
) + 1));
87 if (ERROR_SUCCESS
!= ret
)
90 /* set threading model */
91 ret
= RegSetValueExW(hsubkey
, tmodel_keyname
, 0L, REG_SZ
,
92 (const BYTE
*)szThreadingModel
,
93 sizeof(WCHAR
) * (lstrlenW(szThreadingModel
) + 1));
98 return HRESULT_FROM_WIN32(ret
);
102 * RegisterAllClasses()
104 static HRESULT
SetupRegisterAllClasses(const CFactoryTemplate
* pList
, int num
,
105 LPCWSTR szFileName
, BOOL bRegister
)
107 HRESULT hr
= NOERROR
;
109 OLECHAR szCLSID
[CHARS_IN_GUID
];
110 LONG i
, ret
= RegCreateKeyW(HKEY_CLASSES_ROOT
, clsid_keyname
, &hkey
);
111 if (ERROR_SUCCESS
!= ret
)
112 return HRESULT_FROM_WIN32(ret
);
114 for (i
= 0; i
< num
; i
++, pList
++)
116 /* (un)register CLSID and InprocServer32 */
117 hr
= StringFromGUID2(pList
->m_ClsID
, szCLSID
, CHARS_IN_GUID
);
121 hr
= SetupRegisterClass(hkey
, szCLSID
,
122 pList
->m_Name
, szFileName
,
123 ips32_keyname
, tmodel_both
);
125 hr
= RegDeleteTreeW(hkey
, szCLSID
);
133 /****************************************************************************
134 * SetupRegisterServers
136 * This function is table driven using the static members of the
137 * CFactoryTemplate class defined in the Dll.
139 * It registers the Dll as the InprocServer32 for all the classes in
142 ****************************************************************************/
143 HRESULT
SetupRegisterServers(const CFactoryTemplate
* pList
, int num
,
146 static const WCHAR szFileName
[] = {'q','c','a','p','.','d','l','l',0};
147 HRESULT hr
= NOERROR
;
148 IFilterMapper2
*pIFM2
= NULL
;
150 /* first register all server classes, just to make sure */
152 hr
= SetupRegisterAllClasses(pList
, num
, szFileName
, TRUE
);
154 /* next, register/unregister all filters */
157 hr
= CoInitialize(NULL
);
159 TRACE("Getting IFilterMapper2\r\n");
160 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
161 &IID_IFilterMapper2
, (void **)&pIFM2
);
167 /* scan through array of CFactoryTemplates registering all filters */
168 for (i
= 0; i
< num
; i
++, pList
++)
170 if (pList
->m_pAMovieSetup_Filter
.dwVersion
)
172 hr
= IFilterMapper2_RegisterFilter(pIFM2
, pList
->m_ClsID
, pList
->m_Name
, NULL
, &CLSID_LegacyAmFilterCategory
, NULL
, &pList
->m_pAMovieSetup_Filter
);
175 /* check final error for this pass and break loop if we failed */
180 /* release interface */
181 IFilterMapper2_Release(pIFM2
);
185 CoFreeUnusedLibraries();
189 /* if unregistering, unregister all OLE servers */
190 if (SUCCEEDED(hr
) && !bRegister
)
191 hr
= SetupRegisterAllClasses(pList
, num
, szFileName
, FALSE
);
195 /****************************************************************************
196 * SetupInitializeServers
198 * This function is table driven using the static members of the
199 * CFactoryTemplate class defined in the Dll.
201 * It calls the initialize function for any class in CFactoryTemplate with
204 ****************************************************************************/
205 void SetupInitializeServers(const CFactoryTemplate
* pList
, int num
,
210 for (i
= 0; i
< num
; i
++, pList
++)
212 if (pList
->m_lpfnInit
)
213 pList
->m_lpfnInit(bLoading
, pList
->m_ClsID
);