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 #include "propsys_private.h"
26 static HINSTANCE propsys_hInstance
;
28 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
30 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
34 case DLL_WINE_PREATTACH
:
35 return FALSE
; /* prefer native version */
36 case DLL_PROCESS_ATTACH
:
37 propsys_hInstance
= hinstDLL
;
38 DisableThreadLibraryCalls(hinstDLL
);
45 HRESULT WINAPI
DllRegisterServer(void)
47 return __wine_register_resources( propsys_hInstance
);
50 HRESULT WINAPI
DllUnregisterServer(void)
52 return __wine_unregister_resources( propsys_hInstance
);
55 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
59 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
60 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
62 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
63 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
68 IUnknown_AddRef((IUnknown
*)*ppv
);
72 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
76 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
78 TRACE("(%p)\n", iface
);
82 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
84 TRACE("(%p)\n", iface
);
88 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
90 TRACE("(%p)->(%x)\n", iface
, fLock
);
95 static HRESULT WINAPI
InMemoryPropertyStoreFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
96 REFIID riid
, void **ppv
)
98 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
100 return PropertyStore_CreateInstance(outer
, riid
, ppv
);
103 static const IClassFactoryVtbl InMemoryPropertyStoreFactoryVtbl
= {
104 ClassFactory_QueryInterface
,
106 ClassFactory_Release
,
107 InMemoryPropertyStoreFactory_CreateInstance
,
108 ClassFactory_LockServer
111 static IClassFactory InMemoryPropertyStoreFactory
= { &InMemoryPropertyStoreFactoryVtbl
};
113 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
115 if(IsEqualGUID(&CLSID_InMemoryPropertyStore
, rclsid
)) {
116 TRACE("(CLSID_InMemoryPropertyStore %s %p)\n", debugstr_guid(riid
), ppv
);
117 return IClassFactory_QueryInterface(&InMemoryPropertyStoreFactory
, riid
, ppv
);
120 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
121 return CLASS_E_CLASSNOTAVAILABLE
;
124 HRESULT WINAPI
DllCanUnloadNow(void)
129 HRESULT WINAPI
PSRegisterPropertySchema(PCWSTR path
)
131 FIXME("%s stub\n", debugstr_w(path
));
136 HRESULT WINAPI
PSUnregisterPropertySchema(PCWSTR path
)
138 FIXME("%s stub\n", debugstr_w(path
));
143 HRESULT WINAPI
PSGetPropertyDescription(REFPROPERTYKEY propkey
, REFIID riid
, void **ppv
)
145 FIXME("%p, %p, %p\n", propkey
, riid
, ppv
);
149 HRESULT WINAPI
PSRefreshPropertySchema(void)
155 HRESULT WINAPI
PSStringFromPropertyKey(REFPROPERTYKEY pkey
, LPWSTR psz
, UINT cch
)
157 static const WCHAR guid_fmtW
[] = {'{','%','0','8','X','-','%','0','4','X','-',
158 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
159 '%','0','2','X','%','0','2','X','%','0','2','X',
160 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
161 static const WCHAR pid_fmtW
[] = {'%','u',0};
163 WCHAR pidW
[PKEY_PIDSTR_MAX
+ 1];
167 TRACE("(%p, %p, %u)\n", pkey
, psz
, cch
);
172 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
173 if (cch
<= GUIDSTRING_MAX
+ 1)
174 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
179 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
182 sprintfW(psz
, guid_fmtW
, pkey
->fmtid
.Data1
, pkey
->fmtid
.Data2
,
183 pkey
->fmtid
.Data3
, pkey
->fmtid
.Data4
[0], pkey
->fmtid
.Data4
[1],
184 pkey
->fmtid
.Data4
[2], pkey
->fmtid
.Data4
[3], pkey
->fmtid
.Data4
[4],
185 pkey
->fmtid
.Data4
[5], pkey
->fmtid
.Data4
[6], pkey
->fmtid
.Data4
[7]);
187 /* Overwrite the null terminator with the space character. */
188 p
+= GUIDSTRING_MAX
- 1;
190 cch
-= GUIDSTRING_MAX
- 1 + 1;
192 len
= sprintfW(pidW
, pid_fmtW
, pkey
->pid
);
201 WCHAR
*ptr
= pidW
+ len
- 1;
207 /* Replicate a quirk of the native implementation where the contents
208 * of the property ID string are written backwards to the output
209 * buffer, skipping the rightmost digit. */
217 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
221 static const BYTE hex2bin
[] =
223 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
224 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
225 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
226 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
227 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
228 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
229 0,10,11,12,13,14,15 /* 0x60 */
232 static BOOL
validate_indices(LPCWSTR s
, int min
, int max
)
236 for (i
= min
; i
<= max
; i
++)
246 else if (i
== 9 || i
== 14 || i
== 19 || i
== 24)
258 if (s
[i
] > 'f' || (!hex2bin
[s
[i
]] && s
[i
] != '0'))
266 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
267 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
268 static BOOL
string_to_guid(LPCWSTR s
, LPGUID id
)
270 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
272 if (!validate_indices(s
, 0, 8)) return FALSE
;
273 id
->Data1
= (hex2bin
[s
[1]] << 28 | hex2bin
[s
[2]] << 24 | hex2bin
[s
[3]] << 20 | hex2bin
[s
[4]] << 16 |
274 hex2bin
[s
[5]] << 12 | hex2bin
[s
[6]] << 8 | hex2bin
[s
[7]] << 4 | hex2bin
[s
[8]]);
275 if (!validate_indices(s
, 9, 14)) return FALSE
;
276 id
->Data2
= hex2bin
[s
[10]] << 12 | hex2bin
[s
[11]] << 8 | hex2bin
[s
[12]] << 4 | hex2bin
[s
[13]];
277 if (!validate_indices(s
, 15, 19)) return FALSE
;
278 id
->Data3
= hex2bin
[s
[15]] << 12 | hex2bin
[s
[16]] << 8 | hex2bin
[s
[17]] << 4 | hex2bin
[s
[18]];
280 /* these are just sequential bytes */
282 if (!validate_indices(s
, 20, 21)) return FALSE
;
283 id
->Data4
[0] = hex2bin
[s
[20]] << 4 | hex2bin
[s
[21]];
284 if (!validate_indices(s
, 22, 24)) return FALSE
;
285 id
->Data4
[1] = hex2bin
[s
[22]] << 4 | hex2bin
[s
[23]];
287 if (!validate_indices(s
, 25, 26)) return FALSE
;
288 id
->Data4
[2] = hex2bin
[s
[25]] << 4 | hex2bin
[s
[26]];
289 if (!validate_indices(s
, 27, 28)) return FALSE
;
290 id
->Data4
[3] = hex2bin
[s
[27]] << 4 | hex2bin
[s
[28]];
291 if (!validate_indices(s
, 29, 30)) return FALSE
;
292 id
->Data4
[4] = hex2bin
[s
[29]] << 4 | hex2bin
[s
[30]];
293 if (!validate_indices(s
, 31, 32)) return FALSE
;
294 id
->Data4
[5] = hex2bin
[s
[31]] << 4 | hex2bin
[s
[32]];
295 if (!validate_indices(s
, 33, 34)) return FALSE
;
296 id
->Data4
[6] = hex2bin
[s
[33]] << 4 | hex2bin
[s
[34]];
297 if (!validate_indices(s
, 35, 37)) return FALSE
;
298 id
->Data4
[7] = hex2bin
[s
[35]] << 4 | hex2bin
[s
[36]];
303 HRESULT WINAPI
PSPropertyKeyFromString(LPCWSTR pszString
, PROPERTYKEY
*pkey
)
305 int has_minus
= 0, has_comma
= 0;
307 TRACE("(%s, %p)\n", debugstr_w(pszString
), pkey
);
309 if (!pszString
|| !pkey
)
312 memset(pkey
, 0, sizeof(PROPERTYKEY
));
314 if (!string_to_guid(pszString
, &pkey
->fmtid
))
317 pszString
+= GUIDSTRING_MAX
- 1;
322 /* Only the space seems to be recognized as whitespace. The comma is only
323 * recognized once and processing terminates if another comma is found. */
324 while (*pszString
== ' ' || *pszString
== ',')
326 if (*pszString
== ',')
339 /* Only two minus signs are recognized if no comma is detected. The first
340 * sign is ignored, and the second is interpreted. If a comma is detected
341 * before the minus sign, then only one minus sign counts, and property ID
342 * interpretation begins with the next character. */
345 if (*pszString
== '-')
353 if (*pszString
== '-')
356 /* Skip any intermediate spaces after the first minus sign. */
357 while (*pszString
== ' ')
360 if (*pszString
== '-')
366 /* Skip any remaining spaces after minus sign. */
367 while (*pszString
== ' ')
371 /* Overflow is not checked. */
372 while (isdigitW(*pszString
))
375 pkey
->pid
+= (*pszString
- '0');
380 pkey
->pid
= ~pkey
->pid
+ 1;