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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
43 #include "wine/unicode.h"
44 #include "wine/winbase16.h"
45 #include "compobj_private.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
52 static HTASK16 hETask
= 0;
53 static WORD Table_ETask
[62];
55 static LPMALLOC16 currentMalloc16
=NULL
;
57 /* --- IMalloc16 implementation */
63 const IMalloc16Vtbl
*lpVtbl
;
65 /* IMalloc16 fields */
68 /******************************************************************************
69 * IMalloc16_QueryInterface [COMPOBJ.500]
71 HRESULT CDECL
IMalloc16_fnQueryInterface(IMalloc16
* iface
,REFIID refiid
,LPVOID
*obj
) {
72 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
74 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
75 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
76 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
81 return OLE_E_ENUM_NOMORE
;
84 /******************************************************************************
85 * IMalloc16_AddRef [COMPOBJ.501]
87 ULONG CDECL
IMalloc16_fnAddRef(IMalloc16
* iface
) {
88 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
89 TRACE("(%p)->AddRef()\n",This
);
90 return 1; /* cannot be freed */
93 /******************************************************************************
94 * IMalloc16_Release [COMPOBJ.502]
96 ULONG CDECL
IMalloc16_fnRelease(IMalloc16
* iface
) {
97 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
98 TRACE("(%p)->Release()\n",This
);
99 return 1; /* cannot be freed */
102 /******************************************************************************
103 * IMalloc16_Alloc [COMPOBJ.503]
105 SEGPTR CDECL
IMalloc16_fnAlloc(IMalloc16
* iface
,DWORD cb
) {
106 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
107 TRACE("(%p)->Alloc(%d)\n",This
,cb
);
108 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb
) );
111 /******************************************************************************
112 * IMalloc16_Free [COMPOBJ.505]
114 VOID CDECL
IMalloc16_fnFree(IMalloc16
* iface
,SEGPTR pv
)
116 void *ptr
= MapSL(pv
);
117 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
118 TRACE("(%p)->Free(%08x)\n",This
,pv
);
120 HeapFree( GetProcessHeap(), 0, ptr
);
123 /******************************************************************************
124 * IMalloc16_Realloc [COMPOBJ.504]
126 SEGPTR CDECL
IMalloc16_fnRealloc(IMalloc16
* iface
,SEGPTR pv
,DWORD cb
)
129 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
130 TRACE("(%p)->Realloc(%08x,%d)\n",This
,pv
,cb
);
132 ret
= IMalloc16_fnAlloc(iface
, cb
);
134 ret
= MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv
), cb
) );
137 IMalloc16_fnFree(iface
, pv
);
143 /******************************************************************************
144 * IMalloc16_GetSize [COMPOBJ.506]
146 DWORD CDECL
IMalloc16_fnGetSize(IMalloc16
* iface
,SEGPTR pv
)
148 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
149 TRACE("(%p)->GetSize(%08x)\n",This
,pv
);
150 return HeapSize( GetProcessHeap(), 0, MapSL(pv
) );
153 /******************************************************************************
154 * IMalloc16_DidAlloc [COMPOBJ.507]
156 INT16 CDECL
IMalloc16_fnDidAlloc(IMalloc16
* iface
,LPVOID pv
) {
157 IMalloc16
*This
= iface
;
158 TRACE("(%p)->DidAlloc(%p)\n",This
,pv
);
162 /******************************************************************************
163 * IMalloc16_HeapMinimize [COMPOBJ.508]
165 LPVOID CDECL
IMalloc16_fnHeapMinimize(IMalloc16
* iface
) {
166 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
167 TRACE("(%p)->HeapMinimize()\n",This
);
171 /******************************************************************************
172 * IMalloc16_Constructor [VTABLE]
175 IMalloc16_Constructor(void)
177 static IMalloc16Vtbl vt16
;
178 static SEGPTR msegvt16
;
180 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
182 This
= HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl
) );
185 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
186 VTENT(QueryInterface
);
196 msegvt16
= MapLS( &vt16
);
198 This
->lpVtbl
= (const IMalloc16Vtbl
*)msegvt16
;
200 return (LPMALLOC16
)MapLS( This
);
204 /***********************************************************************
205 * CoGetMalloc [COMPOBJ.4]
207 * Retrieve the current win16 IMalloc interface.
210 * The current win16 IMalloc
212 HRESULT WINAPI
CoGetMalloc16(
213 DWORD dwMemContext
, /* [in] unknown */
214 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
217 currentMalloc16
= IMalloc16_Constructor();
218 *lpMalloc
= currentMalloc16
;
222 /***********************************************************************
223 * CoCreateStandardMalloc [COMPOBJ.71]
225 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
226 LPMALLOC16
*lpMalloc
)
228 /* FIXME: docu says we shouldn't return the same allocator as in
230 *lpMalloc
= IMalloc16_Constructor();
234 /******************************************************************************
235 * CoInitialize [COMPOBJ.2]
236 * Set the win16 IMalloc used for memory management
238 HRESULT WINAPI
CoInitialize16(
239 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
241 currentMalloc16
= (LPMALLOC16
)lpReserved
;
245 /***********************************************************************
246 * CoUninitialize [COMPOBJ.3]
247 * Don't know what it does.
248 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
249 * believe is the correct spelling
251 void WINAPI
CoUninitialize16(void)
254 CoFreeAllLibraries();
257 /***********************************************************************
258 * IsEqualGUID [COMPOBJ.18]
260 * Compares two Unique Identifiers.
265 BOOL16 WINAPI
IsEqualGUID16(
266 GUID
* g1
, /* [in] unique id 1 */
267 GUID
* g2
) /* [in] unique id 2 */
269 return !memcmp( g1
, g2
, sizeof(GUID
) );
272 /******************************************************************************
273 * CLSIDFromString [COMPOBJ.20]
274 * Converts a unique identifier from its string representation into
277 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
282 HRESULT WINAPI
CLSIDFromString16(
283 LPCOLESTR16 idstr
, /* [in] string representation of guid */
284 CLSID
*id
) /* [out] GUID converted from string */
291 memset( id
, 0, sizeof (CLSID
) );
295 /* validate the CLSID string */
296 if (strlen(idstr
) != 38)
297 return CO_E_CLASSSTRING
;
299 s
= (const BYTE
*) idstr
;
300 if ((s
[0]!='{') || (s
[9]!='-') || (s
[14]!='-') || (s
[19]!='-') || (s
[24]!='-') || (s
[37]!='}'))
301 return CO_E_CLASSSTRING
;
303 for (i
=1; i
<37; i
++) {
304 if ((i
== 9)||(i
== 14)||(i
== 19)||(i
== 24)) continue;
305 if (!(((s
[i
] >= '0') && (s
[i
] <= '9')) ||
306 ((s
[i
] >= 'a') && (s
[i
] <= 'f')) ||
307 ((s
[i
] >= 'A') && (s
[i
] <= 'F'))))
308 return CO_E_CLASSSTRING
;
311 TRACE("%s -> %p\n", s
, id
);
313 /* quick lookup table */
314 memset(table
, 0, 256);
316 for (i
= 0; i
< 10; i
++) {
319 for (i
= 0; i
< 6; i
++) {
320 table
['A' + i
] = i
+10;
321 table
['a' + i
] = i
+10;
324 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
326 id
->Data1
= (table
[s
[1]] << 28 | table
[s
[2]] << 24 | table
[s
[3]] << 20 | table
[s
[4]] << 16 |
327 table
[s
[5]] << 12 | table
[s
[6]] << 8 | table
[s
[7]] << 4 | table
[s
[8]]);
328 id
->Data2
= table
[s
[10]] << 12 | table
[s
[11]] << 8 | table
[s
[12]] << 4 | table
[s
[13]];
329 id
->Data3
= table
[s
[15]] << 12 | table
[s
[16]] << 8 | table
[s
[17]] << 4 | table
[s
[18]];
331 /* these are just sequential bytes */
332 id
->Data4
[0] = table
[s
[20]] << 4 | table
[s
[21]];
333 id
->Data4
[1] = table
[s
[22]] << 4 | table
[s
[23]];
334 id
->Data4
[2] = table
[s
[25]] << 4 | table
[s
[26]];
335 id
->Data4
[3] = table
[s
[27]] << 4 | table
[s
[28]];
336 id
->Data4
[4] = table
[s
[29]] << 4 | table
[s
[30]];
337 id
->Data4
[5] = table
[s
[31]] << 4 | table
[s
[32]];
338 id
->Data4
[6] = table
[s
[33]] << 4 | table
[s
[34]];
339 id
->Data4
[7] = table
[s
[35]] << 4 | table
[s
[36]];
344 /******************************************************************************
345 * _xmalloc16 [internal]
346 * Allocates size bytes from the standard ole16 allocator.
349 * the allocated segmented pointer and a HRESULT
352 _xmalloc16(DWORD size
, SEGPTR
*ptr
) {
356 if (CoGetMalloc16(0,&mllc
))
357 return E_OUTOFMEMORY
;
359 args
[0] = (DWORD
)mllc
;
361 /* No need for a Callback entry, we have WOWCallback16Ex which does
362 * everything we need.
364 if (!WOWCallback16Ex(
365 (DWORD
)((const IMalloc16Vtbl
*)MapSL(
366 (SEGPTR
)((LPMALLOC16
)MapSL((SEGPTR
)mllc
))->lpVtbl
)
373 ERR("CallTo16 IMalloc16 (%d) failed\n",size
);
379 /******************************************************************************
380 * StringFromCLSID [COMPOBJ.19]
381 * Converts a GUID into the respective string representation.
382 * The target string is allocated using the OLE IMalloc.
385 * the string representation and HRESULT
388 HRESULT WINAPI
StringFromCLSID16(
389 REFCLSID id
, /* [in] the GUID to be converted */
390 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
395 ret
= _xmalloc16(40,(SEGPTR
*)idstr
);
398 return WINE_StringFromCLSID(id
,MapSL((SEGPTR
)*idstr
));
401 /******************************************************************************
402 * ProgIDFromCLSID [COMPOBJ.62]
404 * Converts a class id into the respective Program ID. (By using a registry lookup)
408 * riid associated with the progid
410 HRESULT WINAPI
ProgIDFromCLSID16(
411 REFCLSID clsid
, /* [in] class id as found in registry */
412 LPOLESTR16
*lplpszProgID
/* [out] associated Program ID */
414 static const WCHAR wszProgID
[] = {'P','r','o','g','I','D',0};
420 ret
= COM_OpenKeyForCLSID(clsid
, wszProgID
, KEY_READ
, &hkey
);
424 if (RegQueryValueA(hkey
, NULL
, NULL
, &len
))
425 ret
= REGDB_E_READREGDB
;
429 buffer
= HeapAlloc(GetProcessHeap(), 0, len
);
430 if (RegQueryValueA(hkey
, NULL
, buffer
, &len
))
431 ret
= REGDB_E_READREGDB
;
435 ret
= _xmalloc16(len
, (SEGPTR
*)lplpszProgID
);
437 strcpy(MapSL((SEGPTR
)*lplpszProgID
),buffer
);
439 HeapFree(GetProcessHeap(), 0, buffer
);
445 /***********************************************************************
446 * LookupETask (COMPOBJ.94)
448 HRESULT WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
449 FIXME("(%p,%p),stub!\n",hTask
,p
);
450 if ((*hTask
= GetCurrentTask()) == hETask
) {
451 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
456 /***********************************************************************
457 * SetETask (COMPOBJ.95)
459 HRESULT WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
460 FIXME("(%04x,%p),stub!\n",hTask
,p
);
465 /***********************************************************************
466 * CALLOBJECTINWOW (COMPOBJ.201)
468 HRESULT WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
469 FIXME("(%p,%p),stub!\n",p1
,p2
);
473 /******************************************************************************
474 * CoRegisterClassObject [COMPOBJ.5]
476 * Don't know where it registers it ...
478 HRESULT WINAPI
CoRegisterClassObject16(
481 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
482 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
485 FIXME("(%s,%p,0x%08x,0x%08x,%p),stub\n",
486 debugstr_guid(rclsid
),pUnk
,dwClsContext
,flags
,lpdwRegister
491 /******************************************************************************
492 * CoRevokeClassObject [COMPOBJ.6]
495 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
) /* [in] token on class obj */
497 FIXME("(0x%08x),stub!\n", dwRegister
);
501 /******************************************************************************
502 * CoFileTimeToDosDateTime [COMPOBJ.30]
504 BOOL16 WINAPI
CoFileTimeToDosDateTime16(const FILETIME
*ft
, LPWORD lpDosDate
, LPWORD lpDosTime
)
506 return FileTimeToDosDateTime(ft
, lpDosDate
, lpDosTime
);
509 /******************************************************************************
510 * CoDosDateTimeToFileTime [COMPOBJ.31]
512 BOOL16 WINAPI
CoDosDateTimeToFileTime16(WORD wDosDate
, WORD wDosTime
, FILETIME
*ft
)
514 return DosDateTimeToFileTime(wDosDate
, wDosTime
, ft
);
517 /******************************************************************************
518 * CoRegisterMessageFilter [COMPOBJ.27]
520 HRESULT WINAPI
CoRegisterMessageFilter16(
521 LPMESSAGEFILTER lpMessageFilter
,
522 LPMESSAGEFILTER
*lplpMessageFilter
524 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
528 /******************************************************************************
529 * CoLockObjectExternal [COMPOBJ.63]
531 HRESULT WINAPI
CoLockObjectExternal16(
532 LPUNKNOWN pUnk
, /* [in] object to be locked */
533 BOOL16 fLock
, /* [in] do lock */
534 BOOL16 fLastUnlockReleases
/* [in] ? */
536 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
540 /***********************************************************************
541 * CoGetState [COMPOBJ.115]
543 HRESULT WINAPI
CoGetState16(LPDWORD state
)
545 FIXME("(%p),stub!\n", state
);
551 /***********************************************************************
552 * DllEntryPoint [COMPOBJ.116]
554 * Initialization code for the COMPOBJ DLL
558 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
560 TRACE("(%08x, %04x, %04x, %04x, %08x, %04x)\n", Reason
, hInst
, ds
, HeapSize
, res1
, res2
);
564 /***********************************************************************
565 * CoMemAlloc [COMPOBJ.151]
567 SEGPTR WINAPI
CoMemAlloc(DWORD size
, DWORD dwMemContext
, DWORD x
) {
571 /* FIXME: check context handling */
572 TRACE("(%d, 0x%08x, 0x%08x)\n", size
, dwMemContext
, x
);
573 hres
= _xmalloc16(size
, &segptr
);
579 /******************************************************************************
580 * CLSIDFromProgID [COMPOBJ.61]
582 * Converts a program ID into the respective GUID.
585 * progid [I] program id as found in registry
586 * riid [O] associated CLSID
590 * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
592 HRESULT WINAPI
CLSIDFromProgID16(LPCOLESTR16 progid
, LPCLSID riid
)
599 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
600 sprintf(buf
,"%s\\CLSID",progid
);
601 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
602 HeapFree(GetProcessHeap(),0,buf
);
603 return CO_E_CLASSSTRING
;
605 HeapFree(GetProcessHeap(),0,buf
);
606 buf2len
= sizeof(buf2
);
607 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
609 return CO_E_CLASSSTRING
;
612 return CLSIDFromString16(buf2
,riid
);
615 /***********************************************************************
616 * CoGetClassObject [COMPOBJ.7]
619 HRESULT WINAPI
CoGetClassObject16(
620 REFCLSID rclsid
, DWORD dwClsContext
, COSERVERINFO
*pServerInfo
,
621 REFIID iid
, LPVOID
*ppv
)
623 FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid
), debugstr_guid(iid
));
626 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo
->pwszName
));
627 FIXME("\t\tpAuthInfo=%p\n",pServerInfo
->pAuthInfo
);
632 /***********************************************************************
633 * CoCreateInstance [COMPOBJ.13]
635 HRESULT WINAPI
CoCreateInstance16(
642 FIXME("(%s, %p, %x, %s, %p), stub!\n",
643 debugstr_guid(rclsid
), pUnkOuter
, dwClsContext
, debugstr_guid(iid
),
649 /***********************************************************************
650 * CoDisconnectObject [COMPOBJ.15]
652 HRESULT WINAPI
CoDisconnectObject16( LPUNKNOWN lpUnk
, DWORD reserved
)
654 FIXME("(%p, 0x%08x): stub!\n", lpUnk
, reserved
);
658 /***********************************************************************
659 * DllGetClassObject [OLE2.4]
661 HRESULT WINAPI
DllGetClassObject16(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
663 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
667 /******************************************************************************
668 * GetRunningObjectTable (OLE2.30)
671 GetRunningObjectTable16(DWORD reserved
, LPRUNNINGOBJECTTABLE
*pprot
)
673 FIXME("(%d,%p),stub!\n",reserved
,pprot
);