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
44 #include "wine/unicode.h"
45 #include "wine/winbase16.h"
46 #include "compobj_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
53 static HTASK16 hETask
= 0;
54 static WORD Table_ETask
[62];
56 static LPMALLOC16 currentMalloc16
=NULL
;
58 /* --- IMalloc16 implementation */
64 const IMalloc16Vtbl
*lpVtbl
;
66 /* IMalloc16 fields */
69 /******************************************************************************
70 * IMalloc16_QueryInterface [COMPOBJ.500]
72 HRESULT CDECL
IMalloc16_fnQueryInterface(IMalloc16
* iface
,REFIID refiid
,LPVOID
*obj
) {
73 IMalloc16Impl
*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
))
82 return OLE_E_ENUM_NOMORE
;
85 /******************************************************************************
86 * IMalloc16_AddRef [COMPOBJ.501]
88 ULONG CDECL
IMalloc16_fnAddRef(IMalloc16
* iface
) {
89 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
90 TRACE("(%p)->AddRef()\n",This
);
91 return 1; /* cannot be freed */
94 /******************************************************************************
95 * IMalloc16_Release [COMPOBJ.502]
97 ULONG CDECL
IMalloc16_fnRelease(IMalloc16
* iface
) {
98 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
99 TRACE("(%p)->Release()\n",This
);
100 return 1; /* cannot be freed */
103 /******************************************************************************
104 * IMalloc16_Alloc [COMPOBJ.503]
106 SEGPTR CDECL
IMalloc16_fnAlloc(IMalloc16
* iface
,DWORD cb
) {
107 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
108 TRACE("(%p)->Alloc(%ld)\n",This
,cb
);
109 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb
) );
112 /******************************************************************************
113 * IMalloc16_Free [COMPOBJ.505]
115 VOID CDECL
IMalloc16_fnFree(IMalloc16
* iface
,SEGPTR pv
)
117 void *ptr
= MapSL(pv
);
118 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
119 TRACE("(%p)->Free(%08lx)\n",This
,pv
);
121 HeapFree( GetProcessHeap(), 0, ptr
);
124 /******************************************************************************
125 * IMalloc16_Realloc [COMPOBJ.504]
127 SEGPTR CDECL
IMalloc16_fnRealloc(IMalloc16
* iface
,SEGPTR pv
,DWORD cb
)
130 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
131 TRACE("(%p)->Realloc(%08lx,%ld)\n",This
,pv
,cb
);
133 ret
= IMalloc16_fnAlloc(iface
, cb
);
135 ret
= MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv
), cb
) );
138 IMalloc16_fnFree(iface
, pv
);
144 /******************************************************************************
145 * IMalloc16_GetSize [COMPOBJ.506]
147 DWORD CDECL
IMalloc16_fnGetSize(IMalloc16
* iface
,SEGPTR pv
)
149 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
150 TRACE("(%p)->GetSize(%08lx)\n",This
,pv
);
151 return HeapSize( GetProcessHeap(), 0, MapSL(pv
) );
154 /******************************************************************************
155 * IMalloc16_DidAlloc [COMPOBJ.507]
157 INT16 CDECL
IMalloc16_fnDidAlloc(IMalloc16
* iface
,LPVOID pv
) {
158 IMalloc16
*This
= (IMalloc16
*)iface
;
159 TRACE("(%p)->DidAlloc(%p)\n",This
,pv
);
163 /******************************************************************************
164 * IMalloc16_HeapMinimize [COMPOBJ.508]
166 LPVOID CDECL
IMalloc16_fnHeapMinimize(IMalloc16
* iface
) {
167 IMalloc16Impl
*This
= (IMalloc16Impl
*)iface
;
168 TRACE("(%p)->HeapMinimize()\n",This
);
172 /******************************************************************************
173 * IMalloc16_Constructor [VTABLE]
176 IMalloc16_Constructor(void)
178 static IMalloc16Vtbl vt16
;
179 static SEGPTR msegvt16
;
181 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
183 This
= HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl
) );
186 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
187 VTENT(QueryInterface
);
197 msegvt16
= MapLS( &vt16
);
199 This
->lpVtbl
= (const IMalloc16Vtbl
*)msegvt16
;
201 return (LPMALLOC16
)MapLS( This
);
205 /***********************************************************************
206 * CoGetMalloc [COMPOBJ.4]
208 * Retrieve the current win16 IMalloc interface.
211 * The current win16 IMalloc
213 HRESULT WINAPI
CoGetMalloc16(
214 DWORD dwMemContext
, /* [in] unknown */
215 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
218 currentMalloc16
= IMalloc16_Constructor();
219 *lpMalloc
= currentMalloc16
;
223 /***********************************************************************
224 * CoCreateStandardMalloc [COMPOBJ.71]
226 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
227 LPMALLOC16
*lpMalloc
)
229 /* FIXME: docu says we shouldn't return the same allocator as in
231 *lpMalloc
= IMalloc16_Constructor();
235 /******************************************************************************
236 * CoInitialize [COMPOBJ.2]
237 * Set the win16 IMalloc used for memory management
239 HRESULT WINAPI
CoInitialize16(
240 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
242 currentMalloc16
= (LPMALLOC16
)lpReserved
;
246 /***********************************************************************
247 * CoUninitialize [COMPOBJ.3]
248 * Don't know what it does.
249 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
250 * believe is the correct spelling
252 void WINAPI
CoUninitialize16(void)
255 CoFreeAllLibraries();
258 /***********************************************************************
259 * IsEqualGUID [COMPOBJ.18]
261 * Compares two Unique Identifiers.
266 BOOL16 WINAPI
IsEqualGUID16(
267 GUID
* g1
, /* [in] unique id 1 */
268 GUID
* g2
) /* [in] unique id 2 */
270 return !memcmp( g1
, g2
, sizeof(GUID
) );
273 /******************************************************************************
274 * CLSIDFromString [COMPOBJ.20]
275 * Converts a unique identifier from its string representation into
278 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
283 HRESULT WINAPI
CLSIDFromString16(
284 LPCOLESTR16 idstr
, /* [in] string representation of guid */
285 CLSID
*id
) /* [out] GUID converted from string */
292 memset( id
, 0, sizeof (CLSID
) );
296 /* validate the CLSID string */
297 if (strlen(idstr
) != 38)
298 return CO_E_CLASSSTRING
;
300 s
= (const BYTE
*) idstr
;
301 if ((s
[0]!='{') || (s
[9]!='-') || (s
[14]!='-') || (s
[19]!='-') || (s
[24]!='-') || (s
[37]!='}'))
302 return CO_E_CLASSSTRING
;
304 for (i
=1; i
<37; i
++) {
305 if ((i
== 9)||(i
== 14)||(i
== 19)||(i
== 24)) continue;
306 if (!(((s
[i
] >= '0') && (s
[i
] <= '9')) ||
307 ((s
[i
] >= 'a') && (s
[i
] <= 'f')) ||
308 ((s
[i
] >= 'A') && (s
[i
] <= 'F'))))
309 return CO_E_CLASSSTRING
;
312 TRACE("%s -> %p\n", s
, id
);
314 /* quick lookup table */
315 memset(table
, 0, 256);
317 for (i
= 0; i
< 10; i
++) {
320 for (i
= 0; i
< 6; i
++) {
321 table
['A' + i
] = i
+10;
322 table
['a' + i
] = i
+10;
325 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
327 id
->Data1
= (table
[s
[1]] << 28 | table
[s
[2]] << 24 | table
[s
[3]] << 20 | table
[s
[4]] << 16 |
328 table
[s
[5]] << 12 | table
[s
[6]] << 8 | table
[s
[7]] << 4 | table
[s
[8]]);
329 id
->Data2
= table
[s
[10]] << 12 | table
[s
[11]] << 8 | table
[s
[12]] << 4 | table
[s
[13]];
330 id
->Data3
= table
[s
[15]] << 12 | table
[s
[16]] << 8 | table
[s
[17]] << 4 | table
[s
[18]];
332 /* these are just sequential bytes */
333 id
->Data4
[0] = table
[s
[20]] << 4 | table
[s
[21]];
334 id
->Data4
[1] = table
[s
[22]] << 4 | table
[s
[23]];
335 id
->Data4
[2] = table
[s
[25]] << 4 | table
[s
[26]];
336 id
->Data4
[3] = table
[s
[27]] << 4 | table
[s
[28]];
337 id
->Data4
[4] = table
[s
[29]] << 4 | table
[s
[30]];
338 id
->Data4
[5] = table
[s
[31]] << 4 | table
[s
[32]];
339 id
->Data4
[6] = table
[s
[33]] << 4 | table
[s
[34]];
340 id
->Data4
[7] = table
[s
[35]] << 4 | table
[s
[36]];
345 /******************************************************************************
346 * _xmalloc16 [internal]
347 * Allocates size bytes from the standard ole16 allocator.
350 * the allocated segmented pointer and a HRESULT
353 _xmalloc16(DWORD size
, SEGPTR
*ptr
) {
357 if (CoGetMalloc16(0,&mllc
))
358 return E_OUTOFMEMORY
;
360 args
[0] = (DWORD
)mllc
;
362 /* No need for a Callback entry, we have WOWCallback16Ex which does
363 * everything we need.
365 if (!WOWCallback16Ex(
366 (DWORD
)((const IMalloc16Vtbl
*)MapSL(
367 (SEGPTR
)((LPMALLOC16
)MapSL((SEGPTR
)mllc
))->lpVtbl
)
374 ERR("CallTo16 IMalloc16 (%ld) failed\n",size
);
380 /******************************************************************************
381 * StringFromCLSID [COMPOBJ.19]
382 * Converts a GUID into the respective string representation.
383 * The target string is allocated using the OLE IMalloc.
386 * the string representation and HRESULT
389 HRESULT WINAPI
StringFromCLSID16(
390 REFCLSID id
, /* [in] the GUID to be converted */
391 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
396 ret
= _xmalloc16(40,(SEGPTR
*)idstr
);
399 return WINE_StringFromCLSID(id
,MapSL((SEGPTR
)*idstr
));
402 /******************************************************************************
403 * ProgIDFromCLSID [COMPOBJ.62]
405 * Converts a class id into the respective Program ID. (By using a registry lookup)
409 * riid associated with the progid
411 HRESULT WINAPI
ProgIDFromCLSID16(
412 REFCLSID clsid
, /* [in] class id as found in registry */
413 LPOLESTR16
*lplpszProgID
/* [out] associated Prog ID */
415 static const WCHAR wszProgID
[] = {'P','r','o','g','I','D',0};
421 ret
= COM_OpenKeyForCLSID(clsid
, wszProgID
, KEY_READ
, &hkey
);
425 if (RegQueryValueA(hkey
, NULL
, NULL
, &len
))
426 ret
= REGDB_E_READREGDB
;
430 buffer
= HeapAlloc(GetProcessHeap(), 0, len
);
431 if (RegQueryValueA(hkey
, NULL
, buffer
, &len
))
432 ret
= REGDB_E_READREGDB
;
436 ret
= _xmalloc16(len
, (SEGPTR
*)lplpszProgID
);
438 strcpy(MapSL((SEGPTR
)*lplpszProgID
),buffer
);
440 HeapFree(GetProcessHeap(), 0, buffer
);
446 /***********************************************************************
447 * LookupETask (COMPOBJ.94)
449 HRESULT WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
450 FIXME("(%p,%p),stub!\n",hTask
,p
);
451 if ((*hTask
= GetCurrentTask()) == hETask
) {
452 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
457 /***********************************************************************
458 * SetETask (COMPOBJ.95)
460 HRESULT WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
461 FIXME("(%04x,%p),stub!\n",hTask
,p
);
466 /***********************************************************************
467 * CALLOBJECTINWOW (COMPOBJ.201)
469 HRESULT WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
470 FIXME("(%p,%p),stub!\n",p1
,p2
);
474 /******************************************************************************
475 * CoRegisterClassObject [COMPOBJ.5]
477 * Don't know where it registers it ...
479 HRESULT WINAPI
CoRegisterClassObject16(
482 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
483 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
486 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
487 debugstr_guid(rclsid
),pUnk
,dwClsContext
,flags
,lpdwRegister
492 /******************************************************************************
493 * CoRevokeClassObject [COMPOBJ.6]
496 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
) /* [in] token on class obj */
498 FIXME("(0x%08lx),stub!\n", dwRegister
);
502 /******************************************************************************
503 * CoFileTimeToDosDateTime [COMPOBJ.30]
505 BOOL16 WINAPI
CoFileTimeToDosDateTime16(const FILETIME
*ft
, LPWORD lpDosDate
, LPWORD lpDosTime
)
507 return FileTimeToDosDateTime(ft
, lpDosDate
, lpDosTime
);
510 /******************************************************************************
511 * CoDosDateTimeToFileTime [COMPOBJ.31]
513 BOOL16 WINAPI
CoDosDateTimeToFileTime16(WORD wDosDate
, WORD wDosTime
, FILETIME
*ft
)
515 return DosDateTimeToFileTime(wDosDate
, wDosTime
, ft
);
518 /******************************************************************************
519 * CoRegisterMessageFilter [COMPOBJ.27]
521 HRESULT WINAPI
CoRegisterMessageFilter16(
522 LPMESSAGEFILTER lpMessageFilter
,
523 LPMESSAGEFILTER
*lplpMessageFilter
525 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
529 /******************************************************************************
530 * CoLockObjectExternal [COMPOBJ.63]
532 HRESULT WINAPI
CoLockObjectExternal16(
533 LPUNKNOWN pUnk
, /* [in] object to be locked */
534 BOOL16 fLock
, /* [in] do lock */
535 BOOL16 fLastUnlockReleases
/* [in] ? */
537 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
541 /***********************************************************************
542 * CoGetState [COMPOBJ.115]
544 HRESULT WINAPI
CoGetState16(LPDWORD state
)
546 FIXME("(%p),stub!\n", state
);
552 /***********************************************************************
553 * DllEntryPoint [COMPOBJ.116]
555 * Initialization code for the COMPOBJ DLL
559 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
561 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
, res1
, res2
);
565 /***********************************************************************
566 * CoMemAlloc [COMPOBJ.151]
568 SEGPTR WINAPI
CoMemAlloc(DWORD size
, DWORD dwMemContext
, DWORD x
) {
572 /* FIXME: check context handling */
573 TRACE("(%ld, 0x%08lx, 0x%08lx)\n", size
, dwMemContext
, x
);
574 hres
= _xmalloc16(size
, &segptr
);
580 /******************************************************************************
581 * CLSIDFromProgID [COMPOBJ.61]
583 * Converts a program ID into the respective GUID.
586 * progid [I] program id as found in registry
587 * riid [O] associated CLSID
591 * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
593 HRESULT WINAPI
CLSIDFromProgID16(LPCOLESTR16 progid
, LPCLSID riid
)
600 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
601 sprintf(buf
,"%s\\CLSID",progid
);
602 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
603 HeapFree(GetProcessHeap(),0,buf
);
604 return CO_E_CLASSSTRING
;
606 HeapFree(GetProcessHeap(),0,buf
);
607 buf2len
= sizeof(buf2
);
608 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
610 return CO_E_CLASSSTRING
;
613 return CLSIDFromString16(buf2
,riid
);
616 /***********************************************************************
617 * CoGetClassObject [COMPOBJ.7]
620 HRESULT WINAPI
CoGetClassObject16(
621 REFCLSID rclsid
, DWORD dwClsContext
, COSERVERINFO
*pServerInfo
,
622 REFIID iid
, LPVOID
*ppv
)
624 FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid
), debugstr_guid(iid
));
627 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo
->pwszName
));
628 FIXME("\t\tpAuthInfo=%p\n",pServerInfo
->pAuthInfo
);
633 /***********************************************************************
634 * CoCreateInstance [COMPOBJ.13]
636 HRESULT WINAPI
CoCreateInstance16(
643 FIXME("(%s, %p, %lx, %s, %p), stub!\n",
644 debugstr_guid(rclsid
), pUnkOuter
, dwClsContext
, debugstr_guid(iid
),
650 /***********************************************************************
651 * DllGetClassObject [OLE2.4]
653 HRESULT WINAPI
DllGetClassObject16(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
655 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
659 /******************************************************************************
660 * GetRunningObjectTable (OLE2.30)
663 GetRunningObjectTable16(DWORD reserved
, LPRUNNINGOBJECTTABLE
*pprot
)
665 FIXME("(%ld,%p),stub!\n",reserved
,pprot
);