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 * CoCreateGuid[OLE32.6]
222 * Just a random 128-bit number?
224 HRESULT WINAPI
CoCreateGuid(GUID
*pguid
) {
225 FIXME(ole
,"stub!\n");
229 /******************************************************************************
230 * CLSIDFromString32 [OLE32.3]
231 * Converts a unique identifier from it's string representation into
236 OLESTATUS WINAPI
CLSIDFromString32(
237 LPCOLESTR32 idstr
, /* [in] string representation of GUID */
238 CLSID
*id
/* [out] GUID represented by above string */
240 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
241 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
243 HeapFree(GetProcessHeap(),0,xid
);
247 /******************************************************************************
248 * WINE_StringFromCLSID [???]
249 * Converts a GUID into the respective string representation.
252 * Why is this WINAPI?
255 * the string representation and OLESTATUS
257 OLESTATUS WINAPI
WINE_StringFromCLSID(
258 const CLSID
*id
, /* [in] GUID to be converted */
259 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
261 static const char *hex
= "0123456789ABCDEF";
266 { ERR(ole
,"called with id=Null\n");
271 sprintf(idstr
, "{%08lx-%04x-%04x-%02x%02x-",
272 id
->Data1
, id
->Data2
, id
->Data3
,
273 id
->Data4
[0], id
->Data4
[1]);
277 for (i
= 2; i
< 8; i
++) {
278 *s
++ = hex
[id
->Data4
[i
]>>4];
279 *s
++ = hex
[id
->Data4
[i
] & 0xf];
285 for (i
= strlen(idstr
)-1; i
>= 0; i
--) {
286 idstr
[i
] = toupper(idstr
[i
]);
289 TRACE(ole
,"%p->%s\n", id
, idstr
);
294 /******************************************************************************
295 * StringFromCLSID16 [COMPOBJ.19]
296 * Converts a GUID into the respective string representation.
297 * The target string is allocated using the OLE IMalloc.
299 * the string representation and OLESTATUS
301 OLESTATUS WINAPI
StringFromCLSID16(
302 const CLSID
*id
, /* [in] the GUID to be converted */
303 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
310 ret
= CoGetMalloc16(0,&mllc
);
313 args
[0] = (DWORD
)mllc
;
316 /* No need for a Callback entry, we have WOWCallback16Ex which does
317 * everything we need.
319 if (!WOWCallback16Ex(
320 (FARPROC16
)((LPMALLOC16_VTABLE
)PTR_SEG_TO_LIN(
321 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
328 WARN(ole
,"CallTo16 IMalloc16 failed\n");
331 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
334 /******************************************************************************
335 * StringFromCLSID32 [OLE32.151]
336 * Converts a GUID into the respective string representation.
337 * The target string is allocated using the OLE IMalloc.
339 * the string representation and OLESTATUS
341 OLESTATUS WINAPI
StringFromCLSID32(
342 const CLSID
*id
, /* [in] the GUID to be converted */
343 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
349 if ((ret
=CoGetMalloc32(0,&mllc
)))
352 ret
=WINE_StringFromCLSID(id
,buf
);
354 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
355 lstrcpyAtoW(*idstr
,buf
);
360 /******************************************************************************
361 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
363 * Converts a global unique identifier into a string of an API-
364 * specified fixed format. (The usual {.....} stuff.)
367 * The (UNICODE) string representation of the GUID in 'str'
368 * The length of the resulting string, 0 if there was any problem.
371 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
375 if (WINE_StringFromCLSID(id
,xguid
))
377 if (strlen(xguid
)>=cmax
)
379 lstrcpyAtoW(str
,xguid
);
380 return strlen(xguid
);
383 /******************************************************************************
384 * CLSIDFromProgID16 [COMPOBJ.61]
385 * Converts a program id into the respective GUID. (By using a registry lookup)
387 * riid associated with the progid
389 OLESTATUS WINAPI
CLSIDFromProgID16(
390 LPCOLESTR16 progid
, /* [in] program id as found in registry */
391 LPCLSID riid
/* [out] associated CLSID */
398 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
399 sprintf(buf
,"%s\\CLSID",progid
);
400 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
401 HeapFree(GetProcessHeap(),0,buf
);
402 return OLE_ERROR_GENERIC
;
404 HeapFree(GetProcessHeap(),0,buf
);
405 buf2len
= sizeof(buf2
);
406 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
408 return OLE_ERROR_GENERIC
;
411 return CLSIDFromString16(buf2
,riid
);
414 /******************************************************************************
415 * CLSIDFromProgID32 [OLE32.2]
416 * Converts a program id into the respective GUID. (By using a registry lookup)
418 * riid associated with the progid
420 OLESTATUS WINAPI
CLSIDFromProgID32(
421 LPCOLESTR32 progid
, /* [in] program id as found in registry */
422 LPCLSID riid
/* [out] associated CLSID */
424 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
425 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
427 HeapFree(GetProcessHeap(),0,pid
);
431 /***********************************************************************
432 * LookupETask (COMPOBJ.94)
434 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
435 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
436 if ((*hTask
= GetCurrentTask()) == hETask
) {
437 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
442 /***********************************************************************
443 * SetETask (COMPOBJ.95)
445 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
446 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
451 /***********************************************************************
452 * CallObjectInWOW (COMPOBJ.201)
454 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
455 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
459 /******************************************************************************
460 * CoRegisterClassObject16 [COMPOBJ.5]
462 * Don't know where it registers it ...
464 OLESTATUS WINAPI
CoRegisterClassObject16(
473 WINE_StringFromCLSID(rclsid
,buf
);
475 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
476 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
481 /******************************************************************************
482 * CoRegisterClassObject32 [OLE32.36]
484 * Don't know where it registers it ...
486 OLESTATUS WINAPI
CoRegisterClassObject32(
495 WINE_StringFromCLSID(rclsid
,buf
);
497 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
498 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
503 /***********************************************************************
504 * CoGetClassObject [COMPOBJ.7]
506 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
507 LPVOID pvReserved
, REFIID iid
, LPVOID
*ppv
)
509 char xclsid
[50],xiid
[50];
510 LPCLASSFACTORY lpclf
;
511 HRESULT hres
= E_UNEXPECTED
;
513 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
514 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
515 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
518 lpclf
= IClassFactory_Constructor();
521 hres
= lpclf
->lpvtbl
->fnQueryInterface(lpclf
,iid
, ppv
);
522 lpclf
->lpvtbl
->fnRelease(lpclf
);
527 /******************************************************************************
528 * CoRegisterMessageFilter16 [COMPOBJ.27]
530 OLESTATUS WINAPI
CoRegisterMessageFilter16(
531 LPMESSAGEFILTER lpMessageFilter
,
532 LPMESSAGEFILTER
*lplpMessageFilter
534 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
538 /***********************************************************************
539 * CoCreateInstance [COMPOBJ.13, OLE32.7]
541 HRESULT WINAPI
CoCreateInstance(
549 char buf
[80],xbuf
[80];
552 WINE_StringFromCLSID(rclsid
,buf
);
554 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
556 WINE_StringFromCLSID(iid
,xbuf
);
558 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
560 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
564 LPCLASSFACTORY lpclf
= 0;
566 CoGetClassObject(rclsid
, dwClsContext
, NULL
, &IID_IClassFactory
, (LPVOID
)&lpclf
);
567 hres
= lpclf
->lpvtbl
->fnCreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
568 lpclf
->lpvtbl
->fnRelease(lpclf
);
573 /***********************************************************************
574 * CoFreeUnusedLibraries [COMPOBJ.17]
576 void WINAPI
CoFreeUnusedLibraries()
578 FIXME(ole
,"(), stub !\n");
581 /***********************************************************************
582 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
584 * the current system time in lpFileTime
586 HRESULT WINAPI
CoFileTimeNow(
587 FILETIME
*lpFileTime
/* [out] the current time */
589 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
593 /***********************************************************************
594 * CoTaskMemAlloc (OLE32.43)
596 * pointer to newly allocated block
598 LPVOID WINAPI
CoTaskMemAlloc(
599 ULONG size
/* [in] size of memoryblock to be allocated */
602 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
606 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
609 /***********************************************************************
610 * CoTaskMemFree (OLE32.44)
612 VOID WINAPI
CoTaskMemFree(
613 LPVOID ptr
/* [in] pointer to be freed */
616 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
619 return lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
622 /***********************************************************************
623 * CoInitializeWOW (OLE32.27)
625 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
626 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
630 /******************************************************************************
631 * CoLockObjectExternal16 [COMPOBJ.63]
633 HRESULT WINAPI
CoLockObjectExternal16(
634 LPUNKNOWN pUnk
, /* [in] object to be locked */
635 BOOL16 fLock
, /* [in] do lock */
636 BOOL16 fLastUnlockReleases
/* [in] ? */
638 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
642 /******************************************************************************
643 * CoLockObjectExternal32 [OLE32.31]
645 HRESULT WINAPI
CoLockObjectExternal32(
646 LPUNKNOWN pUnk
, /* [in] object to be locked */
647 BOOL32 fLock
, /* [in] do lock */
648 BOOL32 fLastUnlockReleases
/* [in] ? */
650 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
654 /***********************************************************************
655 * CoGetState16 [COMPOBJ.115]
657 HRESULT WINAPI
CoGetState16(LPDWORD state
)
659 FIXME(ole
, "(%p),stub!\n", state
);
663 /***********************************************************************
664 * CoSetState32 [COM32.42]
666 HRESULT WINAPI
CoSetState32(LPDWORD state
)
668 FIXME(ole
, "(%p),stub!\n", state
);