4 * Copyright 1995 Martin von Loewis
21 #include "interfaces.h"
28 LPMALLOC16 currentMalloc16
=NULL
;
29 LPMALLOC32 currentMalloc32
=NULL
;
31 /***********************************************************************
32 * CoBuildVersion [COMPOBJ.1]
35 * Current built version, hiword is majornumber, loword is minornumber
37 DWORD WINAPI
CoBuildVersion()
39 TRACE(ole
,"(void)\n");
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 */
50 currentMalloc16
= lpReserved
;
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 */
61 currentMalloc32
= lpReserved
;
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]
77 * The current win16 IMalloc
79 HRESULT WINAPI
CoGetMalloc16(
80 DWORD dwMemContext
, /* [in] unknown */
81 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
84 currentMalloc16
= IMalloc16_Constructor();
85 *lpMalloc
= currentMalloc16
;
89 /***********************************************************************
90 * CoGetMalloc32 [OLE32.4]
92 * The current win32 IMalloc
94 HRESULT WINAPI
CoGetMalloc32(
95 DWORD dwMemContext
, /* [in] unknown */
96 LPMALLOC32
*lpMalloc
/* [out] current win32 malloc interface */
99 currentMalloc32
= IMalloc32_Constructor();
100 *lpMalloc
= currentMalloc32
;
104 /***********************************************************************
107 OLESTATUS WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
109 TRACE(ole
,"%p %lx\n",lpUnk
,reserved
);
113 /***********************************************************************
114 * IsEqualGUID [COMPOBJ.18]
115 * Compares two Unique Identifiers
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
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
;
145 TRACE(ole
,"%s -> %p\n", idstr
, id
);
147 /* quick lookup table */
148 memset(table
, 0, 256);
150 for (i
= 0; i
< 10; 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
;
165 s
++; /* skip leading brace */
166 for (i
= 0; i
< 4; i
++) {
167 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
173 for (i
= 0; i
< 2; i
++) {
174 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
180 for (i
= 0; i
< 2; i
++) {
181 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
187 /* these are just sequential bytes */
188 for (i
= 0; i
< 2; i
++) {
189 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
194 for (i
= 0; i
< 6; i
++) {
195 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
202 /***********************************************************************
203 * CLSIDFromString (OLE32.3)
204 * Converts a unique identifier from it's string representation into
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
);
220 /***********************************************************************
221 * WINE_StringFromCLSID [internal]
222 * Converts a GUID into the respective string representation.
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";
235 { ERR(ole
,"called with id=Null\n");
240 sprintf(idstr
, "{%08lx-%04x-%04x-%02x%02x-",
241 id
->Data1
, id
->Data2
, id
->Data3
,
242 id
->Data4
[0], id
->Data4
[1]);
246 for (i
= 2; i
< 8; i
++) {
247 *s
++ = hex
[id
->Data4
[i
]>>4];
248 *s
++ = hex
[id
->Data4
[i
] & 0xf];
254 for (i
= strlen(idstr
)-1; i
>= 0; i
--) {
255 idstr
[i
] = toupper(idstr
[i
]);
258 TRACE(ole
,"%p->%s\n", id
, idstr
);
263 /***********************************************************************
264 * StringFromCLSID [COMPOBJ.19]
265 * Converts a GUID into the respective string representation.
266 * The target string is allocated using the OLE IMalloc.
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 */
279 ret
= CoGetMalloc16(0,&mllc
);
282 args
[0] = (DWORD
)mllc
;
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
)
297 WARN(ole
,"CallTo16 IMalloc16 failed\n");
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.
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 */
318 if ((ret
=CoGetMalloc32(0,&mllc
)))
321 ret
=WINE_StringFromCLSID(id
,buf
);
323 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
324 lstrcpyAtoW(*idstr
,buf
);
329 /***********************************************************************
330 * StringFromGUID2 (OLE32.152)
332 * Converts a global unique identifier into a string of an API-
333 * specified fixed format. (The usual {.....} stuff.)
336 * The (UNICODE) string representation of the GUID in 'str'
337 * The length of the resulting string, 0 if there was any problem.
340 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
344 if (WINE_StringFromCLSID(id
,xguid
))
346 if (strlen(xguid
)>=cmax
)
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)
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 */
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
))) {
377 return OLE_ERROR_GENERIC
;
380 return CLSIDFromString16(buf2
,riid
);
383 /***********************************************************************
384 * CLSIDFromProgID (OLE32.2)
385 * Converts a program id into the respective GUID. (By using a registry lookup)
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
);
400 /***********************************************************************
401 * LookupETask (COMPOBJ.94)
403 OLESTATUS WINAPI
LookupETask(LPVOID p1
,LPVOID p2
) {
404 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
408 /***********************************************************************
409 * LookupETask (COMPOBJ.201)
411 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
412 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
416 /***********************************************************************
417 * CoRegisterClassObject [COMPOBJ.5]
418 * Don't know where it registers it ...
420 OLESTATUS WINAPI
CoRegisterClassObject16(
429 WINE_StringFromCLSID(rclsid
,buf
);
431 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
432 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
437 /***********************************************************************
438 * CoRegisterClassObject (OLE32.36)
439 * Don't know where it registers it ...
441 OLESTATUS WINAPI
CoRegisterClassObject32(
450 WINE_StringFromCLSID(rclsid
,buf
);
452 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
453 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
458 /***********************************************************************
459 * CoRegisterMessageFilter [COMPOBJ.27]
461 OLESTATUS WINAPI
CoRegisterMessageFilter16(
462 LPMESSAGEFILTER lpMessageFilter
,
463 LPMESSAGEFILTER
*lplpMessageFilter
465 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
469 /***********************************************************************
470 * CoCreateInstance [COMPOBJ.13, OLE32.7]
472 HRESULT WINAPI
CoCreateInstance(
479 char buf
[80],xbuf
[80];
482 WINE_StringFromCLSID(rclsid
,buf
);
484 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
486 WINE_StringFromCLSID(riid
,xbuf
);
488 sprintf(xbuf
,"<riid-0x%08lx>",(DWORD
)riid
);
490 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
495 /***********************************************************************
496 * CoFreeUnusedLibraries [COMPOBJ.17]
498 void WINAPI
CoFreeUnusedLibraries()
500 FIXME(ole
,"(), stub !\n");
503 /***********************************************************************
504 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
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);
515 /***********************************************************************
516 * CoTaskMemAlloc (OLE32.43)
518 * pointer to newly allocated block
520 LPVOID WINAPI
CoTaskMemAlloc(
521 ULONG size
/* [in] size of memoryblock to be allocated */
524 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
528 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
531 /***********************************************************************
532 * CoTaskMemFree (OLE32.44)
534 VOID WINAPI
CoTaskMemFree(
535 LPVOID ptr
/* [in] pointer to be freed */
538 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
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
);
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
);
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
);