dsound/tests: Allow more time for an event to be signalled.
[wine.git] / dlls / propsys / propsys_main.c
blob7ae3870efb2bdc11127856561de154d428a5ba9e
1 /*
2 * propsys main
4 * Copyright 1997, 2002 Alexandre Julliard
5 * Copyright 2008 James Hawkins
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "rpcproxy.h"
30 #include "propsys.h"
31 #include "wine/debug.h"
33 #include "propsys_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
37 static HINSTANCE propsys_hInstance;
39 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
41 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
43 switch (fdwReason)
45 case DLL_WINE_PREATTACH:
46 return FALSE; /* prefer native version */
47 case DLL_PROCESS_ATTACH:
48 propsys_hInstance = hinstDLL;
49 DisableThreadLibraryCalls(hinstDLL);
50 break;
53 return TRUE;
56 HRESULT WINAPI DllRegisterServer(void)
58 return __wine_register_resources( propsys_hInstance );
61 HRESULT WINAPI DllUnregisterServer(void)
63 return __wine_unregister_resources( propsys_hInstance );
66 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
68 *ppv = NULL;
70 if(IsEqualGUID(&IID_IUnknown, riid)) {
71 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
72 *ppv = iface;
73 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
74 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
75 *ppv = iface;
78 if(*ppv) {
79 IUnknown_AddRef((IUnknown*)*ppv);
80 return S_OK;
83 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
84 return E_NOINTERFACE;
87 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
89 TRACE("(%p)\n", iface);
90 return 2;
93 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
95 TRACE("(%p)\n", iface);
96 return 1;
99 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
101 TRACE("(%p)->(%x)\n", iface, fLock);
103 return S_OK;
106 static HRESULT WINAPI InMemoryPropertyStoreFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
107 REFIID riid, void **ppv)
109 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
111 return PropertyStore_CreateInstance(outer, riid, ppv);
114 static const IClassFactoryVtbl InMemoryPropertyStoreFactoryVtbl = {
115 ClassFactory_QueryInterface,
116 ClassFactory_AddRef,
117 ClassFactory_Release,
118 InMemoryPropertyStoreFactory_CreateInstance,
119 ClassFactory_LockServer
122 static IClassFactory InMemoryPropertyStoreFactory = { &InMemoryPropertyStoreFactoryVtbl };
124 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
126 if(IsEqualGUID(&CLSID_InMemoryPropertyStore, rclsid)) {
127 TRACE("(CLSID_InMemoryPropertyStore %s %p)\n", debugstr_guid(riid), ppv);
128 return IClassFactory_QueryInterface(&InMemoryPropertyStoreFactory, riid, ppv);
131 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
132 return CLASS_E_CLASSNOTAVAILABLE;
135 HRESULT WINAPI DllCanUnloadNow(void)
137 return S_FALSE;
140 static HRESULT WINAPI propsys_QueryInterface(IPropertySystem *iface, REFIID riid, void **obj)
142 *obj = NULL;
144 if (IsEqualIID(riid, &IID_IPropertySystem) || IsEqualIID(riid, &IID_IUnknown)) {
145 *obj = iface;
146 IPropertySystem_AddRef(iface);
147 return S_OK;
150 FIXME("%s\n", debugstr_guid(riid));
151 return E_NOINTERFACE;
154 static ULONG WINAPI propsys_AddRef(IPropertySystem *iface)
156 return 2;
159 static ULONG WINAPI propsys_Release(IPropertySystem *iface)
161 return 1;
164 static HRESULT WINAPI propsys_GetPropertyDescription(IPropertySystem *iface,
165 REFPROPERTYKEY propkey, REFIID riid, void **ppv)
167 return PSGetPropertyDescription(propkey, riid, ppv);
170 static HRESULT WINAPI propsys_GetPropertyDescriptionByName(IPropertySystem *iface,
171 LPCWSTR canonical_name, REFIID riid, void **ppv)
173 FIXME("%s %s %p: stub\n", debugstr_w(canonical_name), debugstr_guid(riid), ppv);
174 return E_NOTIMPL;
177 static HRESULT WINAPI propsys_GetPropertyDescriptionListFromString(IPropertySystem *iface,
178 LPCWSTR proplist, REFIID riid, void **ppv)
180 return PSGetPropertyDescriptionListFromString(proplist, riid, ppv);
183 static HRESULT WINAPI propsys_EnumeratePropertyDescriptions(IPropertySystem *iface,
184 PROPDESC_ENUMFILTER filter, REFIID riid, void **ppv)
186 FIXME("%d %s %p: stub\n", filter, debugstr_guid(riid), ppv);
187 return E_NOTIMPL;
190 static HRESULT WINAPI propsys_FormatForDisplay(IPropertySystem *iface,
191 REFPROPERTYKEY key, REFPROPVARIANT propvar, PROPDESC_FORMAT_FLAGS flags,
192 LPWSTR dest, DWORD destlen)
194 FIXME("%p %p %x %p %d: stub\n", key, propvar, flags, dest, destlen);
195 return E_NOTIMPL;
198 static HRESULT WINAPI propsys_FormatForDisplayAlloc(IPropertySystem *iface,
199 REFPROPERTYKEY key, REFPROPVARIANT propvar, PROPDESC_FORMAT_FLAGS flags,
200 LPWSTR *text)
202 FIXME("%p %p %x %p: stub\n", key, propvar, flags, text);
203 return E_NOTIMPL;
206 static HRESULT WINAPI propsys_RegisterPropertySchema(IPropertySystem *iface, LPCWSTR path)
208 return PSRegisterPropertySchema(path);
211 static HRESULT WINAPI propsys_UnregisterPropertySchema(IPropertySystem *iface, LPCWSTR path)
213 return PSUnregisterPropertySchema(path);
216 static HRESULT WINAPI propsys_RefreshPropertySchema(IPropertySystem *iface)
218 return PSRefreshPropertySchema();
221 static const IPropertySystemVtbl propsysvtbl = {
222 propsys_QueryInterface,
223 propsys_AddRef,
224 propsys_Release,
225 propsys_GetPropertyDescription,
226 propsys_GetPropertyDescriptionByName,
227 propsys_GetPropertyDescriptionListFromString,
228 propsys_EnumeratePropertyDescriptions,
229 propsys_FormatForDisplay,
230 propsys_FormatForDisplayAlloc,
231 propsys_RegisterPropertySchema,
232 propsys_UnregisterPropertySchema,
233 propsys_RefreshPropertySchema
236 static IPropertySystem propsys = { &propsysvtbl };
238 HRESULT WINAPI PSGetPropertySystem(REFIID riid, void **obj)
240 return IPropertySystem_QueryInterface(&propsys, riid, obj);
243 HRESULT WINAPI PSRegisterPropertySchema(PCWSTR path)
245 FIXME("%s stub\n", debugstr_w(path));
247 return S_OK;
250 HRESULT WINAPI PSUnregisterPropertySchema(PCWSTR path)
252 FIXME("%s stub\n", debugstr_w(path));
254 return E_NOTIMPL;
257 HRESULT WINAPI PSGetPropertyDescription(REFPROPERTYKEY propkey, REFIID riid, void **ppv)
259 FIXME("%p, %p, %p\n", propkey, riid, ppv);
260 return E_NOTIMPL;
263 HRESULT WINAPI PSGetPropertyDescriptionListFromString(LPCWSTR proplist, REFIID riid, void **ppv)
265 FIXME("%s, %p, %p\n", debugstr_w(proplist), riid, ppv);
266 return E_NOTIMPL;
269 HRESULT WINAPI PSGetPropertyKeyFromName(PCWSTR name, PROPERTYKEY *key)
271 FIXME("%s, %p\n", debugstr_w(name), key);
272 return E_NOTIMPL;
275 HRESULT WINAPI PSRefreshPropertySchema(void)
277 FIXME("\n");
278 return S_OK;
281 HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch)
283 static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-',
284 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
285 '%','0','2','X','%','0','2','X','%','0','2','X',
286 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
287 static const WCHAR pid_fmtW[] = {'%','u',0};
289 WCHAR pidW[PKEY_PIDSTR_MAX + 1];
290 LPWSTR p = psz;
291 int len;
293 TRACE("(%p, %p, %u)\n", pkey, psz, cch);
295 if (!psz)
296 return E_POINTER;
298 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
299 if (cch <= GUIDSTRING_MAX + 1)
300 return E_NOT_SUFFICIENT_BUFFER;
302 if (!pkey)
304 psz[0] = '\0';
305 return E_NOT_SUFFICIENT_BUFFER;
308 swprintf(psz, cch, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2,
309 pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1],
310 pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4],
311 pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]);
313 /* Overwrite the null terminator with the space character. */
314 p += GUIDSTRING_MAX - 1;
315 *p++ = ' ';
316 cch -= GUIDSTRING_MAX - 1 + 1;
318 len = swprintf(pidW, ARRAY_SIZE(pidW), pid_fmtW, pkey->pid);
320 if (cch >= len + 1)
322 lstrcpyW(p, pidW);
323 return S_OK;
325 else
327 WCHAR *ptr = pidW + len - 1;
329 psz[0] = '\0';
330 *p++ = '\0';
331 cch--;
333 /* Replicate a quirk of the native implementation where the contents
334 * of the property ID string are written backwards to the output
335 * buffer, skipping the rightmost digit. */
336 if (cch)
338 ptr--;
339 while (cch--)
340 *p++ = *ptr--;
343 return E_NOT_SUFFICIENT_BUFFER;
347 static const BYTE hex2bin[] =
349 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
350 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
351 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
352 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
353 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
354 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
355 0,10,11,12,13,14,15 /* 0x60 */
358 static BOOL validate_indices(LPCWSTR s, int min, int max)
360 int i;
362 for (i = min; i <= max; i++)
364 if (!s[i])
365 return FALSE;
367 if (i == 0)
369 if (s[i] != '{')
370 return FALSE;
372 else if (i == 9 || i == 14 || i == 19 || i == 24)
374 if (s[i] != '-')
375 return FALSE;
377 else if (i == 37)
379 if (s[i] != '}')
380 return FALSE;
382 else
384 if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0'))
385 return FALSE;
389 return TRUE;
392 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
393 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
394 static BOOL string_to_guid(LPCWSTR s, LPGUID id)
396 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
398 if (!validate_indices(s, 0, 8)) return FALSE;
399 id->Data1 = (hex2bin[s[1]] << 28 | hex2bin[s[2]] << 24 | hex2bin[s[3]] << 20 | hex2bin[s[4]] << 16 |
400 hex2bin[s[5]] << 12 | hex2bin[s[6]] << 8 | hex2bin[s[7]] << 4 | hex2bin[s[8]]);
401 if (!validate_indices(s, 9, 14)) return FALSE;
402 id->Data2 = hex2bin[s[10]] << 12 | hex2bin[s[11]] << 8 | hex2bin[s[12]] << 4 | hex2bin[s[13]];
403 if (!validate_indices(s, 15, 19)) return FALSE;
404 id->Data3 = hex2bin[s[15]] << 12 | hex2bin[s[16]] << 8 | hex2bin[s[17]] << 4 | hex2bin[s[18]];
406 /* these are just sequential bytes */
408 if (!validate_indices(s, 20, 21)) return FALSE;
409 id->Data4[0] = hex2bin[s[20]] << 4 | hex2bin[s[21]];
410 if (!validate_indices(s, 22, 24)) return FALSE;
411 id->Data4[1] = hex2bin[s[22]] << 4 | hex2bin[s[23]];
413 if (!validate_indices(s, 25, 26)) return FALSE;
414 id->Data4[2] = hex2bin[s[25]] << 4 | hex2bin[s[26]];
415 if (!validate_indices(s, 27, 28)) return FALSE;
416 id->Data4[3] = hex2bin[s[27]] << 4 | hex2bin[s[28]];
417 if (!validate_indices(s, 29, 30)) return FALSE;
418 id->Data4[4] = hex2bin[s[29]] << 4 | hex2bin[s[30]];
419 if (!validate_indices(s, 31, 32)) return FALSE;
420 id->Data4[5] = hex2bin[s[31]] << 4 | hex2bin[s[32]];
421 if (!validate_indices(s, 33, 34)) return FALSE;
422 id->Data4[6] = hex2bin[s[33]] << 4 | hex2bin[s[34]];
423 if (!validate_indices(s, 35, 37)) return FALSE;
424 id->Data4[7] = hex2bin[s[35]] << 4 | hex2bin[s[36]];
426 return TRUE;
429 HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR pszString, PROPERTYKEY *pkey)
431 BOOL has_minus = FALSE, has_comma = FALSE;
433 TRACE("(%s, %p)\n", debugstr_w(pszString), pkey);
435 if (!pszString || !pkey)
436 return E_POINTER;
438 memset(pkey, 0, sizeof(PROPERTYKEY));
440 if (!string_to_guid(pszString, &pkey->fmtid))
441 return E_INVALIDARG;
443 pszString += GUIDSTRING_MAX - 1;
445 if (!*pszString)
446 return E_INVALIDARG;
448 /* Only the space seems to be recognized as whitespace. The comma is only
449 * recognized once and processing terminates if another comma is found. */
450 while (*pszString == ' ' || *pszString == ',')
452 if (*pszString == ',')
454 if (has_comma)
455 return S_OK;
456 else
457 has_comma = TRUE;
459 pszString++;
462 if (!*pszString)
463 return E_INVALIDARG;
465 /* Only two minus signs are recognized if no comma is detected. The first
466 * sign is ignored, and the second is interpreted. If a comma is detected
467 * before the minus sign, then only one minus sign counts, and property ID
468 * interpretation begins with the next character. */
469 if (has_comma)
471 if (*pszString == '-')
473 has_minus = TRUE;
474 pszString++;
477 else
479 if (*pszString == '-')
480 pszString++;
482 /* Skip any intermediate spaces after the first minus sign. */
483 while (*pszString == ' ')
484 pszString++;
486 if (*pszString == '-')
488 has_minus = TRUE;
489 pszString++;
492 /* Skip any remaining spaces after minus sign. */
493 while (*pszString == ' ')
494 pszString++;
497 /* Overflow is not checked. */
498 while (iswdigit(*pszString))
500 pkey->pid *= 10;
501 pkey->pid += (*pszString - '0');
502 pszString++;
505 if (has_minus)
506 pkey->pid = ~pkey->pid + 1;
508 return S_OK;
511 HRESULT WINAPI PSCreateMemoryPropertyStore(REFIID riid, void **ppv)
513 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
515 return PropertyStore_CreateInstance(NULL, riid, ppv);