2 * Copyright (C) 2003 Michael Günnewig
3 * Copyright (C) 2003 CodeWeavers Inc. (Ulrich Czekalla)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <wine/unicode.h>
27 #define MSDMO_MAJOR_VERSION 6
29 static const WCHAR szDMORootKey
[] =
31 'D','i','r','e','c','t','S','h','o','w','\\',
32 'M','e','d','i','a','O','b','j','e','c','t','s',0
35 static const WCHAR szDMOInputType
[] =
37 'I','n','p','u','t','T','y','p','e','s',0
40 static const WCHAR szDMOOutputType
[] =
42 'O','u','t','p','u','t','T','y','p','e','s',0
45 static const WCHAR szDMOKeyed
[] =
50 static const WCHAR szDMOCategories
[] =
52 'C','a','t','e','g','o','r','i','e','s',0
55 static const WCHAR szGUIDFmt
[] =
57 '%','0','8','X','-','%','0','4','X','-','%','0','4','X','-','%','0',
58 '2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2',
59 'X','%','0','2','X','%','0','2','X','%','0','2','X',0
62 static const WCHAR szCat3Fmt
[] =
64 '%','s','\\','%','s','\\','%','s',0
67 static const WCHAR szCat2Fmt
[] =
69 '%','s','\\','%','s',0
72 static const WCHAR szToGuidFmt
[] =
80 IEnumDMO IEnumDMO_iface
;
83 const GUID
* guidCategory
;
86 DMO_PARTIAL_MEDIATYPE
*pInTypes
;
88 DMO_PARTIAL_MEDIATYPE
*pOutTypes
;
92 static inline IEnumDMOImpl
*impl_from_IEnumDMO(IEnumDMO
*iface
)
94 return CONTAINING_RECORD(iface
, IEnumDMOImpl
, IEnumDMO_iface
);
97 static HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
);
99 static const IEnumDMOVtbl edmovt
;
101 static LPWSTR
GUIDToString(LPWSTR lpwstr
, REFGUID lpcguid
)
103 wsprintfW(lpwstr
, szGUIDFmt
, lpcguid
->Data1
, lpcguid
->Data2
,
104 lpcguid
->Data3
, lpcguid
->Data4
[0], lpcguid
->Data4
[1],
105 lpcguid
->Data4
[2], lpcguid
->Data4
[3], lpcguid
->Data4
[4],
106 lpcguid
->Data4
[5], lpcguid
->Data4
[6], lpcguid
->Data4
[7]);
111 static BOOL
IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE
* mt1
, const DMO_PARTIAL_MEDIATYPE
* mt2
)
114 return (IsEqualCLSID(&mt1
->type
, &mt2
->type
) ||
115 IsEqualCLSID(&mt2
->type
, &GUID_NULL
) ||
116 IsEqualCLSID(&mt1
->type
, &GUID_NULL
)) &&
117 (IsEqualCLSID(&mt1
->subtype
, &mt2
->subtype
) ||
118 IsEqualCLSID(&mt2
->subtype
, &GUID_NULL
) ||
119 IsEqualCLSID(&mt1
->subtype
, &GUID_NULL
));
122 static HRESULT
write_types(HKEY hkey
, LPCWSTR name
, const DMO_PARTIAL_MEDIATYPE
* types
, DWORD count
)
125 if (MSDMO_MAJOR_VERSION
> 5)
127 hres
= RegSetValueExW(hkey
, name
, 0, REG_BINARY
, (const BYTE
*) types
,
128 count
* sizeof(DMO_PARTIAL_MEDIATYPE
));
132 HKEY skey1
,skey2
,skey3
;
136 hres
= RegCreateKeyExW(hkey
, name
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
137 KEY_WRITE
, NULL
, &skey1
, NULL
);
138 while (index
< count
)
140 GUIDToString(szGuidKey
,&types
[index
].type
);
141 hres
= RegCreateKeyExW(skey1
, szGuidKey
, 0, NULL
,
142 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey2
, NULL
);
143 GUIDToString(szGuidKey
,&types
[index
].subtype
);
144 hres
= RegCreateKeyExW(skey2
, szGuidKey
, 0, NULL
,
145 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey3
, NULL
);
156 /***************************************************************
157 * DMORegister (MSDMO.@)
159 * Register a DirectX Media Object.
161 HRESULT WINAPI
DMORegister(
164 REFGUID guidCategory
,
167 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
169 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
179 TRACE("%s\n", debugstr_w(szName
));
181 hres
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, NULL
,
182 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hrkey
, NULL
);
183 if (ERROR_SUCCESS
!= hres
)
186 /* Create clsidDMO key under MediaObjects */
187 hres
= RegCreateKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
188 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
189 if (ERROR_SUCCESS
!= hres
)
192 /* Set default Name value */
193 hres
= RegSetValueExW(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*) szName
,
194 (strlenW(szName
) + 1) * sizeof(WCHAR
));
197 hres
= write_types(hkey
, szDMOInputType
, pInTypes
, cInTypes
);
199 /* Set OutputTypes */
200 hres
= write_types(hkey
, szDMOOutputType
, pOutTypes
, cOutTypes
);
202 if (dwFlags
& DMO_REGISTERF_IS_KEYED
)
204 /* Create Keyed key */
205 hres
= RegCreateKeyExW(hkey
, szDMOKeyed
, 0, NULL
,
206 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
207 if (ERROR_SUCCESS
!= hres
)
212 /* Register the category */
213 hres
= RegCreateKeyExW(hrkey
, szDMOCategories
, 0, NULL
,
214 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
215 if (ERROR_SUCCESS
!= hres
)
220 hres
= RegCreateKeyExW(hckey
, GUIDToString(szguid
, guidCategory
), 0, NULL
,
221 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
222 if (ERROR_SUCCESS
!= hres
)
224 hres
= RegCreateKeyExW(hkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
225 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hclskey
, NULL
);
226 if (ERROR_SUCCESS
!= hres
)
235 RegCloseKey(hclskey
);
239 TRACE(" hresult=0x%08x\n", hres
);
244 /***************************************************************
245 * DMOUnregister (MSDMO.@)
247 * Unregister a DirectX Media Object.
249 HRESULT WINAPI
DMOUnregister(REFCLSID clsidDMO
, REFGUID guidCategory
)
256 GUIDToString(szguid
, clsidDMO
);
258 TRACE("%s %p\n", debugstr_w(szguid
), guidCategory
);
260 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, KEY_WRITE
, &hrkey
);
261 if (ERROR_SUCCESS
!= hres
)
264 hres
= RegDeleteKeyW(hrkey
, szguid
);
265 if (ERROR_SUCCESS
!= hres
)
268 hres
= RegOpenKeyExW(hrkey
, szDMOCategories
, 0, KEY_WRITE
, &hckey
);
269 if (ERROR_SUCCESS
!= hres
)
272 hres
= RegDeleteKeyW(hckey
, szguid
);
273 if (ERROR_SUCCESS
!= hres
)
286 /***************************************************************
287 * DMOGetName (MSDMO.@)
289 * Get DMP Name from the registry
291 HRESULT WINAPI
DMOGetName(REFCLSID clsidDMO
, WCHAR szName
[])
297 static const INT max_name_len
= 80;
300 TRACE("%s\n", debugstr_guid(clsidDMO
));
302 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
,
303 0, KEY_READ
, &hrkey
);
304 if (ERROR_SUCCESS
!= hres
)
307 hres
= RegOpenKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
),
309 if (ERROR_SUCCESS
!= hres
)
312 count
= max_name_len
* sizeof(WCHAR
);
313 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
,
314 (LPBYTE
) szName
, &count
);
316 TRACE(" szName=%s\n", debugstr_w(szName
));
327 /**************************************************************************
328 * IEnumDMOImpl_Destructor
330 static BOOL
IEnumDMOImpl_Destructor(IEnumDMOImpl
* This
)
335 RegCloseKey(This
->hkey
);
337 HeapFree(GetProcessHeap(), 0, This
->pInTypes
);
338 HeapFree(GetProcessHeap(), 0, This
->pOutTypes
);
344 /**************************************************************************
345 * IEnumDMO_Constructor
347 static IEnumDMO
* IEnumDMO_Constructor(
348 REFGUID guidCategory
,
351 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
353 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
)
356 IEnumDMOImpl
* lpedmo
;
359 lpedmo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumDMOImpl
));
364 lpedmo
->IEnumDMO_iface
.lpVtbl
= &edmovt
;
366 lpedmo
->guidCategory
= guidCategory
;
367 lpedmo
->dwFlags
= dwFlags
;
371 size
= cInTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
372 lpedmo
->pInTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
373 if (!lpedmo
->pInTypes
)
375 memcpy(lpedmo
->pInTypes
, pInTypes
, size
);
376 lpedmo
->cInTypes
= cInTypes
;
381 size
= cOutTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
382 lpedmo
->pOutTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
383 if (!lpedmo
->pOutTypes
)
385 memcpy(lpedmo
->pOutTypes
, pOutTypes
, size
);
386 lpedmo
->cOutTypes
= cOutTypes
;
389 /* If not filtering by category enum from media objects root */
390 if (IsEqualGUID(guidCategory
, &GUID_NULL
))
392 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
,
393 0, KEY_READ
, &lpedmo
->hkey
))
399 WCHAR szKey
[MAX_PATH
];
401 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szDMOCategories
,
402 GUIDToString(szguid
, guidCategory
));
403 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
,
404 0, KEY_READ
, &lpedmo
->hkey
))
411 IEnumDMOImpl_Destructor(lpedmo
);
412 HeapFree(GetProcessHeap(),0,lpedmo
);
417 TRACE("returning %p\n", lpedmo
);
419 return (IEnumDMO
*)lpedmo
;
423 /******************************************************************************
426 static ULONG WINAPI
IEnumDMO_fnAddRef(IEnumDMO
* iface
)
428 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
429 return InterlockedIncrement(&This
->ref
);
433 /**************************************************************************
434 * EnumDMO_QueryInterface
436 static HRESULT WINAPI
IEnumDMO_fnQueryInterface(
441 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
445 if(IsEqualIID(riid
, &IID_IUnknown
))
447 else if(IsEqualIID(riid
, &IID_IEnumDMO
))
452 IEnumDMO_fnAddRef(*ppvObj
);
456 return E_NOINTERFACE
;
460 /******************************************************************************
463 static ULONG WINAPI
IEnumDMO_fnRelease(IEnumDMO
* iface
)
465 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
466 ULONG refCount
= InterlockedDecrement(&This
->ref
);
470 IEnumDMOImpl_Destructor(This
);
471 HeapFree(GetProcessHeap(),0,This
);
477 /******************************************************************************
480 static HRESULT WINAPI
IEnumDMO_fnNext(
485 DWORD
* pcItemsFetched
)
489 WCHAR szNextKey
[MAX_PATH
];
491 WCHAR szKey
[MAX_PATH
];
492 WCHAR szValue
[MAX_PATH
];
497 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
499 TRACE("--> (%p) %d %p %p %p\n", iface
, cItemsToFetch
, pCLSID
, Names
, pcItemsFetched
);
501 if (!pCLSID
|| !Names
|| !pcItemsFetched
)
504 while (count
< cItemsToFetch
)
509 hres
= RegEnumKeyExW(This
->hkey
, This
->index
, szNextKey
, &len
, NULL
, NULL
, NULL
, &ft
);
510 if (hres
!= ERROR_SUCCESS
)
513 TRACE("found %s\n", debugstr_w(szNextKey
));
515 if (!(This
->dwFlags
& DMO_ENUMF_INCLUDE_KEYED
))
517 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szNextKey
, szDMOKeyed
);
518 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
519 if (ERROR_SUCCESS
== hres
)
522 /* Skip Keyed entries */
527 wsprintfW(szKey
, szCat2Fmt
, szDMORootKey
, szNextKey
);
528 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
534 DMO_PARTIAL_MEDIATYPE
* pInTypes
;
536 hres
= read_types(hkey
, szDMOInputType
, &cInTypes
,
537 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
538 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
540 if (ERROR_SUCCESS
!= hres
)
546 pInTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
548 for (i
= 0; i
< This
->cInTypes
; i
++)
550 for (j
= 0; j
< cInTypes
; j
++)
552 if (IsMediaTypeEqual(&pInTypes
[j
], &This
->pInTypes
[i
]))
560 if (i
< This
->cInTypes
)
571 DMO_PARTIAL_MEDIATYPE
* pOutTypes
;
573 hres
= read_types(hkey
, szDMOOutputType
, &cOutTypes
,
574 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
575 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
577 if (ERROR_SUCCESS
!= hres
)
583 pOutTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
585 for (i
= 0; i
< This
->cOutTypes
; i
++)
587 for (j
= 0; j
< cOutTypes
; j
++)
589 if (IsMediaTypeEqual(&pOutTypes
[j
], &This
->pOutTypes
[i
]))
597 if (i
< This
->cOutTypes
)
604 /* Media object wasn't filtered so add it to return list */
606 len
= MAX_PATH
* sizeof(WCHAR
);
607 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
, (LPBYTE
) szValue
, &len
);
608 if (ERROR_SUCCESS
== hres
)
610 Names
[count
] = HeapAlloc(GetProcessHeap(), 0, strlenW(szValue
) + 1);
612 strcmpW(Names
[count
], szValue
);
614 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
615 CLSIDFromString(szGuidKey
, &pCLSID
[count
]);
617 TRACE("found match %s %s\n", debugstr_w(szValue
), debugstr_w(szNextKey
));
622 *pcItemsFetched
= count
;
623 if (*pcItemsFetched
< cItemsToFetch
)
626 TRACE("<-- %i found\n",count
);
631 /******************************************************************************
634 static HRESULT WINAPI
IEnumDMO_fnSkip(IEnumDMO
* iface
, DWORD cItemsToSkip
)
636 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
638 This
->index
+= cItemsToSkip
;
644 /******************************************************************************
647 static HRESULT WINAPI
IEnumDMO_fnReset(IEnumDMO
* iface
)
649 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
657 /******************************************************************************
660 static HRESULT WINAPI
IEnumDMO_fnClone(IEnumDMO
* iface
, IEnumDMO
**ppEnum
)
662 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
664 FIXME("(%p)->() to (%p)->() E_NOTIMPL\n", This
, ppEnum
);
670 /***************************************************************
673 * Enumerate DirectX Media Objects in the registry.
675 HRESULT WINAPI
DMOEnum(
676 REFGUID guidCategory
,
679 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
681 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
,
684 HRESULT hres
= E_FAIL
;
686 TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
687 guidCategory
, dwFlags
, cInTypes
, cOutTypes
);
689 *ppEnum
= IEnumDMO_Constructor(guidCategory
, dwFlags
, cInTypes
,
690 pInTypes
, cOutTypes
, pOutTypes
);
698 static const IEnumDMOVtbl edmovt
=
700 IEnumDMO_fnQueryInterface
,
710 HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
)
713 if (MSDMO_MAJOR_VERSION
> 5)
716 len
= requested
* sizeof(DMO_PARTIAL_MEDIATYPE
);
717 ret
= RegQueryValueExW(root
, key
, NULL
, NULL
, (LPBYTE
) types
, &len
);
718 *supplied
= len
/ sizeof(DMO_PARTIAL_MEDIATYPE
);
726 if (ERROR_SUCCESS
== RegOpenKeyExW(root
, key
, 0, KEY_READ
, &hkey
))
729 WCHAR szNextKey
[MAX_PATH
];
731 LONG rc
= ERROR_SUCCESS
;
733 while (rc
== ERROR_SUCCESS
)
736 rc
= RegEnumKeyExW(hkey
, index
, szNextKey
, &len
, NULL
, NULL
, NULL
, NULL
);
737 if (rc
== ERROR_SUCCESS
)
741 LONG rcs
= ERROR_SUCCESS
;
742 WCHAR szSubKey
[MAX_PATH
];
744 RegOpenKeyExW(hkey
, szNextKey
, 0, KEY_READ
, &subk
);
745 while (rcs
== ERROR_SUCCESS
)
748 rcs
= RegEnumKeyExW(subk
, sub_index
, szSubKey
, &len
, NULL
, NULL
, NULL
, NULL
);
749 if (rcs
== ERROR_SUCCESS
)
751 if (*supplied
>= requested
)
755 rc
= ERROR_MORE_DATA
;
756 rcs
= ERROR_MORE_DATA
;
760 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
761 CLSIDFromString(szGuidKey
, &types
[*supplied
].type
);
762 wsprintfW(szGuidKey
,szToGuidFmt
,szSubKey
);
763 CLSIDFromString(szGuidKey
, &types
[*supplied
].subtype
);
764 TRACE("Adding type %s subtype %s at index %i\n",
765 debugstr_guid(&types
[*supplied
].type
),
766 debugstr_guid(&types
[*supplied
].subtype
),
781 /***************************************************************
782 * DMOGetTypes (MSDMO.@)
784 HRESULT WINAPI
DMOGetTypes(REFCLSID clsidDMO
,
785 ULONG ulInputTypesRequested
,
786 ULONG
* pulInputTypesSupplied
,
787 DMO_PARTIAL_MEDIATYPE
* pInputTypes
,
788 ULONG ulOutputTypesRequested
,
789 ULONG
* pulOutputTypesSupplied
,
790 DMO_PARTIAL_MEDIATYPE
* pOutputTypes
)
796 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO
), ulInputTypesRequested
,
797 pulInputTypesSupplied
, pInputTypes
, ulOutputTypesRequested
, pulOutputTypesSupplied
,
800 if (ERROR_SUCCESS
!= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0,
804 if (ERROR_SUCCESS
!= RegOpenKeyExW(root
,GUIDToString(szguid
,clsidDMO
) , 0,
811 if (ulInputTypesRequested
> 0)
813 ret
= read_types(hkey
, szDMOInputType
, pulInputTypesSupplied
, ulInputTypesRequested
, pInputTypes
);
816 *pulInputTypesSupplied
= 0;
818 if (ulOutputTypesRequested
> 0)
821 ret2
= read_types(hkey
, szDMOOutputType
, pulOutputTypesSupplied
, ulOutputTypesRequested
, pOutputTypes
);
827 *pulOutputTypesSupplied
= 0;