4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
15 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/socket.h>
21 #ifdef HAVE_SYS_SOCKIO_H
22 #include <sys/sockio.h>
27 #ifdef HAVE_NETINET_IN_H
28 #include <netinet/in.h>
42 #include "interfaces.h"
52 LPMALLOC16 currentMalloc16
=NULL
;
53 LPMALLOC32 currentMalloc32
=NULL
;
59 /* this open DLL table belongs in a per process table, but my guess is that
60 * it shouldn't live in the kernel, so I'll put them out here in DLL
61 * space assuming that there is one OLE32 per process.
63 typedef struct tagOpenDll
{
64 char *DllName
; /* really only needed for debugging */
66 struct tagOpenDll
*next
;
69 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
72 /******************************************************************************
73 * CoBuildVersion [COMPOBJ.1]
76 * Current built version, hiword is majornumber, loword is minornumber
78 DWORD WINAPI
CoBuildVersion(void)
80 TRACE(ole
,"(void)\n");
84 /******************************************************************************
85 * CoInitialize16 [COMPOBJ.2]
86 * Set the win16 IMalloc used for memory management
88 HRESULT WINAPI
CoInitialize16(
89 LPMALLOC16 lpReserved
/* [in] pointer to win16 malloc interface */
91 currentMalloc16
= lpReserved
;
95 /******************************************************************************
96 * CoInitialize32 [OLE32.26]
97 * Set the win32 IMalloc used for memorymanagement
99 HRESULT WINAPI
CoInitialize32(
100 LPMALLOC32 lpReserved
/* [in] pointer to win32 malloc interface */
102 /* FIXME: there really should be something here that incrememts a refcount
103 * but I'm supposing that it is a real COM object, so I won't bother
104 * creating one here. (Decrement done in CoUnitialize()) */
105 currentMalloc32
= lpReserved
;
109 /***********************************************************************
110 * CoUnitialize [COMPOBJ.3]
111 * Don't know what it does.
112 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
113 * believe is the correct spelling
115 void WINAPI
CoUninitialize(void)
117 TRACE(ole
,"(void)\n");
118 CoFreeAllLibraries();
121 /***********************************************************************
122 * CoGetMalloc16 [COMPOBJ.4]
124 * The current win16 IMalloc
126 HRESULT WINAPI
CoGetMalloc16(
127 DWORD dwMemContext
, /* [in] unknown */
128 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
131 currentMalloc16
= IMalloc16_Constructor();
132 *lpMalloc
= currentMalloc16
;
136 /******************************************************************************
137 * CoGetMalloc32 [OLE32.20]
140 * The current win32 IMalloc
142 HRESULT WINAPI
CoGetMalloc32(
143 DWORD dwMemContext
, /* [in] unknown */
144 LPMALLOC32
*lpMalloc
/* [out] current win32 malloc interface */
147 currentMalloc32
= IMalloc32_Constructor();
148 *lpMalloc
= currentMalloc32
;
152 /***********************************************************************
153 * CoCreateStandardMalloc16 [COMPOBJ.71]
155 OLESTATUS WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
156 LPMALLOC16
*lpMalloc
)
158 /* FIXME: docu says we shouldn't return the same allocator as in
160 *lpMalloc
= IMalloc16_Constructor();
164 /******************************************************************************
165 * CoDisconnectObject [COMPOBJ.15]
167 OLESTATUS WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
169 TRACE(ole
,"%p %lx\n",lpUnk
,reserved
);
173 /***********************************************************************
174 * IsEqualGUID [COMPOBJ.18]
175 * Compares two Unique Identifiers
179 BOOL16 WINAPI
IsEqualGUID(
180 GUID
* g1
, /* [in] unique id 1 */
181 GUID
* g2
/* [in] unique id 2 */
183 return !memcmp( g1
, g2
, sizeof(GUID
) );
186 /******************************************************************************
187 * CLSIDFromString16 [COMPOBJ.20]
188 * Converts a unique identifier from it's string representation into
191 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
196 OLESTATUS WINAPI
CLSIDFromString16(
197 LPCOLESTR16 idstr
, /* [in] string representation of guid */
198 CLSID
*id
/* [out] GUID converted from string */
200 BYTE
*s
= (BYTE
*) idstr
;
205 TRACE(ole
,"%s -> %p\n", idstr
, id
);
207 /* quick lookup table */
208 memset(table
, 0, 256);
210 for (i
= 0; i
< 10; i
++) {
213 for (i
= 0; i
< 6; i
++) {
214 table
['A' + i
] = i
+10;
215 table
['a' + i
] = i
+10;
218 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
220 if (strlen(idstr
) != 38)
221 return OLE_ERROR_OBJECT
;
225 s
++; /* skip leading brace */
226 for (i
= 0; i
< 4; i
++) {
227 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
233 for (i
= 0; i
< 2; i
++) {
234 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
240 for (i
= 0; i
< 2; i
++) {
241 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
247 /* these are just sequential bytes */
248 for (i
= 0; i
< 2; i
++) {
249 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
254 for (i
= 0; i
< 6; i
++) {
255 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
262 /******************************************************************************
263 * CoCreateGuid[OLE32.6]
264 * Implemented according the DCE specification for UUID generation.
265 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
266 * Copyright (C) 1996, 1997 Theodore Ts'o.
268 int CoCreateGuid(GUID
*pguid
) {
269 static char has_init
= 0;
271 static int adjustment
= 0;
272 static struct timeval last
= {0, 0};
273 static UINT16 clock_seq
;
275 unsigned long long clock_reg
;
276 UINT32 clock_high
, clock_low
;
277 UINT16 temp_clock_seq
, temp_clock_mid
, temp_clock_hi_and_version
;
280 struct ifreq ifr
, *ifrp
;
286 /* Have we already tried to get the MAC address? */
289 /* BSD 4.4 defines the size of an ifreq to be
290 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
291 * However, under earlier systems, sa_len isn't present, so
292 * the size is just sizeof(struct ifreq)
296 # define max(a,b) ((a) > (b) ? (a) : (b))
298 # define ifreq_size(i) max(sizeof(struct ifreq),\
299 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
301 # define ifreq_size(i) sizeof(struct ifreq)
302 # endif /* HAVE_SA_LEN */
304 sd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
306 /* if we can't open a socket, just use random numbers */
307 /* set the multicast bit to prevent conflicts with real cards */
308 a
[0] = (rand() & 0xff) | 0x80;
309 a
[1] = rand() & 0xff;
310 a
[2] = rand() & 0xff;
311 a
[3] = rand() & 0xff;
312 a
[4] = rand() & 0xff;
313 a
[5] = rand() & 0xff;
315 memset(buf
, 0, sizeof(buf
));
316 ifc
.ifc_len
= sizeof(buf
);
318 /* get the ifconf interface */
319 if (ioctl (sd
, SIOCGIFCONF
, (char *)&ifc
) < 0) {
321 /* no ifconf, so just use random numbers */
322 /* set the multicast bit to prevent conflicts with real cards */
323 a
[0] = (rand() & 0xff) | 0x80;
324 a
[1] = rand() & 0xff;
325 a
[2] = rand() & 0xff;
326 a
[3] = rand() & 0xff;
327 a
[4] = rand() & 0xff;
328 a
[5] = rand() & 0xff;
330 /* loop through the interfaces, looking for a valid one */
332 for (i
= 0; i
< n
; i
+= ifreq_size(*ifr
) ) {
333 ifrp
= (struct ifreq
*)((char *) ifc
.ifc_buf
+i
);
334 strncpy(ifr
.ifr_name
, ifrp
->ifr_name
, IFNAMSIZ
);
335 /* try to get the address for this interface */
336 # ifdef SIOCGIFHWADDR
337 if (ioctl(sd
, SIOCGIFHWADDR
, &ifr
) < 0)
339 memcpy(a
, (unsigned char *)&ifr
.ifr_hwaddr
.sa_data
, 6);
342 if (ioctl(sd
, SIOCGENADDR
, &ifr
) < 0)
344 memcpy(a
, (unsigned char *) ifr
.ifr_enaddr
, 6);
346 /* XXX we don't have a way of getting the hardware address */
350 # endif /* SIOCGENADDR */
351 # endif /* SIOCGIFHWADDR */
352 /* make sure it's not blank */
353 if (!a
[0] && !a
[1] && !a
[2] && !a
[3] && !a
[4] && !a
[5])
358 /* if we didn't find a valid address, make a random one */
359 /* once again, set multicast bit to avoid conflicts */
360 a
[0] = (rand() & 0xff) | 0x80;
361 a
[1] = rand() & 0xff;
362 a
[2] = rand() & 0xff;
363 a
[3] = rand() & 0xff;
364 a
[4] = rand() & 0xff;
365 a
[5] = rand() & 0xff;
372 /* no networking info, so generate a random address */
373 a
[0] = (rand() & 0xff) | 0x80;
374 a
[1] = rand() & 0xff;
375 a
[2] = rand() & 0xff;
376 a
[3] = rand() & 0xff;
377 a
[4] = rand() & 0xff;
378 a
[5] = rand() & 0xff;
379 #endif /* HAVE_NET_IF_H */
383 /* generate time element of GUID */
385 /* Assume that the gettimeofday() has microsecond granularity */
386 #define MAX_ADJUSTMENT 10
389 gettimeofday(&tv
, 0);
390 if ((last
.tv_sec
== 0) && (last
.tv_usec
== 0)) {
391 clock_seq
= ((rand() & 0xff) << 8) + (rand() & 0xff);
396 if ((tv
.tv_sec
< last
.tv_sec
) ||
397 ((tv
.tv_sec
== last
.tv_sec
) &&
398 (tv
.tv_usec
< last
.tv_usec
))) {
399 clock_seq
= (clock_seq
+1) & 0x1FFF;
401 } else if ((tv
.tv_sec
== last
.tv_sec
) &&
402 (tv
.tv_usec
== last
.tv_usec
)) {
403 if (adjustment
>= MAX_ADJUSTMENT
)
409 clock_reg
= tv
.tv_usec
*10 + adjustment
;
410 clock_reg
+= ((unsigned long long) tv
.tv_sec
)*10000000;
411 clock_reg
+= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
413 clock_high
= clock_reg
>> 32;
414 clock_low
= clock_reg
;
415 temp_clock_seq
= clock_seq
| 0x8000;
416 temp_clock_mid
= (UINT16
)clock_high
;
417 temp_clock_hi_and_version
= (clock_high
>> 16) | 0x1000;
419 /* pack the information into the GUID structure */
421 ((unsigned char*)&pguid
->Data1
)[3] = (unsigned char)clock_low
;
423 ((unsigned char*)&pguid
->Data1
)[2] = (unsigned char)clock_low
;
425 ((unsigned char*)&pguid
->Data1
)[1] = (unsigned char)clock_low
;
427 ((unsigned char*)&pguid
->Data1
)[0] = (unsigned char)clock_low
;
429 ((unsigned char*)&pguid
->Data2
)[1] = (unsigned char)temp_clock_mid
;
430 temp_clock_mid
>>= 8;
431 ((unsigned char*)&pguid
->Data2
)[0] = (unsigned char)temp_clock_mid
;
433 ((unsigned char*)&pguid
->Data3
)[1] = (unsigned char)temp_clock_hi_and_version
;
434 temp_clock_hi_and_version
>>= 8;
435 ((unsigned char*)&pguid
->Data3
)[0] = (unsigned char)temp_clock_hi_and_version
;
437 ((unsigned char*)pguid
->Data4
)[1] = (unsigned char)temp_clock_seq
;
438 temp_clock_seq
>>= 8;
439 ((unsigned char*)pguid
->Data4
)[0] = (unsigned char)temp_clock_seq
;
441 ((unsigned char*)pguid
->Data4
)[2] = a
[0];
442 ((unsigned char*)pguid
->Data4
)[3] = a
[1];
443 ((unsigned char*)pguid
->Data4
)[4] = a
[2];
444 ((unsigned char*)pguid
->Data4
)[5] = a
[3];
445 ((unsigned char*)pguid
->Data4
)[6] = a
[4];
446 ((unsigned char*)pguid
->Data4
)[7] = a
[5];
448 TRACE(ole
, "%p", pguid
);
453 /******************************************************************************
454 * CLSIDFromString32 [OLE32.3]
455 * Converts a unique identifier from it's string representation into
460 OLESTATUS WINAPI
CLSIDFromString32(
461 LPCOLESTR32 idstr
, /* [in] string representation of GUID */
462 CLSID
*id
/* [out] GUID represented by above string */
464 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
465 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
467 HeapFree(GetProcessHeap(),0,xid
);
471 /******************************************************************************
472 * WINE_StringFromCLSID [???]
473 * Converts a GUID into the respective string representation.
476 * Why is this WINAPI?
479 * the string representation and OLESTATUS
481 OLESTATUS WINAPI
WINE_StringFromCLSID(
482 const CLSID
*id
, /* [in] GUID to be converted */
483 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
485 static const char *hex
= "0123456789ABCDEF";
490 { ERR(ole
,"called with id=Null\n");
495 sprintf(idstr
, "{%08lX-%04X-%04X-%02x%02X-",
496 id
->Data1
, id
->Data2
, id
->Data3
,
497 id
->Data4
[0], id
->Data4
[1]);
501 for (i
= 2; i
< 8; i
++) {
502 *s
++ = hex
[id
->Data4
[i
]>>4];
503 *s
++ = hex
[id
->Data4
[i
] & 0xf];
509 TRACE(ole
,"%p->%s\n", id
, idstr
);
514 /******************************************************************************
515 * StringFromCLSID16 [COMPOBJ.19]
516 * Converts a GUID into the respective string representation.
517 * The target string is allocated using the OLE IMalloc.
519 * the string representation and OLESTATUS
521 OLESTATUS WINAPI
StringFromCLSID16(
522 const CLSID
*id
, /* [in] the GUID to be converted */
523 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
530 ret
= CoGetMalloc16(0,&mllc
);
533 args
[0] = (DWORD
)mllc
;
536 /* No need for a Callback entry, we have WOWCallback16Ex which does
537 * everything we need.
539 if (!WOWCallback16Ex(
540 (FARPROC16
)((LPMALLOC16_VTABLE
)PTR_SEG_TO_LIN(
541 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
548 WARN(ole
,"CallTo16 IMalloc16 failed\n");
551 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
554 /******************************************************************************
555 * StringFromCLSID32 [OLE32.151]
556 * Converts a GUID into the respective string representation.
557 * The target string is allocated using the OLE IMalloc.
559 * the string representation and OLESTATUS
561 OLESTATUS WINAPI
StringFromCLSID32(
562 const CLSID
*id
, /* [in] the GUID to be converted */
563 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
569 if ((ret
=CoGetMalloc32(0,&mllc
)))
572 ret
=WINE_StringFromCLSID(id
,buf
);
574 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
575 lstrcpyAtoW(*idstr
,buf
);
580 /******************************************************************************
581 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
583 * Converts a global unique identifier into a string of an API-
584 * specified fixed format. (The usual {.....} stuff.)
587 * The (UNICODE) string representation of the GUID in 'str'
588 * The length of the resulting string, 0 if there was any problem.
591 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
595 if (WINE_StringFromCLSID(id
,xguid
))
597 if (strlen(xguid
)>=cmax
)
599 lstrcpyAtoW(str
,xguid
);
600 return strlen(xguid
);
603 /******************************************************************************
604 * CLSIDFromProgID16 [COMPOBJ.61]
605 * Converts a program id into the respective GUID. (By using a registry lookup)
607 * riid associated with the progid
609 OLESTATUS WINAPI
CLSIDFromProgID16(
610 LPCOLESTR16 progid
, /* [in] program id as found in registry */
611 LPCLSID riid
/* [out] associated CLSID */
618 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
619 sprintf(buf
,"%s\\CLSID",progid
);
620 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
621 HeapFree(GetProcessHeap(),0,buf
);
622 return OLE_ERROR_GENERIC
;
624 HeapFree(GetProcessHeap(),0,buf
);
625 buf2len
= sizeof(buf2
);
626 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
628 return OLE_ERROR_GENERIC
;
631 return CLSIDFromString16(buf2
,riid
);
634 /******************************************************************************
635 * CLSIDFromProgID32 [OLE32.2]
636 * Converts a program id into the respective GUID. (By using a registry lookup)
638 * riid associated with the progid
640 OLESTATUS WINAPI
CLSIDFromProgID32(
641 LPCOLESTR32 progid
, /* [in] program id as found in registry */
642 LPCLSID riid
/* [out] associated CLSID */
644 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
645 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
647 HeapFree(GetProcessHeap(),0,pid
);
651 /***********************************************************************
652 * LookupETask (COMPOBJ.94)
654 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
655 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
656 if ((*hTask
= GetCurrentTask()) == hETask
) {
657 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
662 /***********************************************************************
663 * SetETask (COMPOBJ.95)
665 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
666 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
671 /***********************************************************************
672 * CallObjectInWOW (COMPOBJ.201)
674 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
675 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
679 /******************************************************************************
680 * CoRegisterClassObject16 [COMPOBJ.5]
682 * Don't know where it registers it ...
684 OLESTATUS WINAPI
CoRegisterClassObject16(
693 WINE_StringFromCLSID(rclsid
,buf
);
695 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
696 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
701 /******************************************************************************
702 * CoRegisterClassObject32 [OLE32.36]
704 * Don't know where it registers it ...
706 OLESTATUS WINAPI
CoRegisterClassObject32(
715 WINE_StringFromCLSID(rclsid
,buf
);
717 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
718 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
723 /***********************************************************************
724 * CoRevokeClassObject [OLE32.40]
726 HRESULT WINAPI
CoRevokeClassObject(DWORD dwRegister
) {
727 FIXME(ole
,"(%08lx),stub!\n",dwRegister
);
731 /***********************************************************************
732 * CoGetClassObject [COMPOBJ.7]
734 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
735 LPVOID pvReserved
, const REFIID iid
, LPVOID
*ppv
)
737 char xclsid
[50],xiid
[50];
738 HRESULT hres
= E_UNEXPECTED
;
740 char dllName
[MAX_PATH
+1];
741 LONG dllNameLen
= sizeof(dllName
);
742 HINSTANCE32 hLibrary
;
743 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
744 REFIID iid
, LPVOID
*ppv
);
745 DllGetClassObjectFunc DllGetClassObject
;
747 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
748 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
749 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
751 /* out of process and remote servers not supported yet */
752 if ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
) {
753 FIXME(ole
, "CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
754 return E_ACCESSDENIED
;
757 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
760 /* lookup CLSID in registry key HKCR/CLSID */
761 hres
= RegOpenKeyEx32A(HKEY_CLASSES_ROOT
, "CLSID", 0,
762 KEY_READ
, &CLSIDkey
);
764 if (hres
!= ERROR_SUCCESS
)
765 return REGDB_E_READREGDB
;
766 hres
= RegOpenKeyEx32A(HKEY_CLASSES_ROOT
,xclsid
,0,KEY_QUERY_VALUE
,
768 if (hres
!= ERROR_SUCCESS
) {
769 RegCloseKey(CLSIDkey
);
770 return REGDB_E_CLASSNOTREG
;
772 hres
= RegQueryValue32A(key
, "InprocServer32", dllName
, &dllNameLen
);
774 RegCloseKey(CLSIDkey
);
775 if (hres
!= ERROR_SUCCESS
)
776 return REGDB_E_READREGDB
;
777 TRACE(ole
,"found InprocServer32 dll %s\n", dllName
);
779 /* open dll, call DllGetClassFactory */
780 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
782 TRACE(ole
,"couldn't load InprocServer32 dll %s\n", dllName
);
783 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
785 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress32(hLibrary
, "DllGetClassObject");
786 if (!DllGetClassObject
) {
787 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
788 TRACE(ole
,"couldn't find function DllGetClassObject in %s\n", dllName
);
789 return E_ACCESSDENIED
;
791 return DllGetClassObject(rclsid
, iid
, ppv
);
796 /******************************************************************************
797 * CoRegisterMessageFilter16 [COMPOBJ.27]
799 OLESTATUS WINAPI
CoRegisterMessageFilter16(
800 LPMESSAGEFILTER lpMessageFilter
,
801 LPMESSAGEFILTER
*lplpMessageFilter
803 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
807 /***********************************************************************
808 * CoCreateInstance [COMPOBJ.13, OLE32.7]
810 HRESULT WINAPI
CoCreateInstance(
818 char buf
[80],xbuf
[80];
821 WINE_StringFromCLSID(rclsid
,buf
);
823 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
825 WINE_StringFromCLSID(iid
,xbuf
);
827 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
829 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
833 LPCLASSFACTORY lpclf
= 0;
835 hres
= CoGetClassObject(rclsid
, dwClsContext
, NULL
, (const REFIID
) &IID_IClassFactory
, (LPVOID
)&lpclf
);
836 if (!SUCCEEDED(hres
)) return hres
;
837 hres
= lpclf
->lpvtbl
->fnCreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
838 lpclf
->lpvtbl
->fnRelease(lpclf
);
845 /***********************************************************************
846 * CoFreeLibrary [COMPOBJ.13]
848 void WINAPI
CoFreeLibrary(HINSTANCE32 hLibrary
)
853 /* lookup library in linked list */
855 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
856 if (ptr
->hLibrary
== hLibrary
) {
863 /* shouldn't happen if user passed in a valid hLibrary */
866 /* assert: ptr points to the library entry to free */
868 /* free library and remove node from list */
869 FreeLibrary32(hLibrary
);
870 if (ptr
== openDllList
) {
871 tmp
= openDllList
->next
;
872 HeapFree(GetProcessHeap(), 0, openDllList
->DllName
);
873 HeapFree(GetProcessHeap(), 0, openDllList
);
877 HeapFree(GetProcessHeap(), 0, ptr
->DllName
);
878 HeapFree(GetProcessHeap(), 0, ptr
);
885 /***********************************************************************
886 * CoFreeAllLibraries [COMPOBJ.12]
888 void WINAPI
CoFreeAllLibraries(void)
892 for (ptr
= openDllList
; ptr
!= NULL
; ) {
894 CoFreeLibrary(ptr
->hLibrary
);
901 /***********************************************************************
902 * CoFreeUnusedLibraries [COMPOBJ.17]
904 void WINAPI
CoFreeUnusedLibraries(void)
907 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
908 DllCanUnloadNowFunc DllCanUnloadNow
;
910 for (ptr
= openDllList
; ptr
!= NULL
; ) {
911 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
912 GetProcAddress32(ptr
->hLibrary
, "DllCanUnloadNow");
914 if (DllCanUnloadNow() == S_OK
) {
916 CoFreeLibrary(ptr
->hLibrary
);
924 /***********************************************************************
925 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
927 * the current system time in lpFileTime
929 HRESULT WINAPI
CoFileTimeNow(
930 FILETIME
*lpFileTime
/* [out] the current time */
932 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
936 /***********************************************************************
937 * CoTaskMemAlloc (OLE32.43)
939 * pointer to newly allocated block
941 LPVOID WINAPI
CoTaskMemAlloc(
942 ULONG size
/* [in] size of memoryblock to be allocated */
945 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
949 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
952 /***********************************************************************
953 * CoTaskMemFree (OLE32.44)
955 VOID WINAPI
CoTaskMemFree(
956 LPVOID ptr
/* [in] pointer to be freed */
959 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
962 return lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
965 /***********************************************************************
966 * CoLoadLibrary (OLE32.30)
968 HINSTANCE32 WINAPI
CoLoadLibrary(LPSTR lpszLibName
, BOOL32 bAutoFree
)
970 HINSTANCE32 hLibrary
;
974 TRACE(ole
,"CoLoadLibrary(%p, %d\n", lpszLibName
, bAutoFree
);
976 hLibrary
= LoadLibrary32A(lpszLibName
);
981 if (openDllList
== NULL
) {
982 /* empty list -- add first node */
983 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
984 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
985 openDllList
->hLibrary
= hLibrary
;
986 openDllList
->next
= NULL
;
988 /* search for this dll */
990 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
991 if (ptr
->hLibrary
== hLibrary
) {
997 /* dll not found, add it */
999 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1000 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1001 openDllList
->hLibrary
= hLibrary
;
1002 openDllList
->next
= tmp
;
1009 /***********************************************************************
1010 * CoInitializeWOW (OLE32.27)
1012 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1013 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
1017 /******************************************************************************
1018 * CoLockObjectExternal16 [COMPOBJ.63]
1020 HRESULT WINAPI
CoLockObjectExternal16(
1021 LPUNKNOWN pUnk
, /* [in] object to be locked */
1022 BOOL16 fLock
, /* [in] do lock */
1023 BOOL16 fLastUnlockReleases
/* [in] ? */
1025 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1029 /******************************************************************************
1030 * CoLockObjectExternal32 [OLE32.31]
1032 HRESULT WINAPI
CoLockObjectExternal32(
1033 LPUNKNOWN pUnk
, /* [in] object to be locked */
1034 BOOL32 fLock
, /* [in] do lock */
1035 BOOL32 fLastUnlockReleases
/* [in] ? */
1037 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1041 /***********************************************************************
1042 * CoGetState16 [COMPOBJ.115]
1044 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1046 FIXME(ole
, "(%p),stub!\n", state
);
1050 /***********************************************************************
1051 * CoSetState32 [COM32.42]
1053 HRESULT WINAPI
CoSetState32(LPDWORD state
)
1055 FIXME(ole
, "(%p),stub!\n", state
);