4 * Copyright 1995 Martin von Loewis
21 #include "interfaces.h"
30 LPMALLOC16 currentMalloc16=NULL;
31 LPMALLOC32 currentMalloc32=NULL;
36 /******************************************************************************
37 * CoBuildVersion [COMPOBJ.1]
40 * Current built version, hiword is majornumber, loword is minornumber
42 DWORD WINAPI CoBuildVersion()
44 TRACE(ole,"(void)\n");
48 /******************************************************************************
49 * CoInitialize16 [COMPOBJ.2]
50 * Set the win16 IMalloc used for memory management
52 HRESULT WINAPI CoInitialize16(
53 LPMALLOC16 lpReserved /* [in] pointer to win16 malloc interface */
55 currentMalloc16 = lpReserved;
59 /******************************************************************************
60 * CoInitialize32 [OLE32.26]
61 * Set the win32 IMalloc used for memorymanagement
63 HRESULT WINAPI CoInitialize32(
64 LPMALLOC32 lpReserved /* [in] pointer to win32 malloc interface */
66 currentMalloc32 = lpReserved;
70 /***********************************************************************
71 * CoUnitialize [COMPOBJ.3]
72 * Don't know what it does.
74 void WINAPI CoUnitialize()
76 TRACE(ole,"(void)\n");
79 /***********************************************************************
80 * CoGetMalloc16 [COMPOBJ.4]
82 * The current win16 IMalloc
84 HRESULT WINAPI CoGetMalloc16(
85 DWORD dwMemContext, /* [in] unknown */
86 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
89 currentMalloc16 = IMalloc16_Constructor();
90 *lpMalloc = currentMalloc16;
94 /******************************************************************************
95 * CoGetMalloc32 [OLE32.20]
98 * The current win32 IMalloc
100 HRESULT WINAPI CoGetMalloc32(
101 DWORD dwMemContext, /* [in] unknown */
102 LPMALLOC32 *lpMalloc /* [out] current win32 malloc interface */
105 currentMalloc32 = IMalloc32_Constructor();
106 *lpMalloc = currentMalloc32;
110 /***********************************************************************
111 * CoCreateStandardMalloc16 [COMPOBJ.71]
113 OLESTATUS WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
114 LPMALLOC16 *lpMalloc)
116 /* FIXME: docu says we shouldn't return the same allocator as in
118 *lpMalloc = IMalloc16_Constructor();
122 /******************************************************************************
123 * CoDisconnectObject [COMPOBJ.15]
125 OLESTATUS WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
127 TRACE(ole,"%p %lx\n",lpUnk,reserved);
131 /***********************************************************************
132 * IsEqualGUID [COMPOBJ.18]
133 * Compares two Unique Identifiers
137 BOOL16 WINAPI IsEqualGUID(
138 GUID* g1, /* [in] unique id 1 */
139 GUID* g2 /* [in] unique id 2 */
141 return !memcmp( g1, g2, sizeof(GUID) );
144 /******************************************************************************
145 * CLSIDFromString16 [COMPOBJ.20]
146 * Converts a unique identifier from it's string representation into
149 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
154 OLESTATUS WINAPI CLSIDFromString16(
155 LPCOLESTR16 idstr, /* [in] string representation of guid */
156 CLSID *id /* [out] GUID converted from string */
158 BYTE *s = (BYTE *) idstr;
163 TRACE(ole,"%s -> %p\n", idstr, id);
165 /* quick lookup table */
166 memset(table, 0, 256);
168 for (i = 0; i < 10; i++) {
171 for (i = 0; i < 6; i++) {
172 table['A' + i] = i+10;
173 table['a' + i] = i+10;
176 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
178 if (strlen(idstr) != 38)
179 return OLE_ERROR_OBJECT;
183 s++; /* skip leading brace */
184 for (i = 0; i < 4; i++) {
185 p[3 - i] = table[*s]<<4 | table[*(s+1)];
191 for (i = 0; i < 2; i++) {
192 p[1-i] = table[*s]<<4 | table[*(s+1)];
198 for (i = 0; i < 2; i++) {
199 p[1-i] = table[*s]<<4 | table[*(s+1)];
205 /* these are just sequential bytes */
206 for (i = 0; i < 2; i++) {
207 *p++ = table[*s]<<4 | table[*(s+1)];
212 for (i = 0; i < 6; i++) {
213 *p++ = table[*s]<<4 | table[*(s+1)];
220 /******************************************************************************
221 * CLSIDFromString32 [OLE32.3]
222 * Converts a unique identifier from it's string representation into
227 OLESTATUS WINAPI CLSIDFromString32(
228 LPCOLESTR32 idstr, /* [in] string representation of GUID */
229 CLSID *id /* [out] GUID represented by above string */
231 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
232 OLESTATUS ret = CLSIDFromString16(xid,id);
234 HeapFree(GetProcessHeap(),0,xid);
238 /******************************************************************************
239 * WINE_StringFromCLSID [???]
240 * Converts a GUID into the respective string representation.
243 * Why is this WINAPI?
246 * the string representation and OLESTATUS
248 OLESTATUS WINAPI WINE_StringFromCLSID(
249 const CLSID *id, /* [in] GUID to be converted */
250 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
252 static const char *hex = "0123456789ABCDEF";
257 { ERR(ole,"called with id=Null\n");
262 sprintf(idstr, "{%08lx-%04x-%04x-%02x%02x-",
263 id->Data1, id->Data2, id->Data3,
264 id->Data4[0], id->Data4[1]);
268 for (i = 2; i < 8; i++) {
269 *s++ = hex[id->Data4[i]>>4];
270 *s++ = hex[id->Data4[i] & 0xf];
276 for (i = strlen(idstr)-1; i >= 0; i--) {
277 idstr[i] = toupper(idstr[i]);
280 TRACE(ole,"%p->%s\n", id, idstr);
285 /******************************************************************************
286 * StringFromCLSID16 [COMPOBJ.19]
287 * Converts a GUID into the respective string representation.
288 * The target string is allocated using the OLE IMalloc.
290 * the string representation and OLESTATUS
292 OLESTATUS WINAPI StringFromCLSID16(
293 const CLSID *id, /* [in] the GUID to be converted */
294 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
301 ret = CoGetMalloc16(0,&mllc);
304 args[0] = (DWORD)mllc;
307 /* No need for a Callback entry, we have WOWCallback16Ex which does
308 * everything we need.
310 if (!WOWCallback16Ex(
311 (FARPROC16)((LPMALLOC16_VTABLE)PTR_SEG_TO_LIN(
312 ((LPMALLOC16)PTR_SEG_TO_LIN(mllc))->lpvtbl)
319 WARN(ole,"CallTo16 IMalloc16 failed\n");
322 return WINE_StringFromCLSID(id,PTR_SEG_TO_LIN(*idstr));
325 /******************************************************************************
326 * StringFromCLSID32 [OLE32.151]
327 * Converts a GUID into the respective string representation.
328 * The target string is allocated using the OLE IMalloc.
330 * the string representation and OLESTATUS
332 OLESTATUS WINAPI StringFromCLSID32(
333 const CLSID *id, /* [in] the GUID to be converted */
334 LPOLESTR32 *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
340 if ((ret=CoGetMalloc32(0,&mllc)))
343 ret=WINE_StringFromCLSID(id,buf);
345 *idstr = mllc->lpvtbl->fnAlloc(mllc,strlen(buf)*2+2);
346 lstrcpyAtoW(*idstr,buf);
351 /******************************************************************************
352 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
354 * Converts a global unique identifier into a string of an API-
355 * specified fixed format. (The usual {.....} stuff.)
358 * The (UNICODE) string representation of the GUID in 'str'
359 * The length of the resulting string, 0 if there was any problem.
362 StringFromGUID2(REFGUID id, LPOLESTR32 str, INT32 cmax)
366 if (WINE_StringFromCLSID(id,xguid))
368 if (strlen(xguid)>=cmax)
370 lstrcpyAtoW(str,xguid);
371 return strlen(xguid);
374 /******************************************************************************
375 * CLSIDFromProgID16 [COMPOBJ.61]
376 * Converts a program id into the respective GUID. (By using a registry lookup)
378 * riid associated with the progid
380 OLESTATUS WINAPI CLSIDFromProgID16(
381 LPCOLESTR16 progid, /* [in] program id as found in registry */
382 LPCLSID riid /* [out] associated CLSID */
389 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
390 sprintf(buf,"%s\\CLSID",progid);
391 if ((err=RegOpenKey32A(HKEY_CLASSES_ROOT,buf,&xhkey))) {
392 HeapFree(GetProcessHeap(),0,buf);
393 return OLE_ERROR_GENERIC;
395 HeapFree(GetProcessHeap(),0,buf);
396 buf2len = sizeof(buf2);
397 if ((err=RegQueryValue32A(xhkey,NULL,buf2,&buf2len))) {
399 return OLE_ERROR_GENERIC;
402 return CLSIDFromString16(buf2,riid);
405 /******************************************************************************
406 * CLSIDFromProgID32 [OLE32.2]
407 * Converts a program id into the respective GUID. (By using a registry lookup)
409 * riid associated with the progid
411 OLESTATUS WINAPI CLSIDFromProgID32(
412 LPCOLESTR32 progid, /* [in] program id as found in registry */
413 LPCLSID riid /* [out] associated CLSID */
415 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
416 OLESTATUS ret = CLSIDFromProgID16(pid,riid);
418 HeapFree(GetProcessHeap(),0,pid);
422 /***********************************************************************
423 * LookupETask (COMPOBJ.94)
425 OLESTATUS WINAPI LookupETask(HTASK16 *hTask,LPVOID p) {
426 FIXME(ole,"(%p,%p),stub!\n",hTask,p);
427 if ((*hTask = GetCurrentTask()) == hETask) {
428 memcpy(p, Table_ETask, sizeof(Table_ETask));
433 /***********************************************************************
434 * SetETask (COMPOBJ.95)
436 OLESTATUS WINAPI SetETask(HTASK16 hTask, LPVOID p) {
437 FIXME(ole,"(%04x,%p),stub!\n",hTask,p);
442 /***********************************************************************
443 * CallObjectInWOW (COMPOBJ.201)
445 OLESTATUS WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
446 FIXME(ole,"(%p,%p),stub!\n",p1,p2);
450 /******************************************************************************
451 * CoRegisterClassObject16 [COMPOBJ.5]
453 * Don't know where it registers it ...
455 OLESTATUS WINAPI CoRegisterClassObject16(
464 WINE_StringFromCLSID(rclsid,buf);
466 FIXME(ole,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
467 buf,pUnk,dwClsContext,flags,lpdwRegister
472 /******************************************************************************
473 * CoRegisterClassObject32 [OLE32.36]
475 * Don't know where it registers it ...
477 OLESTATUS WINAPI CoRegisterClassObject32(
486 WINE_StringFromCLSID(rclsid,buf);
488 FIXME(ole,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
489 buf,pUnk,dwClsContext,flags,lpdwRegister
494 /***********************************************************************
495 * CoGetClassObject [COMPOBJ.7]
497 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext,
498 LPVOID pvReserved, REFIID iid, LPVOID *ppv)
500 char xclsid[50],xiid[50];
501 LPCLASSFACTORY lpclf;
502 HRESULT hres = E_UNEXPECTED;
504 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
505 WINE_StringFromCLSID((LPCLSID)iid,xiid);
506 TRACE(ole,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid,xiid);
509 lpclf = IClassFactory_Constructor();
512 hres = lpclf->lpvtbl->fnQueryInterface(lpclf,iid, ppv);
513 lpclf->lpvtbl->fnRelease(lpclf);
518 /******************************************************************************
519 * CoRegisterMessageFilter16 [COMPOBJ.27]
521 OLESTATUS WINAPI CoRegisterMessageFilter16(
522 LPMESSAGEFILTER lpMessageFilter,
523 LPMESSAGEFILTER *lplpMessageFilter
525 FIXME(ole,"(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
529 /***********************************************************************
530 * CoCreateInstance [COMPOBJ.13, OLE32.7]
532 HRESULT WINAPI CoCreateInstance(
540 char buf[80],xbuf[80];
543 WINE_StringFromCLSID(rclsid,buf);
545 sprintf(buf,"<rclsid-0x%08lx>",(DWORD)rclsid);
547 WINE_StringFromCLSID(iid,xbuf);
549 sprintf(xbuf,"<iid-0x%08lx>",(DWORD)iid);
551 FIXME(ole,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf,pUnkOuter,dwClsContext,xbuf,ppv);
555 LPCLASSFACTORY lpclf = 0;
557 CoGetClassObject(rclsid, dwClsContext, NULL, &IID_IClassFactory, (LPVOID)&lpclf);
558 hres = lpclf->lpvtbl->fnCreateInstance(lpclf, pUnkOuter, iid, ppv);
559 lpclf->lpvtbl->fnRelease(lpclf);
564 /***********************************************************************
565 * CoFreeUnusedLibraries [COMPOBJ.17]
567 void WINAPI CoFreeUnusedLibraries()
569 FIXME(ole,"(), stub !\n");
572 /***********************************************************************
573 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
575 * the current system time in lpFileTime
577 HRESULT WINAPI CoFileTimeNow(
578 FILETIME *lpFileTime /* [out] the current time */
580 DOSFS_UnixTimeToFileTime(time(NULL), lpFileTime, 0);
584 /***********************************************************************
585 * CoTaskMemAlloc (OLE32.43)
587 * pointer to newly allocated block
589 LPVOID WINAPI CoTaskMemAlloc(
590 ULONG size /* [in] size of memoryblock to be allocated */
593 HRESULT ret = CoGetMalloc32(0,&lpmalloc);
597 return lpmalloc->lpvtbl->fnAlloc(lpmalloc,size);
600 /***********************************************************************
601 * CoTaskMemFree (OLE32.44)
603 VOID WINAPI CoTaskMemFree(
604 LPVOID ptr /* [in] pointer to be freed */
607 HRESULT ret = CoGetMalloc32(0,&lpmalloc);
610 return lpmalloc->lpvtbl->fnFree(lpmalloc,ptr);
613 /***********************************************************************
614 * CoInitializeWOW (OLE32.27)
616 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
617 FIXME(ole,"(0x%08lx,0x%08lx),stub!\n",x,y);
621 /******************************************************************************
622 * CoLockObjectExternal16 [COMPOBJ.63]
624 HRESULT WINAPI CoLockObjectExternal16(
625 LPUNKNOWN pUnk, /* [in] object to be locked */
626 BOOL16 fLock, /* [in] do lock */
627 BOOL16 fLastUnlockReleases /* [in] ? */
629 FIXME(ole,"(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
633 /******************************************************************************
634 * CoLockObjectExternal32 [OLE32.31]
636 HRESULT WINAPI CoLockObjectExternal32(
637 LPUNKNOWN pUnk, /* [in] object to be locked */
638 BOOL32 fLock, /* [in] do lock */
639 BOOL32 fLastUnlockReleases /* [in] ? */
641 FIXME(ole,"(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
645 /***********************************************************************
646 * CoGetState16 [COMPOBJ.115]
648 HRESULT WINAPI CoGetState16(LPDWORD state)
650 FIXME(ole, "(%p),stub!\n", state);
654 /***********************************************************************
655 * CoSetState32 [COM32.42]
657 HRESULT WINAPI CoSetState32(LPDWORD state)
659 FIXME(ole, "(%p),stub!\n", state);