netstat: Initial implementation.
[wine] / dlls / compobj.dll16 / compobj.c
1 /*
2  * 16 bit ole functions
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <assert.h>
32
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "objbase.h"
37 #include "ole2.h"
38 #include "rpc.h"
39 #include "winerror.h"
40 #include "winreg.h"
41 #include "wownt32.h"
42 #include "wtypes.h"
43 #include "wine/unicode.h"
44 #include "wine/winbase16.h"
45
46 #include "wine/debug.h"
47
48 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49
50 typedef LPSTR LPOLESTR16;
51 typedef LPCSTR LPCOLESTR16;
52
53 #define STDMETHOD16CALLTYPE __cdecl
54 #define STDMETHOD16(m) HRESULT (STDMETHOD16CALLTYPE *m)
55 #define STDMETHOD16_(t,m) t (STDMETHOD16CALLTYPE *m)
56
57
58 /***********************************************************************
59  * IMalloc16 interface
60  */
61
62 typedef struct IMalloc16 *LPMALLOC16;
63
64 #define INTERFACE IMalloc16
65 DECLARE_INTERFACE_(IMalloc16,IUnknown)
66 {
67     /*** IUnknown methods ***/
68     STDMETHOD16_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
69     STDMETHOD16_(ULONG,AddRef)(THIS) PURE;
70     STDMETHOD16_(ULONG,Release)(THIS) PURE;
71     /*** IMalloc16 methods ***/
72     STDMETHOD16_(LPVOID,Alloc)(THIS_ DWORD   cb) PURE;
73     STDMETHOD16_(LPVOID,Realloc)(THIS_ LPVOID  pv, DWORD  cb) PURE;
74     STDMETHOD16_(void,Free)(THIS_ LPVOID  pv) PURE;
75     STDMETHOD16_(DWORD,GetSize)(THIS_ LPVOID  pv) PURE;
76     STDMETHOD16_(INT16,DidAlloc)(THIS_ LPVOID  pv) PURE;
77     STDMETHOD16_(LPVOID,HeapMinimize)(THIS) PURE;
78 };
79 #undef INTERFACE
80
81 static HTASK16 hETask = 0;
82 static WORD Table_ETask[62];
83
84 static LPMALLOC16 currentMalloc16=NULL;
85
86 /* --- IMalloc16 implementation */
87
88
89 typedef struct
90 {
91         IMalloc16 IMalloc16_iface;
92         DWORD     ref;
93 } IMalloc16Impl;
94
95 static inline IMalloc16Impl *impl_from_IMalloc16(IMalloc16 *iface)
96 {
97         return CONTAINING_RECORD(iface, IMalloc16Impl, IMalloc16_iface);
98 }
99
100 /******************************************************************************
101  *              IMalloc16_QueryInterface        [COMPOBJ.500]
102  */
103 HRESULT CDECL IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
104         IMalloc16Impl *This = impl_from_IMalloc16(iface);
105
106         TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
107         if (    !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
108                 !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
109         ) {
110                 *obj = This;
111                 return 0;
112         }
113         return OLE_E_ENUM_NOMORE;
114 }
115
116 /******************************************************************************
117  *              IMalloc16_AddRef        [COMPOBJ.501]
118  */
119 ULONG CDECL IMalloc16_fnAddRef(IMalloc16* iface) {
120         IMalloc16Impl *This = impl_from_IMalloc16(iface);
121
122         TRACE("(%p)->AddRef()\n",This);
123         return 1; /* cannot be freed */
124 }
125
126 /******************************************************************************
127  *              IMalloc16_Release       [COMPOBJ.502]
128  */
129 ULONG CDECL IMalloc16_fnRelease(IMalloc16* iface) {
130         IMalloc16Impl *This = impl_from_IMalloc16(iface);
131
132         TRACE("(%p)->Release()\n",This);
133         return 1; /* cannot be freed */
134 }
135
136 /******************************************************************************
137  * IMalloc16_Alloc [COMPOBJ.503]
138  */
139 SEGPTR CDECL IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
140         IMalloc16Impl *This = impl_from_IMalloc16(iface);
141
142         TRACE("(%p)->Alloc(%d)\n",This,cb);
143         return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) );
144 }
145
146 /******************************************************************************
147  * IMalloc16_Free [COMPOBJ.505]
148  */
149 VOID CDECL IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
150 {
151     void *ptr = MapSL(pv);
152     IMalloc16Impl *This = impl_from_IMalloc16(iface);
153     TRACE("(%p)->Free(%08x)\n",This,pv);
154     UnMapLS(pv);
155     HeapFree( GetProcessHeap(), 0, ptr );
156 }
157
158 /******************************************************************************
159  * IMalloc16_Realloc [COMPOBJ.504]
160  */
161 SEGPTR CDECL IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
162 {
163     SEGPTR ret;
164     IMalloc16Impl *This = impl_from_IMalloc16(iface);
165
166     TRACE("(%p)->Realloc(%08x,%d)\n",This,pv,cb);
167     if (!pv)
168         ret = IMalloc16_fnAlloc(iface, cb);
169     else if (cb) {
170         ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) );
171         UnMapLS(pv);
172     } else {
173         IMalloc16_fnFree(iface, pv);
174         ret = 0;
175     }
176     return ret;
177 }
178
179 /******************************************************************************
180  * IMalloc16_GetSize [COMPOBJ.506]
181  */
182 DWORD CDECL IMalloc16_fnGetSize(IMalloc16* iface,SEGPTR pv)
183 {
184         IMalloc16Impl *This = impl_from_IMalloc16(iface);
185
186         TRACE("(%p)->GetSize(%08x)\n",This,pv);
187         return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
188 }
189
190 /******************************************************************************
191  * IMalloc16_DidAlloc [COMPOBJ.507]
192  */
193 INT16 CDECL IMalloc16_fnDidAlloc(IMalloc16* iface,LPVOID pv) {
194         IMalloc16Impl *This = impl_from_IMalloc16(iface);
195
196         TRACE("(%p)->DidAlloc(%p)\n",This,pv);
197         return (INT16)-1;
198 }
199
200 /******************************************************************************
201  * IMalloc16_HeapMinimize [COMPOBJ.508]
202  */
203 LPVOID CDECL IMalloc16_fnHeapMinimize(IMalloc16* iface) {
204         IMalloc16Impl *This = impl_from_IMalloc16(iface);
205
206         TRACE("(%p)->HeapMinimize()\n",This);
207         return NULL;
208 }
209
210 /******************************************************************************
211  * IMalloc16_Constructor [VTABLE]
212  */
213 static LPMALLOC16
214 IMalloc16_Constructor(void)
215 {
216     static IMalloc16Vtbl vt16;
217     static SEGPTR msegvt16;
218     IMalloc16Impl* This;
219     HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
220
221     This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) );
222     if (!msegvt16)
223     {
224 #define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
225         VTENT(QueryInterface);
226         VTENT(AddRef);
227         VTENT(Release);
228         VTENT(Alloc);
229         VTENT(Realloc);
230         VTENT(Free);
231         VTENT(GetSize);
232         VTENT(DidAlloc);
233         VTENT(HeapMinimize);
234 #undef VTENT
235         msegvt16 = MapLS( &vt16 );
236     }
237     This->IMalloc16_iface.lpVtbl = (const IMalloc16Vtbl*)msegvt16;
238     This->ref = 1;
239     return (LPMALLOC16)MapLS( This );
240 }
241
242
243 /******************************************************************************
244  *           CoBuildVersion [COMPOBJ.1]
245  */
246 DWORD WINAPI CoBuildVersion16(void)
247 {
248     return CoBuildVersion();
249 }
250
251 /***********************************************************************
252  *           CoGetMalloc    [COMPOBJ.4]
253  *
254  * Retrieve the current win16 IMalloc interface.
255  *
256  * RETURNS
257  *      The current win16 IMalloc
258  */
259 HRESULT WINAPI CoGetMalloc16(
260         DWORD dwMemContext,     /* [in] unknown */
261         LPMALLOC16 * lpMalloc   /* [out] current win16 malloc interface */
262 ) {
263     if(!currentMalloc16)
264         currentMalloc16 = IMalloc16_Constructor();
265     *lpMalloc = currentMalloc16;
266     return S_OK;
267 }
268
269 /***********************************************************************
270  *           CoCreateStandardMalloc [COMPOBJ.71]
271  */
272 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
273                                           LPMALLOC16 *lpMalloc)
274 {
275     /* FIXME: docu says we shouldn't return the same allocator as in
276      * CoGetMalloc16 */
277     *lpMalloc = IMalloc16_Constructor();
278     return S_OK;
279 }
280
281 /******************************************************************************
282  *              CoInitialize    [COMPOBJ.2]
283  * Set the win16 IMalloc used for memory management
284  */
285 HRESULT WINAPI CoInitialize16(
286         LPVOID lpReserved       /* [in] pointer to win16 malloc interface */
287 ) {
288     currentMalloc16 = (LPMALLOC16)lpReserved;
289     return S_OK;
290 }
291
292 /***********************************************************************
293  *           CoUninitialize   [COMPOBJ.3]
294  * Don't know what it does.
295  * 3-Nov-98 -- this was originally misspelled, I changed it to what I
296  *   believe is the correct spelling
297  */
298 void WINAPI CoUninitialize16(void)
299 {
300   TRACE("()\n");
301   CoFreeAllLibraries();
302 }
303
304 /***********************************************************************
305  *           CoFreeUnusedLibraries [COMPOBJ.17]
306  */
307 void WINAPI CoFreeUnusedLibraries16(void)
308 {
309     CoFreeUnusedLibraries();
310 }
311
312 /***********************************************************************
313  *           IsEqualGUID [COMPOBJ.18]
314  *
315  * Compares two Unique Identifiers.
316  *
317  * RETURNS
318  *      TRUE if equal
319  */
320 BOOL16 WINAPI IsEqualGUID16(
321         GUID* g1,       /* [in] unique id 1 */
322         GUID* g2)       /* [in] unique id 2 */
323 {
324     return !memcmp( g1, g2, sizeof(GUID) );
325 }
326
327 /******************************************************************************
328  *              CLSIDFromString [COMPOBJ.20]
329  * Converts a unique identifier from its string representation into
330  * the GUID struct.
331  *
332  * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
333  *
334  * RETURNS
335  *      the converted GUID
336  */
337 HRESULT WINAPI CLSIDFromString16(
338         LPCOLESTR16 idstr,      /* [in] string representation of guid */
339         CLSID *id)              /* [out] GUID converted from string */
340 {
341   const BYTE *s;
342   int   i;
343   BYTE table[256];
344
345   if (!idstr) {
346     memset( id, 0, sizeof (CLSID) );
347     return S_OK;
348   }
349
350   /* validate the CLSID string */
351   if (strlen(idstr) != 38)
352     return CO_E_CLASSSTRING;
353
354   s = (const BYTE *) idstr;
355   if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
356     return CO_E_CLASSSTRING;
357
358   for (i=1; i<37; i++) {
359     if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
360     if (!(((s[i] >= '0') && (s[i] <= '9'))  ||
361           ((s[i] >= 'a') && (s[i] <= 'f'))  ||
362           ((s[i] >= 'A') && (s[i] <= 'F'))))
363        return CO_E_CLASSSTRING;
364   }
365
366   TRACE("%s -> %p\n", s, id);
367
368   /* quick lookup table */
369   memset(table, 0, 256);
370
371   for (i = 0; i < 10; i++) {
372     table['0' + i] = i;
373   }
374   for (i = 0; i < 6; i++) {
375     table['A' + i] = i+10;
376     table['a' + i] = i+10;
377   }
378
379   /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
380
381   id->Data1 = (table[s[1]] << 28 | table[s[2]] << 24 | table[s[3]] << 20 | table[s[4]] << 16 |
382                table[s[5]] << 12 | table[s[6]] << 8  | table[s[7]] << 4  | table[s[8]]);
383   id->Data2 = table[s[10]] << 12 | table[s[11]] << 8 | table[s[12]] << 4 | table[s[13]];
384   id->Data3 = table[s[15]] << 12 | table[s[16]] << 8 | table[s[17]] << 4 | table[s[18]];
385
386   /* these are just sequential bytes */
387   id->Data4[0] = table[s[20]] << 4 | table[s[21]];
388   id->Data4[1] = table[s[22]] << 4 | table[s[23]];
389   id->Data4[2] = table[s[25]] << 4 | table[s[26]];
390   id->Data4[3] = table[s[27]] << 4 | table[s[28]];
391   id->Data4[4] = table[s[29]] << 4 | table[s[30]];
392   id->Data4[5] = table[s[31]] << 4 | table[s[32]];
393   id->Data4[6] = table[s[33]] << 4 | table[s[34]];
394   id->Data4[7] = table[s[35]] << 4 | table[s[36]];
395
396   return S_OK;
397 }
398
399 /******************************************************************************
400  *              _xmalloc16      [internal]
401  * Allocates size bytes from the standard ole16 allocator.
402  *
403  * RETURNS
404  *      the allocated segmented pointer and a HRESULT
405  */
406 static HRESULT
407 _xmalloc16(DWORD size, SEGPTR *ptr) {
408   LPMALLOC16 mllc;
409   DWORD args[2];
410
411   if (CoGetMalloc16(0,&mllc))
412     return E_OUTOFMEMORY;
413
414   args[0] = (DWORD)mllc;
415   args[1] = size;
416   /* No need for a Callback entry, we have WOWCallback16Ex which does
417    * everything we need.
418    */
419   if (!WOWCallback16Ex(
420       (DWORD)((const IMalloc16Vtbl*)MapSL(
421           (SEGPTR)((LPMALLOC16)MapSL((SEGPTR)mllc))->lpVtbl  )
422       )->Alloc,
423       WCB16_CDECL,
424       2*sizeof(DWORD),
425       (LPVOID)args,
426       (LPDWORD)ptr
427   )) {
428       ERR("CallTo16 IMalloc16 (%d) failed\n",size);
429       return E_FAIL;
430   }
431   return S_OK;
432 }
433
434 /******************************************************************************
435  *              StringFromCLSID [COMPOBJ.19]
436  * Converts a GUID into the respective string representation.
437  * The target string is allocated using the OLE IMalloc.
438  *
439  * RETURNS
440  *      the string representation and HRESULT
441  */
442
443 HRESULT WINAPI StringFromCLSID16(
444   REFCLSID id,          /* [in] the GUID to be converted */
445   LPOLESTR16 *idstr )   /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
446 {
447     WCHAR buffer[40];
448     HRESULT ret;
449
450     ret = _xmalloc16(40,(SEGPTR*)idstr);
451     if (ret != S_OK)
452         return ret;
453     StringFromGUID2( id, buffer, 40 );
454     WideCharToMultiByte( CP_ACP, 0, buffer, -1, MapSL((SEGPTR)*idstr), 40, NULL, NULL );
455     return ret;
456 }
457
458 /******************************************************************************
459  * ProgIDFromCLSID [COMPOBJ.62]
460  *
461  * Converts a class id into the respective Program ID. (By using a registry lookup)
462  *
463  * RETURNS
464  *  S_OK on success
465  *  riid associated with the progid
466  */
467 HRESULT WINAPI ProgIDFromCLSID16(
468   REFCLSID clsid, /* [in] class id as found in registry */
469   LPOLESTR16 *lplpszProgID )/* [out] associated Program ID */
470 {
471     LPOLESTR progid;
472     HRESULT ret;
473
474     ret = ProgIDFromCLSID( clsid, &progid );
475     if (ret == S_OK)
476     {
477         INT len = WideCharToMultiByte( CP_ACP, 0, progid, -1, NULL, 0, NULL, NULL );
478         ret = _xmalloc16(len, (SEGPTR*)lplpszProgID);
479         if (ret == S_OK)
480             WideCharToMultiByte( CP_ACP, 0, progid, -1, MapSL((SEGPTR)*lplpszProgID), len, NULL, NULL );
481         CoTaskMemFree( progid );
482     }
483     return ret;
484 }
485
486 /***********************************************************************
487  *           LookupETask (COMPOBJ.94)
488  */
489 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
490         FIXME("(%p,%p),stub!\n",hTask,p);
491         if ((*hTask = GetCurrentTask()) == hETask) {
492                 memcpy(p, Table_ETask, sizeof(Table_ETask));
493         }
494         return 0;
495 }
496
497 /***********************************************************************
498  *           SetETask (COMPOBJ.95)
499  */
500 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
501         FIXME("(%04x,%p),stub!\n",hTask,p);
502         hETask = hTask;
503         return 0;
504 }
505
506 /***********************************************************************
507  *           CALLOBJECTINWOW (COMPOBJ.201)
508  */
509 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
510         FIXME("(%p,%p),stub!\n",p1,p2);
511         return 0;
512 }
513
514 /******************************************************************************
515  *              CoRegisterClassObject   [COMPOBJ.5]
516  *
517  * Don't know where it registers it ...
518  */
519 HRESULT WINAPI CoRegisterClassObject16(
520         REFCLSID rclsid,
521         LPUNKNOWN pUnk,
522         DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
523         DWORD flags,        /* [in] REGCLS flags indicating how connections are made */
524         LPDWORD lpdwRegister
525 ) {
526         FIXME("(%s,%p,0x%08x,0x%08x,%p),stub\n",
527                 debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister
528         );
529         return 0;
530 }
531
532 /******************************************************************************
533  *      CoRevokeClassObject [COMPOBJ.6]
534  *
535  */
536 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
537 {
538     FIXME("(0x%08x),stub!\n", dwRegister);
539     return 0;
540 }
541
542 /******************************************************************************
543  *              IsValidInterface        [COMPOBJ.23]
544  *
545  * Determines whether a pointer is a valid interface.
546  *
547  * PARAMS
548  *  punk [I] Interface to be tested.
549  *
550  * RETURNS
551  *  TRUE, if the passed pointer is a valid interface, or FALSE otherwise.
552  */
553 BOOL WINAPI IsValidInterface16(SEGPTR punk)
554 {
555         DWORD **ptr;
556
557         if (IsBadReadPtr16(punk,4))
558                 return FALSE;
559         ptr = MapSL(punk);
560         if (IsBadReadPtr16((SEGPTR)ptr[0],4))   /* check vtable ptr */
561                 return FALSE;
562         ptr = MapSL((SEGPTR)ptr[0]);            /* ptr to first method */
563         if (IsBadReadPtr16((SEGPTR)ptr[0],2))
564                 return FALSE;
565         return TRUE;
566 }
567
568 /******************************************************************************
569  *      CoFileTimeToDosDateTime [COMPOBJ.30]
570  */
571 BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
572 {
573     return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
574 }
575
576 /******************************************************************************
577  *      CoDosDateTimeToFileTime [COMPOBJ.31]
578  */
579 BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
580 {
581     return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
582 }
583
584 /******************************************************************************
585  *              CoGetCurrentProcess     [COMPOBJ.34]
586  */
587 DWORD WINAPI CoGetCurrentProcess16(void)
588 {
589     return CoGetCurrentProcess();
590 }
591
592 /******************************************************************************
593  *              CoRegisterMessageFilter [COMPOBJ.27]
594  */
595 HRESULT WINAPI CoRegisterMessageFilter16(
596         LPMESSAGEFILTER lpMessageFilter,
597         LPMESSAGEFILTER *lplpMessageFilter
598 ) {
599         FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
600         return 0;
601 }
602
603 /******************************************************************************
604  *              CoLockObjectExternal    [COMPOBJ.63]
605  */
606 HRESULT WINAPI CoLockObjectExternal16(
607     LPUNKNOWN pUnk,             /* [in] object to be locked */
608     BOOL16 fLock,               /* [in] do lock */
609     BOOL16 fLastUnlockReleases  /* [in] ? */
610 ) {
611     FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
612     return S_OK;
613 }
614
615 /***********************************************************************
616  *           CoGetState [COMPOBJ.115]
617  */
618 HRESULT WINAPI CoGetState16(LPDWORD state)
619 {
620     FIXME("(%p),stub!\n", state);
621
622     *state = 0;
623     return S_OK;
624 }
625
626 /***********************************************************************
627  *      DllEntryPoint                   [COMPOBJ.116]
628  *
629  *    Initialization code for the COMPOBJ DLL
630  *
631  * RETURNS:
632  */
633 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
634 {
635         TRACE("(%08x, %04x, %04x, %04x, %08x, %04x)\n", Reason, hInst, ds, HeapSize, res1, res2);
636         return TRUE;
637 }
638
639 /***********************************************************************
640  *           CoMemAlloc [COMPOBJ.151]
641  */
642 SEGPTR WINAPI CoMemAlloc(DWORD size, DWORD dwMemContext, DWORD x) {
643         HRESULT         hres;
644         SEGPTR          segptr;
645
646         /* FIXME: check context handling */
647         TRACE("(%d, 0x%08x, 0x%08x)\n", size, dwMemContext, x);
648         hres = _xmalloc16(size, &segptr);
649         if (hres != S_OK)
650                 return 0;
651         return segptr;
652 }
653
654 /******************************************************************************
655  *              CLSIDFromProgID [COMPOBJ.61]
656  *
657  * Converts a program ID into the respective GUID.
658  *
659  * PARAMS
660  *  progid       [I] program id as found in registry
661  *  riid         [O] associated CLSID
662  *
663  * RETURNS
664  *      Success: S_OK
665  *  Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
666  */
667 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid)
668 {
669         char    *buf,buf2[80];
670         LONG    buf2len;
671         HRESULT err;
672         HKEY    xhkey;
673
674         buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
675         sprintf(buf,"%s\\CLSID",progid);
676         if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
677                 HeapFree(GetProcessHeap(),0,buf);
678                 return CO_E_CLASSSTRING;
679         }
680         HeapFree(GetProcessHeap(),0,buf);
681         buf2len = sizeof(buf2);
682         if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
683                 RegCloseKey(xhkey);
684                 return CO_E_CLASSSTRING;
685         }
686         RegCloseKey(xhkey);
687         return CLSIDFromString16(buf2,riid);
688 }
689
690 /******************************************************************************
691  *              StringFromGUID2 [COMPOBJ.76]
692  */
693 INT WINAPI StringFromGUID216(REFGUID id, LPOLESTR str, INT cmax)
694 {
695     return StringFromGUID2( id, str, cmax );
696 }
697
698
699 /***********************************************************************
700  *           CoFileTimeNow [COMPOBJ.82]
701  */
702 HRESULT WINAPI CoFileTimeNow16( FILETIME *lpFileTime )
703 {
704     return CoFileTimeNow( lpFileTime );
705 }
706
707 /***********************************************************************
708  *           CoGetClassObject [COMPOBJ.7]
709  *
710  */
711 HRESULT WINAPI CoGetClassObject16(
712     REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
713     REFIID iid, LPVOID *ppv)
714 {
715     FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
716
717     if (pServerInfo) {
718         FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
719         FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
720     }
721     return E_NOTIMPL;
722 }
723
724 /******************************************************************************
725  *              CoCreateGuid [COMPOBJ.73]
726  */
727 HRESULT WINAPI CoCreateGuid16(GUID *pguid)
728 {
729     return CoCreateGuid( pguid );
730 }
731
732 /***********************************************************************
733  *           CoCreateInstance [COMPOBJ.13]
734  */
735 HRESULT WINAPI CoCreateInstance16(
736         REFCLSID rclsid,
737         LPUNKNOWN pUnkOuter,
738         DWORD dwClsContext,
739         REFIID iid,
740         LPVOID *ppv)
741 {
742   FIXME("(%s, %p, %x, %s, %p), stub!\n",
743         debugstr_guid(rclsid), pUnkOuter, dwClsContext, debugstr_guid(iid),
744         ppv
745   );
746   return E_NOTIMPL;
747 }
748
749 /***********************************************************************
750  *           CoDisconnectObject [COMPOBJ.15]
751  */
752 HRESULT WINAPI CoDisconnectObject16( LPUNKNOWN lpUnk, DWORD reserved )
753 {
754   FIXME("(%p, 0x%08x): stub!\n", lpUnk, reserved);
755   return E_NOTIMPL;
756 }