Added a framework for testing CreateProcess and a few tests.
[wine] / dlls / oleaut32 / dispstd.c
1 /*
2  * Copyright 2001 Hidenori Takeshima
3  *
4  *      FIXME - stub
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "winerror.h"
24 #include "winnls.h"         /* for PRIMARYLANGID */
25 #include "winreg.h"         /* for HKEY_LOCAL_MACHINE */
26 #include "winuser.h"
27 #include "oleauto.h"
28
29 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ole);
31
32 typedef struct CStdDispImpl
33 {
34         ICOM_VFIELD(IDispatch);
35         struct { ICOM_VFIELD(IUnknown); } unkimpl;
36         UINT ref;
37
38         IUnknown*       punk;
39         void*           pvThis;
40         ITypeInfo*      pti;
41 } CStdDispImpl;
42
43 static HRESULT CStdDispImpl_Construct(
44         CStdDispImpl* This,
45         IUnknown* punkOuter, void* pvThis, ITypeInfo* pti )
46 {
47         This->punk = punkOuter;
48         This->pvThis = pvThis;
49         This->pti = pti; ITypeInfo_AddRef(pti);
50
51         return S_OK;
52 }
53
54 static void CStdDispImpl_Destruct(
55         CStdDispImpl* This )
56 {
57         if ( This->pti != NULL )
58                 ITypeInfo_Release(This->pti);
59 }
60
61
62 /****************************************************************************/
63
64
65 static HRESULT WINAPI In_CStdDispImpl_fnQueryInterface(
66         IUnknown* iface,REFIID riid,void** ppvobj)
67 {
68         CStdDispImpl* This = (CStdDispImpl*)(((BYTE*)iface)-offsetof(CStdDispImpl,unkimpl));
69
70         if ( IsEqualGUID(riid,&IID_IUnknown) )
71         {
72                 *ppvobj = (void*)iface;
73                 IUnknown_AddRef(iface);
74                 return S_OK;
75         }
76         if ( IsEqualGUID(riid,&IID_IDispatch) )
77         {
78                 *ppvobj = (void*)This;
79                 IUnknown_AddRef((IUnknown*)This);
80                 return S_OK;
81         }
82
83         return E_NOINTERFACE;
84 }
85
86 static ULONG WINAPI In_CStdDispImpl_fnAddRef(IUnknown* iface)
87 {
88         CStdDispImpl* This = (CStdDispImpl*)(((BYTE*)iface)-offsetof(CStdDispImpl,unkimpl));
89
90         return ++ This->ref;
91 }
92
93 static ULONG WINAPI In_CStdDispImpl_fnRelease(IUnknown* iface)
94 {
95         CStdDispImpl* This = (CStdDispImpl*)(((BYTE*)iface)-offsetof(CStdDispImpl,unkimpl));
96
97         if ( -- This->ref > 0 ) return This->ref;
98
99         ++ This->ref;
100         CStdDispImpl_Destruct(This);
101         HeapFree(GetProcessHeap(),0,This);
102         return 0;
103 }
104
105
106 /****************************************************************************/
107
108
109
110 static HRESULT WINAPI CStdDispImpl_fnQueryInterface(
111         IDispatch* iface,REFIID riid,void** ppvobj)
112 {
113     ICOM_THIS(CStdDispImpl,iface);
114
115         return IUnknown_QueryInterface(This->punk,riid,ppvobj);
116 }
117
118 static ULONG WINAPI CStdDispImpl_fnAddRef(IDispatch* iface)
119 {
120     ICOM_THIS(CStdDispImpl,iface);
121
122         return IUnknown_AddRef(This->punk);
123 }
124
125 static ULONG WINAPI CStdDispImpl_fnRelease(IDispatch* iface)
126 {
127     ICOM_THIS(CStdDispImpl,iface);
128
129         return IUnknown_Release(This->punk);
130 }
131
132
133 static HRESULT WINAPI CStdDispImpl_fnGetTypeInfoCount(
134         IDispatch* iface,UINT* pctinfo)
135 {
136     ICOM_THIS(CStdDispImpl,iface);
137
138         FIXME("(%p)\n",This);
139         if ( pctinfo == NULL ) return E_POINTER;
140         *pctinfo = 1;
141
142         return S_OK;
143 }
144
145 static HRESULT WINAPI CStdDispImpl_fnGetTypeInfo(
146         IDispatch* iface,
147         UINT itiindex,LCID lcid,ITypeInfo** ppti)
148 {
149     ICOM_THIS(CStdDispImpl,iface);
150
151         FIXME("(%p)\n",This);
152
153         if ( ppti != NULL ) return E_POINTER;
154         *ppti = NULL;
155
156         if ( itiindex != 0 ) return DISP_E_BADINDEX;
157         /* lcid is ignored */
158         ITypeInfo_AddRef(This->pti);
159         *ppti = This->pti;
160
161         return S_OK;
162 }
163
164 static HRESULT WINAPI CStdDispImpl_fnGetIDsOfNames(
165         IDispatch* iface,
166         REFIID riid,LPOLESTR* ppwszNames,UINT cNames,LCID lcid,DISPID* pdispid)
167 {
168     ICOM_THIS(CStdDispImpl,iface);
169
170         FIXME("(%p)\n",This);
171         return DispGetIDsOfNames(This->pti,ppwszNames,cNames,pdispid);
172 }
173
174 static HRESULT WINAPI CStdDispImpl_fnInvoke(
175         IDispatch* iface,
176         DISPID dispid,REFIID riid,LCID lcid,WORD wFlags,
177         DISPPARAMS* pDispParams,VARIANT* pVarResult,
178         EXCEPINFO* pExcepInfo,UINT* puArgErr)
179 {
180     ICOM_THIS(CStdDispImpl,iface);
181
182         FIXME("(%p)\n",This);
183         return DispInvoke(This->pvThis,
184                 This->pti,dispid,wFlags,
185                 pDispParams,pVarResult,
186                 pExcepInfo,puArgErr);
187 }
188
189 static ICOM_VTABLE(IUnknown) iunk =
190 {
191         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
192
193         /* IUnknown */
194         In_CStdDispImpl_fnQueryInterface,
195         In_CStdDispImpl_fnAddRef,
196         In_CStdDispImpl_fnRelease,
197 };
198
199 static ICOM_VTABLE(IDispatch) idisp =
200 {
201         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
202
203         /* IUnknown */
204         CStdDispImpl_fnQueryInterface,
205         CStdDispImpl_fnAddRef,
206         CStdDispImpl_fnRelease,
207         /* IDispatch */
208         CStdDispImpl_fnGetTypeInfoCount,
209         CStdDispImpl_fnGetTypeInfo,
210         CStdDispImpl_fnGetIDsOfNames,
211         CStdDispImpl_fnInvoke,
212 };
213
214 /*****************************************************************************/
215
216 HRESULT WINAPI CreateStdDispatch(
217         IUnknown* punkOuter,
218         void* pvThis,
219         ITypeInfo* pti,
220         IUnknown** ppvobj )
221 {
222         HRESULT hr;
223         CStdDispImpl*   This;
224
225         if ( punkOuter == NULL || pvThis == NULL ||
226              pti == NULL || ppvobj == NULL )
227                 return E_POINTER;
228
229         This = (CStdDispImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdDispImpl));
230         if ( This == NULL ) return E_OUTOFMEMORY;
231         ICOM_VTBL(This) = &idisp;
232         ICOM_VTBL(&(This->unkimpl)) = &iunk;
233         This->ref = 1;
234
235         hr = CStdDispImpl_Construct( This, punkOuter, pvThis, pti );
236         if ( FAILED(hr) )
237         {
238                 IUnknown_Release((IUnknown*)(&This->unkimpl));
239                 return hr;
240         }
241         *ppvobj = (IUnknown*)(&This->unkimpl);
242
243         return S_OK;
244 }