2 * Protected Storage (pstores)
4 * Copyright 2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(pstores
);
43 const IPStoreVtbl
*lpVtbl
;
48 static const WCHAR szPStoresKey
[] = {
49 'S','o','f','t','w','a','r','e','\\',
50 'W','i','n','e','\\','W','i','n','e','\\',
51 'p','s','t','o','r','e','s',0
54 /* convert a guid to a wide character string */
55 static void IPStore_guid2wstr( const GUID
*guid
, LPWSTR wstr
)
59 sprintf(str
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
60 guid
->Data1
, guid
->Data2
, guid
->Data3
,
61 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
62 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
63 MultiByteToWideChar( CP_ACP
, 0, str
, -1, wstr
, 40 );
66 static LONG
IPStore_OpenRoot( PST_KEY Key
, HKEY
*hkey
)
70 case PST_KEY_CURRENT_USER
:
71 return RegCreateKeyW( HKEY_CURRENT_USER
, szPStoresKey
, hkey
);
72 case PST_KEY_LOCAL_MACHINE
:
73 return RegCreateKeyW( HKEY_LOCAL_MACHINE
, szPStoresKey
, hkey
);
75 return ERROR_INVALID_PARAMETER
;
78 /**************************************************************************
79 * IPStore->QueryInterface
81 static HRESULT WINAPI
PStore_fnQueryInterface(
86 PStore_impl
*This
= (PStore_impl
*)iface
;
88 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
92 if (IsEqualIID(riid
, &IID_IUnknown
))
99 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
102 TRACE("-- Interface: E_NOINTERFACE\n");
103 return E_NOINTERFACE
;
106 /******************************************************************************
109 static ULONG WINAPI
PStore_fnAddRef(IPStore
* iface
)
111 PStore_impl
*This
= (PStore_impl
*)iface
;
113 TRACE("%p %u\n", This
, This
->ref
);
115 return InterlockedIncrement( &This
->ref
);
118 /******************************************************************************
121 static ULONG WINAPI
PStore_fnRelease(IPStore
* iface
)
123 PStore_impl
*This
= (PStore_impl
*)iface
;
126 TRACE("%p %u\n", This
, This
->ref
);
128 ref
= InterlockedDecrement( &This
->ref
);
130 HeapFree( GetProcessHeap(), 0, This
);
135 /******************************************************************************
138 static HRESULT WINAPI
PStore_fnGetInfo( IPStore
* iface
, PPST_PROVIDERINFO
* ppProperties
)
144 /******************************************************************************
145 * IPStore->GetProvParam
147 static HRESULT WINAPI
PStore_fnGetProvParam( IPStore
* iface
,
148 DWORD dwParam
, DWORD
* pcbData
, BYTE
** ppbData
, DWORD dwFlags
)
154 /******************************************************************************
155 * IPStore->SetProvParam
157 static HRESULT WINAPI
PStore_fnSetProvParam( IPStore
* This
,
158 DWORD dwParam
, DWORD cbData
, BYTE
* pbData
, DWORD
* dwFlags
)
164 /******************************************************************************
165 * IPStore->CreateType
167 static HRESULT WINAPI
PStore_fnCreateType( IPStore
* This
,
168 PST_KEY Key
, const GUID
* pType
, PPST_TYPEINFO pInfo
, DWORD dwFlags
)
173 HRESULT hres
= E_FAIL
;
176 TRACE("%p %08x %s %p(%d,%s) %08x\n", This
, Key
, debugstr_guid(pType
),
177 pInfo
, pInfo
->cbSize
, debugstr_w(pInfo
->szDisplayName
), dwFlags
);
179 r
= IPStore_OpenRoot( Key
, &hkey
);
183 IPStore_guid2wstr( pType
, szGuid
);
184 r
= RegCreateKeyExW( hkey
, szGuid
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
185 KEY_ALL_ACCESS
, NULL
, &hkeytype
, &dwCreated
);
186 if( r
== ERROR_SUCCESS
)
188 if( dwCreated
== REG_CREATED_NEW_KEY
)
190 r
= RegSetValueW( hkeytype
, NULL
, REG_SZ
,
191 pInfo
->szDisplayName
, strlenW( pInfo
->szDisplayName
) );
192 if( r
== ERROR_SUCCESS
)
194 RegCloseKey( hkeytype
);
197 hres
= PST_E_TYPE_EXISTS
;
204 /******************************************************************************
205 * IPStore->GetTypeInfo
207 static HRESULT WINAPI
PStore_fnGetTypeInfo( IPStore
* This
,
208 PST_KEY Key
, const GUID
* pType
, PPST_TYPEINFO
** ppInfo
, DWORD dwFlags
)
214 /******************************************************************************
215 * IPStore->DeleteType
217 static HRESULT WINAPI
PStore_fnDeleteType( IPStore
* This
,
218 PST_KEY Key
, const GUID
* pType
, DWORD dwFlags
)
223 HRESULT hres
= E_FAIL
;
225 TRACE("%p %d %s %08x\n", This
, Key
, debugstr_guid(pType
), dwFlags
);
227 r
= IPStore_OpenRoot( Key
, &hkey
);
231 IPStore_guid2wstr( pType
, szGuid
);
232 r
= SHDeleteKeyW( hkey
, szGuid
);
233 if( r
== ERROR_SUCCESS
)
240 /******************************************************************************
241 * IPStore->CreateSubtype
243 static HRESULT WINAPI
PStore_fnCreateSubtype( IPStore
* This
,
244 PST_KEY Key
, const GUID
* pType
, const GUID
* pSubtype
,
245 PPST_TYPEINFO pInfo
, PPST_ACCESSRULESET pRules
, DWORD dwFlags
)
248 HKEY hkey
, hkeysubtype
;
250 HRESULT hres
= E_FAIL
;
253 TRACE("%p %08x %s %s %p %p %08x\n", This
, Key
, debugstr_guid(pType
),
254 debugstr_guid(pSubtype
), pInfo
, pRules
, dwFlags
);
256 r
= IPStore_OpenRoot( Key
, &hkey
);
260 IPStore_guid2wstr( pType
, szGuid
);
262 IPStore_guid2wstr( pSubtype
, &szGuid
[39] );
263 r
= RegCreateKeyExW( hkey
, szGuid
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
264 KEY_ALL_ACCESS
, NULL
, &hkeysubtype
, &dwCreated
);
265 if( r
== ERROR_SUCCESS
)
267 if( dwCreated
== REG_CREATED_NEW_KEY
)
269 r
= RegSetValueW( hkeysubtype
, NULL
, REG_SZ
,
270 pInfo
->szDisplayName
, strlenW( pInfo
->szDisplayName
) );
271 if( r
== ERROR_SUCCESS
)
273 RegCloseKey( hkeysubtype
);
276 hres
= PST_E_TYPE_EXISTS
;
283 /******************************************************************************
284 * IPStore->GetSubtypeInfo
286 static HRESULT WINAPI
PStore_fnGetSubtypeInfo( IPStore
* This
,
287 PST_KEY Key
, const GUID
* pType
, const GUID
* pSubtype
,
288 PPST_TYPEINFO
** ppInfo
, DWORD dwFlags
)
294 /******************************************************************************
295 * IPStore->DeleteSubtype
297 static HRESULT WINAPI
PStore_fnDeleteSubtype( IPStore
* This
,
298 PST_KEY Key
, const GUID
* pType
, const GUID
* pSubtype
, DWORD dwFlags
)
303 HRESULT hres
= E_FAIL
;
305 TRACE("%p %u %s %s %08x\n", This
, Key
,
306 debugstr_guid(pType
), debugstr_guid(pSubtype
), dwFlags
);
308 r
= IPStore_OpenRoot( Key
, &hkey
);
312 IPStore_guid2wstr( pType
, szGuid
);
313 r
= RegOpenKeyW( hkey
, szGuid
, &hkeytype
);
314 if( r
== ERROR_SUCCESS
)
316 IPStore_guid2wstr( pSubtype
, szGuid
);
317 r
= SHDeleteKeyW( hkeytype
, szGuid
);
318 if( r
== ERROR_SUCCESS
)
320 RegCloseKey( hkeytype
);
327 /******************************************************************************
328 * IPStore->ReadAccessRuleset
330 static HRESULT WINAPI
PStore_fnReadAccessRuleset( IPStore
* This
,
331 PST_KEY Key
, const GUID
* pType
, const GUID
* pSubtype
, PPST_TYPEINFO pInfo
,
332 PPST_ACCESSRULESET
** ppRules
, DWORD dwFlags
)
338 /******************************************************************************
339 * IPStore->WriteAccessRuleSet
341 static HRESULT WINAPI
PStore_fnWriteAccessRuleset( IPStore
* This
,
342 PST_KEY Key
, const GUID
* pType
, const GUID
* pSubtype
,
343 PPST_TYPEINFO pInfo
, PPST_ACCESSRULESET pRules
, DWORD dwFlags
)
349 /******************************************************************************
352 static HRESULT WINAPI
PStore_fnEnumTypes( IPStore
* This
, PST_KEY Key
,
353 DWORD dwFlags
, IEnumPStoreTypes
** ppenum
)
359 /******************************************************************************
360 * IPStore->EnumSubtypes
362 static HRESULT WINAPI
PStore_fnEnumSubtypes( IPStore
* This
, PST_KEY Key
,
363 const GUID
* pType
, DWORD dwFlags
, IEnumPStoreTypes
** ppenum
)
369 /******************************************************************************
370 * IPStore->DeleteItem
372 static HRESULT WINAPI
PStore_fnDeleteItem( IPStore
* This
, PST_KEY Key
,
373 const GUID
* pItemType
, const GUID
* pItemSubType
, LPCWSTR szItemName
,
374 PPST_PROMPTINFO pPromptInfo
, DWORD dwFlags
)
380 /******************************************************************************
383 static HRESULT WINAPI
PStore_fnReadItem( IPStore
* This
, PST_KEY Key
,
384 const GUID
* pItemType
, const GUID
* pItemSubtype
, LPCWSTR szItemName
,
385 DWORD
*cbData
, BYTE
** pbData
, PPST_PROMPTIFO pPromptInfo
, DWORD dwFlags
)
388 HKEY hkey
, hkeysubtype
;
392 TRACE("%p %08x %s %s %s %p %p %p %08x\n", This
, Key
,
393 debugstr_guid(pItemType
), debugstr_guid(pItemSubtype
),
394 debugstr_w(szItemName
), cbData
, pbData
, pPromptInfo
, dwFlags
);
399 r
= IPStore_OpenRoot( Key
, &hkey
);
403 IPStore_guid2wstr( pItemType
, szGuid
);
405 IPStore_guid2wstr( pItemSubtype
, &szGuid
[39] );
406 r
= RegOpenKeyW( hkey
, szGuid
, &hkeysubtype
);
407 if( r
== ERROR_SUCCESS
)
411 r
= RegQueryValueExW( hkeysubtype
, szItemName
, NULL
, &type
,
413 if( ( r
== ERROR_SUCCESS
) && ( type
== REG_BINARY
) )
415 *pbData
= CoTaskMemAlloc( *cbData
);
416 r
= RegQueryValueExW( hkeysubtype
, szItemName
, NULL
, &type
,
419 RegCloseKey( hkeysubtype
);
424 return ( r
== ERROR_SUCCESS
) ? S_OK
: E_FAIL
;
427 /******************************************************************************
430 static HRESULT WINAPI
PStore_fnWriteItem( IPStore
* This
, PST_KEY Key
,
431 const GUID
* pItemType
, const GUID
* pItemSubtype
, LPCWSTR szItemName
,
432 DWORD cbData
, BYTE
* ppbData
, PPST_PROMPTIFO pPromptInfo
,
433 DWORD dwDefaultConfirmationStyle
, DWORD dwFlags
)
436 HKEY hkey
, hkeysubtype
;
439 TRACE("%p %08x %s %s %s %d %p %p %08x\n", This
, Key
,
440 debugstr_guid(pItemType
), debugstr_guid(pItemSubtype
),
441 debugstr_w(szItemName
), cbData
, ppbData
, pPromptInfo
, dwFlags
);
443 r
= IPStore_OpenRoot( Key
, &hkey
);
447 IPStore_guid2wstr( pItemType
, szGuid
);
449 IPStore_guid2wstr( pItemSubtype
, &szGuid
[39] );
450 r
= RegOpenKeyW( hkey
, szGuid
, &hkeysubtype
);
451 if( r
== ERROR_SUCCESS
)
453 r
= RegSetValueExW( hkeysubtype
, szItemName
, 0, REG_BINARY
,
455 RegCloseKey( hkeysubtype
);
460 return ( r
== ERROR_SUCCESS
) ? S_OK
: E_FAIL
;
463 /******************************************************************************
466 static HRESULT WINAPI
PStore_fnOpenItem( IPStore
* This
, PST_KEY Key
,
467 const GUID
* pItemType
, const GUID
* pItemSubtype
, LPCWSTR szItemName
,
468 PST_ACCESSMODE ModeFlags
, PPST_PROMPTIFO pProomptInfo
, DWORD dwFlags
)
471 HKEY hkey
, hkeysubtype
;
474 TRACE("%p %08x %s %s %p %08x %p %08x\n", This
, Key
,
475 debugstr_guid(pItemType
), debugstr_guid(pItemSubtype
),
476 debugstr_w(szItemName
), ModeFlags
, pProomptInfo
, dwFlags
);
478 r
= IPStore_OpenRoot( Key
, &hkey
);
482 IPStore_guid2wstr( pItemType
, szGuid
);
484 IPStore_guid2wstr( pItemSubtype
, &szGuid
[39] );
485 r
= RegOpenKeyW( hkey
, szGuid
, &hkeysubtype
);
486 if( r
== ERROR_SUCCESS
)
490 r
= RegQueryValueExW( hkeysubtype
, szItemName
, NULL
, &type
,
492 if( ( r
== ERROR_SUCCESS
) && ( type
!= REG_BINARY
) )
493 r
= ERROR_INVALID_DATA
;
495 RegCloseKey( hkeysubtype
);
500 return ( r
== ERROR_SUCCESS
) ? S_OK
: E_FAIL
;
503 /******************************************************************************
506 static HRESULT WINAPI
PStore_fnCloseItem( IPStore
* This
, PST_KEY Key
,
507 const GUID
* pItemType
, const GUID
* pItemSubtype
, LPCWSTR
* szItemName
,
514 /******************************************************************************
517 static HRESULT WINAPI
PStore_fnEnumItems( IPStore
* This
, PST_KEY Key
,
518 const GUID
* pItemType
, const GUID
* pItemSubtype
, DWORD dwFlags
,
519 IEnumPStoreItems
** ppenum
)
526 static const IPStoreVtbl pstores_vtbl
=
528 PStore_fnQueryInterface
,
532 PStore_fnGetProvParam
,
533 PStore_fnSetProvParam
,
535 PStore_fnGetTypeInfo
,
537 PStore_fnCreateSubtype
,
538 PStore_fnGetSubtypeInfo
,
539 PStore_fnDeleteSubtype
,
540 PStore_fnReadAccessRuleset
,
541 PStore_fnWriteAccessRuleset
,
543 PStore_fnEnumSubtypes
,
552 HRESULT WINAPI
PStoreCreateInstance( IPStore
** ppProvider
,
553 PST_PROVIDERID
* pProviderID
, void* pReserved
, DWORD dwFlags
)
557 TRACE("%p %s %p %08x\n", ppProvider
, debugstr_guid(pProviderID
), pReserved
, dwFlags
);
559 ips
= HeapAlloc( GetProcessHeap(), 0, sizeof (PStore_impl
) );
561 return E_OUTOFMEMORY
;
563 ips
->lpVtbl
= &pstores_vtbl
;
566 *ppProvider
= (IPStore
*) ips
;
571 HRESULT WINAPI
DllRegisterServer(void)
577 HRESULT WINAPI
DllUnregisterServer(void)
583 /***********************************************************************
584 * DllGetClassObject (PSTOREC.@)
586 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
588 FIXME("(%s,%s,%p) stub\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
589 return CLASS_E_CLASSNOTAVAILABLE
;
592 HRESULT WINAPI
DllCanUnloadNow(void)