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
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 HINSTANCE16 COMPOBJ_hInstance
= 0;
54 static int COMPOBJ_Attach
= 0;
59 LPMALLOC16 currentMalloc16
=NULL
;
61 /* --- IMalloc16 implementation */
67 ICOM_VFIELD(IMalloc16
);
69 /* IMalloc16 fields */
72 /******************************************************************************
73 * IMalloc16_QueryInterface [COMPOBJ.500]
75 HRESULT WINAPI
IMalloc16_fnQueryInterface(IMalloc16
* iface
,REFIID refiid
,LPVOID
*obj
) {
76 ICOM_THIS(IMalloc16Impl
,iface
);
78 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
79 if ( !memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
)) ||
80 !memcmp(&IID_IMalloc
,refiid
,sizeof(IID_IMalloc
))
85 return OLE_E_ENUM_NOMORE
;
88 /******************************************************************************
89 * IMalloc16_AddRef [COMPOBJ.501]
91 ULONG WINAPI
IMalloc16_fnAddRef(IMalloc16
* iface
) {
92 ICOM_THIS(IMalloc16Impl
,iface
);
93 TRACE("(%p)->AddRef()\n",This
);
94 return 1; /* cannot be freed */
97 /******************************************************************************
98 * IMalloc16_Release [COMPOBJ.502]
100 ULONG WINAPI
IMalloc16_fnRelease(IMalloc16
* iface
) {
101 ICOM_THIS(IMalloc16Impl
,iface
);
102 TRACE("(%p)->Release()\n",This
);
103 return 1; /* cannot be freed */
106 /******************************************************************************
107 * IMalloc16_Alloc [COMPOBJ.503]
109 SEGPTR WINAPI
IMalloc16_fnAlloc(IMalloc16
* iface
,DWORD cb
) {
110 ICOM_THIS(IMalloc16Impl
,iface
);
111 TRACE("(%p)->Alloc(%ld)\n",This
,cb
);
112 return MapLS( HeapAlloc( GetProcessHeap(), 0, cb
) );
115 /******************************************************************************
116 * IMalloc16_Realloc [COMPOBJ.504]
118 SEGPTR WINAPI
IMalloc16_fnRealloc(IMalloc16
* iface
,SEGPTR pv
,DWORD cb
)
121 ICOM_THIS(IMalloc16Impl
,iface
);
122 TRACE("(%p)->Realloc(%08lx,%ld)\n",This
,pv
,cb
);
123 ret
= MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv
), cb
) );
128 /******************************************************************************
129 * IMalloc16_Free [COMPOBJ.505]
131 VOID WINAPI
IMalloc16_fnFree(IMalloc16
* iface
,SEGPTR pv
)
133 void *ptr
= MapSL(pv
);
134 ICOM_THIS(IMalloc16Impl
,iface
);
135 TRACE("(%p)->Free(%08lx)\n",This
,pv
);
137 HeapFree( GetProcessHeap(), 0, ptr
);
140 /******************************************************************************
141 * IMalloc16_GetSize [COMPOBJ.506]
143 DWORD WINAPI
IMalloc16_fnGetSize(const IMalloc16
* iface
,SEGPTR pv
)
145 ICOM_THIS(IMalloc16Impl
,iface
);
146 TRACE("(%p)->GetSize(%08lx)\n",This
,pv
);
147 return HeapSize( GetProcessHeap(), 0, MapSL(pv
) );
150 /******************************************************************************
151 * IMalloc16_DidAlloc [COMPOBJ.507]
153 INT16 WINAPI
IMalloc16_fnDidAlloc(const IMalloc16
* iface
,LPVOID pv
) {
154 ICOM_THIS(IMalloc16
,iface
);
155 TRACE("(%p)->DidAlloc(%p)\n",This
,pv
);
159 /******************************************************************************
160 * IMalloc16_HeapMinimize [COMPOBJ.508]
162 LPVOID WINAPI
IMalloc16_fnHeapMinimize(IMalloc16
* iface
) {
163 ICOM_THIS(IMalloc16Impl
,iface
);
164 TRACE("(%p)->HeapMinimize()\n",This
);
168 /******************************************************************************
169 * IMalloc16_Constructor [VTABLE]
172 IMalloc16_Constructor()
174 static ICOM_VTABLE(IMalloc16
) vt16
;
175 static SEGPTR msegvt16
;
177 HMODULE16 hcomp
= GetModuleHandle16("COMPOBJ");
179 This
= HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl
) );
182 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
183 VTENT(QueryInterface
);
193 msegvt16
= MapLS( &vt16
);
195 This
->lpVtbl
= (ICOM_VTABLE(IMalloc16
)*)msegvt16
;
197 return (LPMALLOC16
)MapLS( This
);
201 /***********************************************************************
202 * CoGetMalloc [COMPOBJ.4]
204 * The current win16 IMalloc
206 HRESULT WINAPI
CoGetMalloc16(
207 DWORD dwMemContext
, /* [in] unknown */
208 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
211 currentMalloc16
= IMalloc16_Constructor();
212 *lpMalloc
= currentMalloc16
;
216 /***********************************************************************
217 * CoCreateStandardMalloc [COMPOBJ.71]
219 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
220 LPMALLOC16
*lpMalloc
)
222 /* FIXME: docu says we shouldn't return the same allocator as in
224 *lpMalloc
= IMalloc16_Constructor();
228 /******************************************************************************
229 * CoInitialize [COMPOBJ.2]
230 * Set the win16 IMalloc used for memory management
232 HRESULT WINAPI
CoInitialize16(
233 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
235 currentMalloc16
= (LPMALLOC16
)lpReserved
;
239 /***********************************************************************
240 * CoUninitialize [COMPOBJ.3]
241 * Don't know what it does.
242 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
243 * believe is the correct spelling
245 void WINAPI
CoUninitialize16(void)
248 CoFreeAllLibraries();
251 /***********************************************************************
252 * IsEqualGUID [COMPOBJ.18]
254 * Compares two Unique Identifiers.
259 BOOL16 WINAPI
IsEqualGUID16(
260 GUID
* g1
, /* [in] unique id 1 */
261 GUID
* g2
) /* [in] unique id 2 */
263 return !memcmp( g1
, g2
, sizeof(GUID
) );
266 /******************************************************************************
267 * CLSIDFromString [COMPOBJ.20]
268 * Converts a unique identifier from its string representation into
271 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
276 HRESULT WINAPI
CLSIDFromString16(
277 LPCOLESTR16 idstr
, /* [in] string representation of guid */
278 CLSID
*id
) /* [out] GUID converted from string */
281 return __CLSIDFromStringA(idstr
,id
);
284 extern BOOL WINAPI
K32WOWCallback16Ex( DWORD vpfn16
, DWORD dwFlags
,
285 DWORD cbArgs
, LPVOID pArgs
,
286 LPDWORD pdwRetCode
);
288 /******************************************************************************
289 * _xmalloc16 [internal]
290 * Allocates size bytes from the standard ole16 allocator.
293 * the allocated segmented pointer and a HRESULT
296 _xmalloc16(DWORD size
, SEGPTR
*ptr
) {
300 if (CoGetMalloc16(0,&mllc
))
301 return E_OUTOFMEMORY
;
303 args
[0] = (DWORD
)mllc
;
305 /* No need for a Callback entry, we have WOWCallback16Ex which does
306 * everything we need.
308 if (!K32WOWCallback16Ex(
309 (DWORD
)((ICOM_VTABLE(IMalloc16
)*)MapSL(
310 (SEGPTR
)((LPMALLOC16
)MapSL((SEGPTR
)mllc
))->lpVtbl
)
317 ERR("CallTo16 IMalloc16 (%ld) failed\n",size
);
323 /******************************************************************************
324 * StringFromCLSID [COMPOBJ.19]
325 * Converts a GUID into the respective string representation.
326 * The target string is allocated using the OLE IMalloc.
329 * the string representation and HRESULT
332 HRESULT WINAPI
StringFromCLSID16(
333 REFCLSID id
, /* [in] the GUID to be converted */
334 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
339 ret
= _xmalloc16(40,(SEGPTR
*)idstr
);
342 return WINE_StringFromCLSID(id
,MapSL((SEGPTR
)*idstr
));
345 /******************************************************************************
346 * ProgIDFromCLSID [COMPOBJ.62]
347 * Converts a class id into the respective Program ID. (By using a registry lookup)
348 * RETURNS S_OK on success
349 * riid associated with the progid
351 HRESULT WINAPI
ProgIDFromCLSID16(
352 REFCLSID clsid
, /* [in] class id as found in registry */
353 LPOLESTR16
*lplpszProgID
/* [out] associated Prog ID */
355 char strCLSID
[50], *buf
, *buf2
;
360 WINE_StringFromCLSID(clsid
, strCLSID
);
362 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID
)+14);
363 sprintf(buf
,"CLSID\\%s\\ProgID", strCLSID
);
364 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
365 ret
= REGDB_E_CLASSNOTREG
;
367 HeapFree(GetProcessHeap(), 0, buf
);
371 buf2
= HeapAlloc(GetProcessHeap(), 0, 255);
373 if (RegQueryValueA(xhkey
, NULL
, buf2
, &buf2len
))
374 ret
= REGDB_E_CLASSNOTREG
;
378 ret
= _xmalloc16(buf2len
+1, (SEGPTR
*)lplpszProgID
);
380 strcpy(MapSL((SEGPTR
)*lplpszProgID
),buf2
);
382 HeapFree(GetProcessHeap(), 0, buf2
);
388 /***********************************************************************
389 * LookupETask (COMPOBJ.94)
391 HRESULT WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
392 FIXME("(%p,%p),stub!\n",hTask
,p
);
393 if ((*hTask
= GetCurrentTask()) == hETask
) {
394 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
399 /***********************************************************************
400 * SetETask (COMPOBJ.95)
402 HRESULT WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
403 FIXME("(%04x,%p),stub!\n",hTask
,p
);
408 /***********************************************************************
409 * CALLOBJECTINWOW (COMPOBJ.201)
411 HRESULT WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
412 FIXME("(%p,%p),stub!\n",p1
,p2
);
416 /******************************************************************************
417 * CoRegisterClassObject [COMPOBJ.5]
419 * Don't know where it registers it ...
421 HRESULT WINAPI
CoRegisterClassObject16(
424 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
425 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
430 WINE_StringFromCLSID(rclsid
,buf
);
432 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
433 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
438 /******************************************************************************
439 * CoRevokeClassObject [COMPOBJ.6]
442 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
) /* [in] token on class obj */
444 FIXME("(0x%08lx),stub!\n", dwRegister
);
448 /******************************************************************************
449 * CoFileTimeToDosDateTime [COMPOBJ.30]
451 BOOL16 WINAPI
CoFileTimeToDosDateTime16(const FILETIME
*ft
, LPWORD lpDosDate
, LPWORD lpDosTime
)
453 return FileTimeToDosDateTime(ft
, lpDosDate
, lpDosTime
);
456 /******************************************************************************
457 * CoDosDateTimeToFileTime [COMPOBJ.31]
459 BOOL16 WINAPI
CoDosDateTimeToFileTime16(WORD wDosDate
, WORD wDosTime
, FILETIME
*ft
)
461 return DosDateTimeToFileTime(wDosDate
, wDosTime
, ft
);
464 /******************************************************************************
465 * CoRegisterMessageFilter [COMPOBJ.27]
467 HRESULT WINAPI
CoRegisterMessageFilter16(
468 LPMESSAGEFILTER lpMessageFilter
,
469 LPMESSAGEFILTER
*lplpMessageFilter
471 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
475 /******************************************************************************
476 * CoLockObjectExternal [COMPOBJ.63]
478 HRESULT WINAPI
CoLockObjectExternal16(
479 LPUNKNOWN pUnk
, /* [in] object to be locked */
480 BOOL16 fLock
, /* [in] do lock */
481 BOOL16 fLastUnlockReleases
/* [in] ? */
483 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
487 /***********************************************************************
488 * CoGetState [COMPOBJ.115]
490 HRESULT WINAPI
CoGetState16(LPDWORD state
)
492 FIXME("(%p),stub!\n", state
);
498 /***********************************************************************
499 * DllEntryPoint [COMPOBJ.116]
501 * Initialization code for the COMPOBJ DLL
505 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
507 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
, res1
, res2
);
510 case DLL_PROCESS_ATTACH
:
511 if (!COMPOBJ_Attach
++) COMPOBJ_hInstance
= hInst
;
514 case DLL_PROCESS_DETACH
:
515 if(!--COMPOBJ_Attach
)
516 COMPOBJ_hInstance
= 0;