Implemented IMemAllocator.
[wine/multimedia.git] / dlls / quartz / monprop.c
blob81a029c08ec1d2ea4655d0569347e701517532b1
1 /*
2 * Implements IPropertyBag. (internal)
4 * hidenori@a2.ctktv.ne.jp
5 */
7 #include "config.h"
9 #include "windef.h"
10 #include "winbase.h"
11 #include "wingdi.h"
12 #include "winuser.h"
13 #include "winreg.h"
14 #include "winerror.h"
15 #include "wine/obj_base.h"
16 #include "objidl.h"
17 #include "oleidl.h"
18 #include "ocidl.h"
19 #include "oleauto.h"
20 #include "strmif.h"
21 #include "wine/unicode.h"
23 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(quartz);
26 #include "quartz_private.h"
27 #include "monprop.h"
30 static HRESULT WINAPI
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);
40 static ULONG WINAPI
41 IPropertyBag_fnAddRef(IPropertyBag* iface)
43 CRegPropertyBag_THIS(iface,propbag);
45 TRACE("(%p)->()\n",This);
47 return IUnknown_AddRef(This->unk.punkControl);
50 static ULONG WINAPI
51 IPropertyBag_fnRelease(IPropertyBag* iface)
53 CRegPropertyBag_THIS(iface,propbag);
55 TRACE("(%p)->()\n",This);
57 return IUnknown_Release(This->unk.punkControl);
60 static HRESULT WINAPI
61 IPropertyBag_fnRead(IPropertyBag* iface,LPCOLESTR lpszPropName,VARIANT* pVar,IErrorLog* pLog)
63 CRegPropertyBag_THIS(iface,propbag);
64 LONG lr;
65 DWORD dwSize;
66 DWORD dwValueType;
68 TRACE("(%p)->(%s,%p,%p)\n",This,
69 debugstr_w(lpszPropName),pVar,pLog);
71 if ( lpszPropName == NULL || pVar == NULL )
72 return E_POINTER;
74 dwSize = 0;
75 lr = RegQueryValueExW(
76 This->m_hKey, lpszPropName, NULL,
77 &dwValueType, NULL, &dwSize );
78 if ( lr != ERROR_SUCCESS )
79 return E_INVALIDARG;
81 switch ( dwValueType )
83 case REG_SZ:
84 if ( pVar->n1.n2.vt == VT_EMPTY )
85 pVar->n1.n2.vt = VT_BSTR;
86 if ( pVar->n1.n2.vt != VT_BSTR )
87 return E_FAIL;
89 pVar->n1.n2.n3.bstrVal = SysAllocStringByteLen(
90 NULL, dwSize );
91 if ( pVar->n1.n2.n3.bstrVal == NULL )
92 return E_OUTOFMEMORY;
93 lr = RegQueryValueExW(
94 This->m_hKey, lpszPropName, NULL,
95 &dwValueType,
96 (BYTE*)pVar->n1.n2.n3.bstrVal, &dwSize );
97 if ( lr != ERROR_SUCCESS )
99 SysFreeString(pVar->n1.n2.n3.bstrVal);
100 return E_FAIL;
102 break;
103 default:
104 FIXME("(%p)->(%s,%p,%p) - unsupported value type.\n",This,
105 debugstr_w(lpszPropName),pVar,pLog);
106 return E_FAIL;
109 return NOERROR;
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 )
121 return E_POINTER;
123 return E_NOTIMPL;
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 */
137 IPropertyBag_fnRead,
138 IPropertyBag_fnWrite,
141 static HRESULT CRegPropertyBag_InitIPropertyBag(
142 CRegPropertyBag* prpb, HKEY hkRoot, LPCWSTR lpKeyPath )
144 ICOM_VTBL(&prpb->propbag) = &ipropbag;
146 if ( RegOpenKeyExW(
147 hkRoot, lpKeyPath, 0,
148 KEY_ALL_ACCESS, &prpb->m_hKey ) != ERROR_SUCCESS )
149 return E_FAIL;
151 return NOERROR;
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;
180 HRESULT hr;
182 TRACE("(%08x,%s,%p)\n",hkRoot,debugstr_w(lpKeyPath),ppPropBag );
184 prpb = (CRegPropertyBag*)QUARTZ_AllocObj( sizeof(CRegPropertyBag) );
185 if ( prpb == NULL )
186 return E_OUTOFMEMORY;
188 QUARTZ_IUnkInit( &prpb->unk, NULL );
189 hr = CRegPropertyBag_InitIPropertyBag( prpb, hkRoot, lpKeyPath );
190 if ( FAILED(hr) )
192 QUARTZ_FreeObj( prpb );
193 return hr;
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);
202 return S_OK;