4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
14 #include <sys/types.h>
17 #ifdef HAVE_SYS_FILE_H
18 # include <sys/file.h>
20 #include <sys/ioctl.h>
21 #ifdef HAVE_SYS_SOCKET_H
22 # include <sys/socket.h>
24 #ifdef HAVE_SYS_SOCKIO_H
25 # include <sys/sockio.h>
30 #ifdef HAVE_NETINET_IN_H
31 # include <netinet/in.h>
38 #include "wine/winbase16.h"
43 #include "debugtools.h"
49 #include "wine/obj_base.h"
50 #include "wine/obj_misc.h"
51 #include "wine/obj_storage.h"
52 #include "wine/obj_clientserver.h"
57 DEFAULT_DEBUG_CHANNEL(ole
)
58 /****************************************************************************
59 * COM External Lock structures and methods declaration
61 * This api provides a linked list to managed external references to
64 * The public interface consists of three calls:
65 * COM_ExternalLockAddRef
66 * COM_ExternalLockRelease
67 * COM_ExternalLockFreeList
70 #define EL_END_OF_LIST 0
71 #define EL_NOT_FOUND 0
74 * Declaration of the static structure that manage the
75 * external lock to COM objects.
77 typedef struct COM_ExternalLock COM_ExternalLock
;
78 typedef struct COM_ExternalLockList COM_ExternalLockList
;
80 struct COM_ExternalLock
82 IUnknown
*pUnk
; /* IUnknown referenced */
83 ULONG uRefCount
; /* external lock counter to IUnknown object*/
84 COM_ExternalLock
*next
; /* Pointer to next element in list */
87 struct COM_ExternalLockList
89 COM_ExternalLock
*head
; /* head of list */
93 * Declaration and initialization of the static structure that manages
94 * the external lock to COM objects.
96 static COM_ExternalLockList elList
= { EL_END_OF_LIST
};
99 * Public Interface to the external lock list
101 static void COM_ExternalLockFreeList();
102 static void COM_ExternalLockAddRef(IUnknown
*pUnk
);
103 static void COM_ExternalLockRelease(IUnknown
*pUnk
, BOOL bRelAll
);
104 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
107 * Private methods used to managed the linked list
109 static BOOL
COM_ExternalLockInsert(
112 static void COM_ExternalLockDelete(
113 COM_ExternalLock
*element
);
115 static COM_ExternalLock
* COM_ExternalLockFind(
118 static COM_ExternalLock
* COM_ExternalLockLocate(
119 COM_ExternalLock
*element
,
122 /****************************************************************************
123 * This section defines variables internal to the COM module.
125 * TODO: Most of these things will have to be made thread-safe.
127 HINSTANCE16 COMPOBJ_hInstance
= 0;
128 HINSTANCE COMPOBJ_hInstance32
= 0;
129 static int COMPOBJ_Attach
= 0;
131 LPMALLOC16 currentMalloc16
=NULL
;
132 LPMALLOC currentMalloc32
=NULL
;
135 WORD Table_ETask
[62];
138 * This lock count counts the number of times CoInitialize is called. It is
139 * decreased every time CoUninitialize is called. When it hits 0, the COM
140 * libraries are freed
142 static ULONG s_COMLockCount
= 0;
145 * This linked list contains the list of registered class objects. These
146 * are mostly used to register the factories for out-of-proc servers of OLE
149 * TODO: Make this data structure aware of inter-process communication. This
150 * means that parts of this will be exported to the Wine Server.
152 typedef struct tagRegisteredClass
154 CLSID classIdentifier
;
155 LPUNKNOWN classObject
;
159 struct tagRegisteredClass
* nextClass
;
162 static RegisteredClass
* firstRegisteredClass
= NULL
;
164 /* this open DLL table belongs in a per process table, but my guess is that
165 * it shouldn't live in the kernel, so I'll put them out here in DLL
166 * space assuming that there is one OLE32 per process.
168 typedef struct tagOpenDll
{
169 char *DllName
; /* really only needed for debugging */
171 struct tagOpenDll
*next
;
174 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
176 /*****************************************************************************
177 * This section contains prototypes to internal methods for this
180 static HRESULT
COM_GetRegisteredClassObject(REFCLSID rclsid
,
184 static void COM_RevokeAllClasses();
187 /******************************************************************************
188 * CoBuildVersion [COMPOBJ.1]
191 * Current built version, hiword is majornumber, loword is minornumber
193 DWORD WINAPI
CoBuildVersion(void)
196 return (rmm
<<16)+rup
;
199 /******************************************************************************
200 * CoInitialize16 [COMPOBJ.2]
201 * Set the win16 IMalloc used for memory management
203 HRESULT WINAPI
CoInitialize16(
204 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
206 currentMalloc16
= (LPMALLOC16
)lpReserved
;
210 /******************************************************************************
211 * CoInitialize32 [OLE32.26]
213 * Initializes the COM libraries.
215 * See CoInitializeEx32
217 HRESULT WINAPI
CoInitialize(
218 LPVOID lpReserved
/* [in] pointer to win32 malloc interface
219 (obsolete, should be NULL) */
223 * Just delegate to the newer method.
225 return CoInitializeEx(lpReserved
, COINIT_APARTMENTTHREADED
);
228 /******************************************************************************
229 * CoInitializeEx32 [OLE32.163]
231 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
232 * used for memory management is obsolete.
235 * S_OK if successful,
236 * S_FALSE if this function was called already.
237 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
241 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
244 * See the windows documentation for more details.
246 HRESULT WINAPI
CoInitializeEx(
247 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface
248 (obsolete, should be NULL) */
249 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
254 TRACE("(%p, %x)\n", lpReserved
, (int)dwCoInit
);
256 if (lpReserved
!=NULL
)
258 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved
, (int)dwCoInit
, lpReserved
);
262 * Check for unsupported features.
264 if (dwCoInit
!=COINIT_APARTMENTTHREADED
)
266 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
267 /* Hope for the best and continue anyway */
271 * Check the lock count. If this is the first time going through the initialize
272 * process, we have to initialize the libraries.
274 if (s_COMLockCount
==0)
277 * Initialize the various COM libraries and data structures.
279 TRACE("() - Initializing the COM libraries\n");
281 RunningObjectTableImpl_Initialize();
289 * Crank-up that lock count.
296 /***********************************************************************
297 * CoUninitialize16 [COMPOBJ.3]
298 * Don't know what it does.
299 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
300 * believe is the correct spelling
302 void WINAPI
CoUninitialize16(void)
305 CoFreeAllLibraries();
308 /***********************************************************************
309 * CoUninitialize32 [OLE32.47]
311 * This method will release the COM libraries.
313 * See the windows documentation for more details.
315 void WINAPI
CoUninitialize(void)
320 * Decrease the reference count.
325 * If we are back to 0 locks on the COM library, make sure we free
326 * all the associated data structures.
328 if (s_COMLockCount
==0)
331 * Release the various COM libraries and data structures.
333 TRACE("() - Releasing the COM libraries\n");
335 RunningObjectTableImpl_UnInitialize();
337 * Release the references to the registered class objects.
339 COM_RevokeAllClasses();
342 * This will free the loaded COM Dlls.
344 CoFreeAllLibraries();
347 * This will free list of external references to COM objects.
349 COM_ExternalLockFreeList();
353 /***********************************************************************
354 * CoGetMalloc16 [COMPOBJ.4]
356 * The current win16 IMalloc
358 HRESULT WINAPI
CoGetMalloc16(
359 DWORD dwMemContext
, /* [in] unknown */
360 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
363 currentMalloc16
= IMalloc16_Constructor();
364 *lpMalloc
= currentMalloc16
;
368 /******************************************************************************
369 * CoGetMalloc32 [OLE32.20]
372 * The current win32 IMalloc
374 HRESULT WINAPI
CoGetMalloc(
375 DWORD dwMemContext
, /* [in] unknown */
376 LPMALLOC
*lpMalloc
/* [out] current win32 malloc interface */
379 currentMalloc32
= IMalloc_Constructor();
380 *lpMalloc
= currentMalloc32
;
384 /***********************************************************************
385 * CoCreateStandardMalloc16 [COMPOBJ.71]
387 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
388 LPMALLOC16
*lpMalloc
)
390 /* FIXME: docu says we shouldn't return the same allocator as in
392 *lpMalloc
= IMalloc16_Constructor();
396 /******************************************************************************
397 * CoDisconnectObject [COMPOBJ.15]
399 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
401 TRACE("%p %lx\n",lpUnk
,reserved
);
405 /***********************************************************************
406 * IsEqualGUID16 [COMPOBJ.18]
408 * Compares two Unique Identifiers.
413 BOOL16 WINAPI
IsEqualGUID16(
414 GUID
* g1
, /* [in] unique id 1 */
417 return !memcmp( g1
, g2
, sizeof(GUID
) );
420 /***********************************************************************
421 * IsEqualGUID32 [OLE32.76]
423 * Compares two Unique Identifiers.
428 BOOL WINAPI
IsEqualGUID32(
429 REFGUID rguid1
, /* [in] unique id 1 */
430 REFGUID rguid2
/* [in] unique id 2 */
433 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));
436 /******************************************************************************
437 * CLSIDFromString16 [COMPOBJ.20]
438 * Converts a unique identifier from it's string representation into
441 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
446 HRESULT WINAPI
CLSIDFromString16(
447 LPCOLESTR16 idstr
, /* [in] string representation of guid */
448 CLSID
*id
/* [out] GUID converted from string */
450 BYTE
*s
= (BYTE
*) idstr
;
455 TRACE("%s -> %p\n", idstr
, id
);
457 /* quick lookup table */
458 memset(table
, 0, 256);
460 for (i
= 0; i
< 10; i
++) {
463 for (i
= 0; i
< 6; i
++) {
464 table
['A' + i
] = i
+10;
465 table
['a' + i
] = i
+10;
468 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
470 if (strlen(idstr
) != 38)
471 return OLE_ERROR_OBJECT
;
475 s
++; /* skip leading brace */
476 for (i
= 0; i
< 4; i
++) {
477 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
483 for (i
= 0; i
< 2; i
++) {
484 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
490 for (i
= 0; i
< 2; i
++) {
491 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
497 /* these are just sequential bytes */
498 for (i
= 0; i
< 2; i
++) {
499 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
504 for (i
= 0; i
< 6; i
++) {
505 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
512 /******************************************************************************
513 * CoCreateGuid[OLE32.6]
515 * Creates a 128bit GUID.
516 * Implemented according the DCE specification for UUID generation.
517 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
518 * Copyright (C) 1996, 1997 Theodore Ts'o.
522 * S_OK if successful.
524 HRESULT WINAPI
CoCreateGuid(
525 GUID
*pguid
/* [out] points to the GUID to initialize */
527 static char has_init
= 0;
529 static int adjustment
= 0;
530 static struct timeval last
= {0, 0};
531 static UINT16 clock_seq
;
533 unsigned long long clock_reg
;
534 UINT clock_high
, clock_low
;
535 UINT16 temp_clock_seq
, temp_clock_mid
, temp_clock_hi_and_version
;
538 struct ifreq ifr
, *ifrp
;
544 /* Have we already tried to get the MAC address? */
547 /* BSD 4.4 defines the size of an ifreq to be
548 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
549 * However, under earlier systems, sa_len isn't present, so
550 * the size is just sizeof(struct ifreq)
554 # define max(a,b) ((a) > (b) ? (a) : (b))
556 # define ifreq_size(i) max(sizeof(struct ifreq),\
557 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
559 # define ifreq_size(i) sizeof(struct ifreq)
560 # endif /* HAVE_SA_LEN */
562 sd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
564 /* if we can't open a socket, just use random numbers */
565 /* set the multicast bit to prevent conflicts with real cards */
566 a
[0] = (rand() & 0xff) | 0x80;
567 a
[1] = rand() & 0xff;
568 a
[2] = rand() & 0xff;
569 a
[3] = rand() & 0xff;
570 a
[4] = rand() & 0xff;
571 a
[5] = rand() & 0xff;
573 memset(buf
, 0, sizeof(buf
));
574 ifc
.ifc_len
= sizeof(buf
);
576 /* get the ifconf interface */
577 if (ioctl (sd
, SIOCGIFCONF
, (char *)&ifc
) < 0) {
579 /* no ifconf, so just use random numbers */
580 /* set the multicast bit to prevent conflicts with real cards */
581 a
[0] = (rand() & 0xff) | 0x80;
582 a
[1] = rand() & 0xff;
583 a
[2] = rand() & 0xff;
584 a
[3] = rand() & 0xff;
585 a
[4] = rand() & 0xff;
586 a
[5] = rand() & 0xff;
588 /* loop through the interfaces, looking for a valid one */
590 for (i
= 0; i
< n
; i
+= ifreq_size(*ifr
) ) {
591 ifrp
= (struct ifreq
*)((char *) ifc
.ifc_buf
+i
);
592 strncpy(ifr
.ifr_name
, ifrp
->ifr_name
, IFNAMSIZ
);
593 /* try to get the address for this interface */
594 # ifdef SIOCGIFHWADDR
595 if (ioctl(sd
, SIOCGIFHWADDR
, &ifr
) < 0)
597 memcpy(a
, (unsigned char *)&ifr
.ifr_hwaddr
.sa_data
, 6);
600 if (ioctl(sd
, SIOCGENADDR
, &ifr
) < 0)
602 memcpy(a
, (unsigned char *) ifr
.ifr_enaddr
, 6);
604 /* XXX we don't have a way of getting the hardware address */
608 # endif /* SIOCGENADDR */
609 # endif /* SIOCGIFHWADDR */
610 /* make sure it's not blank */
611 if (!a
[0] && !a
[1] && !a
[2] && !a
[3] && !a
[4] && !a
[5])
616 /* if we didn't find a valid address, make a random one */
617 /* once again, set multicast bit to avoid conflicts */
618 a
[0] = (rand() & 0xff) | 0x80;
619 a
[1] = rand() & 0xff;
620 a
[2] = rand() & 0xff;
621 a
[3] = rand() & 0xff;
622 a
[4] = rand() & 0xff;
623 a
[5] = rand() & 0xff;
630 /* no networking info, so generate a random address */
631 a
[0] = (rand() & 0xff) | 0x80;
632 a
[1] = rand() & 0xff;
633 a
[2] = rand() & 0xff;
634 a
[3] = rand() & 0xff;
635 a
[4] = rand() & 0xff;
636 a
[5] = rand() & 0xff;
637 #endif /* HAVE_NET_IF_H */
641 /* generate time element of GUID */
643 /* Assume that the gettimeofday() has microsecond granularity */
644 #define MAX_ADJUSTMENT 10
647 gettimeofday(&tv
, 0);
648 if ((last
.tv_sec
== 0) && (last
.tv_usec
== 0)) {
649 clock_seq
= ((rand() & 0xff) << 8) + (rand() & 0xff);
654 if ((tv
.tv_sec
< last
.tv_sec
) ||
655 ((tv
.tv_sec
== last
.tv_sec
) &&
656 (tv
.tv_usec
< last
.tv_usec
))) {
657 clock_seq
= (clock_seq
+1) & 0x1FFF;
659 } else if ((tv
.tv_sec
== last
.tv_sec
) &&
660 (tv
.tv_usec
== last
.tv_usec
)) {
661 if (adjustment
>= MAX_ADJUSTMENT
)
667 clock_reg
= tv
.tv_usec
*10 + adjustment
;
668 clock_reg
+= ((unsigned long long) tv
.tv_sec
)*10000000;
669 clock_reg
+= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
671 clock_high
= clock_reg
>> 32;
672 clock_low
= clock_reg
;
673 temp_clock_seq
= clock_seq
| 0x8000;
674 temp_clock_mid
= (UINT16
)clock_high
;
675 temp_clock_hi_and_version
= (clock_high
>> 16) | 0x1000;
677 /* pack the information into the GUID structure */
679 ((unsigned char*)&pguid
->Data1
)[3] = (unsigned char)clock_low
;
681 ((unsigned char*)&pguid
->Data1
)[2] = (unsigned char)clock_low
;
683 ((unsigned char*)&pguid
->Data1
)[1] = (unsigned char)clock_low
;
685 ((unsigned char*)&pguid
->Data1
)[0] = (unsigned char)clock_low
;
687 ((unsigned char*)&pguid
->Data2
)[1] = (unsigned char)temp_clock_mid
;
688 temp_clock_mid
>>= 8;
689 ((unsigned char*)&pguid
->Data2
)[0] = (unsigned char)temp_clock_mid
;
691 ((unsigned char*)&pguid
->Data3
)[1] = (unsigned char)temp_clock_hi_and_version
;
692 temp_clock_hi_and_version
>>= 8;
693 ((unsigned char*)&pguid
->Data3
)[0] = (unsigned char)temp_clock_hi_and_version
;
695 ((unsigned char*)pguid
->Data4
)[1] = (unsigned char)temp_clock_seq
;
696 temp_clock_seq
>>= 8;
697 ((unsigned char*)pguid
->Data4
)[0] = (unsigned char)temp_clock_seq
;
699 ((unsigned char*)pguid
->Data4
)[2] = a
[0];
700 ((unsigned char*)pguid
->Data4
)[3] = a
[1];
701 ((unsigned char*)pguid
->Data4
)[4] = a
[2];
702 ((unsigned char*)pguid
->Data4
)[5] = a
[3];
703 ((unsigned char*)pguid
->Data4
)[6] = a
[4];
704 ((unsigned char*)pguid
->Data4
)[7] = a
[5];
711 /******************************************************************************
712 * CLSIDFromString32 [OLE32.3]
713 * Converts a unique identifier from it's string representation into
718 HRESULT WINAPI
CLSIDFromString(
719 LPCOLESTR idstr
, /* [in] string representation of GUID */
720 CLSID
*id
/* [out] GUID represented by above string */
722 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
723 OLESTATUS ret
= CLSIDFromString16(xid
,id
);
725 HeapFree(GetProcessHeap(),0,xid
);
729 /******************************************************************************
730 * WINE_StringFromCLSID [Internal]
731 * Converts a GUID into the respective string representation.
736 * the string representation and OLESTATUS
738 HRESULT
WINE_StringFromCLSID(
739 const CLSID
*id
, /* [in] GUID to be converted */
740 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
742 static const char *hex
= "0123456789ABCDEF";
747 { ERR("called with id=Null\n");
752 sprintf(idstr
, "{%08lX-%04X-%04X-%02X%02X-",
753 id
->Data1
, id
->Data2
, id
->Data3
,
754 id
->Data4
[0], id
->Data4
[1]);
758 for (i
= 2; i
< 8; i
++) {
759 *s
++ = hex
[id
->Data4
[i
]>>4];
760 *s
++ = hex
[id
->Data4
[i
] & 0xf];
766 TRACE("%p->%s\n", id
, idstr
);
771 /******************************************************************************
772 * StringFromCLSID16 [COMPOBJ.19]
773 * Converts a GUID into the respective string representation.
774 * The target string is allocated using the OLE IMalloc.
776 * the string representation and OLESTATUS
778 HRESULT WINAPI
StringFromCLSID16(
779 REFCLSID id
, /* [in] the GUID to be converted */
780 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
787 ret
= CoGetMalloc16(0,&mllc
);
790 args
[0] = (DWORD
)mllc
;
793 /* No need for a Callback entry, we have WOWCallback16Ex which does
794 * everything we need.
796 if (!WOWCallback16Ex(
797 (DWORD
)((ICOM_VTABLE(IMalloc16
)*)PTR_SEG_TO_LIN(
798 ICOM_VTBL(((LPMALLOC16
)PTR_SEG_TO_LIN(mllc
))))
805 WARN("CallTo16 IMalloc16 failed\n");
808 return WINE_StringFromCLSID(id
,PTR_SEG_TO_LIN(*idstr
));
811 /******************************************************************************
812 * StringFromCLSID32 [OLE32.151]
813 * Converts a GUID into the respective string representation.
814 * The target string is allocated using the OLE IMalloc.
816 * the string representation and OLESTATUS
818 HRESULT WINAPI
StringFromCLSID(
819 REFCLSID id
, /* [in] the GUID to be converted */
820 LPOLESTR
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
826 if ((ret
=CoGetMalloc(0,&mllc
)))
829 ret
=WINE_StringFromCLSID(id
,buf
);
831 *idstr
= IMalloc_Alloc(mllc
,strlen(buf
)*2+2);
832 lstrcpyAtoW(*idstr
,buf
);
837 /******************************************************************************
838 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
840 * Converts a global unique identifier into a string of an API-
841 * specified fixed format. (The usual {.....} stuff.)
844 * The (UNICODE) string representation of the GUID in 'str'
845 * The length of the resulting string, 0 if there was any problem.
848 StringFromGUID2(REFGUID id
, LPOLESTR str
, INT cmax
)
852 if (WINE_StringFromCLSID(id
,xguid
))
854 if (strlen(xguid
)>=cmax
)
856 lstrcpyAtoW(str
,xguid
);
857 return strlen(xguid
);
860 /******************************************************************************
861 * ProgIDFromCLSID [OLE32.133]
862 * Converts a class id into the respective Program ID. (By using a registry lookup)
863 * RETURNS S_OK on success
864 * riid associated with the progid
867 HRESULT WINAPI
ProgIDFromCLSID(
868 REFCLSID clsid
, /* [in] class id as found in registry */
869 LPOLESTR
*lplpszProgID
/* [out] associated Prog ID */
872 char strCLSID
[50], *buf
, *buf2
;
878 WINE_StringFromCLSID(clsid
, strCLSID
);
880 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID
)+14);
881 sprintf(buf
,"CLSID\\%s\\ProgID", strCLSID
);
882 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
883 ret
= REGDB_E_CLASSNOTREG
;
885 HeapFree(GetProcessHeap(), 0, buf
);
889 buf2
= HeapAlloc(GetProcessHeap(), 0, 255);
891 if (RegQueryValueA(xhkey
, NULL
, buf2
, &buf2len
))
892 ret
= REGDB_E_CLASSNOTREG
;
896 if (CoGetMalloc(0,&mllc
))
900 *lplpszProgID
= IMalloc_Alloc(mllc
, (buf2len
+1)*2);
901 lstrcpyAtoW(*lplpszProgID
, buf2
);
904 HeapFree(GetProcessHeap(), 0, buf2
);
911 /******************************************************************************
912 * CLSIDFromProgID16 [COMPOBJ.61]
913 * Converts a program id into the respective GUID. (By using a registry lookup)
915 * riid associated with the progid
917 HRESULT WINAPI
CLSIDFromProgID16(
918 LPCOLESTR16 progid
, /* [in] program id as found in registry */
919 LPCLSID riid
/* [out] associated CLSID */
926 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
927 sprintf(buf
,"%s\\CLSID",progid
);
928 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
929 HeapFree(GetProcessHeap(),0,buf
);
930 return OLE_ERROR_GENERIC
;
932 HeapFree(GetProcessHeap(),0,buf
);
933 buf2len
= sizeof(buf2
);
934 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
936 return OLE_ERROR_GENERIC
;
939 return CLSIDFromString16(buf2
,riid
);
942 /******************************************************************************
943 * CLSIDFromProgID32 [OLE32.2]
944 * Converts a program id into the respective GUID. (By using a registry lookup)
946 * riid associated with the progid
948 HRESULT WINAPI
CLSIDFromProgID(
949 LPCOLESTR progid
, /* [in] program id as found in registry */
950 LPCLSID riid
/* [out] associated CLSID */
952 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
953 OLESTATUS ret
= CLSIDFromProgID16(pid
,riid
);
955 HeapFree(GetProcessHeap(),0,pid
);
959 /************************************************************************************************
962 * This function write a CLSID on stream
964 HRESULT WINAPI
WriteClassStm(IStream
*pStm
,REFCLSID rclsid
)
966 TRACE("(%p,%p)\n",pStm
,rclsid
);
971 return IStream_Write(pStm
,rclsid
,sizeof(CLSID
),NULL
);
974 /************************************************************************************************
977 * This function read a CLSID from a stream
979 HRESULT WINAPI
ReadClassStm(IStream
*pStm
,REFCLSID rclsid
)
984 TRACE("(%p,%p)\n",pStm
,rclsid
);
989 res
= IStream_Read(pStm
,(void*)rclsid
,sizeof(CLSID
),&nbByte
);
994 if (nbByte
!= sizeof(CLSID
))
1000 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
1001 /***********************************************************************
1002 * LookupETask (COMPOBJ.94)
1004 OLESTATUS WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
1005 FIXME("(%p,%p),stub!\n",hTask
,p
);
1006 if ((*hTask
= GetCurrentTask()) == hETask
) {
1007 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
1012 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
1013 /***********************************************************************
1014 * SetETask (COMPOBJ.95)
1016 OLESTATUS WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
1017 FIXME("(%04x,%p),stub!\n",hTask
,p
);
1022 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
1023 /***********************************************************************
1024 * CallObjectInWOW (COMPOBJ.201)
1026 OLESTATUS WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
1027 FIXME("(%p,%p),stub!\n",p1
,p2
);
1031 /******************************************************************************
1032 * CoRegisterClassObject16 [COMPOBJ.5]
1034 * Don't know where it registers it ...
1036 HRESULT WINAPI
CoRegisterClassObject16(
1039 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
1040 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
1041 LPDWORD lpdwRegister
1045 WINE_StringFromCLSID(rclsid
,buf
);
1047 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
1048 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
1054 /******************************************************************************
1055 * CoRevokeClassObject16 [COMPOBJ.6]
1058 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
/* token on class obj */)
1060 FIXME("(0x%08lx),stub!\n", dwRegister
);
1066 * COM_GetRegisteredClassObject
1068 * This internal method is used to scan the registered class list to
1069 * find a class object.
1072 * rclsid Class ID of the class to find.
1073 * dwClsContext Class context to match.
1074 * ppv [out] returns a pointer to the class object. Complying
1075 * to normal COM usage, this method will increase the
1076 * reference count on this object.
1078 static HRESULT
COM_GetRegisteredClassObject(
1083 RegisteredClass
* curClass
;
1091 * Iterate through the whole list and try to match the class ID.
1093 curClass
= firstRegisteredClass
;
1095 while (curClass
!= 0)
1098 * Check if we have a match on the class ID.
1100 if (IsEqualGUID32(&(curClass
->classIdentifier
), rclsid
))
1103 * Since we don't do out-of process or DCOM just right away, let's ignore the
1108 * We have a match, return the pointer to the class object.
1110 *ppUnk
= curClass
->classObject
;
1112 IUnknown_AddRef(curClass
->classObject
);
1118 * Step to the next class in the list.
1120 curClass
= curClass
->nextClass
;
1124 * If we get to here, we haven't found our class.
1129 /******************************************************************************
1130 * CoRegisterClassObject32 [OLE32.36]
1132 * This method will register the class object for a given class ID.
1134 * See the Windows documentation for more details.
1136 HRESULT WINAPI
CoRegisterClassObject(
1139 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
1140 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
1141 LPDWORD lpdwRegister
1144 RegisteredClass
* newClass
;
1145 LPUNKNOWN foundObject
;
1149 WINE_StringFromCLSID(rclsid
,buf
);
1151 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1152 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
);
1155 * Perform a sanity check on the parameters
1157 if ( (lpdwRegister
==0) || (pUnk
==0) )
1159 return E_INVALIDARG
;
1163 * Initialize the cookie (out parameter)
1168 * First, check if the class is already registered.
1169 * If it is, this should cause an error.
1171 hr
= COM_GetRegisteredClassObject(rclsid
, dwClsContext
, &foundObject
);
1176 * The COM_GetRegisteredClassObject increased the reference count on the
1177 * object so it has to be released.
1179 IUnknown_Release(foundObject
);
1181 return CO_E_OBJISREG
;
1185 * If it is not registered, we must create a new entry for this class and
1186 * append it to the registered class list.
1187 * We use the address of the chain node as the cookie since we are sure it's
1190 newClass
= HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass
));
1193 * Initialize the node.
1195 newClass
->classIdentifier
= *rclsid
;
1196 newClass
->runContext
= dwClsContext
;
1197 newClass
->connectFlags
= flags
;
1198 newClass
->dwCookie
= (DWORD
)newClass
;
1199 newClass
->nextClass
= firstRegisteredClass
;
1202 * Since we're making a copy of the object pointer, we have to increase it's
1205 newClass
->classObject
= pUnk
;
1206 IUnknown_AddRef(newClass
->classObject
);
1208 firstRegisteredClass
= newClass
;
1211 * Assign the out parameter (cookie)
1213 *lpdwRegister
= newClass
->dwCookie
;
1216 * We're successfyl Yippee!
1221 /***********************************************************************
1222 * CoRevokeClassObject32 [OLE32.40]
1224 * This method will remove a class object from the class registry
1226 * See the Windows documentation for more details.
1228 HRESULT WINAPI
CoRevokeClassObject(
1231 RegisteredClass
** prevClassLink
;
1232 RegisteredClass
* curClass
;
1234 TRACE("(%08lx)\n",dwRegister
);
1237 * Iterate through the whole list and try to match the cookie.
1239 curClass
= firstRegisteredClass
;
1240 prevClassLink
= &firstRegisteredClass
;
1242 while (curClass
!= 0)
1245 * Check if we have a match on the cookie.
1247 if (curClass
->dwCookie
== dwRegister
)
1250 * Remove the class from the chain.
1252 *prevClassLink
= curClass
->nextClass
;
1255 * Release the reference to the class object.
1257 IUnknown_Release(curClass
->classObject
);
1260 * Free the memory used by the chain node.
1262 HeapFree(GetProcessHeap(), 0, curClass
);
1268 * Step to the next class in the list.
1270 prevClassLink
= &(curClass
->nextClass
);
1271 curClass
= curClass
->nextClass
;
1275 * If we get to here, we haven't found our class.
1277 return E_INVALIDARG
;
1280 /***********************************************************************
1281 * CoGetClassObject [COMPOBJ.7]
1283 HRESULT WINAPI
CoGetClassObject(REFCLSID rclsid
, DWORD dwClsContext
,
1284 LPVOID pvReserved
, REFIID iid
, LPVOID
*ppv
)
1286 LPUNKNOWN regClassObject
;
1287 char xclsid
[50],xiid
[50];
1288 HRESULT hres
= E_UNEXPECTED
;
1290 char dllName
[MAX_PATH
+1];
1291 DWORD dllNameLen
= sizeof(dllName
);
1293 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
1294 REFIID iid
, LPVOID
*ppv
);
1295 DllGetClassObjectFunc DllGetClassObject
;
1297 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
1298 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
1299 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
1302 * First, try and see if we can't match the class ID with one of the
1303 * registered classes.
1305 if (S_OK
== COM_GetRegisteredClassObject(rclsid
, dwClsContext
, ®ClassObject
))
1308 * Get the required interface from the retrieved pointer.
1310 hres
= IUnknown_QueryInterface(regClassObject
, iid
, ppv
);
1313 * Since QI got another reference on the pointer, we want to release the
1314 * one we already have. If QI was unsuccessful, this will release the object. This
1315 * is good since we are not returning it in the "out" parameter.
1317 IUnknown_Release(regClassObject
);
1322 /* out of process and remote servers not supported yet */
1323 if ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
) {
1324 FIXME("CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
1325 return E_ACCESSDENIED
;
1328 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
1331 /* lookup CLSID in registry key HKCR/CLSID */
1332 hres
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0,
1333 KEY_READ
, &CLSIDkey
);
1335 if (hres
!= ERROR_SUCCESS
)
1336 return REGDB_E_READREGDB
;
1337 hres
= RegOpenKeyExA(CLSIDkey
,xclsid
,0,KEY_QUERY_VALUE
,&key
);
1338 if (hres
!= ERROR_SUCCESS
) {
1339 RegCloseKey(CLSIDkey
);
1340 return REGDB_E_CLASSNOTREG
;
1342 hres
= RegQueryValueA(key
, "InprocServer32", dllName
, &dllNameLen
);
1344 RegCloseKey(CLSIDkey
);
1345 if (hres
!= ERROR_SUCCESS
)
1346 return REGDB_E_READREGDB
;
1347 TRACE("found InprocServer32 dll %s\n", dllName
);
1349 /* open dll, call DllGetClassFactory */
1350 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
1351 if (hLibrary
== 0) {
1352 TRACE("couldn't load InprocServer32 dll %s\n", dllName
);
1353 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
1355 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject");
1356 if (!DllGetClassObject
) {
1357 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1358 TRACE("couldn't find function DllGetClassObject in %s\n", dllName
);
1359 return E_ACCESSDENIED
;
1363 * Ask the DLL for it's class object. (there was a note here about class
1364 * factories but this is good.
1366 return DllGetClassObject(rclsid
, iid
, ppv
);
1371 /****************************************************************************************
1374 * This function supplies the CLSID associated with the given filename.
1376 HRESULT WINAPI
GetClassFile(LPOLESTR filePathName
,CLSID
*pclsid
)
1380 int nbElm
=0,length
=0,i
=0;
1382 LPOLESTR
*pathDec
=0,absFile
=0,progId
=0;
1383 WCHAR extention
[100]={0};
1387 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1388 if((StgIsStorageFile(filePathName
))==S_OK
){
1390 res
=StgOpenStorage(filePathName
,NULL
,STGM_READ
| STGM_SHARE_DENY_WRITE
,NULL
,0,&pstg
);
1393 res
=ReadClassStg(pstg
,pclsid
);
1395 IStorage_Release(pstg
);
1399 /* if the file is not a storage object then attemps to match various bits in the file against a
1400 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1403 for(i=0;i<nFileTypes;i++)
1405 for(i=0;j<nPatternsForType;j++){
1410 pat=ReadPatternFromRegistry(i,j);
1411 hFile=CreateFileW(filePathName,,,,,,hFile);
1412 SetFilePosition(hFile,pat.offset);
1413 ReadFile(hFile,buf,pat.size,NULL,NULL);
1414 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1416 *pclsid=ReadCLSIDFromRegistry(i);
1422 /* if the obove strategies fail then search for the extension key in the registry */
1424 /* get the last element (absolute file) in the path name */
1425 nbElm
=FileMonikerImpl_DecomposePath(filePathName
,&pathDec
);
1426 absFile
=pathDec
[nbElm
-1];
1428 /* failed if the path represente a directory and not an absolute file name*/
1429 if (lstrcmpW(absFile
,(LPOLESTR
)"\\"))
1430 return MK_E_INVALIDEXTENSION
;
1432 /* get the extension of the file */
1433 length
=lstrlenW(absFile
);
1434 for(i
=length
-1; ( (i
>=0) && (extention
[i
]=absFile
[i
]) );i
--);
1436 /* get the progId associated to the extension */
1437 progId
=CoTaskMemAlloc(sizeProgId
);
1439 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1441 if (res
==ERROR_MORE_DATA
){
1443 CoTaskMemRealloc(progId
,sizeProgId
);
1445 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1447 if (res
==ERROR_SUCCESS
)
1448 /* return the clsid associated to the progId */
1449 res
= CLSIDFromProgID(progId
,pclsid
);
1451 for(i
=0; pathDec
[i
]!=NULL
;i
++)
1452 CoTaskMemFree(pathDec
[i
]);
1453 CoTaskMemFree(pathDec
);
1455 CoTaskMemFree(progId
);
1457 if (res
==ERROR_SUCCESS
)
1460 return MK_E_INVALIDEXTENSION
;
1462 /******************************************************************************
1463 * CoRegisterMessageFilter16 [COMPOBJ.27]
1465 HRESULT WINAPI
CoRegisterMessageFilter16(
1466 LPMESSAGEFILTER lpMessageFilter
,
1467 LPMESSAGEFILTER
*lplpMessageFilter
1469 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
1473 /***********************************************************************
1474 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1476 HRESULT WINAPI
CoCreateInstance(
1478 LPUNKNOWN pUnkOuter
,
1484 LPCLASSFACTORY lpclf
= 0;
1493 * Initialize the "out" parameter
1498 * Get a class factory to construct the object we want.
1500 hres
= CoGetClassObject(rclsid
,
1510 * Create the object and don't forget to release the factory
1512 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
1513 IClassFactory_Release(lpclf
);
1518 /***********************************************************************
1519 * CoCreateInstanceEx [OLE32.165]
1521 HRESULT WINAPI
CoCreateInstanceEx(
1523 LPUNKNOWN pUnkOuter
,
1525 COSERVERINFO
* pServerInfo
,
1529 IUnknown
* pUnk
= NULL
;
1532 int successCount
= 0;
1537 if ( (cmq
==0) || (pResults
==NULL
))
1538 return E_INVALIDARG
;
1540 if (pServerInfo
!=NULL
)
1541 FIXME("() non-NULL pServerInfo not supported!\n");
1544 * Initialize all the "out" parameters.
1546 for (index
= 0; index
< cmq
; index
++)
1548 pResults
[index
].pItf
= NULL
;
1549 pResults
[index
].hr
= E_NOINTERFACE
;
1553 * Get the object and get it's IUnknown pointer.
1555 hr
= CoCreateInstance(rclsid
,
1565 * Then, query for all the interfaces requested.
1567 for (index
= 0; index
< cmq
; index
++)
1569 pResults
[index
].hr
= IUnknown_QueryInterface(pUnk
,
1570 pResults
[index
].pIID
,
1571 (VOID
**)&(pResults
[index
].pItf
));
1573 if (pResults
[index
].hr
== S_OK
)
1578 * Release our temporary unknown pointer.
1580 IUnknown_Release(pUnk
);
1582 if (successCount
== 0)
1583 return E_NOINTERFACE
;
1585 if (successCount
!=cmq
)
1586 return CO_S_NOTALLINTERFACES
;
1591 /***********************************************************************
1592 * CoFreeLibrary [COMPOBJ.13]
1594 void WINAPI
CoFreeLibrary(HINSTANCE hLibrary
)
1596 OpenDll
*ptr
, *prev
;
1599 /* lookup library in linked list */
1601 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
1602 if (ptr
->hLibrary
== hLibrary
) {
1609 /* shouldn't happen if user passed in a valid hLibrary */
1612 /* assert: ptr points to the library entry to free */
1614 /* free library and remove node from list */
1615 FreeLibrary(hLibrary
);
1616 if (ptr
== openDllList
) {
1617 tmp
= openDllList
->next
;
1618 HeapFree(GetProcessHeap(), 0, openDllList
->DllName
);
1619 HeapFree(GetProcessHeap(), 0, openDllList
);
1623 HeapFree(GetProcessHeap(), 0, ptr
->DllName
);
1624 HeapFree(GetProcessHeap(), 0, ptr
);
1631 /***********************************************************************
1632 * CoFreeAllLibraries [COMPOBJ.12]
1634 void WINAPI
CoFreeAllLibraries(void)
1638 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1640 CoFreeLibrary(ptr
->hLibrary
);
1647 /***********************************************************************
1648 * CoFreeUnusedLibraries [COMPOBJ.17]
1650 void WINAPI
CoFreeUnusedLibraries(void)
1653 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
1654 DllCanUnloadNowFunc DllCanUnloadNow
;
1656 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1657 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
1658 GetProcAddress(ptr
->hLibrary
, "DllCanUnloadNow");
1660 if ( (DllCanUnloadNow
!= NULL
) &&
1661 (DllCanUnloadNow() == S_OK
) ) {
1663 CoFreeLibrary(ptr
->hLibrary
);
1671 /***********************************************************************
1672 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1674 * the current system time in lpFileTime
1676 HRESULT WINAPI
CoFileTimeNow(
1677 FILETIME
*lpFileTime
/* [out] the current time */
1679 DOSFS_UnixTimeToFileTime(time(NULL
), lpFileTime
, 0);
1683 /***********************************************************************
1684 * CoTaskMemAlloc (OLE32.43)
1686 * pointer to newly allocated block
1688 LPVOID WINAPI
CoTaskMemAlloc(
1689 ULONG size
/* [in] size of memoryblock to be allocated */
1692 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1697 return IMalloc_Alloc(lpmalloc
,size
);
1699 /***********************************************************************
1700 * CoTaskMemFree (OLE32.44)
1702 VOID WINAPI
CoTaskMemFree(
1703 LPVOID ptr
/* [in] pointer to be freed */
1706 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1711 IMalloc_Free(lpmalloc
, ptr
);
1714 /***********************************************************************
1715 * CoTaskMemRealloc (OLE32.45)
1717 * pointer to newly allocated block
1719 LPVOID WINAPI
CoTaskMemRealloc(
1721 ULONG size
) /* [in] size of memoryblock to be allocated */
1724 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1729 return IMalloc_Realloc(lpmalloc
, pvOld
, size
);
1732 /***********************************************************************
1733 * CoLoadLibrary (OLE32.30)
1735 HINSTANCE WINAPI
CoLoadLibrary(LPOLESTR16 lpszLibName
, BOOL bAutoFree
)
1741 TRACE("CoLoadLibrary(%p, %d\n", lpszLibName
, bAutoFree
);
1743 hLibrary
= LoadLibraryExA(lpszLibName
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
1748 if (openDllList
== NULL
) {
1749 /* empty list -- add first node */
1750 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1751 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1752 openDllList
->hLibrary
= hLibrary
;
1753 openDllList
->next
= NULL
;
1755 /* search for this dll */
1757 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1758 if (ptr
->hLibrary
== hLibrary
) {
1764 /* dll not found, add it */
1766 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1767 openDllList
->DllName
= HEAP_strdupA(GetProcessHeap(), 0, lpszLibName
);
1768 openDllList
->hLibrary
= hLibrary
;
1769 openDllList
->next
= tmp
;
1776 /***********************************************************************
1777 * CoInitializeWOW (OLE32.27)
1779 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1780 FIXME("(0x%08lx,0x%08lx),stub!\n",x
,y
);
1784 /******************************************************************************
1785 * CoLockObjectExternal16 [COMPOBJ.63]
1787 HRESULT WINAPI
CoLockObjectExternal16(
1788 LPUNKNOWN pUnk
, /* [in] object to be locked */
1789 BOOL16 fLock
, /* [in] do lock */
1790 BOOL16 fLastUnlockReleases
/* [in] ? */
1792 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1796 /******************************************************************************
1797 * CoLockObjectExternal32 [OLE32.31]
1799 HRESULT WINAPI
CoLockObjectExternal(
1800 LPUNKNOWN pUnk
, /* [in] object to be locked */
1801 BOOL fLock
, /* [in] do lock */
1802 BOOL fLastUnlockReleases
) /* [in] unlock all */
1808 * Increment the external lock coutner, COM_ExternalLockAddRef also
1809 * increment the object's internal lock counter.
1811 COM_ExternalLockAddRef( pUnk
);
1816 * Decrement the external lock coutner, COM_ExternalLockRelease also
1817 * decrement the object's internal lock counter.
1819 COM_ExternalLockRelease( pUnk
, fLastUnlockReleases
);
1825 /***********************************************************************
1826 * CoGetState16 [COMPOBJ.115]
1828 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1830 FIXME("(%p),stub!\n", state
);
1834 /***********************************************************************
1835 * CoSetState32 [COM32.42]
1837 HRESULT WINAPI
CoSetState(LPDWORD state
)
1839 FIXME("(%p),stub!\n", state
);
1840 if (state
) *state
= 0;
1845 /***********************************************************************
1846 * DllGetClassObject [OLE32.63]
1848 HRESULT WINAPI
OLE32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
1850 char xclsid
[50],xiid
[50];
1851 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
1852 WINE_StringFromCLSID((LPCLSID
)iid
,xiid
);
1853 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",xclsid
,xiid
);
1857 return CLASS_E_CLASSNOTAVAILABLE
;
1862 * COM_RevokeAllClasses
1864 * This method is called when the COM libraries are uninitialized to
1865 * release all the references to the class objects registered with
1868 static void COM_RevokeAllClasses()
1870 while (firstRegisteredClass
!=0)
1872 CoRevokeClassObject(firstRegisteredClass
->dwCookie
);
1876 /****************************************************************************
1877 * COM External Lock methods implementation
1880 /****************************************************************************
1881 * Public - Method that increments the count for a IUnknown* in the linked
1882 * list. The item is inserted if not already in the list.
1884 static void COM_ExternalLockAddRef(
1887 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1890 * Add an external lock to the object. If it was already externally
1891 * locked, just increase the reference count. If it was not.
1892 * add the item to the list.
1894 if ( externalLock
== EL_NOT_FOUND
)
1895 COM_ExternalLockInsert(pUnk
);
1897 externalLock
->uRefCount
++;
1900 * Add an internal lock to the object
1902 IUnknown_AddRef(pUnk
);
1905 /****************************************************************************
1906 * Public - Method that decrements the count for a IUnknown* in the linked
1907 * list. The item is removed from the list if its count end up at zero or if
1910 static void COM_ExternalLockRelease(
1914 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1916 if ( externalLock
!= EL_NOT_FOUND
)
1920 externalLock
->uRefCount
--; /* release external locks */
1921 IUnknown_Release(pUnk
); /* release local locks as well */
1923 if ( bRelAll
== FALSE
)
1924 break; /* perform single release */
1926 } while ( externalLock
->uRefCount
> 0 );
1928 if ( externalLock
->uRefCount
== 0 ) /* get rid of the list entry */
1929 COM_ExternalLockDelete(externalLock
);
1932 /****************************************************************************
1933 * Public - Method that frees the content of the list.
1935 static void COM_ExternalLockFreeList()
1937 COM_ExternalLock
*head
;
1939 head
= elList
.head
; /* grab it by the head */
1940 while ( head
!= EL_END_OF_LIST
)
1942 COM_ExternalLockDelete(head
); /* get rid of the head stuff */
1944 head
= elList
.head
; /* get the new head... */
1948 /****************************************************************************
1949 * Public - Method that dump the content of the list.
1951 void COM_ExternalLockDump()
1953 COM_ExternalLock
*current
= elList
.head
;
1955 printf("\nExternal lock list contains:\n");
1957 while ( current
!= EL_END_OF_LIST
)
1959 printf( "\t%p with %lu references count.\n",
1961 current
->uRefCount
);
1963 /* Skip to the next item */
1964 current
= current
->next
;
1969 /****************************************************************************
1970 * Internal - Find a IUnknown* in the linked list
1972 static COM_ExternalLock
* COM_ExternalLockFind(
1975 return COM_ExternalLockLocate(elList
.head
, pUnk
);
1978 /****************************************************************************
1979 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1981 static COM_ExternalLock
* COM_ExternalLockLocate(
1982 COM_ExternalLock
*element
,
1985 if ( element
== EL_END_OF_LIST
)
1986 return EL_NOT_FOUND
;
1988 else if ( element
->pUnk
== pUnk
) /* We found it */
1991 else /* Not the right guy, keep on looking */
1992 return COM_ExternalLockLocate( element
->next
, pUnk
);
1995 /****************************************************************************
1996 * Internal - Insert a new IUnknown* to the linked list
1998 static BOOL
COM_ExternalLockInsert(
2001 COM_ExternalLock
*newLock
= NULL
;
2002 COM_ExternalLock
*previousHead
= NULL
;
2005 * Allocate space for the new storage object
2007 newLock
= HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock
));
2011 if ( elList
.head
== EL_END_OF_LIST
)
2013 elList
.head
= newLock
; /* The list is empty */
2018 * insert does it at the head
2020 previousHead
= elList
.head
;
2021 elList
.head
= newLock
;
2025 * Set new list item data member
2027 newLock
->pUnk
= pUnk
;
2028 newLock
->uRefCount
= 1;
2029 newLock
->next
= previousHead
;
2037 /****************************************************************************
2038 * Internal - Method that removes an item from the linked list.
2040 static void COM_ExternalLockDelete(
2041 COM_ExternalLock
*itemList
)
2043 COM_ExternalLock
*current
= elList
.head
;
2045 if ( current
== itemList
)
2048 * this section handles the deletion of the first node
2050 elList
.head
= itemList
->next
;
2051 HeapFree( GetProcessHeap(), 0, itemList
);
2057 if ( current
->next
== itemList
) /* We found the item to free */
2059 current
->next
= itemList
->next
; /* readjust the list pointers */
2061 HeapFree( GetProcessHeap(), 0, itemList
);
2065 /* Skip to the next item */
2066 current
= current
->next
;
2068 } while ( current
!= EL_END_OF_LIST
);
2072 /***********************************************************************
2073 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
2075 * Initialization code for the COMPOBJ DLL
2079 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
2081 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
,
2085 case DLL_PROCESS_ATTACH
:
2087 if(COMPOBJ_hInstance
)
2089 ERR("compobj.dll instantiated twice!\n");
2091 * We should return FALSE here, but that will break
2092 * most apps that use CreateProcess because we do
2093 * not yet support seperate address-spaces.
2098 COMPOBJ_hInstance
= hInst
;
2101 case DLL_PROCESS_DETACH
:
2102 if(!--COMPOBJ_Attach
)
2103 COMPOBJ_hInstance
= 0;