wined3d: Record sampler usage for WINED3DSIH_LD_RAW.
[wine.git] / dlls / propsys / propsys_main.c
blob7631023b832758cff0972d9507a2deae035fb494
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
23 #include "config.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "rpcproxy.h"
31 #include "propsys.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "propsys_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
39 static HINSTANCE propsys_hInstance;
41 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
43 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
45 switch (fdwReason)
47 case DLL_WINE_PREATTACH:
48 return FALSE; /* prefer native version */
49 case DLL_PROCESS_ATTACH:
50 propsys_hInstance = hinstDLL;
51 DisableThreadLibraryCalls(hinstDLL);
52 break;
55 return TRUE;
58 HRESULT WINAPI DllRegisterServer(void)
60 return __wine_register_resources( propsys_hInstance );
63 HRESULT WINAPI DllUnregisterServer(void)
65 return __wine_unregister_resources( propsys_hInstance );
68 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
70 *ppv = NULL;
72 if(IsEqualGUID(&IID_IUnknown, riid)) {
73 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
74 *ppv = iface;
75 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
76 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
77 *ppv = iface;
80 if(*ppv) {
81 IUnknown_AddRef((IUnknown*)*ppv);
82 return S_OK;
85 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
86 return E_NOINTERFACE;
89 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
91 TRACE("(%p)\n", iface);
92 return 2;
95 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
97 TRACE("(%p)\n", iface);
98 return 1;
101 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
103 TRACE("(%p)->(%x)\n", iface, fLock);
105 return S_OK;
108 static HRESULT WINAPI InMemoryPropertyStoreFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
109 REFIID riid, void **ppv)
111 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
113 return PropertyStore_CreateInstance(outer, riid, ppv);
116 static const IClassFactoryVtbl InMemoryPropertyStoreFactoryVtbl = {
117 ClassFactory_QueryInterface,
118 ClassFactory_AddRef,
119 ClassFactory_Release,
120 InMemoryPropertyStoreFactory_CreateInstance,
121 ClassFactory_LockServer
124 static IClassFactory InMemoryPropertyStoreFactory = { &InMemoryPropertyStoreFactoryVtbl };
126 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
128 if(IsEqualGUID(&CLSID_InMemoryPropertyStore, rclsid)) {
129 TRACE("(CLSID_InMemoryPropertyStore %s %p)\n", debugstr_guid(riid), ppv);
130 return IClassFactory_QueryInterface(&InMemoryPropertyStoreFactory, riid, ppv);
133 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
134 return CLASS_E_CLASSNOTAVAILABLE;
137 HRESULT WINAPI DllCanUnloadNow(void)
139 return S_FALSE;
142 static HRESULT WINAPI propsys_QueryInterface(IPropertySystem *iface, REFIID riid, void **obj)
144 *obj = NULL;
146 if (IsEqualIID(riid, &IID_IPropertySystem) || IsEqualIID(riid, &IID_IUnknown)) {
147 *obj = iface;
148 IPropertySystem_AddRef(iface);
149 return S_OK;
152 FIXME("%s\n", debugstr_guid(riid));
153 return E_NOINTERFACE;
156 static ULONG WINAPI propsys_AddRef(IPropertySystem *iface)
158 return 2;
161 static ULONG WINAPI propsys_Release(IPropertySystem *iface)
163 return 1;
166 static HRESULT WINAPI propsys_GetPropertyDescription(IPropertySystem *iface,
167 REFPROPERTYKEY propkey, REFIID riid, void **ppv)
169 return PSGetPropertyDescription(propkey, riid, ppv);
172 static HRESULT WINAPI propsys_GetPropertyDescriptionByName(IPropertySystem *iface,
173 LPCWSTR canonical_name, REFIID riid, void **ppv)
175 FIXME("%s %s %p: stub\n", debugstr_w(canonical_name), debugstr_guid(riid), ppv);
176 return E_NOTIMPL;
179 static HRESULT WINAPI propsys_GetPropertyDescriptionListFromString(IPropertySystem *iface,
180 LPCWSTR proplist, REFIID riid, void **ppv)
182 return PSGetPropertyDescriptionListFromString(proplist, riid, ppv);
185 static HRESULT WINAPI propsys_EnumeratePropertyDescriptions(IPropertySystem *iface,
186 PROPDESC_ENUMFILTER filter, REFIID riid, void **ppv)
188 FIXME("%d %s %p: stub\n", filter, debugstr_guid(riid), ppv);
189 return E_NOTIMPL;
192 static HRESULT WINAPI propsys_FormatForDisplay(IPropertySystem *iface,
193 REFPROPERTYKEY key, REFPROPVARIANT propvar, PROPDESC_FORMAT_FLAGS flags,
194 LPWSTR dest, DWORD destlen)
196 FIXME("%p %p %x %p %d: stub\n", key, propvar, flags, dest, destlen);
197 return E_NOTIMPL;
200 static HRESULT WINAPI propsys_FormatForDisplayAlloc(IPropertySystem *iface,
201 REFPROPERTYKEY key, REFPROPVARIANT propvar, PROPDESC_FORMAT_FLAGS flags,
202 LPWSTR *text)
204 FIXME("%p %p %x %p: stub\n", key, propvar, flags, text);
205 return E_NOTIMPL;
208 static HRESULT WINAPI propsys_RegisterPropertySchema(IPropertySystem *iface, LPCWSTR path)
210 return PSRegisterPropertySchema(path);
213 static HRESULT WINAPI propsys_UnregisterPropertySchema(IPropertySystem *iface, LPCWSTR path)
215 return PSUnregisterPropertySchema(path);
218 static HRESULT WINAPI propsys_RefreshPropertySchema(IPropertySystem *iface)
220 return PSRefreshPropertySchema();
223 static const IPropertySystemVtbl propsysvtbl = {
224 propsys_QueryInterface,
225 propsys_AddRef,
226 propsys_Release,
227 propsys_GetPropertyDescription,
228 propsys_GetPropertyDescriptionByName,
229 propsys_GetPropertyDescriptionListFromString,
230 propsys_EnumeratePropertyDescriptions,
231 propsys_FormatForDisplay,
232 propsys_FormatForDisplayAlloc,
233 propsys_RegisterPropertySchema,
234 propsys_UnregisterPropertySchema,
235 propsys_RefreshPropertySchema
238 static IPropertySystem propsys = { &propsysvtbl };
240 HRESULT WINAPI PSGetPropertySystem(REFIID riid, void **obj)
242 return IPropertySystem_QueryInterface(&propsys, riid, obj);
245 HRESULT WINAPI PSRegisterPropertySchema(PCWSTR path)
247 FIXME("%s stub\n", debugstr_w(path));
249 return S_OK;
252 HRESULT WINAPI PSUnregisterPropertySchema(PCWSTR path)
254 FIXME("%s stub\n", debugstr_w(path));
256 return E_NOTIMPL;
259 HRESULT WINAPI PSGetPropertyDescription(REFPROPERTYKEY propkey, REFIID riid, void **ppv)
261 FIXME("%p, %p, %p\n", propkey, riid, ppv);
262 return E_NOTIMPL;
265 HRESULT WINAPI PSGetPropertyDescriptionListFromString(LPCWSTR proplist, REFIID riid, void **ppv)
267 FIXME("%s, %p, %p\n", debugstr_w(proplist), riid, ppv);
268 return E_NOTIMPL;
271 HRESULT WINAPI PSRefreshPropertySchema(void)
273 FIXME("\n");
274 return S_OK;
277 HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch)
279 static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-',
280 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
281 '%','0','2','X','%','0','2','X','%','0','2','X',
282 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
283 static const WCHAR pid_fmtW[] = {'%','u',0};
285 WCHAR pidW[PKEY_PIDSTR_MAX + 1];
286 LPWSTR p = psz;
287 int len;
289 TRACE("(%p, %p, %u)\n", pkey, psz, cch);
291 if (!psz)
292 return E_POINTER;
294 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
295 if (cch <= GUIDSTRING_MAX + 1)
296 return E_NOT_SUFFICIENT_BUFFER;
298 if (!pkey)
300 psz[0] = '\0';
301 return E_NOT_SUFFICIENT_BUFFER;
304 sprintfW(psz, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2,
305 pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1],
306 pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4],
307 pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]);
309 /* Overwrite the null terminator with the space character. */
310 p += GUIDSTRING_MAX - 1;
311 *p++ = ' ';
312 cch -= GUIDSTRING_MAX - 1 + 1;
314 len = sprintfW(pidW, pid_fmtW, pkey->pid);
316 if (cch >= len + 1)
318 strcpyW(p, pidW);
319 return S_OK;
321 else
323 WCHAR *ptr = pidW + len - 1;
325 psz[0] = '\0';
326 *p++ = '\0';
327 cch--;
329 /* Replicate a quirk of the native implementation where the contents
330 * of the property ID string are written backwards to the output
331 * buffer, skipping the rightmost digit. */
332 if (cch)
334 ptr--;
335 while (cch--)
336 *p++ = *ptr--;
339 return E_NOT_SUFFICIENT_BUFFER;
343 static const BYTE hex2bin[] =
345 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
346 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
347 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
348 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
349 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
350 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
351 0,10,11,12,13,14,15 /* 0x60 */
354 static BOOL validate_indices(LPCWSTR s, int min, int max)
356 int i;
358 for (i = min; i <= max; i++)
360 if (!s[i])
361 return FALSE;
363 if (i == 0)
365 if (s[i] != '{')
366 return FALSE;
368 else if (i == 9 || i == 14 || i == 19 || i == 24)
370 if (s[i] != '-')
371 return FALSE;
373 else if (i == 37)
375 if (s[i] != '}')
376 return FALSE;
378 else
380 if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0'))
381 return FALSE;
385 return TRUE;
388 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
389 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
390 static BOOL string_to_guid(LPCWSTR s, LPGUID id)
392 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
394 if (!validate_indices(s, 0, 8)) return FALSE;
395 id->Data1 = (hex2bin[s[1]] << 28 | hex2bin[s[2]] << 24 | hex2bin[s[3]] << 20 | hex2bin[s[4]] << 16 |
396 hex2bin[s[5]] << 12 | hex2bin[s[6]] << 8 | hex2bin[s[7]] << 4 | hex2bin[s[8]]);
397 if (!validate_indices(s, 9, 14)) return FALSE;
398 id->Data2 = hex2bin[s[10]] << 12 | hex2bin[s[11]] << 8 | hex2bin[s[12]] << 4 | hex2bin[s[13]];
399 if (!validate_indices(s, 15, 19)) return FALSE;
400 id->Data3 = hex2bin[s[15]] << 12 | hex2bin[s[16]] << 8 | hex2bin[s[17]] << 4 | hex2bin[s[18]];
402 /* these are just sequential bytes */
404 if (!validate_indices(s, 20, 21)) return FALSE;
405 id->Data4[0] = hex2bin[s[20]] << 4 | hex2bin[s[21]];
406 if (!validate_indices(s, 22, 24)) return FALSE;
407 id->Data4[1] = hex2bin[s[22]] << 4 | hex2bin[s[23]];
409 if (!validate_indices(s, 25, 26)) return FALSE;
410 id->Data4[2] = hex2bin[s[25]] << 4 | hex2bin[s[26]];
411 if (!validate_indices(s, 27, 28)) return FALSE;
412 id->Data4[3] = hex2bin[s[27]] << 4 | hex2bin[s[28]];
413 if (!validate_indices(s, 29, 30)) return FALSE;
414 id->Data4[4] = hex2bin[s[29]] << 4 | hex2bin[s[30]];
415 if (!validate_indices(s, 31, 32)) return FALSE;
416 id->Data4[5] = hex2bin[s[31]] << 4 | hex2bin[s[32]];
417 if (!validate_indices(s, 33, 34)) return FALSE;
418 id->Data4[6] = hex2bin[s[33]] << 4 | hex2bin[s[34]];
419 if (!validate_indices(s, 35, 37)) return FALSE;
420 id->Data4[7] = hex2bin[s[35]] << 4 | hex2bin[s[36]];
422 return TRUE;
425 HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR pszString, PROPERTYKEY *pkey)
427 BOOL has_minus = FALSE, has_comma = FALSE;
429 TRACE("(%s, %p)\n", debugstr_w(pszString), pkey);
431 if (!pszString || !pkey)
432 return E_POINTER;
434 memset(pkey, 0, sizeof(PROPERTYKEY));
436 if (!string_to_guid(pszString, &pkey->fmtid))
437 return E_INVALIDARG;
439 pszString += GUIDSTRING_MAX - 1;
441 if (!*pszString)
442 return E_INVALIDARG;
444 /* Only the space seems to be recognized as whitespace. The comma is only
445 * recognized once and processing terminates if another comma is found. */
446 while (*pszString == ' ' || *pszString == ',')
448 if (*pszString == ',')
450 if (has_comma)
451 return S_OK;
452 else
453 has_comma = TRUE;
455 pszString++;
458 if (!*pszString)
459 return E_INVALIDARG;
461 /* Only two minus signs are recognized if no comma is detected. The first
462 * sign is ignored, and the second is interpreted. If a comma is detected
463 * before the minus sign, then only one minus sign counts, and property ID
464 * interpretation begins with the next character. */
465 if (has_comma)
467 if (*pszString == '-')
469 has_minus = TRUE;
470 pszString++;
473 else
475 if (*pszString == '-')
476 pszString++;
478 /* Skip any intermediate spaces after the first minus sign. */
479 while (*pszString == ' ')
480 pszString++;
482 if (*pszString == '-')
484 has_minus = TRUE;
485 pszString++;
488 /* Skip any remaining spaces after minus sign. */
489 while (*pszString == ' ')
490 pszString++;
493 /* Overflow is not checked. */
494 while (isdigitW(*pszString))
496 pkey->pid *= 10;
497 pkey->pid += (*pszString - '0');
498 pszString++;
501 if (has_minus)
502 pkey->pid = ~pkey->pid + 1;
504 return S_OK;