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 * CoGetMalloc [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 * CoGetMalloc (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";
234 sprintf(idstr
, "{%08lx-%04x-%04x-%02x%02x-",
235 id
->Data1
, id
->Data2
, id
->Data3
,
236 id
->Data4
[0], id
->Data4
[1]);
240 for (i
= 2; i
< 8; i
++) {
241 *s
++ = hex
[id
->Data4
[i
]>>4];
242 *s
++ = hex
[id
->Data4
[i
] & 0xf];
248 for (i
= strlen(idstr
)-1; i
>= 0; i
--) {
249 idstr
[i
] = toupper(idstr
[i
]);
252 TRACE(ole
,"%p->%s\n", id
, idstr
);
257 /***********************************************************************
258 * StringFromCLSID [COMPOBJ.19]
259 * Converts a GUID into the respective string representation.
260 * The target string is allocated using the OLE IMalloc.
262 * the string representation and OLESTATUS
264 OLESTATUS WINAPI
StringFromCLSID16(
265 const CLSID
*id
, /* [in] the GUID to be converted */
266 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
273 ret
= CoGetMalloc16(0,&mllc
);
276 args
[0] = (DWORD
)mllc
;
279 /* No need for a Callback entry, we have WOWCallback16Ex which does
280 * everything we need.
282 if (!WOWCallback16Ex(
283 (FARPROC16
)((LPMALLOC16_VTABLE
)PTR_SEG_TO_LIN(
284 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
291 WARN(ole
,"CallTo16 IMalloc16 failed\n");
294 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
297 /***********************************************************************
298 * StringFromCLSID [OLE32.151]
299 * Converts a GUID into the respective string representation.
300 * The target string is allocated using the OLE IMalloc.
302 * the string representation and OLESTATUS
304 OLESTATUS WINAPI
StringFromCLSID32(
305 const CLSID
*id
, /* [in] the GUID to be converted */
306 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
312 if ((ret
=CoGetMalloc32(0,&mllc
)))
315 ret
=WINE_StringFromCLSID(id
,buf
);
317 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
318 lstrcpyAtoW(*idstr
,buf
);
323 /***********************************************************************
324 * StringFromGUID2 (OLE32.152)
326 * Converts a global unique identifier into a string of an API-
327 * specified fixed format. (The usual {.....} stuff.)
330 * The (UNICODE) string representation of the GUID in 'str'
331 * The length of the resulting string, 0 if there was any problem.
334 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
338 if (WINE_StringFromCLSID(id
,xguid
))
340 if (strlen(xguid
)>=cmax
)
342 lstrcpyAtoW(str
,xguid
);
343 return strlen(xguid
);
346 /***********************************************************************
347 * CLSIDFromProgID [COMPOBJ.61]
348 * Converts a program id into the respective GUID. (By using a registry lookup)
350 * riid associated with the progid
352 OLESTATUS WINAPI
CLSIDFromProgID16(
353 LPCOLESTR16 progid
, /* [in] program id as found in registry */
354 LPCLSID riid
/* [out] associated CLSID */
361 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
362 sprintf(buf
,"%s\\CLSID",progid
);
363 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
364 HeapFree(GetProcessHeap(),0,buf
);
365 return OLE_ERROR_GENERIC
;
367 HeapFree(GetProcessHeap(),0,buf
);
368 buf2len
= sizeof(buf2
);
369 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
371 return OLE_ERROR_GENERIC
;
374 return CLSIDFromString16(buf2
,riid
);
377 /***********************************************************************
378 * CLSIDFromProgID (OLE32.2)
379 * Converts a program id into the respective GUID. (By using a registry lookup)
381 * riid associated with the progid
383 OLESTATUS WINAPI
CLSIDFromProgID32(
384 LPCOLESTR32 progid
, /* [in] program id as found in registry */
385 LPCLSID riid
/* [out] associated CLSID */
387 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
388 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
390 HeapFree(GetProcessHeap(),0,pid
);
394 /***********************************************************************
395 * LookupETask (COMPOBJ.94)
397 OLESTATUS WINAPI
LookupETask(LPVOID p1
,LPVOID p2
) {
398 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
402 /***********************************************************************
403 * LookupETask (COMPOBJ.201)
405 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
406 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
410 /***********************************************************************
411 * CoRegisterClassObject [COMPOBJ.5]
412 * Don't know where it registers it ...
414 OLESTATUS WINAPI
CoRegisterClassObject16(
423 WINE_StringFromCLSID(rclsid
,buf
);
425 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
426 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
431 /***********************************************************************
432 * CoRegisterClassObject (OLE32.36)
433 * Don't know where it registers it ...
435 OLESTATUS WINAPI
CoRegisterClassObject32(
444 WINE_StringFromCLSID(rclsid
,buf
);
446 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
447 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
452 /***********************************************************************
453 * CoRegisterMessageFilter [COMPOBJ.27]
455 OLESTATUS WINAPI
CoRegisterMessageFilter16(
456 LPMESSAGEFILTER lpMessageFilter
,
457 LPMESSAGEFILTER
*lplpMessageFilter
459 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
463 /***********************************************************************
464 * CoCreateInstance [COMPOBJ.13, OLE32.7]
466 HRESULT WINAPI
CoCreateInstance(
473 char buf
[80],xbuf
[80];
476 WINE_StringFromCLSID(rclsid
,buf
);
478 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
480 WINE_StringFromCLSID(riid
,xbuf
);
482 sprintf(xbuf
,"<riid-0x%08lx>",(DWORD
)riid
);
484 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
489 /***********************************************************************
490 * CoFreeUnusedLibraries [COMPOBJ.17]
492 void WINAPI
CoFreeUnusedLibraries()
494 FIXME(ole
,"(), stub !\n");
497 /***********************************************************************
498 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
500 * the current system time in lpFileTime
502 HRESULT WINAPI
CoFileTimeNow(
503 FILETIME
*lpFileTime
/* [out] the current time */
505 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
509 /***********************************************************************
510 * CoTaskMemAlloc (OLE32.43)
512 * pointer to newly allocated block
514 LPVOID WINAPI
CoTaskMemAlloc(
515 ULONG size
/* [in] size of memoryblock to be allocated */
518 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
522 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
525 /***********************************************************************
526 * CoTaskMemFree (OLE32.44)
528 VOID WINAPI
CoTaskMemFree(
529 LPVOID ptr
/* [in] pointer to be freed */
532 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
535 return lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
538 /***********************************************************************
539 * CoInitializeWOW (OLE32.27)
541 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
542 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
546 /***********************************************************************
547 * CoLockObjectExternal (COMPOBJ.63)
549 HRESULT WINAPI
CoLockObjectExternal16(
550 LPUNKNOWN pUnk
, /* [in] object to be locked */
551 BOOL16 fLock
, /* [in] do lock */
552 BOOL16 fLastUnlockReleases
/* [in] ? */
554 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);