Got rid of CLIENT_GetProcessInfo.
[wine/multimedia.git] / ole / ifs.c
blob9e8ebca6d0a7757dd6085c85963332fed727868d
1 /*
2 * basic interfaces
4 * Copyright 1997 Marcus Meissner
5 */
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 #include "winerror.h"
12 #include "ole.h"
13 #include "ole2.h"
14 #include "ldt.h"
15 #include "heap.h"
16 #include "compobj.h"
17 #include "interfaces.h"
18 #include "shlobj.h"
19 #include "local.h"
20 #include "module.h"
21 #include "debug.h"
23 /* --- IUnknown implementation */
25 typedef struct _IUnknown {
26 /* IUnknown fields */
27 ICOM_VTABLE(IUnknown)* lpvtbl;
28 DWORD ref;
29 } _IUnknown;
31 /******************************************************************************
32 * IUnknown_AddRef [VTABLE:IUNKNOWN.1]
34 static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) {
35 ICOM_THIS(IUnknown,iface);
36 TRACE(relay,"(%p)->AddRef()\n",this);
37 return ++(this->ref);
40 /******************************************************************************
41 * IUnknown_Release [VTABLE:IUNKNOWN.2]
43 static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) {
44 ICOM_THIS(IUnknown,iface);
45 TRACE(relay,"(%p)->Release()\n",this);
46 if (!--(this->ref)) {
47 HeapFree(GetProcessHeap(),0,this);
48 return 0;
50 return this->ref;
53 /******************************************************************************
54 * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0]
56 static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) {
57 ICOM_THIS(IUnknown,iface);
58 char xrefiid[50];
60 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
61 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
63 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
64 *obj = this;
65 return 0;
67 return OLE_E_ENUM_NOMORE;
70 static ICOM_VTABLE(IUnknown) uvt = {
71 IUnknown_fnQueryInterface,
72 IUnknown_fnAddRef,
73 IUnknown_fnRelease
76 /******************************************************************************
77 * IUnknown_Constructor [INTERNAL]
79 LPUNKNOWN
80 IUnknown_Constructor() {
81 _IUnknown* unk;
83 unk = (_IUnknown*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknown));
84 unk->lpvtbl = &uvt;
85 unk->ref = 1;
86 return (LPUNKNOWN)unk;
90 * IMalloc
93 /******************************************************************************
94 * IMalloc16_AddRef [COMPOBJ.501]
96 ULONG WINAPI IMalloc16_AddRef(LPMALLOC16 this) {
97 TRACE(relay,"(%p)->AddRef()\n",this);
98 return 1; /* cannot be freed */
101 /******************************************************************************
102 * IMalloc16_Release [COMPOBJ.502]
104 ULONG WINAPI IMalloc16_Release(LPMALLOC16 this) {
105 TRACE(relay,"(%p)->Release()\n",this);
106 return 1; /* cannot be freed */
109 /******************************************************************************
110 * IMalloc16_QueryInterface [COMPOBJ.500]
112 HRESULT WINAPI IMalloc16_QueryInterface(LPMALLOC16 this,REFIID refiid,LPVOID *obj) {
113 char xrefiid[50];
115 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
116 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
117 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
118 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
120 *obj = this;
121 return 0;
123 return OLE_E_ENUM_NOMORE;
126 /******************************************************************************
127 * IMalloc16_Alloc [COMPOBJ.503]
129 LPVOID WINAPI IMalloc16_Alloc(LPMALLOC16 this,DWORD cb) {
130 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
131 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_Alloc(this->heap,0,cb));
134 /******************************************************************************
135 * IMalloc16_Realloc [COMPOBJ.504]
137 LPVOID WINAPI IMalloc16_Realloc(LPMALLOC16 this,LPVOID pv,DWORD cb) {
138 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
139 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_ReAlloc(this->heap,0,LOWORD(pv),cb));
142 /******************************************************************************
143 * IMalloc16_Free [COMPOBJ.505]
145 VOID WINAPI IMalloc16_Free(LPMALLOC16 this,LPVOID pv) {
146 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
147 LOCAL_Free(this->heap,LOWORD(pv));
150 /******************************************************************************
151 * IMalloc16_GetSize [COMPOBJ.506]
153 DWORD WINAPI IMalloc16_GetSize(LPMALLOC16 this,LPVOID pv) {
154 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
155 return LOCAL_Size(this->heap,LOWORD(pv));
158 /******************************************************************************
159 * IMalloc16_DidAlloc [COMPOBJ.507]
161 INT16 WINAPI IMalloc16_DidAlloc(LPMALLOC16 this,LPVOID pv) {
162 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
163 return (INT16)-1;
166 /******************************************************************************
167 * IMalloc16_HeapMinimize [COMPOBJ.508]
169 LPVOID WINAPI IMalloc16_HeapMinimize(LPMALLOC16 this) {
170 TRACE(relay,"(%p)->HeapMinimize()\n",this);
171 return NULL;
174 #ifdef OLD_TABLE
175 /* FIXME: This is unused */
176 static IMalloc16_VTable mvt16 = {
177 IMalloc16_QueryInterface,
178 IMalloc16_AddRef,
179 IMalloc16_Release,
180 IMalloc16_Alloc,
181 IMalloc16_Realloc,
182 IMalloc16_Free,
183 IMalloc16_GetSize,
184 IMalloc16_DidAlloc,
185 IMalloc16_HeapMinimize,
187 #endif
188 static IMalloc16_VTable *msegvt16 = NULL;
190 /******************************************************************************
191 * IMalloc16_Constructor [VTABLE]
193 LPMALLOC16
194 IMalloc16_Constructor() {
195 LPMALLOC16 this;
196 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
198 this = (LPMALLOC16)SEGPTR_NEW(IMalloc16);
199 if (!msegvt16) {
200 this->lpvtbl = msegvt16 = SEGPTR_NEW(IMalloc16_VTable);
202 #define FN(x) this->lpvtbl->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(this->lpvtbl->fn##x)
203 FN(QueryInterface);
204 FN(AddRef);
205 FN(Release);
206 FN(Alloc);
207 FN(Realloc);
208 FN(Free);
209 FN(GetSize);
210 FN(DidAlloc);
211 FN(HeapMinimize);
212 msegvt16 = (LPMALLOC16_VTABLE)SEGPTR_GET(msegvt16);
213 #undef FN
214 this->lpvtbl = msegvt16;
216 this->ref = 1;
217 /* FIXME: implement multiple heaps */
218 this->heap = GlobalAlloc16(GMEM_MOVEABLE,64000);
219 LocalInit(this->heap,0,64000);
220 return (LPMALLOC16)SEGPTR_GET(this);
224 * IMalloc32
227 /******************************************************************************
228 * IMalloc32_AddRef [VTABLE]
230 static ULONG WINAPI IMalloc32_AddRef(LPMALLOC32 this) {
231 TRACE(relay,"(%p)->AddRef()\n",this);
232 return 1; /* cannot be freed */
235 /******************************************************************************
236 * IMalloc32_Release [VTABLE]
238 static ULONG WINAPI IMalloc32_Release(LPMALLOC32 this) {
239 TRACE(relay,"(%p)->Release()\n",this);
240 return 1; /* cannot be freed */
243 /******************************************************************************
244 * IMalloc32_QueryInterface [VTABLE]
246 static HRESULT WINAPI IMalloc32_QueryInterface(LPMALLOC32 this,REFIID refiid,LPVOID *obj) {
247 char xrefiid[50];
249 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
250 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
251 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
252 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
254 *obj = this;
255 return 0;
257 return OLE_E_ENUM_NOMORE;
260 /******************************************************************************
261 * IMalloc32_Alloc [VTABLE]
263 static LPVOID WINAPI IMalloc32_Alloc(LPMALLOC32 this,DWORD cb) {
264 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
265 return HeapAlloc(GetProcessHeap(),0,cb);
268 /******************************************************************************
269 * IMalloc32_Realloc [VTABLE]
271 static LPVOID WINAPI IMalloc32_Realloc(LPMALLOC32 this,LPVOID pv,DWORD cb) {
272 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
273 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
276 /******************************************************************************
277 * IMalloc32_Free [VTABLE]
279 static VOID WINAPI IMalloc32_Free(LPMALLOC32 this,LPVOID pv) {
280 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
281 HeapFree(GetProcessHeap(),0,pv);
284 /******************************************************************************
285 * IMalloc32_GetSize [VTABLE]
287 static DWORD WINAPI IMalloc32_GetSize(LPMALLOC32 this,LPVOID pv) {
288 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
289 return HeapSize(GetProcessHeap(),0,pv);
292 /******************************************************************************
293 * IMalloc32_DidAlloc [VTABLE]
295 static INT32 WINAPI IMalloc32_DidAlloc(LPMALLOC32 this,LPVOID pv) {
296 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
297 return -1;
300 /******************************************************************************
301 * IMalloc32_HeapMinimize [VTABLE]
303 static LPVOID WINAPI IMalloc32_HeapMinimize(LPMALLOC32 this) {
304 TRACE(relay,"(%p)->HeapMinimize()\n",this);
305 return NULL;
308 static IMalloc32_VTable VT_IMalloc32 = {
309 IMalloc32_QueryInterface,
310 IMalloc32_AddRef,
311 IMalloc32_Release,
312 IMalloc32_Alloc,
313 IMalloc32_Realloc,
314 IMalloc32_Free,
315 IMalloc32_GetSize,
316 IMalloc32_DidAlloc,
317 IMalloc32_HeapMinimize,
320 /******************************************************************************
321 * IMalloc32_Constructor [VTABLE]
323 LPMALLOC32
324 IMalloc32_Constructor() {
325 LPMALLOC32 this;
327 this = (LPMALLOC32)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32));
328 this->lpvtbl = &VT_IMalloc32;
329 this->ref = 1;
330 return this;
333 /****************************************************************************
334 * API Functions
337 /******************************************************************************
338 * IsValidInterface32 [OLE32.78]
340 * RETURNS
341 * True, if the passed pointer is a valid interface
343 BOOL32 WINAPI IsValidInterface32(
344 LPUNKNOWN punk /* [in] interface to be tested */
346 return !(
347 IsBadReadPtr32(punk,4) ||
348 IsBadReadPtr32(punk->lpvtbl,4) ||
349 IsBadReadPtr32(punk->lpvtbl->fnQueryInterface,9) ||
350 IsBadCodePtr32(punk->lpvtbl->fnQueryInterface)