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 /* FIXME: we include all the header files containing GUIDs
46 * so that the corresponding variables get defined. But they
47 * don't even all belong to the same DLL !!!
60 LPMALLOC16 currentMalloc16
=NULL
;
61 LPMALLOC32 currentMalloc32
=NULL
;
67 /* this open DLL table belongs in a per process table, but my guess is that
68 * it shouldn't live in the kernel, so I'll put them out here in DLL
69 * space assuming that there is one OLE32 per process.
71 typedef struct tagOpenDll
{
72 char *DllName
; /* really only needed for debugging */
74 struct tagOpenDll
*next
;
77 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
80 /******************************************************************************
81 * CoBuildVersion [COMPOBJ.1]
84 * Current built version, hiword is majornumber, loword is minornumber
86 DWORD WINAPI
CoBuildVersion(void)
88 TRACE(ole
,"(void)\n");
92 /******************************************************************************
93 * CoInitialize16 [COMPOBJ.2]
94 * Set the win16 IMalloc used for memory management
96 HRESULT WINAPI
CoInitialize16(
97 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
99 currentMalloc16
= (LPMALLOC16
)lpReserved
;
103 /******************************************************************************
104 * CoInitialize32 [OLE32.26]
106 * Set the win32 IMalloc used for memorymanagement
109 * S_OK if successful, S_FALSE otherwise, RPC_E_CHANGED_MODE if a previous
110 * call to CoInitializeEx specified another threading model.
113 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
116 HRESULT WINAPI
CoInitialize32(
117 LPVOID lpReserved
/* [in] pointer to win32 malloc interface */
119 /* FIXME: there really should be something here that incrememts a refcount
120 * but I'm supposing that it is a real COM object, so I won't bother
121 * creating one here. (Decrement done in CoUnitialize()) */
122 currentMalloc32
= (LPMALLOC32
)lpReserved
;
126 /******************************************************************************
127 * CoInitializeEx32 [OLE32.163]
129 * Set the win32 IMalloc used for memory management
132 * S_OK if successful, S_FALSE otherwise, RPC_E_CHANGED_MODE if a previous
133 * call to CoInitializeEx specified another threading model.
136 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
139 HRESULT WINAPI
CoInitializeEx32(
140 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface */
141 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
143 if (dwCoInit
!=COINIT_APARTMENTTHREADED
) {
144 FIXME(ole
, ":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
145 /* Hope for the best and continue anyway */
147 return CoInitialize32(lpReserved
);
150 /***********************************************************************
151 * CoUnitialize [COMPOBJ.3]
152 * Don't know what it does.
153 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
154 * believe is the correct spelling
156 void WINAPI
CoUninitialize(void)
158 TRACE(ole
,"(void)\n");
159 CoFreeAllLibraries();
162 /***********************************************************************
163 * CoGetMalloc16 [COMPOBJ.4]
165 * The current win16 IMalloc
167 HRESULT WINAPI
CoGetMalloc16(
168 DWORD dwMemContext
, /* [in] unknown */
169 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
172 currentMalloc16
= IMalloc16_Constructor();
173 *lpMalloc
= currentMalloc16
;
177 /******************************************************************************
178 * CoGetMalloc32 [OLE32.20]
181 * The current win32 IMalloc
183 HRESULT WINAPI
CoGetMalloc32(
184 DWORD dwMemContext
, /* [in] unknown */
185 LPMALLOC32
*lpMalloc
/* [out] current win32 malloc interface */
188 currentMalloc32
= IMalloc32_Constructor();
189 *lpMalloc
= currentMalloc32
;
193 /***********************************************************************
194 * CoCreateStandardMalloc16 [COMPOBJ.71]
196 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
197 LPMALLOC16
*lpMalloc
)
199 /* FIXME: docu says we shouldn't return the same allocator as in
201 *lpMalloc
= IMalloc16_Constructor();
205 /******************************************************************************
206 * CoDisconnectObject [COMPOBJ.15]
208 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
210 TRACE(ole
,"%p %lx\n",lpUnk
,reserved
);
214 /***********************************************************************
215 * IsEqualGUID16 [COMPOBJ.18]
217 * Compares two Unique Identifiers.
222 BOOL16 WINAPI
IsEqualGUID16(
223 GUID
* g1
, /* [in] unique id 1 */
226 return !memcmp( g1
, g2
, sizeof(GUID
) );
229 /***********************************************************************
230 * IsEqualGUID32 [OLE32.76]
232 * Compares two Unique Identifiers.
237 BOOL32 WINAPI
IsEqualGUID32(
238 REFGUID rguid1
, /* [in] unique id 1 */
239 REFGUID rguid2
/* [in] unique id 2 */
242 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));
245 /******************************************************************************
246 * CLSIDFromString16 [COMPOBJ.20]
247 * Converts a unique identifier from it's string representation into
250 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
255 HRESULT WINAPI
CLSIDFromString16(
256 LPCOLESTR16 idstr
, /* [in] string representation of guid */
257 CLSID
*id
/* [out] GUID converted from string */
259 BYTE
*s
= (BYTE
*) idstr
;
264 TRACE(ole
,"%s -> %p\n", idstr
, id
);
266 /* quick lookup table */
267 memset(table
, 0, 256);
269 for (i
= 0; i
< 10; i
++) {
272 for (i
= 0; i
< 6; i
++) {
273 table
['A' + i
] = i
+10;
274 table
['a' + i
] = i
+10;
277 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
279 if (strlen(idstr
) != 38)
280 return OLE_ERROR_OBJECT
;
284 s
++; /* skip leading brace */
285 for (i
= 0; i
< 4; i
++) {
286 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
292 for (i
= 0; i
< 2; i
++) {
293 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
299 for (i
= 0; i
< 2; i
++) {
300 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
306 /* these are just sequential bytes */
307 for (i
= 0; i
< 2; i
++) {
308 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
313 for (i
= 0; i
< 6; i
++) {
314 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
321 /******************************************************************************
322 * CoCreateGuid[OLE32.6]
324 * Creates a 128bit GUID.
325 * Implemented according the DCE specification for UUID generation.
326 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
327 * Copyright (C) 1996, 1997 Theodore Ts'o.
331 * S_OK if successful.
333 HRESULT WINAPI
CoCreateGuid(
334 GUID
*pguid
/* [out] points to the GUID to initialize */
336 static char has_init
= 0;
338 static int adjustment
= 0;
339 static struct timeval last
= {0, 0};
340 static UINT16 clock_seq
;
342 unsigned long long clock_reg
;
343 UINT32 clock_high
, clock_low
;
344 UINT16 temp_clock_seq
, temp_clock_mid
, temp_clock_hi_and_version
;
347 struct ifreq ifr
, *ifrp
;
353 /* Have we already tried to get the MAC address? */
356 /* BSD 4.4 defines the size of an ifreq to be
357 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
358 * However, under earlier systems, sa_len isn't present, so
359 * the size is just sizeof(struct ifreq)
363 # define max(a,b) ((a) > (b) ? (a) : (b))
365 # define ifreq_size(i) max(sizeof(struct ifreq),\
366 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
368 # define ifreq_size(i) sizeof(struct ifreq)
369 # endif /* HAVE_SA_LEN */
371 sd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
373 /* if we can't open a socket, 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 memset(buf
, 0, sizeof(buf
));
383 ifc
.ifc_len
= sizeof(buf
);
385 /* get the ifconf interface */
386 if (ioctl (sd
, SIOCGIFCONF
, (char *)&ifc
) < 0) {
388 /* no ifconf, so just use random numbers */
389 /* set the multicast bit to prevent conflicts with real cards */
390 a
[0] = (rand() & 0xff) | 0x80;
391 a
[1] = rand() & 0xff;
392 a
[2] = rand() & 0xff;
393 a
[3] = rand() & 0xff;
394 a
[4] = rand() & 0xff;
395 a
[5] = rand() & 0xff;
397 /* loop through the interfaces, looking for a valid one */
399 for (i
= 0; i
< n
; i
+= ifreq_size(*ifr
) ) {
400 ifrp
= (struct ifreq
*)((char *) ifc
.ifc_buf
+i
);
401 strncpy(ifr
.ifr_name
, ifrp
->ifr_name
, IFNAMSIZ
);
402 /* try to get the address for this interface */
403 # ifdef SIOCGIFHWADDR
404 if (ioctl(sd
, SIOCGIFHWADDR
, &ifr
) < 0)
406 memcpy(a
, (unsigned char *)&ifr
.ifr_hwaddr
.sa_data
, 6);
409 if (ioctl(sd
, SIOCGENADDR
, &ifr
) < 0)
411 memcpy(a
, (unsigned char *) ifr
.ifr_enaddr
, 6);
413 /* XXX we don't have a way of getting the hardware address */
417 # endif /* SIOCGENADDR */
418 # endif /* SIOCGIFHWADDR */
419 /* make sure it's not blank */
420 if (!a
[0] && !a
[1] && !a
[2] && !a
[3] && !a
[4] && !a
[5])
425 /* if we didn't find a valid address, make a random one */
426 /* once again, set multicast bit to avoid conflicts */
427 a
[0] = (rand() & 0xff) | 0x80;
428 a
[1] = rand() & 0xff;
429 a
[2] = rand() & 0xff;
430 a
[3] = rand() & 0xff;
431 a
[4] = rand() & 0xff;
432 a
[5] = rand() & 0xff;
439 /* no networking info, so generate a random address */
440 a
[0] = (rand() & 0xff) | 0x80;
441 a
[1] = rand() & 0xff;
442 a
[2] = rand() & 0xff;
443 a
[3] = rand() & 0xff;
444 a
[4] = rand() & 0xff;
445 a
[5] = rand() & 0xff;
446 #endif /* HAVE_NET_IF_H */
450 /* generate time element of GUID */
452 /* Assume that the gettimeofday() has microsecond granularity */
453 #define MAX_ADJUSTMENT 10
456 gettimeofday(&tv
, 0);
457 if ((last
.tv_sec
== 0) && (last
.tv_usec
== 0)) {
458 clock_seq
= ((rand() & 0xff) << 8) + (rand() & 0xff);
463 if ((tv
.tv_sec
< last
.tv_sec
) ||
464 ((tv
.tv_sec
== last
.tv_sec
) &&
465 (tv
.tv_usec
< last
.tv_usec
))) {
466 clock_seq
= (clock_seq
+1) & 0x1FFF;
468 } else if ((tv
.tv_sec
== last
.tv_sec
) &&
469 (tv
.tv_usec
== last
.tv_usec
)) {
470 if (adjustment
>= MAX_ADJUSTMENT
)
476 clock_reg
= tv
.tv_usec
*10 + adjustment
;
477 clock_reg
+= ((unsigned long long) tv
.tv_sec
)*10000000;
478 clock_reg
+= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
480 clock_high
= clock_reg
>> 32;
481 clock_low
= clock_reg
;
482 temp_clock_seq
= clock_seq
| 0x8000;
483 temp_clock_mid
= (UINT16
)clock_high
;
484 temp_clock_hi_and_version
= (clock_high
>> 16) | 0x1000;
486 /* pack the information into the GUID structure */
488 ((unsigned char*)&pguid
->Data1
)[3] = (unsigned char)clock_low
;
490 ((unsigned char*)&pguid
->Data1
)[2] = (unsigned char)clock_low
;
492 ((unsigned char*)&pguid
->Data1
)[1] = (unsigned char)clock_low
;
494 ((unsigned char*)&pguid
->Data1
)[0] = (unsigned char)clock_low
;
496 ((unsigned char*)&pguid
->Data2
)[1] = (unsigned char)temp_clock_mid
;
497 temp_clock_mid
>>= 8;
498 ((unsigned char*)&pguid
->Data2
)[0] = (unsigned char)temp_clock_mid
;
500 ((unsigned char*)&pguid
->Data3
)[1] = (unsigned char)temp_clock_hi_and_version
;
501 temp_clock_hi_and_version
>>= 8;
502 ((unsigned char*)&pguid
->Data3
)[0] = (unsigned char)temp_clock_hi_and_version
;
504 ((unsigned char*)pguid
->Data4
)[1] = (unsigned char)temp_clock_seq
;
505 temp_clock_seq
>>= 8;
506 ((unsigned char*)pguid
->Data4
)[0] = (unsigned char)temp_clock_seq
;
508 ((unsigned char*)pguid
->Data4
)[2] = a
[0];
509 ((unsigned char*)pguid
->Data4
)[3] = a
[1];
510 ((unsigned char*)pguid
->Data4
)[4] = a
[2];
511 ((unsigned char*)pguid
->Data4
)[5] = a
[3];
512 ((unsigned char*)pguid
->Data4
)[6] = a
[4];
513 ((unsigned char*)pguid
->Data4
)[7] = a
[5];
515 TRACE(ole
, "%p", pguid
);
520 /******************************************************************************
521 * CLSIDFromString32 [OLE32.3]
522 * Converts a unique identifier from it's string representation into
527 HRESULT WINAPI
CLSIDFromString32(
528 LPCOLESTR32 idstr
, /* [in] string representation of GUID */
529 CLSID
*id
/* [out] GUID represented by above string */
531 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
532 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
534 HeapFree(GetProcessHeap(),0,xid
);
538 /******************************************************************************
539 * WINE_StringFromCLSID [???]
540 * Converts a GUID into the respective string representation.
545 * the string representation and OLESTATUS
547 HRESULT
WINE_StringFromCLSID(
548 const CLSID
*id
, /* [in] GUID to be converted */
549 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
551 static const char *hex
= "0123456789ABCDEF";
556 { ERR(ole
,"called with id=Null\n");
561 sprintf(idstr
, "{%08lX-%04X-%04X-%02x%02X-",
562 id
->Data1
, id
->Data2
, id
->Data3
,
563 id
->Data4
[0], id
->Data4
[1]);
567 for (i
= 2; i
< 8; i
++) {
568 *s
++ = hex
[id
->Data4
[i
]>>4];
569 *s
++ = hex
[id
->Data4
[i
] & 0xf];
575 TRACE(ole
,"%p->%s\n", id
, idstr
);
580 /******************************************************************************
581 * StringFromCLSID16 [COMPOBJ.19]
582 * Converts a GUID into the respective string representation.
583 * The target string is allocated using the OLE IMalloc.
585 * the string representation and OLESTATUS
587 HRESULT WINAPI
StringFromCLSID16(
588 const CLSID
*id
, /* [in] the GUID to be converted */
589 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
596 ret
= CoGetMalloc16(0,&mllc
);
599 args
[0] = (DWORD
)mllc
;
602 /* No need for a Callback entry, we have WOWCallback16Ex which does
603 * everything we need.
605 if (!WOWCallback16Ex(
606 (FARPROC16
)((ICOM_VTABLE(IMalloc16
)*)PTR_SEG_TO_LIN(
607 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
614 WARN(ole
,"CallTo16 IMalloc16 failed\n");
617 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
620 /******************************************************************************
621 * StringFromCLSID32 [OLE32.151]
622 * Converts a GUID into the respective string representation.
623 * The target string is allocated using the OLE IMalloc.
625 * the string representation and OLESTATUS
627 HRESULT WINAPI
StringFromCLSID32(
628 const CLSID
*id
, /* [in] the GUID to be converted */
629 LPOLESTR32
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
635 if ((ret
=CoGetMalloc32(0,&mllc
)))
638 ret
=WINE_StringFromCLSID(id
,buf
);
640 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
641 lstrcpyAtoW(*idstr
,buf
);
646 /******************************************************************************
647 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
649 * Converts a global unique identifier into a string of an API-
650 * specified fixed format. (The usual {.....} stuff.)
653 * The (UNICODE) string representation of the GUID in 'str'
654 * The length of the resulting string, 0 if there was any problem.
657 StringFromGUID2(REFGUID id
, LPOLESTR32 str
, INT32 cmax
)
661 if (WINE_StringFromCLSID(id
,xguid
))
663 if (strlen(xguid
)>=cmax
)
665 lstrcpyAtoW(str
,xguid
);
666 return strlen(xguid
);
669 /******************************************************************************
670 * CLSIDFromProgID16 [COMPOBJ.61]
671 * Converts a program id into the respective GUID. (By using a registry lookup)
673 * riid associated with the progid
675 HRESULT WINAPI
CLSIDFromProgID16(
676 LPCOLESTR16 progid
, /* [in] program id as found in registry */
677 LPCLSID riid
/* [out] associated CLSID */
684 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
685 sprintf(buf
,"%s\\CLSID",progid
);
686 if ((err
=RegOpenKey32A(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
687 HeapFree(GetProcessHeap(),0,buf
);
688 return OLE_ERROR_GENERIC
;
690 HeapFree(GetProcessHeap(),0,buf
);
691 buf2len
= sizeof(buf2
);
692 if ((err
=RegQueryValue32A(xhkey
,NULL
,buf2
,&buf2len
))) {
694 return OLE_ERROR_GENERIC
;
697 return CLSIDFromString16(buf2
,riid
);
700 /******************************************************************************
701 * CLSIDFromProgID32 [OLE32.2]
702 * Converts a program id into the respective GUID. (By using a registry lookup)
704 * riid associated with the progid
706 HRESULT WINAPI
CLSIDFromProgID32(
707 LPCOLESTR32 progid
, /* [in] program id as found in registry */
708 LPCLSID riid
/* [out] associated CLSID */
710 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
711 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
713 HeapFree(GetProcessHeap(),0,pid
);
717 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
718 /***********************************************************************
719 * LookupETask (COMPOBJ.94)
721 OLESTATUS WINAPI
LookupETask(HTASK16
*hTask
,LPVOID p
) {
722 FIXME(ole
,"(%p,%p),stub!\n",hTask
,p
);
723 if ((*hTask
= GetCurrentTask()) == hETask
) {
724 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
729 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
730 /***********************************************************************
731 * SetETask (COMPOBJ.95)
733 OLESTATUS WINAPI
SetETask(HTASK16 hTask
, LPVOID p
) {
734 FIXME(ole
,"(%04x,%p),stub!\n",hTask
,p
);
739 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
740 /***********************************************************************
741 * CallObjectInWOW (COMPOBJ.201)
743 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
744 FIXME(ole
,"(%p,%p),stub!\n",p1
,p2
);
748 /******************************************************************************
749 * CoRegisterClassObject16 [COMPOBJ.5]
751 * Don't know where it registers it ...
753 HRESULT WINAPI
CoRegisterClassObject16(
756 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
757 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
762 WINE_StringFromCLSID(rclsid
,buf
);
764 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
765 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
770 /******************************************************************************
771 * CoRegisterClassObject32 [OLE32.36]
773 * Don't know where it registers it ...
775 HRESULT WINAPI
CoRegisterClassObject32(
778 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
779 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
784 WINE_StringFromCLSID(rclsid
,buf
);
786 FIXME(ole
,"(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
787 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
792 /***********************************************************************
793 * CoRevokeClassObject [OLE32.40]
795 HRESULT WINAPI
CoRevokeClassObject(DWORD dwRegister
) {
796 FIXME(ole
,"(%08lx),stub!\n",dwRegister
);
800 /***********************************************************************
801 * CoGetClassObject [COMPOBJ.7]
803 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
804 LPVOID pvReserved
, const REFIID iid
, LPVOID
*ppv
)
806 char xclsid
[50],xiid
[50];
807 HRESULT hres
= E_UNEXPECTED
;
809 char dllName
[MAX_PATH
+1];
810 DWORD dllNameLen
= sizeof(dllName
);
811 HINSTANCE32 hLibrary
;
812 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
813 REFIID iid
, LPVOID
*ppv
);
814 DllGetClassObjectFunc DllGetClassObject
;
816 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
817 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
818 TRACE(ole
,"\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
820 /* out of process and remote servers not supported yet */
821 if ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
) {
822 FIXME(ole
, "CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
823 return E_ACCESSDENIED
;
826 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
829 /* lookup CLSID in registry key HKCR/CLSID */
830 hres
= RegOpenKeyEx32A(HKEY_CLASSES_ROOT
, "CLSID", 0,
831 KEY_READ
, &CLSIDkey
);
833 if (hres
!= ERROR_SUCCESS
)
834 return REGDB_E_READREGDB
;
835 hres
= RegOpenKeyEx32A(CLSIDkey
,xclsid
,0,KEY_QUERY_VALUE
,&key
);
836 if (hres
!= ERROR_SUCCESS
) {
837 RegCloseKey(CLSIDkey
);
838 return REGDB_E_CLASSNOTREG
;
840 hres
= RegQueryValue32A(key
, "InprocServer32", dllName
, &dllNameLen
);
842 RegCloseKey(CLSIDkey
);
843 if (hres
!= ERROR_SUCCESS
)
844 return REGDB_E_READREGDB
;
845 TRACE(ole
,"found InprocServer32 dll %s\n", dllName
);
847 /* open dll, call DllGetClassFactory */
848 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
850 TRACE(ole
,"couldn't load InprocServer32 dll %s\n", dllName
);
851 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
853 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress32(hLibrary
, "DllGetClassObject");
854 if (!DllGetClassObject
) {
855 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
856 TRACE(ole
,"couldn't find function DllGetClassObject in %s\n", dllName
);
857 return E_ACCESSDENIED
;
859 /* FIXME: Shouldn't we get a classfactory and use this to create
860 * the required object?
862 return DllGetClassObject(rclsid
, iid
, ppv
);
867 /******************************************************************************
868 * CoRegisterMessageFilter16 [COMPOBJ.27]
870 HRESULT WINAPI
CoRegisterMessageFilter16(
871 LPMESSAGEFILTER lpMessageFilter
,
872 LPMESSAGEFILTER
*lplpMessageFilter
874 FIXME(ole
,"(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
878 /***********************************************************************
879 * CoCreateInstance [COMPOBJ.13, OLE32.7]
881 HRESULT WINAPI
CoCreateInstance(
889 char buf
[80],xbuf
[80];
892 WINE_StringFromCLSID(rclsid
,buf
);
894 sprintf(buf
,"<rclsid-0x%08lx>",(DWORD
)rclsid
);
896 WINE_StringFromCLSID(iid
,xbuf
);
898 sprintf(xbuf
,"<iid-0x%08lx>",(DWORD
)iid
);
900 FIXME(ole
,"(%s,%p,0x%08lx,%s,%p): stub !\n",buf
,pUnkOuter
,dwClsContext
,xbuf
,ppv
);
904 LPCLASSFACTORY lpclf
= 0;
906 hres
= CoGetClassObject(rclsid
, dwClsContext
, NULL
, (const REFIID
) &IID_IClassFactory
, (LPVOID
)&lpclf
);
907 if (!SUCCEEDED(hres
)) return hres
;
908 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
909 IClassFactory_Release(lpclf
);
916 /***********************************************************************
917 * CoFreeLibrary [COMPOBJ.13]
919 void WINAPI
CoFreeLibrary(HINSTANCE32 hLibrary
)
924 /* lookup library in linked list */
926 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
927 if (ptr
->hLibrary
== hLibrary
) {
934 /* shouldn't happen if user passed in a valid hLibrary */
937 /* assert: ptr points to the library entry to free */
939 /* free library and remove node from list */
940 FreeLibrary32(hLibrary
);
941 if (ptr
== openDllList
) {
942 tmp
= openDllList
->next
;
943 HeapFree(GetProcessHeap(), 0, openDllList
->DllName
);
944 HeapFree(GetProcessHeap(), 0, openDllList
);
948 HeapFree(GetProcessHeap(), 0, ptr
->DllName
);
949 HeapFree(GetProcessHeap(), 0, ptr
);
956 /***********************************************************************
957 * CoFreeAllLibraries [COMPOBJ.12]
959 void WINAPI
CoFreeAllLibraries(void)
963 for (ptr
= openDllList
; ptr
!= NULL
; ) {
965 CoFreeLibrary(ptr
->hLibrary
);
972 /***********************************************************************
973 * CoFreeUnusedLibraries [COMPOBJ.17]
975 void WINAPI
CoFreeUnusedLibraries(void)
978 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
979 DllCanUnloadNowFunc DllCanUnloadNow
;
981 for (ptr
= openDllList
; ptr
!= NULL
; ) {
982 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
983 GetProcAddress32(ptr
->hLibrary
, "DllCanUnloadNow");
985 if (DllCanUnloadNow() == S_OK
) {
987 CoFreeLibrary(ptr
->hLibrary
);
995 /***********************************************************************
996 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
998 * the current system time in lpFileTime
1000 HRESULT WINAPI
CoFileTimeNow(
1001 FILETIME
*lpFileTime
/* [out] the current time */
1003 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
1007 /***********************************************************************
1008 * CoTaskMemAlloc (OLE32.43)
1010 * pointer to newly allocated block
1012 LPVOID WINAPI
CoTaskMemAlloc(
1013 ULONG size
/* [in] size of memoryblock to be allocated */
1015 LPMALLOC32 lpmalloc
;
1016 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
1020 return lpmalloc
->lpvtbl
->fnAlloc(lpmalloc
,size
);
1023 /***********************************************************************
1024 * CoTaskMemFree (OLE32.44)
1026 VOID WINAPI
CoTaskMemFree(
1027 LPVOID ptr
/* [in] pointer to be freed */
1029 LPMALLOC32 lpmalloc
;
1030 HRESULT ret
= CoGetMalloc32(0,&lpmalloc
);
1033 lpmalloc
->lpvtbl
->fnFree(lpmalloc
,ptr
);
1036 /***********************************************************************
1037 * CoLoadLibrary (OLE32.30)
1039 HINSTANCE32 WINAPI
CoLoadLibrary(LPOLESTR16 lpszLibName
, BOOL32 bAutoFree
)
1041 HINSTANCE32 hLibrary
;
1045 TRACE(ole
,"CoLoadLibrary(%p, %d\n", lpszLibName
, bAutoFree
);
1047 hLibrary
= LoadLibrary32A(lpszLibName
);
1052 if (openDllList
== NULL
) {
1053 /* empty list -- add first node */
1054 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1055 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1056 openDllList
->hLibrary
= hLibrary
;
1057 openDllList
->next
= NULL
;
1059 /* search for this dll */
1061 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1062 if (ptr
->hLibrary
== hLibrary
) {
1068 /* dll not found, add it */
1070 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1071 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1072 openDllList
->hLibrary
= hLibrary
;
1073 openDllList
->next
= tmp
;
1080 /***********************************************************************
1081 * CoInitializeWOW (OLE32.27)
1083 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1084 FIXME(ole
,"(0x%08lx,0x%08lx),stub!\n",x
,y
);
1088 /******************************************************************************
1089 * CoLockObjectExternal16 [COMPOBJ.63]
1091 HRESULT WINAPI
CoLockObjectExternal16(
1092 LPUNKNOWN pUnk
, /* [in] object to be locked */
1093 BOOL16 fLock
, /* [in] do lock */
1094 BOOL16 fLastUnlockReleases
/* [in] ? */
1096 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1100 /******************************************************************************
1101 * CoLockObjectExternal32 [OLE32.31]
1103 HRESULT WINAPI
CoLockObjectExternal32(
1104 LPUNKNOWN pUnk
, /* [in] object to be locked */
1105 BOOL32 fLock
, /* [in] do lock */
1106 BOOL32 fLastUnlockReleases
/* [in] ? */
1108 FIXME(ole
,"(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1112 /***********************************************************************
1113 * CoGetState16 [COMPOBJ.115]
1115 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1117 FIXME(ole
, "(%p),stub!\n", state
);
1121 /***********************************************************************
1122 * CoSetState32 [COM32.42]
1124 HRESULT WINAPI
CoSetState32(LPDWORD state
)
1126 FIXME(ole
, "(%p),stub!\n", state
);