4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
15 #include <sys/types.h>
18 #ifdef HAVE_SYS_FILE_H
19 # include <sys/file.h>
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
23 #ifdef HAVE_SYS_SOCKIO_H
24 # include <sys/sockio.h>
29 #ifdef HAVE_NETINET_IN_H
30 # include <netinet/in.h>
37 #include "wine/winbase16.h"
38 #include "wine/winestring.h"
42 #include "debugtools.h"
48 #include "wine/obj_base.h"
49 #include "wine/obj_misc.h"
50 #include "wine/obj_clientserver.h"
55 DEFAULT_DEBUG_CHANNEL(ole
)
56 /****************************************************************************
57 * COM External Lock structures and methods declaration
59 * This api provides a linked list to managed external references to
62 * The public interface consists of three calls:
63 * COM_ExternalLockAddRef
64 * COM_ExternalLockRelease
65 * COM_ExternalLockFreeList
68 #define EL_END_OF_LIST 0
69 #define EL_NOT_FOUND 0
72 * Declaration of the static structure that manage the
73 * external lock to COM objects.
75 typedef struct COM_ExternalLock COM_ExternalLock
;
76 typedef struct COM_ExternalLockList COM_ExternalLockList
;
78 struct COM_ExternalLock
80 IUnknown
*pUnk
; /* IUnknown referenced */
81 ULONG uRefCount
; /* external lock counter to IUnknown object*/
82 COM_ExternalLock
*next
; /* Pointer to next element in list */
85 struct COM_ExternalLockList
87 COM_ExternalLock
*head
; /* head of list */
91 * Declaration and initialization of the static structure that manages
92 * the external lock to COM objects.
94 static COM_ExternalLockList elList
= { EL_END_OF_LIST
};
97 * Public Interface to the external lock list
99 static void COM_ExternalLockFreeList();
100 static void COM_ExternalLockAddRef(IUnknown
*pUnk
);
101 static void COM_ExternalLockRelease(IUnknown
*pUnk
, BOOL bRelAll
);
102 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
105 * Private methods used to managed the linked list
107 static BOOL
COM_ExternalLockInsert(
110 static void COM_ExternalLockDelete(
111 COM_ExternalLock
*element
);
113 static COM_ExternalLock
* COM_ExternalLockFind(
116 static COM_ExternalLock
* COM_ExternalLockLocate(
117 COM_ExternalLock
*element
,
120 /****************************************************************************
121 * This section defines variables internal to the COM module.
123 * TODO: Most of these things will have to be made thread-safe.
125 HINSTANCE16 COMPOBJ_hInstance
= 0;
126 HINSTANCE COMPOBJ_hInstance32
= 0;
127 static int COMPOBJ_Attach
= 0;
129 LPMALLOC16 currentMalloc16
=NULL
;
130 LPMALLOC currentMalloc32
=NULL
;
133 WORD Table_ETask
[62];
136 * This lock count counts the number of times CoInitialize is called. It is
137 * decreased every time CoUninitialize is called. When it hits 0, the COM
138 * libraries are freed
140 static ULONG s_COMLockCount
= 0;
143 * This linked list contains the list of registered class objects. These
144 * are mostly used to register the factories for out-of-proc servers of OLE
147 * TODO: Make this data structure aware of inter-process communication. This
148 * means that parts of this will be exported to the Wine Server.
150 typedef struct tagRegisteredClass
152 CLSID classIdentifier
;
153 LPUNKNOWN classObject
;
157 struct tagRegisteredClass
* nextClass
;
160 static RegisteredClass
* firstRegisteredClass
= NULL
;
162 /* this open DLL table belongs in a per process table, but my guess is that
163 * it shouldn't live in the kernel, so I'll put them out here in DLL
164 * space assuming that there is one OLE32 per process.
166 typedef struct tagOpenDll
{
167 char *DllName
; /* really only needed for debugging */
169 struct tagOpenDll
*next
;
172 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
174 /*****************************************************************************
175 * This section contains prototypes to internal methods for this
178 static HRESULT
COM_GetRegisteredClassObject(REFCLSID rclsid
,
182 static void COM_RevokeAllClasses();
185 /******************************************************************************
186 * CoBuildVersion [COMPOBJ.1]
189 * Current built version, hiword is majornumber, loword is minornumber
191 DWORD WINAPI
CoBuildVersion(void)
194 return (rmm
<<16)+rup
;
197 /******************************************************************************
198 * CoInitialize16 [COMPOBJ.2]
199 * Set the win16 IMalloc used for memory management
201 HRESULT WINAPI
CoInitialize16(
202 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
204 currentMalloc16
= (LPMALLOC16
)lpReserved
;
208 /******************************************************************************
209 * CoInitialize32 [OLE32.26]
211 * Initializes the COM libraries.
213 * See CoInitializeEx32
215 HRESULT WINAPI
CoInitialize(
216 LPVOID lpReserved
/* [in] pointer to win32 malloc interface
217 (obsolete, should be NULL) */
221 * Just delegate to the newer method.
223 return CoInitializeEx(lpReserved
, COINIT_APARTMENTTHREADED
);
226 /******************************************************************************
227 * CoInitializeEx32 [OLE32.163]
229 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
230 * used for memory management is obsolete.
233 * S_OK if successful,
234 * S_FALSE if this function was called already.
235 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
239 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
242 * See the windows documentation for more details.
244 HRESULT WINAPI
CoInitializeEx(
245 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface
246 (obsolete, should be NULL) */
247 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
252 TRACE("(%p, %x)\n", lpReserved
, (int)dwCoInit
);
254 if (lpReserved
!=NULL
)
256 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved
, (int)dwCoInit
, lpReserved
);
260 * Check for unsupported features.
262 if (dwCoInit
!=COINIT_APARTMENTTHREADED
)
264 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
265 /* Hope for the best and continue anyway */
269 * Check the lock count. If this is the first time going through the initialize
270 * process, we have to initialize the libraries.
272 if (s_COMLockCount
==0)
275 * Initialize the various COM libraries and data structures.
277 TRACE("() - Initializing the COM libraries\n");
279 RunningObjectTableImpl_Initialize();
287 * Crank-up that lock count.
294 /***********************************************************************
295 * CoUninitialize16 [COMPOBJ.3]
296 * Don't know what it does.
297 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
298 * believe is the correct spelling
300 void WINAPI
CoUninitialize16(void)
303 CoFreeAllLibraries();
306 /***********************************************************************
307 * CoUninitialize32 [OLE32.47]
309 * This method will release the COM libraries.
311 * See the windows documentation for more details.
313 void WINAPI
CoUninitialize(void)
318 * Decrease the reference count.
323 * If we are back to 0 locks on the COM library, make sure we free
324 * all the associated data structures.
326 if (s_COMLockCount
==0)
329 * Release the various COM libraries and data structures.
331 TRACE("() - Releasing the COM libraries\n");
333 RunningObjectTableImpl_UnInitialize();
335 * Release the references to the registered class objects.
337 COM_RevokeAllClasses();
340 * This will free the loaded COM Dlls.
342 CoFreeAllLibraries();
345 * This will free list of external references to COM objects.
347 COM_ExternalLockFreeList();
351 /***********************************************************************
352 * CoGetMalloc16 [COMPOBJ.4]
354 * The current win16 IMalloc
356 HRESULT WINAPI
CoGetMalloc16(
357 DWORD dwMemContext
, /* [in] unknown */
358 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
361 currentMalloc16
= IMalloc16_Constructor();
362 *lpMalloc
= currentMalloc16
;
366 /******************************************************************************
367 * CoGetMalloc32 [OLE32.20]
370 * The current win32 IMalloc
372 HRESULT WINAPI
CoGetMalloc(
373 DWORD dwMemContext
, /* [in] unknown */
374 LPMALLOC
*lpMalloc
/* [out] current win32 malloc interface */
377 currentMalloc32
= IMalloc_Constructor();
378 *lpMalloc
= currentMalloc32
;
382 /***********************************************************************
383 * CoCreateStandardMalloc16 [COMPOBJ.71]
385 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
386 LPMALLOC16
*lpMalloc
)
388 /* FIXME: docu says we shouldn't return the same allocator as in
390 *lpMalloc
= IMalloc16_Constructor();
394 /******************************************************************************
395 * CoDisconnectObject [COMPOBJ.15]
397 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
399 TRACE("%p %lx\n",lpUnk
,reserved
);
403 /***********************************************************************
404 * IsEqualGUID16 [COMPOBJ.18]
406 * Compares two Unique Identifiers.
411 BOOL16 WINAPI
IsEqualGUID16(
412 GUID
* g1
, /* [in] unique id 1 */
415 return !memcmp( g1
, g2
, sizeof(GUID
) );
418 /***********************************************************************
419 * IsEqualGUID32 [OLE32.76]
421 * Compares two Unique Identifiers.
426 BOOL WINAPI
IsEqualGUID32(
427 REFGUID rguid1
, /* [in] unique id 1 */
428 REFGUID rguid2
/* [in] unique id 2 */
431 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));
434 /******************************************************************************
435 * CLSIDFromString16 [COMPOBJ.20]
436 * Converts a unique identifier from it's string representation into
439 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
444 HRESULT WINAPI
CLSIDFromString16(
445 LPCOLESTR16 idstr
, /* [in] string representation of guid */
446 CLSID
*id
/* [out] GUID converted from string */
448 BYTE
*s
= (BYTE
*) idstr
;
453 TRACE("%s -> %p\n", idstr
, id
);
455 /* quick lookup table */
456 memset(table
, 0, 256);
458 for (i
= 0; i
< 10; i
++) {
461 for (i
= 0; i
< 6; i
++) {
462 table
['A' + i
] = i
+10;
463 table
['a' + i
] = i
+10;
466 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
468 if (strlen(idstr
) != 38)
469 return OLE_ERROR_OBJECT
;
473 s
++; /* skip leading brace */
474 for (i
= 0; i
< 4; i
++) {
475 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
481 for (i
= 0; i
< 2; i
++) {
482 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
488 for (i
= 0; i
< 2; i
++) {
489 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
495 /* these are just sequential bytes */
496 for (i
= 0; i
< 2; i
++) {
497 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
502 for (i
= 0; i
< 6; i
++) {
503 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
510 /******************************************************************************
511 * CoCreateGuid[OLE32.6]
513 * Creates a 128bit GUID.
514 * Implemented according the DCE specification for UUID generation.
515 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
516 * Copyright (C) 1996, 1997 Theodore Ts'o.
520 * S_OK if successful.
522 HRESULT WINAPI
CoCreateGuid(
523 GUID
*pguid
/* [out] points to the GUID to initialize */
525 static char has_init
= 0;
527 static int adjustment
= 0;
528 static struct timeval last
= {0, 0};
529 static UINT16 clock_seq
;
531 unsigned long long clock_reg
;
532 UINT clock_high
, clock_low
;
533 UINT16 temp_clock_seq
, temp_clock_mid
, temp_clock_hi_and_version
;
536 struct ifreq ifr
, *ifrp
;
542 /* Have we already tried to get the MAC address? */
545 /* BSD 4.4 defines the size of an ifreq to be
546 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
547 * However, under earlier systems, sa_len isn't present, so
548 * the size is just sizeof(struct ifreq)
552 # define max(a,b) ((a) > (b) ? (a) : (b))
554 # define ifreq_size(i) max(sizeof(struct ifreq),\
555 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
557 # define ifreq_size(i) sizeof(struct ifreq)
558 # endif /* HAVE_SA_LEN */
560 sd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
562 /* if we can't open a socket, just use random numbers */
563 /* set the multicast bit to prevent conflicts with real cards */
564 a
[0] = (rand() & 0xff) | 0x80;
565 a
[1] = rand() & 0xff;
566 a
[2] = rand() & 0xff;
567 a
[3] = rand() & 0xff;
568 a
[4] = rand() & 0xff;
569 a
[5] = rand() & 0xff;
571 memset(buf
, 0, sizeof(buf
));
572 ifc
.ifc_len
= sizeof(buf
);
574 /* get the ifconf interface */
575 if (ioctl (sd
, SIOCGIFCONF
, (char *)&ifc
) < 0) {
577 /* no ifconf, so just use random numbers */
578 /* set the multicast bit to prevent conflicts with real cards */
579 a
[0] = (rand() & 0xff) | 0x80;
580 a
[1] = rand() & 0xff;
581 a
[2] = rand() & 0xff;
582 a
[3] = rand() & 0xff;
583 a
[4] = rand() & 0xff;
584 a
[5] = rand() & 0xff;
586 /* loop through the interfaces, looking for a valid one */
588 for (i
= 0; i
< n
; i
+= ifreq_size(*ifr
) ) {
589 ifrp
= (struct ifreq
*)((char *) ifc
.ifc_buf
+i
);
590 strncpy(ifr
.ifr_name
, ifrp
->ifr_name
, IFNAMSIZ
);
591 /* try to get the address for this interface */
592 # ifdef SIOCGIFHWADDR
593 if (ioctl(sd
, SIOCGIFHWADDR
, &ifr
) < 0)
595 memcpy(a
, (unsigned char *)&ifr
.ifr_hwaddr
.sa_data
, 6);
598 if (ioctl(sd
, SIOCGENADDR
, &ifr
) < 0)
600 memcpy(a
, (unsigned char *) ifr
.ifr_enaddr
, 6);
602 /* XXX we don't have a way of getting the hardware address */
606 # endif /* SIOCGENADDR */
607 # endif /* SIOCGIFHWADDR */
608 /* make sure it's not blank */
609 if (!a
[0] && !a
[1] && !a
[2] && !a
[3] && !a
[4] && !a
[5])
614 /* if we didn't find a valid address, make a random one */
615 /* once again, set multicast bit to avoid conflicts */
616 a
[0] = (rand() & 0xff) | 0x80;
617 a
[1] = rand() & 0xff;
618 a
[2] = rand() & 0xff;
619 a
[3] = rand() & 0xff;
620 a
[4] = rand() & 0xff;
621 a
[5] = rand() & 0xff;
628 /* no networking info, so generate a random address */
629 a
[0] = (rand() & 0xff) | 0x80;
630 a
[1] = rand() & 0xff;
631 a
[2] = rand() & 0xff;
632 a
[3] = rand() & 0xff;
633 a
[4] = rand() & 0xff;
634 a
[5] = rand() & 0xff;
635 #endif /* HAVE_NET_IF_H */
639 /* generate time element of GUID */
641 /* Assume that the gettimeofday() has microsecond granularity */
642 #define MAX_ADJUSTMENT 10
645 gettimeofday(&tv
, 0);
646 if ((last
.tv_sec
== 0) && (last
.tv_usec
== 0)) {
647 clock_seq
= ((rand() & 0xff) << 8) + (rand() & 0xff);
652 if ((tv
.tv_sec
< last
.tv_sec
) ||
653 ((tv
.tv_sec
== last
.tv_sec
) &&
654 (tv
.tv_usec
< last
.tv_usec
))) {
655 clock_seq
= (clock_seq
+1) & 0x1FFF;
657 } else if ((tv
.tv_sec
== last
.tv_sec
) &&
658 (tv
.tv_usec
== last
.tv_usec
)) {
659 if (adjustment
>= MAX_ADJUSTMENT
)
665 clock_reg
= tv
.tv_usec
*10 + adjustment
;
666 clock_reg
+= ((unsigned long long) tv
.tv_sec
)*10000000;
667 clock_reg
+= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
669 clock_high
= clock_reg
>> 32;
670 clock_low
= clock_reg
;
671 temp_clock_seq
= clock_seq
| 0x8000;
672 temp_clock_mid
= (UINT16
)clock_high
;
673 temp_clock_hi_and_version
= (clock_high
>> 16) | 0x1000;
675 /* pack the information into the GUID structure */
677 ((unsigned char*)&pguid
->Data1
)[3] = (unsigned char)clock_low
;
679 ((unsigned char*)&pguid
->Data1
)[2] = (unsigned char)clock_low
;
681 ((unsigned char*)&pguid
->Data1
)[1] = (unsigned char)clock_low
;
683 ((unsigned char*)&pguid
->Data1
)[0] = (unsigned char)clock_low
;
685 ((unsigned char*)&pguid
->Data2
)[1] = (unsigned char)temp_clock_mid
;
686 temp_clock_mid
>>= 8;
687 ((unsigned char*)&pguid
->Data2
)[0] = (unsigned char)temp_clock_mid
;
689 ((unsigned char*)&pguid
->Data3
)[1] = (unsigned char)temp_clock_hi_and_version
;
690 temp_clock_hi_and_version
>>= 8;
691 ((unsigned char*)&pguid
->Data3
)[0] = (unsigned char)temp_clock_hi_and_version
;
693 ((unsigned char*)pguid
->Data4
)[1] = (unsigned char)temp_clock_seq
;
694 temp_clock_seq
>>= 8;
695 ((unsigned char*)pguid
->Data4
)[0] = (unsigned char)temp_clock_seq
;
697 ((unsigned char*)pguid
->Data4
)[2] = a
[0];
698 ((unsigned char*)pguid
->Data4
)[3] = a
[1];
699 ((unsigned char*)pguid
->Data4
)[4] = a
[2];
700 ((unsigned char*)pguid
->Data4
)[5] = a
[3];
701 ((unsigned char*)pguid
->Data4
)[6] = a
[4];
702 ((unsigned char*)pguid
->Data4
)[7] = a
[5];
709 /******************************************************************************
710 * CLSIDFromString32 [OLE32.3]
711 * Converts a unique identifier from it's string representation into
716 HRESULT WINAPI
CLSIDFromString(
717 LPCOLESTR idstr
, /* [in] string representation of GUID */
718 CLSID
*id
/* [out] GUID represented by above string */
720 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
721 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
723 HeapFree(GetProcessHeap(),0,xid
);
727 /******************************************************************************
728 * WINE_StringFromCLSID [Internal]
729 * Converts a GUID into the respective string representation.
734 * the string representation and OLESTATUS
736 HRESULT
WINE_StringFromCLSID(
737 const CLSID
*id
, /* [in] GUID to be converted */
738 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
740 static const char *hex
= "0123456789ABCDEF";
745 { ERR("called with id=Null\n");
750 sprintf(idstr
, "{%08lX-%04X-%04X-%02X%02X-",
751 id
->Data1
, id
->Data2
, id
->Data3
,
752 id
->Data4
[0], id
->Data4
[1]);
756 for (i
= 2; i
< 8; i
++) {
757 *s
++ = hex
[id
->Data4
[i
]>>4];
758 *s
++ = hex
[id
->Data4
[i
] & 0xf];
764 TRACE("%p->%s\n", id
, idstr
);
769 /******************************************************************************
770 * StringFromCLSID16 [COMPOBJ.19]
771 * Converts a GUID into the respective string representation.
772 * The target string is allocated using the OLE IMalloc.
774 * the string representation and OLESTATUS
776 HRESULT WINAPI
StringFromCLSID16(
777 REFCLSID id
, /* [in] the GUID to be converted */
778 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
785 ret
= CoGetMalloc16(0,&mllc
);
788 args
[0] = (DWORD
)mllc
;
791 /* No need for a Callback entry, we have WOWCallback16Ex which does
792 * everything we need.
794 if (!WOWCallback16Ex(
795 (FARPROC16
)((ICOM_VTABLE(IMalloc16
)*)PTR_SEG_TO_LIN(
796 ((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))->lpvtbl
)
803 WARN("CallTo16 IMalloc16 failed\n");
806 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
809 /******************************************************************************
810 * StringFromCLSID32 [OLE32.151]
811 * Converts a GUID into the respective string representation.
812 * The target string is allocated using the OLE IMalloc.
814 * the string representation and OLESTATUS
816 HRESULT WINAPI
StringFromCLSID(
817 REFCLSID id
, /* [in] the GUID to be converted */
818 LPOLESTR
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
824 if ((ret
=CoGetMalloc(0,&mllc
)))
827 ret
=WINE_StringFromCLSID(id
,buf
);
829 *idstr
= mllc
->lpvtbl
->fnAlloc(mllc
,strlen(buf
)*2+2);
830 lstrcpyAtoW(*idstr
,buf
);
835 /******************************************************************************
836 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
838 * Converts a global unique identifier into a string of an API-
839 * specified fixed format. (The usual {.....} stuff.)
842 * The (UNICODE) string representation of the GUID in 'str'
843 * The length of the resulting string, 0 if there was any problem.
846 StringFromGUID2(REFGUID id
, LPOLESTR str
, INT cmax
)
850 if (WINE_StringFromCLSID(id
,xguid
))
852 if (strlen(xguid
)>=cmax
)
854 lstrcpyAtoW(str
,xguid
);
855 return strlen(xguid
);
858 /******************************************************************************
859 * CLSIDFromProgID16 [COMPOBJ.61]
860 * Converts a program id into the respective GUID. (By using a registry lookup)
862 * riid associated with the progid
864 HRESULT WINAPI
CLSIDFromProgID16(
865 LPCOLESTR16 progid
, /* [in] program id as found in registry */
866 LPCLSID riid
/* [out] associated CLSID */
873 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
874 sprintf(buf
,"%s\\CLSID",progid
);
875 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
876 HeapFree(GetProcessHeap(),0,buf
);
877 return OLE_ERROR_GENERIC
;
879 HeapFree(GetProcessHeap(),0,buf
);
880 buf2len
= sizeof(buf2
);
881 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
883 return OLE_ERROR_GENERIC
;
886 return CLSIDFromString16(buf2
,riid
);
889 /******************************************************************************
890 * CLSIDFromProgID32 [OLE32.2]
891 * Converts a program id into the respective GUID. (By using a registry lookup)
893 * riid associated with the progid
895 HRESULT WINAPI
CLSIDFromProgID(
896 LPCOLESTR progid
, /* [in] program id as found in registry */
897 LPCLSID riid
/* [out] associated CLSID */
899 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
900 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
902 HeapFree(GetProcessHeap(),0,pid
);
906 /************************************************************************************************
909 * This function write a CLSID on stream
911 HRESULT WINAPI
WriteClassStm(IStream
*pStm
,REFCLSID rclsid
)
913 TRACE("(%p,%p)\n",pStm
,rclsid
);
918 return IStream_Write(pStm
,rclsid
,sizeof(CLSID
),NULL
);
921 /************************************************************************************************
924 * This function read a CLSID from a stream
926 HRESULT WINAPI
ReadClassStm(IStream
*pStm
,REFCLSID rclsid
)
931 TRACE("(%p,%p)\n",pStm
,rclsid
);
936 res
= IStream_Read(pStm
,(void*)rclsid
,sizeof(CLSID
),&nbByte
);
941 if (nbByte
!= sizeof(CLSID
))
947 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
948 /***********************************************************************
949 * LookupETask (COMPOBJ.94)
951 OLESTATUS WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
952 FIXME("(%p,%p),stub!\n",hTask
,p
);
953 if ((*hTask
= GetCurrentTask()) == hETask
) {
954 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
959 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
960 /***********************************************************************
961 * SetETask (COMPOBJ.95)
963 OLESTATUS WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
964 FIXME("(%04x,%p),stub!\n",hTask
,p
);
969 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
970 /***********************************************************************
971 * CallObjectInWOW (COMPOBJ.201)
973 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
974 FIXME("(%p,%p),stub!\n",p1
,p2
);
978 /******************************************************************************
979 * CoRegisterClassObject16 [COMPOBJ.5]
981 * Don't know where it registers it ...
983 HRESULT WINAPI
CoRegisterClassObject16(
986 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
987 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
992 WINE_StringFromCLSID(rclsid
,buf
);
994 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
995 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
1001 /******************************************************************************
1002 * CoRevokeClassObject16 [COMPOBJ.6]
1005 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
/* token on class obj */)
1007 FIXME("(0x%08lx),stub!\n", dwRegister
);
1013 * COM_GetRegisteredClassObject
1015 * This internal method is used to scan the registered class list to
1016 * find a class object.
1019 * rclsid Class ID of the class to find.
1020 * dwClsContext Class context to match.
1021 * ppv [out] returns a pointer to the class object. Complying
1022 * to normal COM usage, this method will increase the
1023 * reference count on this object.
1025 static HRESULT
COM_GetRegisteredClassObject(
1030 RegisteredClass
* curClass
;
1038 * Iterate through the whole list and try to match the class ID.
1040 curClass
= firstRegisteredClass
;
1042 while (curClass
!= 0)
1045 * Check if we have a match on the class ID.
1047 if (IsEqualGUID32(&(curClass
->classIdentifier
), rclsid
))
1050 * Since we don't do out-of process or DCOM just right away, let's ignore the
1055 * We have a match, return the pointer to the class object.
1057 *ppUnk
= curClass
->classObject
;
1059 IUnknown_AddRef(curClass
->classObject
);
1065 * Step to the next class in the list.
1067 curClass
= curClass
->nextClass
;
1071 * If we get to here, we haven't found our class.
1076 /******************************************************************************
1077 * CoRegisterClassObject32 [OLE32.36]
1079 * This method will register the class object for a given class ID.
1081 * See the Windows documentation for more details.
1083 HRESULT WINAPI
CoRegisterClassObject(
1086 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
1087 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
1088 LPDWORD lpdwRegister
1091 RegisteredClass
* newClass
;
1092 LPUNKNOWN foundObject
;
1096 WINE_StringFromCLSID(rclsid
,buf
);
1098 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1099 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
);
1102 * Perform a sanity check on the parameters
1104 if ( (lpdwRegister
==0) || (pUnk
==0) )
1106 return E_INVALIDARG
;
1110 * Initialize the cookie (out parameter)
1115 * First, check if the class is already registered.
1116 * If it is, this should cause an error.
1118 hr
= COM_GetRegisteredClassObject(rclsid
, dwClsContext
, &foundObject
);
1123 * The COM_GetRegisteredClassObject increased the reference count on the
1124 * object so it has to be released.
1126 IUnknown_Release(foundObject
);
1128 return CO_E_OBJISREG
;
1132 * If it is not registered, we must create a new entry for this class and
1133 * append it to the registered class list.
1134 * We use the address of the chain node as the cookie since we are sure it's
1137 newClass
= HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass
));
1140 * Initialize the node.
1142 newClass
->classIdentifier
= *rclsid
;
1143 newClass
->runContext
= dwClsContext
;
1144 newClass
->connectFlags
= flags
;
1145 newClass
->dwCookie
= (DWORD
)newClass
;
1146 newClass
->nextClass
= firstRegisteredClass
;
1149 * Since we're making a copy of the object pointer, we have to increase it's
1152 newClass
->classObject
= pUnk
;
1153 IUnknown_AddRef(newClass
->classObject
);
1155 firstRegisteredClass
= newClass
;
1158 * Assign the out parameter (cookie)
1160 *lpdwRegister
= newClass
->dwCookie
;
1163 * We're successfyl Yippee!
1168 /***********************************************************************
1169 * CoRevokeClassObject32 [OLE32.40]
1171 * This method will remove a class object from the class registry
1173 * See the Windows documentation for more details.
1175 HRESULT WINAPI
CoRevokeClassObject(
1178 RegisteredClass
** prevClassLink
;
1179 RegisteredClass
* curClass
;
1181 TRACE("(%08lx)\n",dwRegister
);
1184 * Iterate through the whole list and try to match the cookie.
1186 curClass
= firstRegisteredClass
;
1187 prevClassLink
= &firstRegisteredClass
;
1189 while (curClass
!= 0)
1192 * Check if we have a match on the cookie.
1194 if (curClass
->dwCookie
== dwRegister
)
1197 * Remove the class from the chain.
1199 *prevClassLink
= curClass
->nextClass
;
1202 * Release the reference to the class object.
1204 IUnknown_Release(curClass
->classObject
);
1207 * Free the memory used by the chain node.
1209 HeapFree(GetProcessHeap(), 0, curClass
);
1215 * Step to the next class in the list.
1217 prevClassLink
= &(curClass
->nextClass
);
1218 curClass
= curClass
->nextClass
;
1222 * If we get to here, we haven't found our class.
1224 return E_INVALIDARG
;
1227 /***********************************************************************
1228 * CoGetClassObject [COMPOBJ.7]
1230 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
1231 LPVOID pvReserved
, REFIID iid
, LPVOID
*ppv
)
1233 LPUNKNOWN regClassObject
;
1234 char xclsid
[50],xiid
[50];
1235 HRESULT hres
= E_UNEXPECTED
;
1237 char dllName
[MAX_PATH
+1];
1238 DWORD dllNameLen
= sizeof(dllName
);
1240 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
1241 REFIID iid
, LPVOID
*ppv
);
1242 DllGetClassObjectFunc DllGetClassObject
;
1244 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
1245 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
1246 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
1249 * First, try and see if we can't match the class ID with one of the
1250 * registered classes.
1252 if (S_OK
== COM_GetRegisteredClassObject(rclsid
, dwClsContext
, ®ClassObject
))
1255 * Get the required interface from the retrieved pointer.
1257 hres
= IUnknown_QueryInterface(regClassObject
, iid
, ppv
);
1260 * Since QI got another reference on the pointer, we want to release the
1261 * one we already have. If QI was unsuccessful, this will release the object. This
1262 * is good since we are not returning it in the "out" parameter.
1264 IUnknown_Release(regClassObject
);
1269 /* out of process and remote servers not supported yet */
1270 if ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
) {
1271 FIXME("CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
1272 return E_ACCESSDENIED
;
1275 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
1278 /* lookup CLSID in registry key HKCR/CLSID */
1279 hres
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0,
1280 KEY_READ
, &CLSIDkey
);
1282 if (hres
!= ERROR_SUCCESS
)
1283 return REGDB_E_READREGDB
;
1284 hres
= RegOpenKeyExA(CLSIDkey
,xclsid
,0,KEY_QUERY_VALUE
,&key
);
1285 if (hres
!= ERROR_SUCCESS
) {
1286 RegCloseKey(CLSIDkey
);
1287 return REGDB_E_CLASSNOTREG
;
1289 hres
= RegQueryValueA(key
, "InprocServer32", dllName
, &dllNameLen
);
1291 RegCloseKey(CLSIDkey
);
1292 if (hres
!= ERROR_SUCCESS
)
1293 return REGDB_E_READREGDB
;
1294 TRACE("found InprocServer32 dll %s\n", dllName
);
1296 /* open dll, call DllGetClassFactory */
1297 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
1298 if (hLibrary
== 0) {
1299 TRACE("couldn't load InprocServer32 dll %s\n", dllName
);
1300 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
1302 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject");
1303 if (!DllGetClassObject
) {
1304 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1305 TRACE("couldn't find function DllGetClassObject in %s\n", dllName
);
1306 return E_ACCESSDENIED
;
1310 * Ask the DLL for it's class object. (there was a note here about class
1311 * factories but this is good.
1313 return DllGetClassObject(rclsid
, iid
, ppv
);
1318 /****************************************************************************************
1321 * This function supplies the CLSID associated with the given filename.
1323 HRESULT WINAPI
GetClassFile(LPOLESTR filePathName
,CLSID
*pclsid
)
1327 int nbElm
=0,length
=0,i
=0;
1329 LPOLESTR
*pathDec
=0,absFile
=0,progId
=0;
1330 WCHAR extention
[100]={0};
1334 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1335 if((StgIsStorageFile(filePathName
))==S_OK
){
1337 res
=StgOpenStorage(filePathName
,NULL
,STGM_READ
| STGM_SHARE_DENY_WRITE
,NULL
,0,&pstg
);
1340 res
=ReadClassStg(pstg
,pclsid
);
1342 IStorage_Release(pstg
);
1346 /* if the file is not a storage object then attemps to match various bits in the file against a
1347 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1350 for(i=0;i<nFileTypes;i++)
1352 for(i=0;j<nPatternsForType;j++){
1357 pat=ReadPatternFromRegistry(i,j);
1358 hFile=CreateFileW(filePathName,,,,,,hFile);
1359 SetFilePosition(hFile,pat.offset);
1360 ReadFile(hFile,buf,pat.size,NULL,NULL);
1361 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1363 *pclsid=ReadCLSIDFromRegistry(i);
1369 /* if the obove strategies fail then search for the extension key in the registry */
1371 /* get the last element (absolute file) in the path name */
1372 nbElm
=FileMonikerImpl_DecomposePath(filePathName
,&pathDec
);
1373 absFile
=pathDec
[nbElm
-1];
1375 /* failed if the path represente a directory and not an absolute file name*/
1376 if (lstrcmpW(absFile
,(LPOLESTR
)"\\"))
1377 return MK_E_INVALIDEXTENSION
;
1379 /* get the extension of the file */
1380 length
=lstrlenW(absFile
);
1381 for(i
=length
-1; ( (i
>=0) && (extention
[i
]=absFile
[i
]) );i
--);
1383 /* get the progId associated to the extension */
1384 progId
=CoTaskMemAlloc(sizeProgId
);
1386 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1388 if (res
==ERROR_MORE_DATA
){
1390 CoTaskMemRealloc(progId
,sizeProgId
);
1392 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1394 if (res
==ERROR_SUCCESS
)
1395 /* return the clsid associated to the progId */
1396 res
= CLSIDFromProgID(progId
,pclsid
);
1398 for(i
=0; pathDec
[i
]!=NULL
;i
++)
1399 CoTaskMemFree(pathDec
[i
]);
1400 CoTaskMemFree(pathDec
);
1402 CoTaskMemFree(progId
);
1404 if (res
==ERROR_SUCCESS
)
1407 return MK_E_INVALIDEXTENSION
;
1409 /******************************************************************************
1410 * CoRegisterMessageFilter16 [COMPOBJ.27]
1412 HRESULT WINAPI
CoRegisterMessageFilter16(
1413 LPMESSAGEFILTER lpMessageFilter
,
1414 LPMESSAGEFILTER
*lplpMessageFilter
1416 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
1420 /***********************************************************************
1421 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1423 HRESULT WINAPI
CoCreateInstance(
1425 LPUNKNOWN pUnkOuter
,
1431 LPCLASSFACTORY lpclf
= 0;
1440 * Initialize the "out" parameter
1445 * Get a class factory to construct the object we want.
1447 hres
= CoGetClassObject(rclsid
,
1457 * Create the object and don't forget to release the factory
1459 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
1460 IClassFactory_Release(lpclf
);
1465 /***********************************************************************
1466 * CoCreateInstanceEx [OLE32.165]
1468 HRESULT WINAPI
CoCreateInstanceEx(
1470 LPUNKNOWN pUnkOuter
,
1472 COSERVERINFO
* pServerInfo
,
1476 IUnknown
* pUnk
= NULL
;
1479 int successCount
= 0;
1484 if ( (cmq
==0) || (pResults
==NULL
))
1485 return E_INVALIDARG
;
1487 if (pServerInfo
!=NULL
)
1488 FIXME("() non-NULL pServerInfo not supported!\n");
1491 * Initialize all the "out" parameters.
1493 for (index
= 0; index
< cmq
; index
++)
1495 pResults
[index
].pItf
= NULL
;
1496 pResults
[index
].hr
= E_NOINTERFACE
;
1500 * Get the object and get it's IUnknown pointer.
1502 hr
= CoCreateInstance(rclsid
,
1512 * Then, query for all the interfaces requested.
1514 for (index
= 0; index
< cmq
; index
++)
1516 pResults
[index
].hr
= IUnknown_QueryInterface(pUnk
,
1517 pResults
[index
].pIID
,
1518 (VOID
**)&(pResults
[index
].pItf
));
1520 if (pResults
[index
].hr
== S_OK
)
1525 * Release our temporary unknown pointer.
1527 IUnknown_Release(pUnk
);
1529 if (successCount
== 0)
1530 return E_NOINTERFACE
;
1532 if (successCount
!=cmq
)
1533 return CO_S_NOTALLINTERFACES
;
1538 /***********************************************************************
1539 * CoFreeLibrary [COMPOBJ.13]
1541 void WINAPI
CoFreeLibrary(HINSTANCE hLibrary
)
1543 OpenDll
*ptr
, *prev
;
1546 /* lookup library in linked list */
1548 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
1549 if (ptr
->hLibrary
== hLibrary
) {
1556 /* shouldn't happen if user passed in a valid hLibrary */
1559 /* assert: ptr points to the library entry to free */
1561 /* free library and remove node from list */
1562 FreeLibrary(hLibrary
);
1563 if (ptr
== openDllList
) {
1564 tmp
= openDllList
->next
;
1565 HeapFree(GetProcessHeap(), 0, openDllList
->DllName
);
1566 HeapFree(GetProcessHeap(), 0, openDllList
);
1570 HeapFree(GetProcessHeap(), 0, ptr
->DllName
);
1571 HeapFree(GetProcessHeap(), 0, ptr
);
1578 /***********************************************************************
1579 * CoFreeAllLibraries [COMPOBJ.12]
1581 void WINAPI
CoFreeAllLibraries(void)
1585 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1587 CoFreeLibrary(ptr
->hLibrary
);
1594 /***********************************************************************
1595 * CoFreeUnusedLibraries [COMPOBJ.17]
1597 void WINAPI
CoFreeUnusedLibraries(void)
1600 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
1601 DllCanUnloadNowFunc DllCanUnloadNow
;
1603 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1604 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
1605 GetProcAddress(ptr
->hLibrary
, "DllCanUnloadNow");
1607 if ( (DllCanUnloadNow
!= NULL
) &&
1608 (DllCanUnloadNow() == S_OK
) ) {
1610 CoFreeLibrary(ptr
->hLibrary
);
1618 /***********************************************************************
1619 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1621 * the current system time in lpFileTime
1623 HRESULT WINAPI
CoFileTimeNow(
1624 FILETIME
*lpFileTime
/* [out] the current time */
1626 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
1630 /***********************************************************************
1631 * CoTaskMemAlloc (OLE32.43)
1633 * pointer to newly allocated block
1635 LPVOID WINAPI
CoTaskMemAlloc(
1636 ULONG size
/* [in] size of memoryblock to be allocated */
1639 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1644 return IMalloc_Alloc(lpmalloc
,size
);
1646 /***********************************************************************
1647 * CoTaskMemFree (OLE32.44)
1649 VOID WINAPI
CoTaskMemFree(
1650 LPVOID ptr
/* [in] pointer to be freed */
1653 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1658 IMalloc_Free(lpmalloc
, ptr
);
1661 /***********************************************************************
1662 * CoTaskMemRealloc (OLE32.45)
1664 * pointer to newly allocated block
1666 LPVOID WINAPI
CoTaskMemRealloc(
1668 ULONG size
) /* [in] size of memoryblock to be allocated */
1671 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1676 return IMalloc_Realloc(lpmalloc
, pvOld
, size
);
1679 /***********************************************************************
1680 * CoLoadLibrary (OLE32.30)
1682 HINSTANCE WINAPI
CoLoadLibrary(LPOLESTR16 lpszLibName
, BOOL bAutoFree
)
1688 TRACE("CoLoadLibrary(%p, %d\n", lpszLibName
, bAutoFree
);
1690 hLibrary
= LoadLibraryExA(lpszLibName
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
1695 if (openDllList
== NULL
) {
1696 /* empty list -- add first node */
1697 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1698 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1699 openDllList
->hLibrary
= hLibrary
;
1700 openDllList
->next
= NULL
;
1702 /* search for this dll */
1704 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1705 if (ptr
->hLibrary
== hLibrary
) {
1711 /* dll not found, add it */
1713 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1714 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1715 openDllList
->hLibrary
= hLibrary
;
1716 openDllList
->next
= tmp
;
1723 /***********************************************************************
1724 * CoInitializeWOW (OLE32.27)
1726 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1727 FIXME("(0x%08lx,0x%08lx),stub!\n",x
,y
);
1731 /******************************************************************************
1732 * CoLockObjectExternal16 [COMPOBJ.63]
1734 HRESULT WINAPI
CoLockObjectExternal16(
1735 LPUNKNOWN pUnk
, /* [in] object to be locked */
1736 BOOL16 fLock
, /* [in] do lock */
1737 BOOL16 fLastUnlockReleases
/* [in] ? */
1739 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1743 /******************************************************************************
1744 * CoLockObjectExternal32 [OLE32.31]
1746 HRESULT WINAPI
CoLockObjectExternal(
1747 LPUNKNOWN pUnk
, /* [in] object to be locked */
1748 BOOL fLock
, /* [in] do lock */
1749 BOOL fLastUnlockReleases
) /* [in] unlock all */
1755 * Increment the external lock coutner, COM_ExternalLockAddRef also
1756 * increment the object's internal lock counter.
1758 COM_ExternalLockAddRef( pUnk
);
1763 * Decrement the external lock coutner, COM_ExternalLockRelease also
1764 * decrement the object's internal lock counter.
1766 COM_ExternalLockRelease( pUnk
, fLastUnlockReleases
);
1772 /***********************************************************************
1773 * CoGetState16 [COMPOBJ.115]
1775 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1777 FIXME("(%p),stub!\n", state
);
1781 /***********************************************************************
1782 * CoSetState32 [COM32.42]
1784 HRESULT WINAPI
CoSetState(LPDWORD state
)
1786 FIXME("(%p),stub!\n", state
);
1787 if (state
) *state
= 0;
1792 * COM_RevokeAllClasses
1794 * This method is called when the COM libraries are uninitialized to
1795 * release all the references to the class objects registered with
1798 static void COM_RevokeAllClasses()
1800 while (firstRegisteredClass
!=0)
1802 CoRevokeClassObject(firstRegisteredClass
->dwCookie
);
1806 /****************************************************************************
1807 * COM External Lock methods implementation
1810 /****************************************************************************
1811 * Public - Method that increments the count for a IUnknown* in the linked
1812 * list. The item is inserted if not already in the list.
1814 static void COM_ExternalLockAddRef(
1817 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1820 * Add an external lock to the object. If it was already externally
1821 * locked, just increase the reference count. If it was not.
1822 * add the item to the list.
1824 if ( externalLock
== EL_NOT_FOUND
)
1825 COM_ExternalLockInsert(pUnk
);
1827 externalLock
->uRefCount
++;
1830 * Add an internal lock to the object
1832 IUnknown_AddRef(pUnk
);
1835 /****************************************************************************
1836 * Public - Method that decrements the count for a IUnknown* in the linked
1837 * list. The item is removed from the list if its count end up at zero or if
1840 static void COM_ExternalLockRelease(
1844 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1846 if ( externalLock
!= EL_NOT_FOUND
)
1850 externalLock
->uRefCount
--; /* release external locks */
1851 IUnknown_Release(pUnk
); /* release local locks as well */
1853 if ( bRelAll
== FALSE
)
1854 break; /* perform single release */
1856 } while ( externalLock
->uRefCount
> 0 );
1858 if ( externalLock
->uRefCount
== 0 ) /* get rid of the list entry */
1859 COM_ExternalLockDelete(externalLock
);
1862 /****************************************************************************
1863 * Public - Method that frees the content of the list.
1865 static void COM_ExternalLockFreeList()
1867 COM_ExternalLock
*head
;
1869 head
= elList
.head
; /* grab it by the head */
1870 while ( head
!= EL_END_OF_LIST
)
1872 COM_ExternalLockDelete(head
); /* get rid of the head stuff */
1874 head
= elList
.head
; /* get the new head... */
1878 /****************************************************************************
1879 * Public - Method that dump the content of the list.
1881 void COM_ExternalLockDump()
1883 COM_ExternalLock
*current
= elList
.head
;
1885 printf("\nExternal lock list contains:\n");
1887 while ( current
!= EL_END_OF_LIST
)
1889 printf( "\t%p with %lu references count.\n",
1891 current
->uRefCount
);
1893 /* Skip to the next item */
1894 current
= current
->next
;
1899 /****************************************************************************
1900 * Internal - Find a IUnknown* in the linked list
1902 static COM_ExternalLock
* COM_ExternalLockFind(
1905 return COM_ExternalLockLocate(elList
.head
, pUnk
);
1908 /****************************************************************************
1909 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1911 static COM_ExternalLock
* COM_ExternalLockLocate(
1912 COM_ExternalLock
*element
,
1915 if ( element
== EL_END_OF_LIST
)
1916 return EL_NOT_FOUND
;
1918 else if ( element
->pUnk
== pUnk
) /* We found it */
1921 else /* Not the right guy, keep on looking */
1922 return COM_ExternalLockLocate( element
->next
, pUnk
);
1925 /****************************************************************************
1926 * Internal - Insert a new IUnknown* to the linked list
1928 static BOOL
COM_ExternalLockInsert(
1931 COM_ExternalLock
*newLock
= NULL
;
1932 COM_ExternalLock
*previousHead
= NULL
;
1935 * Allocate space for the new storage object
1937 newLock
= HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock
));
1941 if ( elList
.head
== EL_END_OF_LIST
)
1943 elList
.head
= newLock
; /* The list is empty */
1948 * insert does it at the head
1950 previousHead
= elList
.head
;
1951 elList
.head
= newLock
;
1955 * Set new list item data member
1957 newLock
->pUnk
= pUnk
;
1958 newLock
->uRefCount
= 1;
1959 newLock
->next
= previousHead
;
1967 /****************************************************************************
1968 * Internal - Method that removes an item from the linked list.
1970 static void COM_ExternalLockDelete(
1971 COM_ExternalLock
*itemList
)
1973 COM_ExternalLock
*current
= elList
.head
;
1975 if ( current
== itemList
)
1978 * this section handles the deletion of the first node
1980 elList
.head
= itemList
->next
;
1981 HeapFree( GetProcessHeap(), 0, itemList
);
1987 if ( current
->next
== itemList
) /* We found the item to free */
1989 current
->next
= itemList
->next
; /* readjust the list pointers */
1991 HeapFree( GetProcessHeap(), 0, itemList
);
1995 /* Skip to the next item */
1996 current
= current
->next
;
1998 } while ( current
!= EL_END_OF_LIST
);
2002 /***********************************************************************
2003 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
2005 * Initialization code for the COMPOBJ DLL
2009 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
2011 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
,
2015 case DLL_PROCESS_ATTACH
:
2017 if(COMPOBJ_hInstance
)
2019 ERR("compobj.dll instantiated twice!\n");
2021 * We should return FALSE here, but that will break
2022 * most apps that use CreateProcess because we do
2023 * not yet support seperate address-spaces.
2028 COMPOBJ_hInstance
= hInst
;
2031 case DLL_PROCESS_DETACH
:
2032 if(!--COMPOBJ_Attach
)
2033 COMPOBJ_hInstance
= 0;