Added two printer error codes.
[wine/multimedia.git] / dlls / ole32 / ole16.c
blob0369e8b6062f2cc56944054764520863cb83d72e
1 /*
2 * 16 bit ole functions
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
8 * Copyright 2002 Marcus Meissner
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "config.h"
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <assert.h>
32 #include "windef.h"
33 #include "objbase.h"
34 #include "ole2.h"
35 #include "ole2ver.h"
36 #include "rpc.h"
37 #include "winerror.h"
38 #include "winreg.h"
39 #include "wownt32.h"
40 #include "wtypes.h"
41 #include "wine/unicode.h"
42 #include "wine/winbase16.h"
43 #include "compobj_private.h"
44 #include "ifs.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(ole);
50 HINSTANCE16 COMPOBJ_hInstance = 0;
51 static int COMPOBJ_Attach = 0;
53 HTASK16 hETask = 0;
54 WORD Table_ETask[62];
56 LPMALLOC16 currentMalloc16=NULL;
58 /* --- IMalloc16 implementation */
61 typedef struct
63 /* IUnknown fields */
64 ICOM_VFIELD(IMalloc16);
65 DWORD ref;
66 /* IMalloc16 fields */
67 } IMalloc16Impl;
69 /******************************************************************************
70 * IMalloc16_QueryInterface [COMPOBJ.500]
72 HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
73 ICOM_THIS(IMalloc16Impl,iface);
75 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
76 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
77 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
78 ) {
79 *obj = This;
80 return 0;
82 return OLE_E_ENUM_NOMORE;
85 /******************************************************************************
86 * IMalloc16_AddRef [COMPOBJ.501]
88 ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) {
89 ICOM_THIS(IMalloc16Impl,iface);
90 TRACE("(%p)->AddRef()\n",This);
91 return 1; /* cannot be freed */
94 /******************************************************************************
95 * IMalloc16_Release [COMPOBJ.502]
97 ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
98 ICOM_THIS(IMalloc16Impl,iface);
99 TRACE("(%p)->Release()\n",This);
100 return 1; /* cannot be freed */
103 /******************************************************************************
104 * IMalloc16_Alloc [COMPOBJ.503]
106 SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
107 ICOM_THIS(IMalloc16Impl,iface);
108 TRACE("(%p)->Alloc(%ld)\n",This,cb);
109 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) );
112 /******************************************************************************
113 * IMalloc16_Realloc [COMPOBJ.504]
115 SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
117 SEGPTR ret;
118 ICOM_THIS(IMalloc16Impl,iface);
119 TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
120 ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) );
121 UnMapLS(pv);
122 return ret;
125 /******************************************************************************
126 * IMalloc16_Free [COMPOBJ.505]
128 VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
130 void *ptr = MapSL(pv);
131 ICOM_THIS(IMalloc16Impl,iface);
132 TRACE("(%p)->Free(%08lx)\n",This,pv);
133 UnMapLS(pv);
134 HeapFree( GetProcessHeap(), 0, ptr );
137 /******************************************************************************
138 * IMalloc16_GetSize [COMPOBJ.506]
140 DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
142 ICOM_THIS(IMalloc16Impl,iface);
143 TRACE("(%p)->GetSize(%08lx)\n",This,pv);
144 return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
147 /******************************************************************************
148 * IMalloc16_DidAlloc [COMPOBJ.507]
150 INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) {
151 ICOM_THIS(IMalloc16,iface);
152 TRACE("(%p)->DidAlloc(%p)\n",This,pv);
153 return (INT16)-1;
156 /******************************************************************************
157 * IMalloc16_HeapMinimize [COMPOBJ.508]
159 LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) {
160 ICOM_THIS(IMalloc16Impl,iface);
161 TRACE("(%p)->HeapMinimize()\n",This);
162 return NULL;
165 /******************************************************************************
166 * IMalloc16_Constructor [VTABLE]
168 LPMALLOC16
169 IMalloc16_Constructor()
171 static ICOM_VTABLE(IMalloc16) vt16;
172 static SEGPTR msegvt16;
173 IMalloc16Impl* This;
174 HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
176 This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) );
177 if (!msegvt16)
179 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
180 VTENT(QueryInterface);
181 VTENT(AddRef);
182 VTENT(Release);
183 VTENT(Alloc);
184 VTENT(Realloc);
185 VTENT(Free);
186 VTENT(GetSize);
187 VTENT(DidAlloc);
188 VTENT(HeapMinimize);
189 #undef VTENT
190 msegvt16 = MapLS( &vt16 );
192 This->lpVtbl = (ICOM_VTABLE(IMalloc16)*)msegvt16;
193 This->ref = 1;
194 return (LPMALLOC16)MapLS( This );
198 /***********************************************************************
199 * CoGetMalloc [COMPOBJ.4]
200 * RETURNS
201 * The current win16 IMalloc
203 HRESULT WINAPI CoGetMalloc16(
204 DWORD dwMemContext, /* [in] unknown */
205 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
207 if(!currentMalloc16)
208 currentMalloc16 = IMalloc16_Constructor();
209 *lpMalloc = currentMalloc16;
210 return S_OK;
213 /***********************************************************************
214 * CoCreateStandardMalloc [COMPOBJ.71]
216 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
217 LPMALLOC16 *lpMalloc)
219 /* FIXME: docu says we shouldn't return the same allocator as in
220 * CoGetMalloc16 */
221 *lpMalloc = IMalloc16_Constructor();
222 return S_OK;
225 /******************************************************************************
226 * CoInitialize [COMPOBJ.2]
227 * Set the win16 IMalloc used for memory management
229 HRESULT WINAPI CoInitialize16(
230 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
232 currentMalloc16 = (LPMALLOC16)lpReserved;
233 return S_OK;
236 /***********************************************************************
237 * CoUninitialize [COMPOBJ.3]
238 * Don't know what it does.
239 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
240 * believe is the correct spelling
242 void WINAPI CoUninitialize16(void)
244 TRACE("()\n");
245 CoFreeAllLibraries();
248 /***********************************************************************
249 * IsEqualGUID [COMPOBJ.18]
251 * Compares two Unique Identifiers.
253 * RETURNS
254 * TRUE if equal
256 BOOL16 WINAPI IsEqualGUID16(
257 GUID* g1, /* [in] unique id 1 */
258 GUID* g2) /* [in] unique id 2 */
260 return !memcmp( g1, g2, sizeof(GUID) );
263 /******************************************************************************
264 * CLSIDFromString [COMPOBJ.20]
265 * Converts a unique identifier from its string representation into
266 * the GUID struct.
268 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
270 * RETURNS
271 * the converted GUID
273 HRESULT WINAPI CLSIDFromString16(
274 LPCOLESTR16 idstr, /* [in] string representation of guid */
275 CLSID *id) /* [out] GUID converted from string */
278 return __CLSIDFromStringA(idstr,id);
281 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
282 DWORD cbArgs, LPVOID pArgs,
283 LPDWORD pdwRetCode );
285 /******************************************************************************
286 * _xmalloc16 [internal]
287 * Allocates size bytes from the standard ole16 allocator.
289 * RETURNS
290 * the allocated segmented pointer and a HRESULT
292 HRESULT
293 _xmalloc16(DWORD size, SEGPTR *ptr) {
294 LPMALLOC16 mllc;
295 DWORD args[2];
297 if (CoGetMalloc16(0,&mllc))
298 return E_OUTOFMEMORY;
300 args[0] = (DWORD)mllc;
301 args[1] = size;
302 /* No need for a Callback entry, we have WOWCallback16Ex which does
303 * everything we need.
305 if (!K32WOWCallback16Ex(
306 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
307 (SEGPTR)((LPMALLOC16)MapSL((SEGPTR)mllc))->lpVtbl )
308 )->Alloc,
309 WCB16_CDECL,
310 2*sizeof(DWORD),
311 (LPVOID)args,
312 (LPDWORD)ptr
313 )) {
314 ERR("CallTo16 IMalloc16 (%ld) failed\n",size);
315 return E_FAIL;
317 return S_OK;
320 /******************************************************************************
321 * StringFromCLSID [COMPOBJ.19]
322 * Converts a GUID into the respective string representation.
323 * The target string is allocated using the OLE IMalloc.
325 * RETURNS
326 * the string representation and HRESULT
329 HRESULT WINAPI StringFromCLSID16(
330 REFCLSID id, /* [in] the GUID to be converted */
331 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
334 HRESULT ret;
336 ret = _xmalloc16(40,(SEGPTR*)idstr);
337 if (ret != S_OK)
338 return ret;
339 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
342 /******************************************************************************
343 * ProgIDFromCLSID [COMPOBJ.62]
344 * Converts a class id into the respective Program ID. (By using a registry lookup)
345 * RETURNS S_OK on success
346 * riid associated with the progid
348 HRESULT WINAPI ProgIDFromCLSID16(
349 REFCLSID clsid, /* [in] class id as found in registry */
350 LPOLESTR16 *lplpszProgID/* [out] associated Prog ID */
352 char strCLSID[50], *buf, *buf2;
353 DWORD buf2len;
354 HKEY xhkey;
355 HRESULT ret = S_OK;
357 WINE_StringFromCLSID(clsid, strCLSID);
359 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
360 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
361 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
362 ret = REGDB_E_CLASSNOTREG;
364 HeapFree(GetProcessHeap(), 0, buf);
366 if (ret == S_OK)
368 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
369 buf2len = 255;
370 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
371 ret = REGDB_E_CLASSNOTREG;
373 if (ret == S_OK)
375 ret = _xmalloc16(buf2len+1, (SEGPTR*)lplpszProgID);
376 if (ret != S_OK)
377 return ret;
378 strcpy(MapSL((SEGPTR)*lplpszProgID),buf2);
379 ret = S_OK;
381 HeapFree(GetProcessHeap(), 0, buf2);
383 RegCloseKey(xhkey);
384 return ret;
387 /***********************************************************************
388 * LookupETask (COMPOBJ.94)
390 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
391 FIXME("(%p,%p),stub!\n",hTask,p);
392 if ((*hTask = GetCurrentTask()) == hETask) {
393 memcpy(p, Table_ETask, sizeof(Table_ETask));
395 return 0;
398 /***********************************************************************
399 * SetETask (COMPOBJ.95)
401 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
402 FIXME("(%04x,%p),stub!\n",hTask,p);
403 hETask = hTask;
404 return 0;
407 /***********************************************************************
408 * CALLOBJECTINWOW (COMPOBJ.201)
410 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
411 FIXME("(%p,%p),stub!\n",p1,p2);
412 return 0;
415 /******************************************************************************
416 * CoRegisterClassObject [COMPOBJ.5]
418 * Don't know where it registers it ...
420 HRESULT WINAPI CoRegisterClassObject16(
421 REFCLSID rclsid,
422 LPUNKNOWN pUnk,
423 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
424 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
425 LPDWORD lpdwRegister
427 char buf[80];
429 WINE_StringFromCLSID(rclsid,buf);
431 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
432 buf,pUnk,dwClsContext,flags,lpdwRegister
434 return 0;
437 /******************************************************************************
438 * CoRevokeClassObject [COMPOBJ.6]
441 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
443 FIXME("(0x%08lx),stub!\n", dwRegister);
444 return 0;
447 /******************************************************************************
448 * CoFileTimeToDosDateTime [COMPOBJ.30]
450 BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
452 return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
455 /******************************************************************************
456 * CoDosDateTimeToFileTime [COMPOBJ.31]
458 BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
460 return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
463 /******************************************************************************
464 * CoRegisterMessageFilter [COMPOBJ.27]
466 HRESULT WINAPI CoRegisterMessageFilter16(
467 LPMESSAGEFILTER lpMessageFilter,
468 LPMESSAGEFILTER *lplpMessageFilter
470 FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
471 return 0;
474 /******************************************************************************
475 * CoLockObjectExternal [COMPOBJ.63]
477 HRESULT WINAPI CoLockObjectExternal16(
478 LPUNKNOWN pUnk, /* [in] object to be locked */
479 BOOL16 fLock, /* [in] do lock */
480 BOOL16 fLastUnlockReleases /* [in] ? */
482 FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
483 return S_OK;
486 /***********************************************************************
487 * CoGetState [COMPOBJ.115]
489 HRESULT WINAPI CoGetState16(LPDWORD state)
491 FIXME("(%p),stub!\n", state);
493 *state = 0;
494 return S_OK;
497 /***********************************************************************
498 * DllEntryPoint [COMPOBJ.116]
500 * Initialization code for the COMPOBJ DLL
502 * RETURNS:
504 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
506 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize, res1, res2);
507 switch(Reason)
509 case DLL_PROCESS_ATTACH:
510 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
511 break;
513 case DLL_PROCESS_DETACH:
514 if(!--COMPOBJ_Attach)
515 COMPOBJ_hInstance = 0;
516 break;
518 return TRUE;