1 | /*
|
---|
2 | * Implements IPropertyBag. (internal)
|
---|
3 | *
|
---|
4 | * hidenori@a2.ctktv.ne.jp
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "config.h"
|
---|
8 |
|
---|
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"
|
---|
22 |
|
---|
23 | #include "debugtools.h"
|
---|
24 | DEFAULT_DEBUG_CHANNEL(quartz);
|
---|
25 |
|
---|
26 | #include "quartz_private.h"
|
---|
27 | #include "monprop.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | static HRESULT WINAPI
|
---|
31 | IPropertyBag_fnQueryInterface(IPropertyBag* iface,REFIID riid,void** ppobj)
|
---|
32 | {
|
---|
33 | CRegPropertyBag_THIS(iface,propbag);
|
---|
34 |
|
---|
35 | TRACE("(%p)->()\n",This);
|
---|
36 |
|
---|
37 | return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
|
---|
38 | }
|
---|
39 |
|
---|
40 | static ULONG WINAPI
|
---|
41 | IPropertyBag_fnAddRef(IPropertyBag* iface)
|
---|
42 | {
|
---|
43 | CRegPropertyBag_THIS(iface,propbag);
|
---|
44 |
|
---|
45 | TRACE("(%p)->()\n",This);
|
---|
46 |
|
---|
47 | return IUnknown_AddRef(This->unk.punkControl);
|
---|
48 | }
|
---|
49 |
|
---|
50 | static ULONG WINAPI
|
---|
51 | IPropertyBag_fnRelease(IPropertyBag* iface)
|
---|
52 | {
|
---|
53 | CRegPropertyBag_THIS(iface,propbag);
|
---|
54 |
|
---|
55 | TRACE("(%p)->()\n",This);
|
---|
56 |
|
---|
57 | return IUnknown_Release(This->unk.punkControl);
|
---|
58 | }
|
---|
59 |
|
---|
60 | static HRESULT WINAPI
|
---|
61 | IPropertyBag_fnRead(IPropertyBag* iface,LPCOLESTR lpszPropName,VARIANT* pVar,IErrorLog* pLog)
|
---|
62 | {
|
---|
63 | CRegPropertyBag_THIS(iface,propbag);
|
---|
64 | LONG lr;
|
---|
65 | DWORD dwSize;
|
---|
66 | DWORD dwValueType;
|
---|
67 |
|
---|
68 | TRACE("(%p)->(%s,%p,%p)\n",This,
|
---|
69 | debugstr_w(lpszPropName),pVar,pLog);
|
---|
70 |
|
---|
71 | if ( lpszPropName == NULL || pVar == NULL )
|
---|
72 | return E_POINTER;
|
---|
73 |
|
---|
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;
|
---|
80 |
|
---|
81 | switch ( dwValueType )
|
---|
82 | {
|
---|
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;
|
---|
88 |
|
---|
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 )
|
---|
98 | {
|
---|
99 | SysFreeString(pVar->n1.n2.n3.bstrVal);
|
---|
100 | return E_FAIL;
|
---|
101 | }
|
---|
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;
|
---|
107 | }
|
---|
108 |
|
---|
109 | return NOERROR;
|
---|
110 | }
|
---|
111 |
|
---|
112 | static HRESULT WINAPI
|
---|
113 | IPropertyBag_fnWrite(IPropertyBag* iface,LPCOLESTR lpszPropName,VARIANT* pVar)
|
---|
114 | {
|
---|
115 | CRegPropertyBag_THIS(iface,propbag);
|
---|
116 |
|
---|
117 | FIXME("(%p)->(%s,%p) stub!\n",This,
|
---|
118 | debugstr_w(lpszPropName),pVar);
|
---|
119 |
|
---|
120 | if ( lpszPropName == NULL || pVar == NULL )
|
---|
121 | return E_POINTER;
|
---|
122 |
|
---|
123 | return E_NOTIMPL;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 | static ICOM_VTABLE(IPropertyBag) ipropbag =
|
---|
130 | {
|
---|
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,
|
---|
139 | };
|
---|
140 |
|
---|
141 | static HRESULT CRegPropertyBag_InitIPropertyBag(
|
---|
142 | CRegPropertyBag* prpb, HKEY hkRoot, LPCWSTR lpKeyPath )
|
---|
143 | {
|
---|
144 | ICOM_VTBL(&prpb->propbag) = &ipropbag;
|
---|
145 |
|
---|
146 | if ( RegOpenKeyExW(
|
---|
147 | hkRoot, lpKeyPath, 0,
|
---|
148 | KEY_ALL_ACCESS, &prpb->m_hKey ) != ERROR_SUCCESS )
|
---|
149 | return E_FAIL;
|
---|
150 |
|
---|
151 | return NOERROR;
|
---|
152 | }
|
---|
153 |
|
---|
154 | static void CRegPropertyBag_UninitIPropertyBag(
|
---|
155 | CRegPropertyBag* prpb )
|
---|
156 | {
|
---|
157 | RegCloseKey( prpb->m_hKey );
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | static void QUARTZ_DestroyRegPropertyBag(IUnknown* punk)
|
---|
162 | {
|
---|
163 | CRegPropertyBag_THIS(punk,unk);
|
---|
164 |
|
---|
165 | CRegPropertyBag_UninitIPropertyBag(This);
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | /* can I use offsetof safely? - FIXME? */
|
---|
170 | static QUARTZ_IFEntry IFEntries[] =
|
---|
171 | {
|
---|
172 | { &IID_IPropertyBag, offsetof(CRegPropertyBag,propbag)-offsetof(CRegPropertyBag,unk) },
|
---|
173 | };
|
---|
174 |
|
---|
175 | HRESULT QUARTZ_CreateRegPropertyBag(
|
---|
176 | HKEY hkRoot, LPCWSTR lpKeyPath,
|
---|
177 | IPropertyBag** ppPropBag )
|
---|
178 | {
|
---|
179 | CRegPropertyBag* prpb;
|
---|
180 | HRESULT hr;
|
---|
181 |
|
---|
182 | TRACE("(%08x,%s,%p)\n",hkRoot,debugstr_w(lpKeyPath),ppPropBag );
|
---|
183 |
|
---|
184 | prpb = (CRegPropertyBag*)QUARTZ_AllocObj( sizeof(CRegPropertyBag) );
|
---|
185 | if ( prpb == NULL )
|
---|
186 | return E_OUTOFMEMORY;
|
---|
187 |
|
---|
188 | QUARTZ_IUnkInit( &prpb->unk, NULL );
|
---|
189 | hr = CRegPropertyBag_InitIPropertyBag( prpb, hkRoot, lpKeyPath );
|
---|
190 | if ( FAILED(hr) )
|
---|
191 | {
|
---|
192 | QUARTZ_FreeObj( prpb );
|
---|
193 | return hr;
|
---|
194 | }
|
---|
195 |
|
---|
196 | prpb->unk.pEntries = IFEntries;
|
---|
197 | prpb->unk.dwEntries = sizeof(IFEntries)/sizeof(IFEntries[0]);
|
---|
198 | prpb->unk.pOnFinalRelease = &QUARTZ_DestroyRegPropertyBag;
|
---|
199 |
|
---|
200 | *ppPropBag = (IPropertyBag*)(&prpb->propbag);
|
---|
201 |
|
---|
202 | return S_OK;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|