4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
13 #include <sys/types.h>
16 #ifdef HAVE_SYS_FILE_H
17 # include <sys/file.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>
45 LPMALLOC16 currentMalloc16
=NULL
;
46 LPMALLOC32 currentMalloc32
=NULL
;
52 /* this open DLL table belongs in a per process table, but my guess is that
53 * it shouldn't live in the kernel, so I'll put them out here in DLL
54 * space assuming that there is one OLE32 per process.
56 typedef struct tagOpenDll
{
57 char *DllName
; /* really only needed for debugging */
59 struct tagOpenDll
*next
;
62 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
65 /******************************************************************************
66 * CoBuildVersion [COMPOBJ.1]
69 * Current built version, hiword is majornumber, loword is minornumber
71 DWORD WINAPI
CoBuildVersion(void)
73 TRACE(ole
,"(void)\n");
77 /******************************************************************************
78 * CoInitialize16 [COMPOBJ.2]
79 * Set the win16 IMalloc used for memory management
81 HRESULT WINAPI
CoInitialize16(
82 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
84 currentMalloc16
= (LPMALLOC16
)lpReserved
;
88 /******************************************************************************
89 * CoInitialize32 [OLE32.26]
91 * Set the win32 IMalloc used for memorymanagement
94 * S_OK if successful, S_FALSE otherwise, RPC_E_CHANGED_MODE if a previous
95 * call to CoInitializeEx specified another threading model.
98 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
101 HRESULT WINAPI
CoInitialize32(
102 LPVOID lpReserved
/* [in] pointer to win32 malloc interface */
104 /* FIXME: there really should be something here that incrememts a refcount
105 * but I'm supposing that it is a real COM object, so I won't bother
106 * creating one here. (Decrement done in CoUnitialize()) */
107 currentMalloc32
= (LPMALLOC32
)lpReserved
;
111 /******************************************************************************
112 * CoInitializeEx32 [OLE32.163]
114 * Set the win32 IMalloc used for memory management
117 * S_OK if successful, S_FALSE otherwise, RPC_E_CHANGED_MODE if a previous
118 * call to CoInitializeEx specified another threading model.
121 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
124 HRESULT WINAPI
CoInitializeEx32(
125 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface */
126 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
128 if (dwCoInit
!=COINIT_APARTMENTTHREADED
) {
129 FIXME(ole
, ":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
130 /* Hope for the best and continue anyway */
132 return CoInitialize32(lpReserved
);
135 /***********************************************************************
136 * CoUnitialize [COMPOBJ.3]
137 * Don't know what it does.
138 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
139 * believe is the correct spelling
141 void WINAPI
CoUninitialize(void)
143 TRACE(ole
,"(void)\n");
144 CoFreeAllLibraries();
147 /***********************************************************************
148 * CoGetMalloc16 [COMPOBJ.4]
150 * The current win16 IMalloc
152 HRESULT WINAPI
CoGetMalloc16(
153 DWORD dwMemContext
, /* [in] unknown */
154 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
157 currentMalloc16
= IMalloc16_Constructor();
158 *lpMalloc
= currentMalloc16
;
162 /******************************************************************************
163 * CoGetMalloc32 [OLE32.20]
166 * The current win32 IMalloc
168 HRESULT WINAPI
CoGetMalloc32(
169 DWORD dwMemContext
, /* [in] unknown */
170 LPMALLOC32
*lpMalloc
/* [out] current win32 malloc interface */
173 currentMalloc32
= IMalloc32_Constructor();
174 *lpMalloc
= currentMalloc32
;
178 /***********************************************************************
179 * CoCreateStandardMalloc16 [COMPOBJ.71]
181 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
182 LPMALLOC16
*lpMalloc
)
184 /* FIXME: docu says we shouldn't return the same allocator as in
186 *lpMalloc
= IMalloc16_Constructor();
190 /******************************************************************************
191 * CoDisconnectObject [COMPOBJ.15]
193 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
195 TRACE(ole
,"%p %lx\n",lpUnk
,reserved
);
199 /***********************************************************************
200 * IsEqualGUID16 [COMPOBJ.18]
202 * Compares two Unique Identifiers.
207 BOOL16 WINAPI
IsEqualGUID16(
208 GUID
* g1
, /* [in] unique id 1 */
211 return !memcmp( g1
, g2
, sizeof(GUID
) );
214 /***********************************************************************
215 * IsEqualGUID32 [OLE32.76]
217 * Compares two Unique Identifiers.
222 BOOL32 WINAPI
IsEqualGUID32(
223 REFGUID rguid1
, /* [in] unique id 1 */
224 REFGUID rguid2
/* [in] unique id 2 */
227 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));
230 /******************************************************************************
231 * CLSIDFromString16 [COMPOBJ.20]
232 * Converts a unique identifier from it's string representation into
235 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
240 HRESULT WINAPI
CLSIDFromString16(
241 LPCOLESTR16 idstr
, /* [in] string representation of guid */
242 CLSID
*id
/* [out] GUID converted from string */
244 BYTE
*s
= (BYTE
*) idstr
;
249 TRACE(ole
,"%s -> %p\n", idstr
, id
);
251 /* quick lookup table */
252 memset(table
, 0, 256);
254 for (i
= 0; i
< 10; i
++) {
257 for (i
= 0; i
< 6; i
++) {
258 table
['A' + i
] = i
+10;
259 table
['a' + i
] = i
+10;
262 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
264 if (strlen(idstr
) != 38)
265 return OLE_ERROR_OBJECT
;
269 s
++; /* skip leading brace */
270 for (i
= 0; i
< 4; i
++) {
271 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
277 for (i
= 0; i
< 2; i
++) {
278 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
284 for (i
= 0; i
< 2; i
++) {
285 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
291 /* these are just sequential bytes */
292 for (i
= 0; i
< 2; i
++) {
293 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
298 for (i
= 0; i
< 6; i
++) {
299 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
306 /******************************************************************************
307 * CoCreateGuid[OLE32.6]
309 * Creates a 128bit GUID.
310 * Implemented according the DCE specification for UUID generation.
311 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
312 * Copyright (C) 1996, 1997 Theodore Ts'o.
316 * S_OK if successful.
318 HRESULT WINAPI
CoCreateGuid(
319 GUID
*pguid
/* [out] points to the GUID to initialize */
321 static char has_init
= 0;
323 static int adjustment
= 0;
324 static struct timeval last
= {0, 0};
325 static UINT16 clock_seq
;
327 unsigned long long clock_reg
;
328 UINT32 clock_high
, clock_low
;
329 UINT16 temp_clock_seq
, temp_clock_mid
, temp_clock_hi_and_version
;
332 struct ifreq ifr
, *ifrp
;
338 /* Have we already tried to get the MAC address? */
341 /* BSD 4.4 defines the size of an ifreq to be
342 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
343 * However, under earlier systems, sa_len isn't present, so
344 * the size is just sizeof(struct ifreq)
348 # define max(a,b) ((a) > (b) ? (a) : (b))
350 # define ifreq_size(i) max(sizeof(struct ifreq),\
351 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
353 # define ifreq_size(i) sizeof(struct ifreq)
354 # endif /* HAVE_SA_LEN */
356 sd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
358 /* if we can't open a socket, just use random numbers */
359 /* set the multicast bit to prevent conflicts with real cards */
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;
367 memset(buf
, 0, sizeof(buf
));
368 ifc
.ifc_len
= sizeof(buf
);
370 /* get the ifconf interface */
371 if (ioctl (sd
, SIOCGIFCONF
, (char *)&ifc
) < 0) {
373 /* no ifconf, so just use random numbers */
374 /* set the multicast bit to prevent conflicts with real cards */
375 a
[0] = (rand() & 0xff) | 0x80;
376 a
[1] = rand() & 0xff;
377 a
[2] = rand() & 0xff;
378 a
[3] = rand() & 0xff;
379 a
[4] = rand() & 0xff;
380 a
[5] = rand() & 0xff;
382 /* loop through the interfaces, looking for a valid one */
384 for (i
= 0; i
< n
; i
+= ifreq_size(*ifr
) ) {
385 ifrp
= (struct ifreq
*)((char *) ifc
.ifc_buf
+i
);
386 strncpy(ifr
.ifr_name
, ifrp
->ifr_name
, IFNAMSIZ
);
387 /* try to get the address for this interface */
388 # ifdef SIOCGIFHWADDR
389 if (ioctl(sd
, SIOCGIFHWADDR
, &ifr
) < 0)
391 memcpy(a
, (unsigned char *)&ifr
.ifr_hwaddr
.sa_data
, 6);
394 if (ioctl(sd
, SIOCGENADDR
, &ifr
) < 0)
396 memcpy(a
, (unsigned char *) ifr
.ifr_enaddr
, 6);
398 /* XXX we don't have a way of getting the hardware address */
402 # endif /* SIOCGENADDR */
403 # endif /* SIOCGIFHWADDR */
404 /* make sure it's not blank */
405 if (!a
[0] && !a
[1] && !a
[2] && !a
[3] && !a
[4] && !a
[5])
410 /* if we didn't find a valid address, make a random one */
411 /* once again, set multicast bit to avoid conflicts */
412 a
[0] = (rand() & 0xff) | 0x80;
413 a
[1] = rand() & 0xff;
414 a
[2] = rand() & 0xff;
415 a
[3] = rand() & 0xff;
416 a
[4] = rand() & 0xff;
417 a
[5] = rand() & 0xff;
424 /* no networking info, so generate a random address */
425 a
[0] = (rand() & 0xff) | 0x80;
426 a
[1] = rand() & 0xff;
427 a
[2] = rand() & 0xff;
428 a
[3] = rand() & 0xff;
429 a
[4] = rand() & 0xff;
430 a
[5] = rand() & 0xff;
431 #endif /* HAVE_NET_IF_H */
435 /* generate time element of GUID */
437 /* Assume that the gettimeofday() has microsecond granularity */
438 #define MAX_ADJUSTMENT 10
441 gettimeofday(&tv
, 0);
442 if ((last
.tv_sec
== 0) && (last
.tv_usec
== 0)) {
443 clock_seq
= ((rand() & 0xff) << 8) + (rand() & 0xff);
448 if ((tv
.tv_sec
< last
.tv_sec
) ||
449 ((tv
.tv_sec
== last
.tv_sec
) &&
450 (tv
.tv_usec
< last
.tv_usec
))) {
451 clock_seq
= (clock_seq
+1) & 0x1FFF;
453 } else if ((tv
.tv_sec
== last
.tv_sec
) &&
454 (tv
.tv_usec
== last
.tv_usec
)) {
455 if (adjustment
>= MAX_ADJUSTMENT
)
461 clock_reg
= tv
.tv_usec
*10 + adjustment
;
462 clock_reg
+= ((unsigned long long) tv
.tv_sec
)*10000000;
463 clock_reg
+= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
465 clock_high
= clock_reg
>> 32;
466 clock_low
= clock_reg
;
467 temp_clock_seq
= clock_seq
| 0x8000;
468 temp_clock_mid
= (UINT16
)clock_high
;
469 temp_clock_hi_and_version
= (clock_high
>> 16) | 0x1000;
471 /* pack the information into the GUID structure */
473 ((unsigned char*)&pguid
->Data1
)[3] = (unsigned char)clock_low
;
475 ((unsigned char*)&pguid
->Data1
)[2] = (unsigned char)clock_low
;
477 ((unsigned char*)&pguid
->Data1
)[1] = (unsigned char)clock_low
;
479 ((unsigned char*)&pguid
->Data1
)[0] = (unsigned char)clock_low
;
481 ((unsigned char*)&pguid
->Data2
)[1] = (unsigned char)temp_clock_mid
;
482 temp_clock_mid
>>= 8;
483 ((unsigned char*)&pguid
->Data2
)[0] = (unsigned char)temp_clock_mid
;
485 ((unsigned char*)&pguid
->Data3
)[1] = (unsigned char)temp_clock_hi_and_version
;
486 temp_clock_hi_and_version
>>= 8;
487 ((unsigned char*)&pguid
->Data3
)[0] = (unsigned char)temp_clock_hi_and_version
;
489 ((unsigned char*)pguid
->Data4
)[1] = (unsigned char)temp_clock_seq
;
490 temp_clock_seq
>>= 8;
491 ((unsigned char*)pguid
->Data4
)[0] = (unsigned char)temp_clock_seq
;
493 ((unsigned char*)pguid
->Data4
)[2] = a
[0];
494 ((unsigned char*)pguid
->Data4
)[3] = a
[1];
495 ((unsigned char*)pguid
->Data4
)[4] = a
[2];
496 ((unsigned char*)pguid
->Data4
)[5] = a
[3];
497 ((unsigned char*)pguid
->Data4
)[6] = a
[4];
498 ((unsigned char*)pguid
->Data4
)[7] = a
[5];
500 TRACE(ole
, "%p", pguid
);
505 /******************************************************************************
506 * CLSIDFromString32 [OLE32.3]
507 * Converts a unique identifier from it's string representation into
512 HRESULT WINAPI
CLSIDFromString32(
513 LPCOLESTR32 idstr
, /* [in] string representation of GUID */
514 CLSID
*id
/* [out] GUID represented by above string */
516 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
517 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
519 HeapFree(GetProcessHeap(),0,xid
);
523 /******************************************************************************
524 * WINE_StringFromCLSID [???]
525 * Converts a GUID into the respective string representation.
530 * the string representation and OLESTATUS
532 HRESULT
WINE_StringFromCLSID(
533 const CLSID
*id
, /* [in] GUID to be converted */
534 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
536 static const char *hex
= "0123456789ABCDEF";
541 { ERR(ole
,"called with id=Null\n");
546 sprintf(idstr
, "{%08lX-%04X-%04X-%02x%02X-",
547 id
->Data1
, id
->Data2
, id
->Data3
,
548 id
->Data4
[0], id
->Data4
[1]);
552 for (i
= 2; i
< 8; i
++) {
553 *s
++ = hex
[id
->Data4
[i
]>>4];
554 *s
++ = hex
[id
->Data4
[i
] & 0xf];
560 TRACE(ole
,"%p->%s\n", id
, idstr
);
565 /******************************************************************************
566 * StringFromCLSID16 [COMPOBJ.19]
567 * Converts a GUID into the respective string representation.
568 * The target string is allocated using the OLE IMalloc.
570 * the string representation and OLESTATUS
572 HRESULT WINAPI
StringFromCLSID16(
573 const CLSID
*id
, /* [in] the GUID to be converted */
574 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
581 ret
= CoGetMalloc16(0,&mllc
);
584 args
[0] = (DWORD
)mllc
;
587 /* No need for a Callback entry, we have WOWCallback16Ex which does
588 * everything we need.
590 if (!WOWCallback16Ex(
591 (FARPROC16
)((ICOM_VTABLE(IMalloc16
)*)PTR_SEG_TO_LIN(
592 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
599 WARN(ole
,"CallTo16 IMalloc16 failed\n");
602 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
605 /******************************************************************************
606 * StringFromCLSID32 [OLE32.151]
607 * Converts a GUID into the respective string representation.
608 * The target string is allocated using the OLE IMalloc.
610 * the string representation and OLESTATUS
612 HRESULT WINAPI
StringFromCLSID32(
613 const CLSID
*id
, /* [in] the GUID to be converted */
614 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
620 if ((ret
=CoGetMalloc32(0,&mllc
)))
623 ret
=WINE_StringFromCLSID(id
,buf
);
625 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
626 lstrcpyAtoW(*idstr
,buf
);
631 /******************************************************************************
632 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
634 * Converts a global unique identifier into a string of an API-
635 * specified fixed format. (The usual {.....} stuff.)
638 * The (UNICODE) string representation of the GUID in 'str'
639 * The length of the resulting string, 0 if there was any problem.
642 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
646 if (WINE_StringFromCLSID(id
,xguid
))
648 if (strlen(xguid
)>=cmax
)
650 lstrcpyAtoW(str
,xguid
);
651 return strlen(xguid
);
654 /******************************************************************************
655 * CLSIDFromProgID16 [COMPOBJ.61]
656 * Converts a program id into the respective GUID. (By using a registry lookup)
658 * riid associated with the progid
660 HRESULT WINAPI
CLSIDFromProgID16(
661 LPCOLESTR16 progid
, /* [in] program id as found in registry */
662 LPCLSID riid
/* [out] associated CLSID */
669 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
670 sprintf(buf
,"%s\\CLSID",progid
);
671 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
672 HeapFree(GetProcessHeap(),0,buf
);
673 return OLE_ERROR_GENERIC
;
675 HeapFree(GetProcessHeap(),0,buf
);
676 buf2len
= sizeof(buf2
);
677 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
679 return OLE_ERROR_GENERIC
;
682 return CLSIDFromString16(buf2
,riid
);
685 /******************************************************************************
686 * CLSIDFromProgID32 [OLE32.2]
687 * Converts a program id into the respective GUID. (By using a registry lookup)
689 * riid associated with the progid
691 HRESULT WINAPI
CLSIDFromProgID32(
692 LPCOLESTR32 progid
, /* [in] program id as found in registry */
693 LPCLSID riid
/* [out] associated CLSID */
695 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
696 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
698 HeapFree(GetProcessHeap(),0,pid
);
702 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
703 /***********************************************************************
704 * LookupETask (COMPOBJ.94)
706 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
707 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
708 if ((*hTask
= GetCurrentTask()) == hETask
) {
709 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
714 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
715 /***********************************************************************
716 * SetETask (COMPOBJ.95)
718 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
719 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
724 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
725 /***********************************************************************
726 * CallObjectInWOW (COMPOBJ.201)
728 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
729 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
733 /******************************************************************************
734 * CoRegisterClassObject16 [COMPOBJ.5]
736 * Don't know where it registers it ...
738 HRESULT WINAPI
CoRegisterClassObject16(
741 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
742 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
747 WINE_StringFromCLSID(rclsid
,buf
);
749 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
750 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
755 /******************************************************************************
756 * CoRegisterClassObject32 [OLE32.36]
758 * Don't know where it registers it ...
760 HRESULT WINAPI
CoRegisterClassObject32(
763 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
764 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
769 WINE_StringFromCLSID(rclsid
,buf
);
771 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
772 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
777 /***********************************************************************
778 * CoRevokeClassObject [OLE32.40]
780 HRESULT WINAPI
CoRevokeClassObject(DWORD dwRegister
) {
781 FIXME(ole
,"(%08lx),stub!\n",dwRegister
);
785 /***********************************************************************
786 * CoGetClassObject [COMPOBJ.7]
788 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
789 LPVOID pvReserved
, const REFIID iid
, LPVOID
*ppv
)
791 char xclsid
[50],xiid
[50];
792 HRESULT hres
= E_UNEXPECTED
;
794 char dllName
[MAX_PATH
+1];
795 DWORD dllNameLen
= sizeof(dllName
);
796 HINSTANCE32 hLibrary
;
797 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
798 REFIID iid
, LPVOID
*ppv
);
799 DllGetClassObjectFunc DllGetClassObject
;
801 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
802 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
803 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
805 /* out of process and remote servers not supported yet */
806 if ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
) {
807 FIXME(ole
, "CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
808 return E_ACCESSDENIED
;
811 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
814 /* lookup CLSID in registry key HKCR/CLSID */
815 hres
= RegOpenKeyEx32A(HKEY_CLASSES_ROOT
, "CLSID", 0,
816 KEY_READ
, &CLSIDkey
);
818 if (hres
!= ERROR_SUCCESS
)
819 return REGDB_E_READREGDB
;
820 hres
= RegOpenKeyEx32A(CLSIDkey
,xclsid
,0,KEY_QUERY_VALUE
,&key
);
821 if (hres
!= ERROR_SUCCESS
) {
822 RegCloseKey(CLSIDkey
);
823 return REGDB_E_CLASSNOTREG
;
825 hres
= RegQueryValue32A(key
, "InprocServer32", dllName
, &dllNameLen
);
827 RegCloseKey(CLSIDkey
);
828 if (hres
!= ERROR_SUCCESS
)
829 return REGDB_E_READREGDB
;
830 TRACE(ole
,"found InprocServer32 dll %s\n", dllName
);
832 /* open dll, call DllGetClassFactory */
833 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
835 TRACE(ole
,"couldn't load InprocServer32 dll %s\n", dllName
);
836 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
838 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress32(hLibrary
, "DllGetClassObject");
839 if (!DllGetClassObject
) {
840 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
841 TRACE(ole
,"couldn't find function DllGetClassObject in %s\n", dllName
);
842 return E_ACCESSDENIED
;
844 /* FIXME: Shouldn't we get a classfactory and use this to create
845 * the required object?
847 return DllGetClassObject(rclsid
, iid
, ppv
);
852 /******************************************************************************
853 * CoRegisterMessageFilter16 [COMPOBJ.27]
855 HRESULT WINAPI
CoRegisterMessageFilter16(
856 LPMESSAGEFILTER lpMessageFilter
,
857 LPMESSAGEFILTER
*lplpMessageFilter
859 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
863 /***********************************************************************
864 * CoCreateInstance [COMPOBJ.13, OLE32.7]
866 HRESULT WINAPI
CoCreateInstance(
874 char buf
[80],xbuf
[80];
877 WINE_StringFromCLSID(rclsid
,buf
);
879 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
881 WINE_StringFromCLSID(iid
,xbuf
);
883 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
885 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
889 LPCLASSFACTORY lpclf
= 0;
891 hres
= CoGetClassObject(rclsid
, dwClsContext
, NULL
, (const REFIID
) &IID_IClassFactory
, (LPVOID
)&lpclf
);
892 if (!SUCCEEDED(hres
)) return hres
;
893 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
894 IClassFactory_Release(lpclf
);
901 /***********************************************************************
902 * CoFreeLibrary [COMPOBJ.13]
904 void WINAPI
CoFreeLibrary(HINSTANCE32 hLibrary
)
909 /* lookup library in linked list */
911 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
912 if (ptr
->hLibrary
== hLibrary
) {
919 /* shouldn't happen if user passed in a valid hLibrary */
922 /* assert: ptr points to the library entry to free */
924 /* free library and remove node from list */
925 FreeLibrary32(hLibrary
);
926 if (ptr
== openDllList
) {
927 tmp
= openDllList
->next
;
928 HeapFree(GetProcessHeap(), 0, openDllList
->DllName
);
929 HeapFree(GetProcessHeap(), 0, openDllList
);
933 HeapFree(GetProcessHeap(), 0, ptr
->DllName
);
934 HeapFree(GetProcessHeap(), 0, ptr
);
941 /***********************************************************************
942 * CoFreeAllLibraries [COMPOBJ.12]
944 void WINAPI
CoFreeAllLibraries(void)
948 for (ptr
= openDllList
; ptr
!= NULL
; ) {
950 CoFreeLibrary(ptr
->hLibrary
);
957 /***********************************************************************
958 * CoFreeUnusedLibraries [COMPOBJ.17]
960 void WINAPI
CoFreeUnusedLibraries(void)
963 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
964 DllCanUnloadNowFunc DllCanUnloadNow
;
966 for (ptr
= openDllList
; ptr
!= NULL
; ) {
967 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
968 GetProcAddress32(ptr
->hLibrary
, "DllCanUnloadNow");
970 if (DllCanUnloadNow() == S_OK
) {
972 CoFreeLibrary(ptr
->hLibrary
);
980 /***********************************************************************
981 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
983 * the current system time in lpFileTime
985 HRESULT WINAPI
CoFileTimeNow(
986 FILETIME
*lpFileTime
/* [out] the current time */
988 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
992 /***********************************************************************
993 * CoTaskMemAlloc (OLE32.43)
995 * pointer to newly allocated block
997 LPVOID WINAPI
CoTaskMemAlloc(
998 ULONG size
/* [in] size of memoryblock to be allocated */
1000 LPMALLOC32 lpmalloc
;
1001 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
1005 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
1008 /***********************************************************************
1009 * CoTaskMemFree (OLE32.44)
1011 VOID WINAPI
CoTaskMemFree(
1012 LPVOID ptr
/* [in] pointer to be freed */
1014 LPMALLOC32 lpmalloc
;
1015 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
1018 lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
1021 /***********************************************************************
1022 * CoLoadLibrary (OLE32.30)
1024 HINSTANCE32 WINAPI
CoLoadLibrary(LPOLESTR16 lpszLibName
, BOOL32 bAutoFree
)
1026 HINSTANCE32 hLibrary
;
1030 TRACE(ole
,"CoLoadLibrary(%p, %d\n", lpszLibName
, bAutoFree
);
1032 hLibrary
= LoadLibrary32A(lpszLibName
);
1037 if (openDllList
== NULL
) {
1038 /* empty list -- add first node */
1039 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1040 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1041 openDllList
->hLibrary
= hLibrary
;
1042 openDllList
->next
= NULL
;
1044 /* search for this dll */
1046 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1047 if (ptr
->hLibrary
== hLibrary
) {
1053 /* dll not found, add it */
1055 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1056 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1057 openDllList
->hLibrary
= hLibrary
;
1058 openDllList
->next
= tmp
;
1065 /***********************************************************************
1066 * CoInitializeWOW (OLE32.27)
1068 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1069 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
1073 /******************************************************************************
1074 * CoLockObjectExternal16 [COMPOBJ.63]
1076 HRESULT WINAPI
CoLockObjectExternal16(
1077 LPUNKNOWN pUnk
, /* [in] object to be locked */
1078 BOOL16 fLock
, /* [in] do lock */
1079 BOOL16 fLastUnlockReleases
/* [in] ? */
1081 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1085 /******************************************************************************
1086 * CoLockObjectExternal32 [OLE32.31]
1088 HRESULT WINAPI
CoLockObjectExternal32(
1089 LPUNKNOWN pUnk
, /* [in] object to be locked */
1090 BOOL32 fLock
, /* [in] do lock */
1091 BOOL32 fLastUnlockReleases
/* [in] ? */
1093 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1097 /***********************************************************************
1098 * CoGetState16 [COMPOBJ.115]
1100 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1102 FIXME(ole
, "(%p),stub!\n", state
);
1106 /***********************************************************************
1107 * CoSetState32 [COM32.42]
1109 HRESULT WINAPI
CoSetState32(LPDWORD state
)
1111 FIXME(ole
, "(%p),stub!\n", state
);