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
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msdmo
);
35 #define MSDMO_MAJOR_VERSION 6
37 static const WCHAR szDMORootKey
[] =
39 'D','i','r','e','c','t','S','h','o','w','\\',
40 'M','e','d','i','a','O','b','j','e','c','t','s',0
43 static const WCHAR szDMOInputType
[] =
45 'I','n','p','u','t','T','y','p','e','s',0
48 static const WCHAR szDMOOutputType
[] =
50 'O','u','t','p','u','t','T','y','p','e','s',0
53 static const WCHAR szDMOKeyed
[] =
58 static const WCHAR szDMOCategories
[] =
60 'C','a','t','e','g','o','r','i','e','s',0
63 static const WCHAR szGUIDFmt
[] =
65 '%','0','8','X','-','%','0','4','X','-','%','0','4','X','-','%','0',
66 '2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2',
67 'X','%','0','2','X','%','0','2','X','%','0','2','X',0
70 static const WCHAR szCat3Fmt
[] =
72 '%','s','\\','%','s','\\','%','s',0
75 static const WCHAR szCat2Fmt
[] =
77 '%','s','\\','%','s',0
80 static const WCHAR szToGuidFmt
[] =
88 IEnumDMO IEnumDMO_iface
;
91 const GUID
* guidCategory
;
94 DMO_PARTIAL_MEDIATYPE
*pInTypes
;
96 DMO_PARTIAL_MEDIATYPE
*pOutTypes
;
100 static inline IEnumDMOImpl
*impl_from_IEnumDMO(IEnumDMO
*iface
)
102 return CONTAINING_RECORD(iface
, IEnumDMOImpl
, IEnumDMO_iface
);
105 static HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
);
107 static const IEnumDMOVtbl edmovt
;
109 static LPWSTR
GUIDToString(LPWSTR lpwstr
, REFGUID lpcguid
)
111 wsprintfW(lpwstr
, szGUIDFmt
, lpcguid
->Data1
, lpcguid
->Data2
,
112 lpcguid
->Data3
, lpcguid
->Data4
[0], lpcguid
->Data4
[1],
113 lpcguid
->Data4
[2], lpcguid
->Data4
[3], lpcguid
->Data4
[4],
114 lpcguid
->Data4
[5], lpcguid
->Data4
[6], lpcguid
->Data4
[7]);
119 static BOOL
IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE
* mt1
, const DMO_PARTIAL_MEDIATYPE
* mt2
)
122 return (IsEqualCLSID(&mt1
->type
, &mt2
->type
) ||
123 IsEqualCLSID(&mt2
->type
, &GUID_NULL
) ||
124 IsEqualCLSID(&mt1
->type
, &GUID_NULL
)) &&
125 (IsEqualCLSID(&mt1
->subtype
, &mt2
->subtype
) ||
126 IsEqualCLSID(&mt2
->subtype
, &GUID_NULL
) ||
127 IsEqualCLSID(&mt1
->subtype
, &GUID_NULL
));
130 static HRESULT
write_types(HKEY hkey
, LPCWSTR name
, const DMO_PARTIAL_MEDIATYPE
* types
, DWORD count
)
133 if (MSDMO_MAJOR_VERSION
> 5)
135 hres
= RegSetValueExW(hkey
, name
, 0, REG_BINARY
, (const BYTE
*) types
,
136 count
* sizeof(DMO_PARTIAL_MEDIATYPE
));
140 HKEY skey1
,skey2
,skey3
;
144 hres
= RegCreateKeyExW(hkey
, name
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
145 KEY_WRITE
, NULL
, &skey1
, NULL
);
146 while (index
< count
)
148 GUIDToString(szGuidKey
,&types
[index
].type
);
149 hres
= RegCreateKeyExW(skey1
, szGuidKey
, 0, NULL
,
150 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey2
, NULL
);
151 GUIDToString(szGuidKey
,&types
[index
].subtype
);
152 hres
= RegCreateKeyExW(skey2
, szGuidKey
, 0, NULL
,
153 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey3
, NULL
);
164 /***************************************************************
165 * DMORegister (MSDMO.@)
167 * Register a DirectX Media Object.
169 HRESULT WINAPI
DMORegister(
172 REFGUID guidCategory
,
175 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
177 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
187 TRACE("%s\n", debugstr_w(szName
));
189 hres
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, NULL
,
190 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hrkey
, NULL
);
191 if (ERROR_SUCCESS
!= hres
)
194 /* Create clsidDMO key under MediaObjects */
195 hres
= RegCreateKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
196 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
197 if (ERROR_SUCCESS
!= hres
)
200 /* Set default Name value */
201 hres
= RegSetValueExW(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*) szName
,
202 (strlenW(szName
) + 1) * sizeof(WCHAR
));
205 hres
= write_types(hkey
, szDMOInputType
, pInTypes
, cInTypes
);
207 /* Set OutputTypes */
208 hres
= write_types(hkey
, szDMOOutputType
, pOutTypes
, cOutTypes
);
210 if (dwFlags
& DMO_REGISTERF_IS_KEYED
)
212 /* Create Keyed key */
213 hres
= RegCreateKeyExW(hkey
, szDMOKeyed
, 0, NULL
,
214 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
215 if (ERROR_SUCCESS
!= hres
)
220 /* Register the category */
221 hres
= RegCreateKeyExW(hrkey
, szDMOCategories
, 0, NULL
,
222 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
223 if (ERROR_SUCCESS
!= hres
)
228 hres
= RegCreateKeyExW(hckey
, GUIDToString(szguid
, guidCategory
), 0, NULL
,
229 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
230 if (ERROR_SUCCESS
!= hres
)
232 hres
= RegCreateKeyExW(hkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
233 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hclskey
, NULL
);
234 if (ERROR_SUCCESS
!= hres
)
243 RegCloseKey(hclskey
);
247 TRACE(" hresult=0x%08x\n", hres
);
252 /***************************************************************
253 * DMOUnregister (MSDMO.@)
255 * Unregister a DirectX Media Object.
257 HRESULT WINAPI
DMOUnregister(REFCLSID clsidDMO
, REFGUID guidCategory
)
264 GUIDToString(szguid
, clsidDMO
);
266 TRACE("%s %p\n", debugstr_w(szguid
), guidCategory
);
268 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, KEY_WRITE
, &hrkey
);
269 if (ERROR_SUCCESS
!= hres
)
272 hres
= RegDeleteKeyW(hrkey
, szguid
);
273 if (ERROR_SUCCESS
!= hres
)
276 hres
= RegOpenKeyExW(hrkey
, szDMOCategories
, 0, KEY_WRITE
, &hckey
);
277 if (ERROR_SUCCESS
!= hres
)
280 hres
= RegDeleteKeyW(hckey
, szguid
);
281 if (ERROR_SUCCESS
!= hres
)
294 /***************************************************************
295 * DMOGetName (MSDMO.@)
297 * Get DMP Name from the registry
299 HRESULT WINAPI
DMOGetName(REFCLSID clsidDMO
, WCHAR szName
[])
305 static const INT max_name_len
= 80;
308 TRACE("%s\n", debugstr_guid(clsidDMO
));
310 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
,
311 0, KEY_READ
, &hrkey
);
312 if (ERROR_SUCCESS
!= hres
)
315 hres
= RegOpenKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
),
317 if (ERROR_SUCCESS
!= hres
)
320 count
= max_name_len
* sizeof(WCHAR
);
321 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
,
322 (LPBYTE
) szName
, &count
);
324 TRACE(" szName=%s\n", debugstr_w(szName
));
335 /**************************************************************************
336 * IEnumDMOImpl_Destructor
338 static BOOL
IEnumDMOImpl_Destructor(IEnumDMOImpl
* This
)
343 RegCloseKey(This
->hkey
);
345 HeapFree(GetProcessHeap(), 0, This
->pInTypes
);
346 HeapFree(GetProcessHeap(), 0, This
->pOutTypes
);
352 /**************************************************************************
353 * IEnumDMO_Constructor
355 static IEnumDMO
* IEnumDMO_Constructor(
356 REFGUID guidCategory
,
359 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
361 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
)
364 IEnumDMOImpl
* lpedmo
;
367 lpedmo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumDMOImpl
));
372 lpedmo
->IEnumDMO_iface
.lpVtbl
= &edmovt
;
374 lpedmo
->guidCategory
= guidCategory
;
375 lpedmo
->dwFlags
= dwFlags
;
379 size
= cInTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
380 lpedmo
->pInTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
381 if (!lpedmo
->pInTypes
)
383 memcpy(lpedmo
->pInTypes
, pInTypes
, size
);
384 lpedmo
->cInTypes
= cInTypes
;
389 size
= cOutTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
390 lpedmo
->pOutTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
391 if (!lpedmo
->pOutTypes
)
393 memcpy(lpedmo
->pOutTypes
, pOutTypes
, size
);
394 lpedmo
->cOutTypes
= cOutTypes
;
397 /* If not filtering by category enum from media objects root */
398 if (IsEqualGUID(guidCategory
, &GUID_NULL
))
400 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
,
401 0, KEY_READ
, &lpedmo
->hkey
))
407 WCHAR szKey
[MAX_PATH
];
409 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szDMOCategories
,
410 GUIDToString(szguid
, guidCategory
));
411 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
,
412 0, KEY_READ
, &lpedmo
->hkey
))
419 IEnumDMOImpl_Destructor(lpedmo
);
420 HeapFree(GetProcessHeap(),0,lpedmo
);
425 TRACE("returning %p\n", lpedmo
);
427 return (IEnumDMO
*)lpedmo
;
431 /******************************************************************************
434 static ULONG WINAPI
IEnumDMO_fnAddRef(IEnumDMO
* iface
)
436 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
437 return InterlockedIncrement(&This
->ref
);
441 /**************************************************************************
442 * EnumDMO_QueryInterface
444 static HRESULT WINAPI
IEnumDMO_fnQueryInterface(
449 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
453 if(IsEqualIID(riid
, &IID_IUnknown
))
455 else if(IsEqualIID(riid
, &IID_IEnumDMO
))
460 IEnumDMO_fnAddRef(*ppvObj
);
464 return E_NOINTERFACE
;
468 /******************************************************************************
471 static ULONG WINAPI
IEnumDMO_fnRelease(IEnumDMO
* iface
)
473 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
474 ULONG refCount
= InterlockedDecrement(&This
->ref
);
478 IEnumDMOImpl_Destructor(This
);
479 HeapFree(GetProcessHeap(),0,This
);
485 /******************************************************************************
488 static HRESULT WINAPI
IEnumDMO_fnNext(
493 DWORD
* pcItemsFetched
)
497 WCHAR szNextKey
[MAX_PATH
];
499 WCHAR szKey
[MAX_PATH
];
500 WCHAR szValue
[MAX_PATH
];
505 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
507 TRACE("--> (%p) %d %p %p %p\n", iface
, cItemsToFetch
, pCLSID
, Names
, pcItemsFetched
);
509 if (!pCLSID
|| !Names
|| !pcItemsFetched
)
512 while (count
< cItemsToFetch
)
517 hres
= RegEnumKeyExW(This
->hkey
, This
->index
, szNextKey
, &len
, NULL
, NULL
, NULL
, &ft
);
518 if (hres
!= ERROR_SUCCESS
)
521 TRACE("found %s\n", debugstr_w(szNextKey
));
523 if (!(This
->dwFlags
& DMO_ENUMF_INCLUDE_KEYED
))
525 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szNextKey
, szDMOKeyed
);
526 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
527 if (ERROR_SUCCESS
== hres
)
530 /* Skip Keyed entries */
535 wsprintfW(szKey
, szCat2Fmt
, szDMORootKey
, szNextKey
);
536 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
542 DMO_PARTIAL_MEDIATYPE
* pInTypes
;
544 hres
= read_types(hkey
, szDMOInputType
, &cInTypes
,
545 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
546 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
548 if (ERROR_SUCCESS
!= hres
)
554 pInTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
556 for (i
= 0; i
< This
->cInTypes
; i
++)
558 for (j
= 0; j
< cInTypes
; j
++)
560 if (IsMediaTypeEqual(&pInTypes
[j
], &This
->pInTypes
[i
]))
568 if (i
< This
->cInTypes
)
579 DMO_PARTIAL_MEDIATYPE
* pOutTypes
;
581 hres
= read_types(hkey
, szDMOOutputType
, &cOutTypes
,
582 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
583 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
585 if (ERROR_SUCCESS
!= hres
)
591 pOutTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
593 for (i
= 0; i
< This
->cOutTypes
; i
++)
595 for (j
= 0; j
< cOutTypes
; j
++)
597 if (IsMediaTypeEqual(&pOutTypes
[j
], &This
->pOutTypes
[i
]))
605 if (i
< This
->cOutTypes
)
612 /* Media object wasn't filtered so add it to return list */
614 len
= MAX_PATH
* sizeof(WCHAR
);
615 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
, (LPBYTE
) szValue
, &len
);
616 if (ERROR_SUCCESS
== hres
)
618 Names
[count
] = HeapAlloc(GetProcessHeap(), 0, (strlenW(szValue
) + 1) * sizeof(WCHAR
));
620 strcpyW(Names
[count
], szValue
);
622 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
623 CLSIDFromString(szGuidKey
, &pCLSID
[count
]);
625 TRACE("found match %s %s\n", debugstr_w(szValue
), debugstr_w(szNextKey
));
630 *pcItemsFetched
= count
;
631 if (*pcItemsFetched
< cItemsToFetch
)
634 TRACE("<-- %i found\n",count
);
639 /******************************************************************************
642 static HRESULT WINAPI
IEnumDMO_fnSkip(IEnumDMO
* iface
, DWORD cItemsToSkip
)
644 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
646 This
->index
+= cItemsToSkip
;
652 /******************************************************************************
655 static HRESULT WINAPI
IEnumDMO_fnReset(IEnumDMO
* iface
)
657 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
665 /******************************************************************************
668 static HRESULT WINAPI
IEnumDMO_fnClone(IEnumDMO
* iface
, IEnumDMO
**ppEnum
)
670 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
672 FIXME("(%p)->() to (%p)->() E_NOTIMPL\n", This
, ppEnum
);
678 /***************************************************************
681 * Enumerate DirectX Media Objects in the registry.
683 HRESULT WINAPI
DMOEnum(
684 REFGUID guidCategory
,
687 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
689 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
,
692 HRESULT hres
= E_FAIL
;
694 TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
695 guidCategory
, dwFlags
, cInTypes
, cOutTypes
);
697 *ppEnum
= IEnumDMO_Constructor(guidCategory
, dwFlags
, cInTypes
,
698 pInTypes
, cOutTypes
, pOutTypes
);
706 static const IEnumDMOVtbl edmovt
=
708 IEnumDMO_fnQueryInterface
,
718 HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
)
721 if (MSDMO_MAJOR_VERSION
> 5)
724 len
= requested
* sizeof(DMO_PARTIAL_MEDIATYPE
);
725 ret
= RegQueryValueExW(root
, key
, NULL
, NULL
, (LPBYTE
) types
, &len
);
726 *supplied
= len
/ sizeof(DMO_PARTIAL_MEDIATYPE
);
734 if (ERROR_SUCCESS
== RegOpenKeyExW(root
, key
, 0, KEY_READ
, &hkey
))
737 WCHAR szNextKey
[MAX_PATH
];
739 LONG rc
= ERROR_SUCCESS
;
741 while (rc
== ERROR_SUCCESS
)
744 rc
= RegEnumKeyExW(hkey
, index
, szNextKey
, &len
, NULL
, NULL
, NULL
, NULL
);
745 if (rc
== ERROR_SUCCESS
)
749 LONG rcs
= ERROR_SUCCESS
;
750 WCHAR szSubKey
[MAX_PATH
];
752 RegOpenKeyExW(hkey
, szNextKey
, 0, KEY_READ
, &subk
);
753 while (rcs
== ERROR_SUCCESS
)
756 rcs
= RegEnumKeyExW(subk
, sub_index
, szSubKey
, &len
, NULL
, NULL
, NULL
, NULL
);
757 if (rcs
== ERROR_SUCCESS
)
759 if (*supplied
>= requested
)
763 rc
= ERROR_MORE_DATA
;
764 rcs
= ERROR_MORE_DATA
;
768 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
769 CLSIDFromString(szGuidKey
, &types
[*supplied
].type
);
770 wsprintfW(szGuidKey
,szToGuidFmt
,szSubKey
);
771 CLSIDFromString(szGuidKey
, &types
[*supplied
].subtype
);
772 TRACE("Adding type %s subtype %s at index %i\n",
773 debugstr_guid(&types
[*supplied
].type
),
774 debugstr_guid(&types
[*supplied
].subtype
),
789 /***************************************************************
790 * DMOGetTypes (MSDMO.@)
792 HRESULT WINAPI
DMOGetTypes(REFCLSID clsidDMO
,
793 ULONG ulInputTypesRequested
,
794 ULONG
* pulInputTypesSupplied
,
795 DMO_PARTIAL_MEDIATYPE
* pInputTypes
,
796 ULONG ulOutputTypesRequested
,
797 ULONG
* pulOutputTypesSupplied
,
798 DMO_PARTIAL_MEDIATYPE
* pOutputTypes
)
804 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO
), ulInputTypesRequested
,
805 pulInputTypesSupplied
, pInputTypes
, ulOutputTypesRequested
, pulOutputTypesSupplied
,
808 if (ERROR_SUCCESS
!= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0,
812 if (ERROR_SUCCESS
!= RegOpenKeyExW(root
,GUIDToString(szguid
,clsidDMO
) , 0,
819 if (ulInputTypesRequested
> 0)
821 ret
= read_types(hkey
, szDMOInputType
, pulInputTypesSupplied
, ulInputTypesRequested
, pInputTypes
);
824 *pulInputTypesSupplied
= 0;
826 if (ulOutputTypesRequested
> 0)
829 ret2
= read_types(hkey
, szDMOOutputType
, pulOutputTypesSupplied
, ulOutputTypesRequested
, pOutputTypes
);
835 *pulOutputTypesSupplied
= 0;