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.
242 * the string representation and OLESTATUS
244 OLESTATUS WINAPI
WINE_StringFromCLSID(
245 const CLSID
*id
, /* [in] GUID to be converted */
246 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
248 static const char *hex
= "0123456789ABCDEF";
253 { ERR(ole
,"called with id=Null\n");
258 sprintf(idstr
, "{%08lx-%04x-%04x-%02x%02x-",
259 id
->Data1
, id
->Data2
, id
->Data3
,
260 id
->Data4
[0], id
->Data4
[1]);
264 for (i
= 2; i
< 8; i
++) {
265 *s
++ = hex
[id
->Data4
[i
]>>4];
266 *s
++ = hex
[id
->Data4
[i
] & 0xf];
272 for (i
= strlen(idstr
)-1; i
>= 0; i
--) {
273 idstr
[i
] = toupper(idstr
[i
]);
276 TRACE(ole
,"%p->%s\n", id
, idstr
);
281 /******************************************************************************
282 * StringFromCLSID16 [COMPOBJ.19]
283 * Converts a GUID into the respective string representation.
284 * The target string is allocated using the OLE IMalloc.
286 * the string representation and OLESTATUS
288 OLESTATUS WINAPI
StringFromCLSID16(
289 const CLSID
*id
, /* [in] the GUID to be converted */
290 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
297 ret
= CoGetMalloc16(0,&mllc
);
300 args
[0] = (DWORD
)mllc
;
303 /* No need for a Callback entry, we have WOWCallback16Ex which does
304 * everything we need.
306 if (!WOWCallback16Ex(
307 (FARPROC16
)((LPMALLOC16_VTABLE
)PTR_SEG_TO_LIN(
308 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
315 WARN(ole
,"CallTo16 IMalloc16 failed\n");
318 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
321 /******************************************************************************
322 * StringFromCLSID32 [OLE32.151]
323 * Converts a GUID into the respective string representation.
324 * The target string is allocated using the OLE IMalloc.
326 * the string representation and OLESTATUS
328 OLESTATUS WINAPI
StringFromCLSID32(
329 const CLSID
*id
, /* [in] the GUID to be converted */
330 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
336 if ((ret
=CoGetMalloc32(0,&mllc
)))
339 ret
=WINE_StringFromCLSID(id
,buf
);
341 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
342 lstrcpyAtoW(*idstr
,buf
);
347 /******************************************************************************
348 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
350 * Converts a global unique identifier into a string of an API-
351 * specified fixed format. (The usual {.....} stuff.)
354 * The (UNICODE) string representation of the GUID in 'str'
355 * The length of the resulting string, 0 if there was any problem.
358 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
362 if (WINE_StringFromCLSID(id
,xguid
))
364 if (strlen(xguid
)>=cmax
)
366 lstrcpyAtoW(str
,xguid
);
367 return strlen(xguid
);
370 /******************************************************************************
371 * CLSIDFromProgID16 [COMPOBJ.61]
372 * Converts a program id into the respective GUID. (By using a registry lookup)
374 * riid associated with the progid
376 OLESTATUS WINAPI
CLSIDFromProgID16(
377 LPCOLESTR16 progid
, /* [in] program id as found in registry */
378 LPCLSID riid
/* [out] associated CLSID */
385 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
386 sprintf(buf
,"%s\\CLSID",progid
);
387 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
388 HeapFree(GetProcessHeap(),0,buf
);
389 return OLE_ERROR_GENERIC
;
391 HeapFree(GetProcessHeap(),0,buf
);
392 buf2len
= sizeof(buf2
);
393 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
395 return OLE_ERROR_GENERIC
;
398 return CLSIDFromString16(buf2
,riid
);
401 /******************************************************************************
402 * CLSIDFromProgID32 [OLE32.2]
403 * Converts a program id into the respective GUID. (By using a registry lookup)
405 * riid associated with the progid
407 OLESTATUS WINAPI
CLSIDFromProgID32(
408 LPCOLESTR32 progid
, /* [in] program id as found in registry */
409 LPCLSID riid
/* [out] associated CLSID */
411 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
412 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
414 HeapFree(GetProcessHeap(),0,pid
);
418 /***********************************************************************
419 * LookupETask (COMPOBJ.94)
421 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
422 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
423 if ((*hTask
= GetCurrentTask()) == hETask
) {
424 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
429 /***********************************************************************
430 * SetETask (COMPOBJ.95)
432 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
433 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
438 /***********************************************************************
439 * CallObjectInWOW (COMPOBJ.201)
441 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
442 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
446 /******************************************************************************
447 * CoRegisterClassObject16 [COMPOBJ.5]
449 * Don't know where it registers it ...
451 OLESTATUS WINAPI
CoRegisterClassObject16(
460 WINE_StringFromCLSID(rclsid
,buf
);
462 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
463 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
468 /******************************************************************************
469 * CoRegisterClassObject32 [OLE32.36]
471 * Don't know where it registers it ...
473 OLESTATUS WINAPI
CoRegisterClassObject32(
482 WINE_StringFromCLSID(rclsid
,buf
);
484 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
485 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
490 /***********************************************************************
491 * CoGetClassObject [COMPOBJ.7]
493 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
494 LPVOID pvReserved
, REFIID iid
, LPVOID
*ppv
)
496 char xclsid
[50],xiid
[50];
497 LPCLASSFACTORY lpclf
;
498 HRESULT hres
= E_UNEXPECTED
;
500 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
501 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
502 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
505 lpclf
= IClassFactory_Constructor();
508 hres
= lpclf
->lpvtbl
->fnQueryInterface(lpclf
,iid
, ppv
);
509 lpclf
->lpvtbl
->fnRelease(lpclf
);
514 /******************************************************************************
515 * CoRegisterMessageFilter16 [COMPOBJ.27]
517 OLESTATUS WINAPI
CoRegisterMessageFilter16(
518 LPMESSAGEFILTER lpMessageFilter
,
519 LPMESSAGEFILTER
*lplpMessageFilter
521 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
525 /***********************************************************************
526 * CoCreateInstance [COMPOBJ.13, OLE32.7]
528 HRESULT WINAPI
CoCreateInstance(
536 char buf
[80],xbuf
[80];
539 WINE_StringFromCLSID(rclsid
,buf
);
541 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
543 WINE_StringFromCLSID(iid
,xbuf
);
545 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
547 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
551 LPCLASSFACTORY lpclf
= 0;
553 CoGetClassObject(rclsid
, dwClsContext
, NULL
, &IID_IClassFactory
, (LPVOID
)&lpclf
);
554 hres
= lpclf
->lpvtbl
->fnCreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
555 lpclf
->lpvtbl
->fnRelease(lpclf
);
560 /***********************************************************************
561 * CoFreeUnusedLibraries [COMPOBJ.17]
563 void WINAPI
CoFreeUnusedLibraries()
565 FIXME(ole
,"(), stub !\n");
568 /***********************************************************************
569 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
571 * the current system time in lpFileTime
573 HRESULT WINAPI
CoFileTimeNow(
574 FILETIME
*lpFileTime
/* [out] the current time */
576 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
580 /***********************************************************************
581 * CoTaskMemAlloc (OLE32.43)
583 * pointer to newly allocated block
585 LPVOID WINAPI
CoTaskMemAlloc(
586 ULONG size
/* [in] size of memoryblock to be allocated */
589 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
593 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
596 /***********************************************************************
597 * CoTaskMemFree (OLE32.44)
599 VOID WINAPI
CoTaskMemFree(
600 LPVOID ptr
/* [in] pointer to be freed */
603 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
606 return lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
609 /***********************************************************************
610 * CoInitializeWOW (OLE32.27)
612 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
613 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
617 /******************************************************************************
618 * CoLockObjectExternal16 [COMPOBJ.63]
620 HRESULT WINAPI
CoLockObjectExternal16(
621 LPUNKNOWN pUnk
, /* [in] object to be locked */
622 BOOL16 fLock
, /* [in] do lock */
623 BOOL16 fLastUnlockReleases
/* [in] ? */
625 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
629 /******************************************************************************
630 * CoLockObjectExternal32 [OLE32.31]
632 HRESULT WINAPI
CoLockObjectExternal32(
633 LPUNKNOWN pUnk
, /* [in] object to be locked */
634 BOOL32 fLock
, /* [in] do lock */
635 BOOL32 fLastUnlockReleases
/* [in] ? */
637 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
641 /***********************************************************************
642 * CoGetState16 [COMPOBJ.115]
644 HRESULT WINAPI
CoGetState16(LPDWORD state
)
646 FIXME(ole
, "(%p),stub!\n", state
);