2 * Implements IPropertyBag. (internal)
4 * hidenori@a2.ctktv.ne.jp
15 #include "wine/obj_base.h"
21 #include "wine/unicode.h"
23 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(quartz
);
26 #include "quartz_private.h"
31 IPropertyBag_fnQueryInterface(IPropertyBag
* iface
,REFIID riid
,void** ppobj
)
33 CRegPropertyBag_THIS(iface
,propbag
);
35 TRACE("(%p)->()\n",This
);
37 return IUnknown_QueryInterface(This
->unk
.punkControl
,riid
,ppobj
);
41 IPropertyBag_fnAddRef(IPropertyBag
* iface
)
43 CRegPropertyBag_THIS(iface
,propbag
);
45 TRACE("(%p)->()\n",This
);
47 return IUnknown_AddRef(This
->unk
.punkControl
);
51 IPropertyBag_fnRelease(IPropertyBag
* iface
)
53 CRegPropertyBag_THIS(iface
,propbag
);
55 TRACE("(%p)->()\n",This
);
57 return IUnknown_Release(This
->unk
.punkControl
);
61 IPropertyBag_fnRead(IPropertyBag
* iface
,LPCOLESTR lpszPropName
,VARIANT
* pVar
,IErrorLog
* pLog
)
63 CRegPropertyBag_THIS(iface
,propbag
);
68 TRACE("(%p)->(%s,%p,%p)\n",This
,
69 debugstr_w(lpszPropName
),pVar
,pLog
);
71 if ( lpszPropName
== NULL
|| pVar
== NULL
)
75 lr
= RegQueryValueExW(
76 This
->m_hKey
, lpszPropName
, NULL
,
77 &dwValueType
, NULL
, &dwSize
);
78 if ( lr
!= ERROR_SUCCESS
)
81 switch ( dwValueType
)
84 if ( pVar
->n1
.n2
.vt
== VT_EMPTY
)
85 pVar
->n1
.n2
.vt
= VT_BSTR
;
86 if ( pVar
->n1
.n2
.vt
!= VT_BSTR
)
89 pVar
->n1
.n2
.n3
.bstrVal
= SysAllocStringByteLen(
91 if ( pVar
->n1
.n2
.n3
.bstrVal
== NULL
)
93 lr
= RegQueryValueExW(
94 This
->m_hKey
, lpszPropName
, NULL
,
96 (BYTE
*)pVar
->n1
.n2
.n3
.bstrVal
, &dwSize
);
97 if ( lr
!= ERROR_SUCCESS
)
99 SysFreeString(pVar
->n1
.n2
.n3
.bstrVal
);
104 FIXME("(%p)->(%s,%p,%p) - unsupported value type.\n",This
,
105 debugstr_w(lpszPropName
),pVar
,pLog
);
112 static HRESULT WINAPI
113 IPropertyBag_fnWrite(IPropertyBag
* iface
,LPCOLESTR lpszPropName
,VARIANT
* pVar
)
115 CRegPropertyBag_THIS(iface
,propbag
);
117 FIXME("(%p)->(%s,%p) stub!\n",This
,
118 debugstr_w(lpszPropName
),pVar
);
120 if ( lpszPropName
== NULL
|| pVar
== NULL
)
129 static ICOM_VTABLE(IPropertyBag
) ipropbag
=
131 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
132 /* IUnknown fields */
133 IPropertyBag_fnQueryInterface
,
134 IPropertyBag_fnAddRef
,
135 IPropertyBag_fnRelease
,
136 /* IPropertyBag fields */
138 IPropertyBag_fnWrite
,
141 static HRESULT
CRegPropertyBag_InitIPropertyBag(
142 CRegPropertyBag
* prpb
, HKEY hkRoot
, LPCWSTR lpKeyPath
)
144 ICOM_VTBL(&prpb
->propbag
) = &ipropbag
;
147 hkRoot
, lpKeyPath
, 0,
148 KEY_ALL_ACCESS
, &prpb
->m_hKey
) != ERROR_SUCCESS
)
154 static void CRegPropertyBag_UninitIPropertyBag(
155 CRegPropertyBag
* prpb
)
157 RegCloseKey( prpb
->m_hKey
);
161 static void QUARTZ_DestroyRegPropertyBag(IUnknown
* punk
)
163 CRegPropertyBag_THIS(punk
,unk
);
165 CRegPropertyBag_UninitIPropertyBag(This
);
169 /* can I use offsetof safely? - FIXME? */
170 static QUARTZ_IFEntry IFEntries
[] =
172 { &IID_IPropertyBag
, offsetof(CRegPropertyBag
,propbag
)-offsetof(CRegPropertyBag
,unk
) },
175 HRESULT
QUARTZ_CreateRegPropertyBag(
176 HKEY hkRoot
, LPCWSTR lpKeyPath
,
177 IPropertyBag
** ppPropBag
)
179 CRegPropertyBag
* prpb
;
182 TRACE("(%08x,%s,%p)\n",hkRoot
,debugstr_w(lpKeyPath
),ppPropBag
);
184 prpb
= (CRegPropertyBag
*)QUARTZ_AllocObj( sizeof(CRegPropertyBag
) );
186 return E_OUTOFMEMORY
;
188 QUARTZ_IUnkInit( &prpb
->unk
, NULL
);
189 hr
= CRegPropertyBag_InitIPropertyBag( prpb
, hkRoot
, lpKeyPath
);
192 QUARTZ_FreeObj( prpb
);
196 prpb
->unk
.pEntries
= IFEntries
;
197 prpb
->unk
.dwEntries
= sizeof(IFEntries
)/sizeof(IFEntries
[0]);
198 prpb
->unk
.pOnFinalRelease
= &QUARTZ_DestroyRegPropertyBag
;
200 *ppPropBag
= (IPropertyBag
*)(&prpb
->propbag
);