Release 980726
[wine/multimedia.git] / ole / compobj.c
bloba5fc327083ff8ec6169b80eb35c5700695d49115
1 /*
2 * COMPOBJ library
4 * Copyright 1995 Martin von Loewis
5 */
7 #define INITGUID
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <time.h>
13 #include "ole.h"
14 #include "ole2.h"
15 #include "winerror.h"
16 #include "debug.h"
17 #include "file.h"
18 #include "compobj.h"
19 #include "heap.h"
20 #include "ldt.h"
21 #include "interfaces.h"
22 #include "shlobj.h"
23 #include "ddraw.h"
24 #include "dsound.h"
25 #include "dinput.h"
26 #include "d3d.h"
28 LPMALLOC16 currentMalloc16=NULL;
29 LPMALLOC32 currentMalloc32=NULL;
31 /***********************************************************************
32 * CoBuildVersion [COMPOBJ.1]
34 * RETURNS
35 * Current built version, hiword is majornumber, loword is minornumber
37 DWORD WINAPI CoBuildVersion()
39 TRACE(ole,"(void)\n");
40 return (rmm<<16)+rup;
43 /***********************************************************************
44 * CoInitialize [COMPOBJ.2]
45 * Set the win16 IMalloc used for memory management
47 HRESULT WINAPI CoInitialize16(
48 LPMALLOC16 lpReserved /* [in] pointer to win16 malloc interface */
49 ) {
50 currentMalloc16 = lpReserved;
51 return S_OK;
54 /***********************************************************************
55 * CoInitialize (OLE32.26)
56 * Set the win32 IMalloc used for memorymanagement
58 HRESULT WINAPI CoInitialize32(
59 LPMALLOC32 lpReserved /* [in] pointer to win32 malloc interface */
60 ) {
61 currentMalloc32 = lpReserved;
62 return S_OK;
65 /***********************************************************************
66 * CoUnitialize [COMPOBJ.3]
67 * Don't know what it does.
69 void WINAPI CoUnitialize()
71 TRACE(ole,"(void)\n");
74 /***********************************************************************
75 * CoGetMalloc16 [COMPOBJ.4]
76 * RETURNS
77 * The current win16 IMalloc
79 HRESULT WINAPI CoGetMalloc16(
80 DWORD dwMemContext, /* [in] unknown */
81 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
82 ) {
83 if(!currentMalloc16)
84 currentMalloc16 = IMalloc16_Constructor();
85 *lpMalloc = currentMalloc16;
86 return S_OK;
89 /***********************************************************************
90 * CoGetMalloc32 [OLE32.4]
91 * RETURNS
92 * The current win32 IMalloc
94 HRESULT WINAPI CoGetMalloc32(
95 DWORD dwMemContext, /* [in] unknown */
96 LPMALLOC32 *lpMalloc /* [out] current win32 malloc interface */
97 ) {
98 if(!currentMalloc32)
99 currentMalloc32 = IMalloc32_Constructor();
100 *lpMalloc = currentMalloc32;
101 return S_OK;
104 /***********************************************************************
105 * CoDisconnectObject
107 OLESTATUS WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
109 TRACE(ole,"%p %lx\n",lpUnk,reserved);
110 return S_OK;
113 /***********************************************************************
114 * IsEqualGUID [COMPOBJ.18]
115 * Compares two Unique Identifiers
116 * RETURNS
117 * TRUE if equal
119 BOOL16 WINAPI IsEqualGUID(
120 GUID* g1, /* [in] unique id 1 */
121 GUID* g2 /* [in] unique id 2 */
123 return !memcmp( g1, g2, sizeof(GUID) );
126 /***********************************************************************
127 * CLSIDFromString [COMPOBJ.20]
128 * Converts a unique identifier from it's string representation into
129 * the GUID struct.
130 * RETURNS
131 * the converted GUID
134 /* Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6] */
136 OLESTATUS WINAPI CLSIDFromString16(
137 LPCOLESTR16 idstr, /* [in] string representation of guid */
138 CLSID *id /* [out] GUID converted from string */
140 BYTE *s = (BYTE *) idstr;
141 BYTE *p;
142 int i;
143 BYTE table[256];
145 TRACE(ole,"%s -> %p\n", idstr, id);
147 /* quick lookup table */
148 memset(table, 0, 256);
150 for (i = 0; i < 10; i++) {
151 table['0' + i] = i;
153 for (i = 0; i < 6; i++) {
154 table['A' + i] = i+10;
155 table['a' + i] = i+10;
158 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
160 if (strlen(idstr) != 38)
161 return OLE_ERROR_OBJECT;
163 p = (BYTE *) id;
165 s++; /* skip leading brace */
166 for (i = 0; i < 4; i++) {
167 p[3 - i] = table[*s]<<4 | table[*(s+1)];
168 s += 2;
170 p += 4;
171 s++; /* skip - */
173 for (i = 0; i < 2; i++) {
174 p[1-i] = table[*s]<<4 | table[*(s+1)];
175 s += 2;
177 p += 2;
178 s++; /* skip - */
180 for (i = 0; i < 2; i++) {
181 p[1-i] = table[*s]<<4 | table[*(s+1)];
182 s += 2;
184 p += 2;
185 s++; /* skip - */
187 /* these are just sequential bytes */
188 for (i = 0; i < 2; i++) {
189 *p++ = table[*s]<<4 | table[*(s+1)];
190 s += 2;
192 s++; /* skip - */
194 for (i = 0; i < 6; i++) {
195 *p++ = table[*s]<<4 | table[*(s+1)];
196 s += 2;
199 return S_OK;
202 /***********************************************************************
203 * CLSIDFromString (OLE32.3)
204 * Converts a unique identifier from it's string representation into
205 * the GUID struct.
206 * RETURNS
207 * the converted GUID
209 OLESTATUS WINAPI CLSIDFromString32(
210 LPCOLESTR32 idstr, /* [in] string representation of GUID */
211 CLSID *id /* [out] GUID represented by above string */
213 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
214 OLESTATUS ret = CLSIDFromString16(xid,id);
216 HeapFree(GetProcessHeap(),0,xid);
217 return ret;
220 /***********************************************************************
221 * WINE_StringFromCLSID [internal]
222 * Converts a GUID into the respective string representation.
223 * RETURNS
224 * the string representation and OLESTATUS
226 OLESTATUS WINAPI WINE_StringFromCLSID(
227 const CLSID *id, /* [in] GUID to be converted */
228 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
230 static const char *hex = "0123456789ABCDEF";
231 char *s;
232 int i;
234 if (!id)
235 { ERR(ole,"called with id=Null\n");
236 *idstr = 0x00;
237 return E_FAIL;
240 sprintf(idstr, "{%08lx-%04x-%04x-%02x%02x-",
241 id->Data1, id->Data2, id->Data3,
242 id->Data4[0], id->Data4[1]);
243 s = &idstr[25];
245 /* 6 hex bytes */
246 for (i = 2; i < 8; i++) {
247 *s++ = hex[id->Data4[i]>>4];
248 *s++ = hex[id->Data4[i] & 0xf];
251 *s++ = '}';
252 *s++ = '\0';
254 for (i = strlen(idstr)-1; i >= 0; i--) {
255 idstr[i] = toupper(idstr[i]);
258 TRACE(ole,"%p->%s\n", id, idstr);
260 return OLE_OK;
263 /***********************************************************************
264 * StringFromCLSID [COMPOBJ.19]
265 * Converts a GUID into the respective string representation.
266 * The target string is allocated using the OLE IMalloc.
267 * RETURNS
268 * the string representation and OLESTATUS
270 OLESTATUS WINAPI StringFromCLSID16(
271 const CLSID *id, /* [in] the GUID to be converted */
272 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
275 LPMALLOC16 mllc;
276 OLESTATUS ret;
277 DWORD args[2];
279 ret = CoGetMalloc16(0,&mllc);
280 if (ret) return ret;
282 args[0] = (DWORD)mllc;
283 args[1] = 40;
285 /* No need for a Callback entry, we have WOWCallback16Ex which does
286 * everything we need.
288 if (!WOWCallback16Ex(
289 (FARPROC16)((LPMALLOC16_VTABLE)PTR_SEG_TO_LIN(
290 ((LPMALLOC16)PTR_SEG_TO_LIN(mllc))->lpvtbl)
291 )->fnAlloc,
292 WCB16_CDECL,
294 (LPVOID)args,
295 (LPDWORD)idstr
296 )) {
297 WARN(ole,"CallTo16 IMalloc16 failed\n");
298 return E_FAIL;
300 return WINE_StringFromCLSID(id,PTR_SEG_TO_LIN(*idstr));
303 /***********************************************************************
304 * StringFromCLSID [OLE32.151]
305 * Converts a GUID into the respective string representation.
306 * The target string is allocated using the OLE IMalloc.
307 * RETURNS
308 * the string representation and OLESTATUS
310 OLESTATUS WINAPI StringFromCLSID32(
311 const CLSID *id, /* [in] the GUID to be converted */
312 LPOLESTR32 *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
314 char buf[80];
315 OLESTATUS ret;
316 LPMALLOC32 mllc;
318 if ((ret=CoGetMalloc32(0,&mllc)))
319 return ret;
321 ret=WINE_StringFromCLSID(id,buf);
322 if (!ret) {
323 *idstr = mllc->lpvtbl->fnAlloc(mllc,strlen(buf)*2+2);
324 lstrcpyAtoW(*idstr,buf);
326 return ret;
329 /***********************************************************************
330 * StringFromGUID2 (OLE32.152)
332 * Converts a global unique identifier into a string of an API-
333 * specified fixed format. (The usual {.....} stuff.)
335 * RETURNS
336 * The (UNICODE) string representation of the GUID in 'str'
337 * The length of the resulting string, 0 if there was any problem.
339 INT32 WINAPI
340 StringFromGUID2(REFGUID id, LPOLESTR32 str, INT32 cmax)
342 char xguid[80];
344 if (WINE_StringFromCLSID(id,xguid))
345 return 0;
346 if (strlen(xguid)>=cmax)
347 return 0;
348 lstrcpyAtoW(str,xguid);
349 return strlen(xguid);
352 /***********************************************************************
353 * CLSIDFromProgID [COMPOBJ.61]
354 * Converts a program id into the respective GUID. (By using a registry lookup)
355 * RETURNS
356 * riid associated with the progid
358 OLESTATUS WINAPI CLSIDFromProgID16(
359 LPCOLESTR16 progid, /* [in] program id as found in registry */
360 LPCLSID riid /* [out] associated CLSID */
362 char *buf,buf2[80];
363 DWORD buf2len;
364 HRESULT err;
365 HKEY xhkey;
367 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
368 sprintf(buf,"%s\\CLSID",progid);
369 if ((err=RegOpenKey32A(HKEY_CLASSES_ROOT,buf,&xhkey))) {
370 HeapFree(GetProcessHeap(),0,buf);
371 return OLE_ERROR_GENERIC;
373 HeapFree(GetProcessHeap(),0,buf);
374 buf2len = sizeof(buf2);
375 if ((err=RegQueryValue32A(xhkey,NULL,buf2,&buf2len))) {
376 RegCloseKey(xhkey);
377 return OLE_ERROR_GENERIC;
379 RegCloseKey(xhkey);
380 return CLSIDFromString16(buf2,riid);
383 /***********************************************************************
384 * CLSIDFromProgID (OLE32.2)
385 * Converts a program id into the respective GUID. (By using a registry lookup)
386 * RETURNS
387 * riid associated with the progid
389 OLESTATUS WINAPI CLSIDFromProgID32(
390 LPCOLESTR32 progid, /* [in] program id as found in registry */
391 LPCLSID riid /* [out] associated CLSID */
393 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
394 OLESTATUS ret = CLSIDFromProgID16(pid,riid);
396 HeapFree(GetProcessHeap(),0,pid);
397 return ret;
400 /***********************************************************************
401 * LookupETask (COMPOBJ.94)
403 OLESTATUS WINAPI LookupETask(LPVOID p1,LPVOID p2) {
404 FIXME(ole,"(%p,%p),stub!\n",p1,p2);
405 return 0;
408 /***********************************************************************
409 * LookupETask (COMPOBJ.201)
411 OLESTATUS WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
412 FIXME(ole,"(%p,%p),stub!\n",p1,p2);
413 return 0;
416 /***********************************************************************
417 * CoRegisterClassObject [COMPOBJ.5]
418 * Don't know where it registers it ...
420 OLESTATUS WINAPI CoRegisterClassObject16(
421 REFCLSID rclsid,
422 LPUNKNOWN pUnk,
423 DWORD dwClsContext,
424 DWORD flags,
425 LPDWORD lpdwRegister
427 char buf[80];
429 WINE_StringFromCLSID(rclsid,buf);
431 FIXME(ole,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
432 buf,pUnk,dwClsContext,flags,lpdwRegister
434 return 0;
437 /***********************************************************************
438 * CoRegisterClassObject (OLE32.36)
439 * Don't know where it registers it ...
441 OLESTATUS WINAPI CoRegisterClassObject32(
442 REFCLSID rclsid,
443 LPUNKNOWN pUnk,
444 DWORD dwClsContext,
445 DWORD flags,
446 LPDWORD lpdwRegister
448 char buf[80];
450 WINE_StringFromCLSID(rclsid,buf);
452 FIXME(ole,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
453 buf,pUnk,dwClsContext,flags,lpdwRegister
455 return 0;
458 /***********************************************************************
459 * CoRegisterMessageFilter [COMPOBJ.27]
461 OLESTATUS WINAPI CoRegisterMessageFilter16(
462 LPMESSAGEFILTER lpMessageFilter,
463 LPMESSAGEFILTER *lplpMessageFilter
465 FIXME(ole,"(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
466 return 0;
469 /***********************************************************************
470 * CoCreateInstance [COMPOBJ.13, OLE32.7]
472 HRESULT WINAPI CoCreateInstance(
473 REFCLSID rclsid,
474 LPUNKNOWN pUnkOuter,
475 DWORD dwClsContext,
476 REFIID riid,
477 LPVOID *ppv
479 char buf[80],xbuf[80];
481 if (rclsid)
482 WINE_StringFromCLSID(rclsid,buf);
483 else
484 sprintf(buf,"<rclsid-0x%08lx>",(DWORD)rclsid);
485 if (riid)
486 WINE_StringFromCLSID(riid,xbuf);
487 else
488 sprintf(xbuf,"<riid-0x%08lx>",(DWORD)riid);
490 FIXME(ole,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf,pUnkOuter,dwClsContext,xbuf,ppv);
491 *ppv = NULL;
492 return S_OK;
495 /***********************************************************************
496 * CoFreeUnusedLibraries [COMPOBJ.17]
498 void WINAPI CoFreeUnusedLibraries()
500 FIXME(ole,"(), stub !\n");
503 /***********************************************************************
504 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
505 * RETURNS
506 * the current system time in lpFileTime
508 HRESULT WINAPI CoFileTimeNow(
509 FILETIME *lpFileTime /* [out] the current time */
511 DOSFS_UnixTimeToFileTime(time(NULL), lpFileTime, 0);
512 return S_OK;
515 /***********************************************************************
516 * CoTaskMemAlloc (OLE32.43)
517 * RETURNS
518 * pointer to newly allocated block
520 LPVOID WINAPI CoTaskMemAlloc(
521 ULONG size /* [in] size of memoryblock to be allocated */
523 LPMALLOC32 lpmalloc;
524 HRESULT ret = CoGetMalloc32(0,&lpmalloc);
526 if (ret)
527 return NULL;
528 return lpmalloc->lpvtbl->fnAlloc(lpmalloc,size);
531 /***********************************************************************
532 * CoTaskMemFree (OLE32.44)
534 VOID WINAPI CoTaskMemFree(
535 LPVOID ptr /* [in] pointer to be freed */
537 LPMALLOC32 lpmalloc;
538 HRESULT ret = CoGetMalloc32(0,&lpmalloc);
540 if (ret) return;
541 return lpmalloc->lpvtbl->fnFree(lpmalloc,ptr);
544 /***********************************************************************
545 * CoInitializeWOW (OLE32.27)
547 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
548 FIXME(ole,"(0x%08lx,0x%08lx),stub!\n",x,y);
549 return 0;
552 /***********************************************************************
553 * CoLockObjectExternal (COMPOBJ.63)
555 HRESULT WINAPI CoLockObjectExternal16(
556 LPUNKNOWN pUnk, /* [in] object to be locked */
557 BOOL16 fLock, /* [in] do lock */
558 BOOL16 fLastUnlockReleases /* [in] ? */
560 FIXME(ole,"(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
561 return S_OK;
563 /***********************************************************************
564 * CoLockObjectExternal (OLE32.31)
566 HRESULT WINAPI CoLockObjectExternal32(
567 LPUNKNOWN pUnk, /* [in] object to be locked */
568 BOOL32 fLock, /* [in] do lock */
569 BOOL32 fLastUnlockReleases /* [in] ? */
571 FIXME(ole,"(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
572 return S_OK;