4 * Copyright 1995 Martin von Loewis
21 #include "interfaces.h"
28 LPMALLOC16 currentMalloc16
=NULL
;
29 LPMALLOC32 currentMalloc32
=NULL
;
34 /***********************************************************************
35 * CoBuildVersion [COMPOBJ.1]
38 * Current built version, hiword is majornumber, loword is minornumber
40 DWORD WINAPI
CoBuildVersion()
42 TRACE(ole
,"(void)\n");
46 /***********************************************************************
47 * CoInitialize [COMPOBJ.2]
48 * Set the win16 IMalloc used for memory management
50 HRESULT WINAPI
CoInitialize16(
51 LPMALLOC16 lpReserved
/* [in] pointer to win16 malloc interface */
53 currentMalloc16
= lpReserved
;
57 /***********************************************************************
58 * CoInitialize (OLE32.26)
59 * Set the win32 IMalloc used for memorymanagement
61 HRESULT WINAPI
CoInitialize32(
62 LPMALLOC32 lpReserved
/* [in] pointer to win32 malloc interface */
64 currentMalloc32
= lpReserved
;
68 /***********************************************************************
69 * CoUnitialize [COMPOBJ.3]
70 * Don't know what it does.
72 void WINAPI
CoUnitialize()
74 TRACE(ole
,"(void)\n");
77 /***********************************************************************
78 * CoGetMalloc16 [COMPOBJ.4]
80 * The current win16 IMalloc
82 HRESULT WINAPI
CoGetMalloc16(
83 DWORD dwMemContext
, /* [in] unknown */
84 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
87 currentMalloc16
= IMalloc16_Constructor();
88 *lpMalloc
= currentMalloc16
;
92 /***********************************************************************
93 * CoGetMalloc32 [OLE32.4]
95 * The current win32 IMalloc
97 HRESULT WINAPI
CoGetMalloc32(
98 DWORD dwMemContext
, /* [in] unknown */
99 LPMALLOC32
*lpMalloc
/* [out] current win32 malloc interface */
102 currentMalloc32
= IMalloc32_Constructor();
103 *lpMalloc
= currentMalloc32
;
107 /***********************************************************************
108 * CoCreateStandardMalloc16 [COMPOBJ.71]
110 OLESTATUS WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
111 LPMALLOC16
*lpMalloc
)
113 /* FIXME: docu says we shouldn't return the same allocator as in
115 *lpMalloc
= IMalloc16_Constructor();
119 /***********************************************************************
122 OLESTATUS WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
124 TRACE(ole
,"%p %lx\n",lpUnk
,reserved
);
128 /***********************************************************************
129 * IsEqualGUID [COMPOBJ.18]
130 * Compares two Unique Identifiers
134 BOOL16 WINAPI
IsEqualGUID(
135 GUID
* g1
, /* [in] unique id 1 */
136 GUID
* g2
/* [in] unique id 2 */
138 return !memcmp( g1
, g2
, sizeof(GUID
) );
141 /***********************************************************************
142 * CLSIDFromString [COMPOBJ.20]
143 * Converts a unique identifier from it's string representation into
149 /* Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6] */
151 OLESTATUS WINAPI
CLSIDFromString16(
152 LPCOLESTR16 idstr
, /* [in] string representation of guid */
153 CLSID
*id
/* [out] GUID converted from string */
155 BYTE
*s
= (BYTE
*) idstr
;
160 TRACE(ole
,"%s -> %p\n", idstr
, id
);
162 /* quick lookup table */
163 memset(table
, 0, 256);
165 for (i
= 0; i
< 10; i
++) {
168 for (i
= 0; i
< 6; i
++) {
169 table
['A' + i
] = i
+10;
170 table
['a' + i
] = i
+10;
173 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
175 if (strlen(idstr
) != 38)
176 return OLE_ERROR_OBJECT
;
180 s
++; /* skip leading brace */
181 for (i
= 0; i
< 4; i
++) {
182 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
188 for (i
= 0; i
< 2; i
++) {
189 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
195 for (i
= 0; i
< 2; i
++) {
196 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
202 /* these are just sequential bytes */
203 for (i
= 0; i
< 2; i
++) {
204 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
209 for (i
= 0; i
< 6; i
++) {
210 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
217 /***********************************************************************
218 * CLSIDFromString (OLE32.3)
219 * Converts a unique identifier from it's string representation into
224 OLESTATUS WINAPI
CLSIDFromString32(
225 LPCOLESTR32 idstr
, /* [in] string representation of GUID */
226 CLSID
*id
/* [out] GUID represented by above string */
228 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
229 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
231 HeapFree(GetProcessHeap(),0,xid
);
235 /***********************************************************************
236 * WINE_StringFromCLSID [internal]
237 * Converts a GUID into the respective string representation.
239 * the string representation and OLESTATUS
241 OLESTATUS WINAPI
WINE_StringFromCLSID(
242 const CLSID
*id
, /* [in] GUID to be converted */
243 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
245 static const char *hex
= "0123456789ABCDEF";
250 { ERR(ole
,"called with id=Null\n");
255 sprintf(idstr
, "{%08lx-%04x-%04x-%02x%02x-",
256 id
->Data1
, id
->Data2
, id
->Data3
,
257 id
->Data4
[0], id
->Data4
[1]);
261 for (i
= 2; i
< 8; i
++) {
262 *s
++ = hex
[id
->Data4
[i
]>>4];
263 *s
++ = hex
[id
->Data4
[i
] & 0xf];
269 for (i
= strlen(idstr
)-1; i
>= 0; i
--) {
270 idstr
[i
] = toupper(idstr
[i
]);
273 TRACE(ole
,"%p->%s\n", id
, idstr
);
278 /***********************************************************************
279 * StringFromCLSID [COMPOBJ.19]
280 * Converts a GUID into the respective string representation.
281 * The target string is allocated using the OLE IMalloc.
283 * the string representation and OLESTATUS
285 OLESTATUS WINAPI
StringFromCLSID16(
286 const CLSID
*id
, /* [in] the GUID to be converted */
287 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
294 ret
= CoGetMalloc16(0,&mllc
);
297 args
[0] = (DWORD
)mllc
;
300 /* No need for a Callback entry, we have WOWCallback16Ex which does
301 * everything we need.
303 if (!WOWCallback16Ex(
304 (FARPROC16
)((LPMALLOC16_VTABLE
)PTR_SEG_TO_LIN(
305 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
312 WARN(ole
,"CallTo16 IMalloc16 failed\n");
315 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
318 /***********************************************************************
319 * StringFromCLSID [OLE32.151]
320 * Converts a GUID into the respective string representation.
321 * The target string is allocated using the OLE IMalloc.
323 * the string representation and OLESTATUS
325 OLESTATUS WINAPI
StringFromCLSID32(
326 const CLSID
*id
, /* [in] the GUID to be converted */
327 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
333 if ((ret
=CoGetMalloc32(0,&mllc
)))
336 ret
=WINE_StringFromCLSID(id
,buf
);
338 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
339 lstrcpyAtoW(*idstr
,buf
);
344 /***********************************************************************
345 * StringFromGUID2 (OLE32.152)
347 * Converts a global unique identifier into a string of an API-
348 * specified fixed format. (The usual {.....} stuff.)
351 * The (UNICODE) string representation of the GUID in 'str'
352 * The length of the resulting string, 0 if there was any problem.
355 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
359 if (WINE_StringFromCLSID(id
,xguid
))
361 if (strlen(xguid
)>=cmax
)
363 lstrcpyAtoW(str
,xguid
);
364 return strlen(xguid
);
367 /***********************************************************************
368 * CLSIDFromProgID [COMPOBJ.61]
369 * Converts a program id into the respective GUID. (By using a registry lookup)
371 * riid associated with the progid
373 OLESTATUS WINAPI
CLSIDFromProgID16(
374 LPCOLESTR16 progid
, /* [in] program id as found in registry */
375 LPCLSID riid
/* [out] associated CLSID */
382 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
383 sprintf(buf
,"%s\\CLSID",progid
);
384 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
385 HeapFree(GetProcessHeap(),0,buf
);
386 return OLE_ERROR_GENERIC
;
388 HeapFree(GetProcessHeap(),0,buf
);
389 buf2len
= sizeof(buf2
);
390 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
392 return OLE_ERROR_GENERIC
;
395 return CLSIDFromString16(buf2
,riid
);
398 /***********************************************************************
399 * CLSIDFromProgID (OLE32.2)
400 * Converts a program id into the respective GUID. (By using a registry lookup)
402 * riid associated with the progid
404 OLESTATUS WINAPI
CLSIDFromProgID32(
405 LPCOLESTR32 progid
, /* [in] program id as found in registry */
406 LPCLSID riid
/* [out] associated CLSID */
408 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
409 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
411 HeapFree(GetProcessHeap(),0,pid
);
415 /***********************************************************************
416 * LookupETask (COMPOBJ.94)
418 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
419 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
420 if ((*hTask
= GetCurrentTask()) == hETask
) {
421 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
426 /***********************************************************************
427 * SetETask (COMPOBJ.95)
429 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
430 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
435 /***********************************************************************
436 * CallObjectInWOW (COMPOBJ.201)
438 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
439 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
443 /***********************************************************************
444 * CoRegisterClassObject [COMPOBJ.5]
445 * Don't know where it registers it ...
447 OLESTATUS WINAPI
CoRegisterClassObject16(
456 WINE_StringFromCLSID(rclsid
,buf
);
458 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
459 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
464 /***********************************************************************
465 * CoRegisterClassObject (OLE32.36)
466 * Don't know where it registers it ...
468 OLESTATUS WINAPI
CoRegisterClassObject32(
477 WINE_StringFromCLSID(rclsid
,buf
);
479 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
480 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
485 /***********************************************************************
486 * CoGetClassObject [COMPOBJ.7]
488 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
489 LPVOID pvReserved
, REFIID iid
, LPVOID
*ppv
)
491 char xclsid
[50],xiid
[50];
492 LPCLASSFACTORY lpclf
;
493 HRESULT hres
= E_UNEXPECTED
;
495 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
496 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
497 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
500 lpclf
= IClassFactory_Constructor();
503 hres
= lpclf
->lpvtbl
->fnQueryInterface(lpclf
,iid
, ppv
);
504 lpclf
->lpvtbl
->fnRelease(lpclf
);
509 /***********************************************************************
510 * CoRegisterMessageFilter [COMPOBJ.27]
512 OLESTATUS WINAPI
CoRegisterMessageFilter16(
513 LPMESSAGEFILTER lpMessageFilter
,
514 LPMESSAGEFILTER
*lplpMessageFilter
516 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
520 /***********************************************************************
521 * CoCreateInstance [COMPOBJ.13, OLE32.7]
523 HRESULT WINAPI
CoCreateInstance(
531 char buf
[80],xbuf
[80];
534 WINE_StringFromCLSID(rclsid
,buf
);
536 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
538 WINE_StringFromCLSID(iid
,xbuf
);
540 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
542 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
546 LPCLASSFACTORY lpclf
= 0;
548 CoGetClassObject(rclsid
, dwClsContext
, NULL
, &IID_IClassFactory
, (LPVOID
)&lpclf
);
549 hres
= lpclf
->lpvtbl
->fnCreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
550 lpclf
->lpvtbl
->fnRelease(lpclf
);
555 /***********************************************************************
556 * CoFreeUnusedLibraries [COMPOBJ.17]
558 void WINAPI
CoFreeUnusedLibraries()
560 FIXME(ole
,"(), stub !\n");
563 /***********************************************************************
564 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
566 * the current system time in lpFileTime
568 HRESULT WINAPI
CoFileTimeNow(
569 FILETIME
*lpFileTime
/* [out] the current time */
571 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
575 /***********************************************************************
576 * CoTaskMemAlloc (OLE32.43)
578 * pointer to newly allocated block
580 LPVOID WINAPI
CoTaskMemAlloc(
581 ULONG size
/* [in] size of memoryblock to be allocated */
584 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
588 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
591 /***********************************************************************
592 * CoTaskMemFree (OLE32.44)
594 VOID WINAPI
CoTaskMemFree(
595 LPVOID ptr
/* [in] pointer to be freed */
598 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
601 return lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
604 /***********************************************************************
605 * CoInitializeWOW (OLE32.27)
607 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
608 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
612 /***********************************************************************
613 * CoLockObjectExternal (COMPOBJ.63)
615 HRESULT WINAPI
CoLockObjectExternal16(
616 LPUNKNOWN pUnk
, /* [in] object to be locked */
617 BOOL16 fLock
, /* [in] do lock */
618 BOOL16 fLastUnlockReleases
/* [in] ? */
620 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
623 /***********************************************************************
624 * CoLockObjectExternal (OLE32.31)
626 HRESULT WINAPI
CoLockObjectExternal32(
627 LPUNKNOWN pUnk
, /* [in] object to be locked */
628 BOOL32 fLock
, /* [in] do lock */
629 BOOL32 fLastUnlockReleases
/* [in] ? */
631 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
635 /***********************************************************************
636 * CoGetState16 [COMPOBJ.115]
638 HRESULT WINAPI
CoGetState16(LPDWORD state
)
640 FIXME(ole
, "(%p),stub!\n", state
);