Bugfixes, shellview uses DPA's now, IShellView_GetItemObject implemented.
[wine/multimedia.git] / ole / ifs.c
blobf126068f98d5776bc96a6cafda2ee8a8397a8320
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"
24 * IUnknown
27 /******************************************************************************
28 * IUnknown_AddRef [???]
30 static ULONG WINAPI IUnknown_AddRef(LPUNKNOWN this) {
31 TRACE(relay,"(%p)->AddRef()\n",this);
32 return ++(this->ref);
34 static ULONG WINAPI IUnknown_Release(LPUNKNOWN this) {
35 TRACE(relay,"(%p)->Release()\n",this);
36 if (!--(this->ref)) {
37 HeapFree(GetProcessHeap(),0,this);
38 return 0;
40 return this->ref;
43 static HRESULT WINAPI IUnknown_QueryInterface(LPUNKNOWN this,REFIID refiid,LPVOID *obj) {
44 char xrefiid[50];
46 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
47 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
49 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
50 *obj = this;
51 return 0;
53 return OLE_E_ENUM_NOMORE;
56 static IUnknown_VTable uvt = {
57 IUnknown_QueryInterface,
58 IUnknown_AddRef,
59 IUnknown_Release
63 LPUNKNOWN
64 IUnknown_Constructor() {
65 LPUNKNOWN unk;
67 unk = (LPUNKNOWN)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknown));
68 unk->lpvtbl = &uvt;
69 unk->ref = 1;
70 return unk;
74 * IMalloc
77 /******************************************************************************
78 * IMalloc16_AddRef [COMPOBJ.501]
80 ULONG WINAPI IMalloc16_AddRef(LPMALLOC16 this) {
81 TRACE(relay,"(%p)->AddRef()\n",this);
82 return 1; /* cannot be freed */
85 /******************************************************************************
86 * IMalloc16_Release [COMPOBJ.502]
88 ULONG WINAPI IMalloc16_Release(LPMALLOC16 this) {
89 TRACE(relay,"(%p)->Release()\n",this);
90 return 1; /* cannot be freed */
93 /******************************************************************************
94 * IMalloc16_QueryInterface [COMPOBJ.500]
96 HRESULT WINAPI IMalloc16_QueryInterface(LPMALLOC16 this,REFIID refiid,LPVOID *obj) {
97 char xrefiid[50];
99 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
100 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
101 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
102 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
104 *obj = this;
105 return 0;
107 return OLE_E_ENUM_NOMORE;
110 LPVOID WINAPI IMalloc16_Alloc(LPMALLOC16 this,DWORD cb) {
111 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
112 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_Alloc(this->heap,0,cb));
115 LPVOID WINAPI IMalloc16_Realloc(LPMALLOC16 this,LPVOID pv,DWORD cb) {
116 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
117 return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(this->heap,LOCAL_ReAlloc(this->heap,0,LOWORD(pv),cb));
119 VOID WINAPI IMalloc16_Free(LPMALLOC16 this,LPVOID pv) {
120 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
121 LOCAL_Free(this->heap,LOWORD(pv));
124 DWORD WINAPI IMalloc16_GetSize(LPMALLOC16 this,LPVOID pv) {
125 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
126 return LOCAL_Size(this->heap,LOWORD(pv));
129 INT16 WINAPI IMalloc16_DidAlloc(LPMALLOC16 this,LPVOID pv) {
130 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
131 return (INT16)-1;
133 LPVOID WINAPI IMalloc16_HeapMinimize(LPMALLOC16 this) {
134 TRACE(relay,"(%p)->HeapMinimize()\n",this);
135 return NULL;
138 #ifdef OLD_TABLE
139 /* FIXME: This is unused */
140 static IMalloc16_VTable mvt16 = {
141 IMalloc16_QueryInterface,
142 IMalloc16_AddRef,
143 IMalloc16_Release,
144 IMalloc16_Alloc,
145 IMalloc16_Realloc,
146 IMalloc16_Free,
147 IMalloc16_GetSize,
148 IMalloc16_DidAlloc,
149 IMalloc16_HeapMinimize,
151 #endif
152 static IMalloc16_VTable *msegvt16 = NULL;
154 LPMALLOC16
155 IMalloc16_Constructor() {
156 LPMALLOC16 this;
157 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
159 this = (LPMALLOC16)SEGPTR_NEW(IMalloc16);
160 if (!msegvt16) {
161 this->lpvtbl = msegvt16 = SEGPTR_NEW(IMalloc16_VTable);
163 #define FN(x) this->lpvtbl->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(this->lpvtbl->fn##x)
164 FN(QueryInterface);
165 FN(AddRef);
166 FN(Release);
167 FN(Alloc);
168 FN(Realloc);
169 FN(Free);
170 FN(GetSize);
171 FN(DidAlloc);
172 FN(HeapMinimize);
173 msegvt16 = (LPMALLOC16_VTABLE)SEGPTR_GET(msegvt16);
174 #undef FN
175 this->lpvtbl = msegvt16;
177 this->ref = 1;
178 /* FIXME: implement multiple heaps */
179 this->heap = GlobalAlloc16(GMEM_MOVEABLE,64000);
180 LocalInit(this->heap,0,64000);
181 return (LPMALLOC16)SEGPTR_GET(this);
185 * IMalloc32
188 /******************************************************************************
189 * IMalloc32_AddRef [???]
191 static ULONG WINAPI IMalloc32_AddRef(LPMALLOC32 this) {
192 TRACE(relay,"(%p)->AddRef()\n",this);
193 return 1; /* cannot be freed */
196 /******************************************************************************
197 * IMalloc32_Release [???]
199 static ULONG WINAPI IMalloc32_Release(LPMALLOC32 this) {
200 TRACE(relay,"(%p)->Release()\n",this);
201 return 1; /* cannot be freed */
204 /******************************************************************************
205 * IMalloc32_QueryInterface [???]
207 static HRESULT WINAPI IMalloc32_QueryInterface(LPMALLOC32 this,REFIID refiid,LPVOID *obj) {
208 char xrefiid[50];
210 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
211 TRACE(relay,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid,obj);
212 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
213 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
215 *obj = this;
216 return 0;
218 return OLE_E_ENUM_NOMORE;
221 static LPVOID WINAPI IMalloc32_Alloc(LPMALLOC32 this,DWORD cb) {
222 TRACE(relay,"(%p)->Alloc(%ld)\n",this,cb);
223 return HeapAlloc(GetProcessHeap(),0,cb);
226 static LPVOID WINAPI IMalloc32_Realloc(LPMALLOC32 this,LPVOID pv,DWORD cb) {
227 TRACE(relay,"(%p)->Realloc(%p,%ld)\n",this,pv,cb);
228 return HeapReAlloc(GetProcessHeap(),0,pv,cb);
230 static VOID WINAPI IMalloc32_Free(LPMALLOC32 this,LPVOID pv) {
231 TRACE(relay,"(%p)->Free(%p)\n",this,pv);
232 HeapFree(GetProcessHeap(),0,pv);
235 static DWORD WINAPI IMalloc32_GetSize(LPMALLOC32 this,LPVOID pv) {
236 TRACE(relay,"(%p)->GetSize(%p)\n",this,pv);
237 return HeapSize(GetProcessHeap(),0,pv);
240 static INT32 WINAPI IMalloc32_DidAlloc(LPMALLOC32 this,LPVOID pv) {
241 TRACE(relay,"(%p)->DidAlloc(%p)\n",this,pv);
242 return -1;
244 static LPVOID WINAPI IMalloc32_HeapMinimize(LPMALLOC32 this) {
245 TRACE(relay,"(%p)->HeapMinimize()\n",this);
246 return NULL;
249 static IMalloc32_VTable VT_IMalloc32 = {
250 IMalloc32_QueryInterface,
251 IMalloc32_AddRef,
252 IMalloc32_Release,
253 IMalloc32_Alloc,
254 IMalloc32_Realloc,
255 IMalloc32_Free,
256 IMalloc32_GetSize,
257 IMalloc32_DidAlloc,
258 IMalloc32_HeapMinimize,
261 LPMALLOC32
262 IMalloc32_Constructor() {
263 LPMALLOC32 this;
265 this = (LPMALLOC32)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32));
266 this->lpvtbl = &VT_IMalloc32;
267 this->ref = 1;
268 return this;
271 /****************************************************************************
272 * API Functions
275 /******************************************************************************
276 * IsValidInterface32 [OLE32.78]
278 * RETURNS
279 * True, if the passed pointer is a valid interface
281 BOOL32 WINAPI IsValidInterface32(
282 LPUNKNOWN punk /* [in] interface to be tested */
284 return !(
285 IsBadReadPtr32(punk,4) ||
286 IsBadReadPtr32(punk->lpvtbl,4) ||
287 IsBadReadPtr32(punk->lpvtbl->fnQueryInterface,9) ||
288 IsBadCodePtr32(punk->lpvtbl->fnQueryInterface)