4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
19 #include "wine/winbase16.h"
23 #include "debugtools.h"
28 #include "wine/obj_base.h"
29 #include "wine/obj_misc.h"
30 #include "wine/obj_storage.h"
31 #include "wine/obj_clientserver.h"
35 #include "compobj_private.h"
37 DEFAULT_DEBUG_CHANNEL(ole
);
39 /****************************************************************************
40 * COM External Lock structures and methods declaration
42 * This api provides a linked list to managed external references to
45 * The public interface consists of three calls:
46 * COM_ExternalLockAddRef
47 * COM_ExternalLockRelease
48 * COM_ExternalLockFreeList
51 #define EL_END_OF_LIST 0
52 #define EL_NOT_FOUND 0
55 * Declaration of the static structure that manage the
56 * external lock to COM objects.
58 typedef struct COM_ExternalLock COM_ExternalLock
;
59 typedef struct COM_ExternalLockList COM_ExternalLockList
;
61 struct COM_ExternalLock
63 IUnknown
*pUnk
; /* IUnknown referenced */
64 ULONG uRefCount
; /* external lock counter to IUnknown object*/
65 COM_ExternalLock
*next
; /* Pointer to next element in list */
68 struct COM_ExternalLockList
70 COM_ExternalLock
*head
; /* head of list */
74 * Declaration and initialization of the static structure that manages
75 * the external lock to COM objects.
77 static COM_ExternalLockList elList
= { EL_END_OF_LIST
};
80 * Public Interface to the external lock list
82 static void COM_ExternalLockFreeList();
83 static void COM_ExternalLockAddRef(IUnknown
*pUnk
);
84 static void COM_ExternalLockRelease(IUnknown
*pUnk
, BOOL bRelAll
);
85 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
88 * Private methods used to managed the linked list
90 static BOOL
COM_ExternalLockInsert(
93 static void COM_ExternalLockDelete(
94 COM_ExternalLock
*element
);
96 static COM_ExternalLock
* COM_ExternalLockFind(
99 static COM_ExternalLock
* COM_ExternalLockLocate(
100 COM_ExternalLock
*element
,
103 /****************************************************************************
104 * This section defines variables internal to the COM module.
106 * TODO: Most of these things will have to be made thread-safe.
108 HINSTANCE16 COMPOBJ_hInstance
= 0;
109 HINSTANCE COMPOBJ_hInstance32
= 0;
110 static int COMPOBJ_Attach
= 0;
112 LPMALLOC16 currentMalloc16
=NULL
;
113 LPMALLOC currentMalloc32
=NULL
;
116 WORD Table_ETask
[62];
119 * This lock count counts the number of times CoInitialize is called. It is
120 * decreased every time CoUninitialize is called. When it hits 0, the COM
121 * libraries are freed
123 static ULONG s_COMLockCount
= 0;
126 * This linked list contains the list of registered class objects. These
127 * are mostly used to register the factories for out-of-proc servers of OLE
130 * TODO: Make this data structure aware of inter-process communication. This
131 * means that parts of this will be exported to the Wine Server.
133 typedef struct tagRegisteredClass
135 CLSID classIdentifier
;
136 LPUNKNOWN classObject
;
140 struct tagRegisteredClass
* nextClass
;
143 static RegisteredClass
* firstRegisteredClass
= NULL
;
145 /* this open DLL table belongs in a per process table, but my guess is that
146 * it shouldn't live in the kernel, so I'll put them out here in DLL
147 * space assuming that there is one OLE32 per process.
149 typedef struct tagOpenDll
{
151 struct tagOpenDll
*next
;
154 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
156 /*****************************************************************************
157 * This section contains prototypes to internal methods for this
160 static HRESULT
COM_GetRegisteredClassObject(REFCLSID rclsid
,
164 static void COM_RevokeAllClasses();
167 /******************************************************************************
168 * CoBuildVersion [COMPOBJ.1]
171 * Current build version, hiword is majornumber, loword is minornumber
173 DWORD WINAPI
CoBuildVersion(void)
175 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
176 return (rmm
<<16)+rup
;
179 /******************************************************************************
180 * CoInitialize16 [COMPOBJ.2]
181 * Set the win16 IMalloc used for memory management
183 HRESULT WINAPI
CoInitialize16(
184 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
186 currentMalloc16
= (LPMALLOC16
)lpReserved
;
190 /******************************************************************************
191 * CoInitialize [OLE32.26]
193 * Initializes the COM libraries.
197 HRESULT WINAPI
CoInitialize(
198 LPVOID lpReserved
/* [in] pointer to win32 malloc interface
199 (obsolete, should be NULL) */
203 * Just delegate to the newer method.
205 return CoInitializeEx(lpReserved
, COINIT_APARTMENTTHREADED
);
208 /******************************************************************************
209 * CoInitializeEx [OLE32.163]
211 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
212 * used for memory management is obsolete.
215 * S_OK if successful,
216 * S_FALSE if this function was called already.
217 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
221 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
224 * See the windows documentation for more details.
226 HRESULT WINAPI
CoInitializeEx(
227 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface
228 (obsolete, should be NULL) */
229 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
234 TRACE("(%p, %x)\n", lpReserved
, (int)dwCoInit
);
236 if (lpReserved
!=NULL
)
238 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved
, (int)dwCoInit
, lpReserved
);
242 * Check for unsupported features.
244 if (dwCoInit
!=COINIT_APARTMENTTHREADED
)
246 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
247 /* Hope for the best and continue anyway */
251 * Check the lock count. If this is the first time going through the initialize
252 * process, we have to initialize the libraries.
254 if (s_COMLockCount
==0)
257 * Initialize the various COM libraries and data structures.
259 TRACE("() - Initializing the COM libraries\n");
261 RunningObjectTableImpl_Initialize();
269 * Crank-up that lock count.
276 /***********************************************************************
277 * CoUninitialize16 [COMPOBJ.3]
278 * Don't know what it does.
279 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
280 * believe is the correct spelling
282 void WINAPI
CoUninitialize16(void)
285 CoFreeAllLibraries();
288 /***********************************************************************
289 * CoUninitialize [OLE32.47]
291 * This method will release the COM libraries.
293 * See the windows documentation for more details.
295 void WINAPI
CoUninitialize(void)
300 * Decrease the reference count.
305 * If we are back to 0 locks on the COM library, make sure we free
306 * all the associated data structures.
308 if (s_COMLockCount
==0)
311 * Release the various COM libraries and data structures.
313 TRACE("() - Releasing the COM libraries\n");
315 RunningObjectTableImpl_UnInitialize();
317 * Release the references to the registered class objects.
319 COM_RevokeAllClasses();
322 * This will free the loaded COM Dlls.
324 CoFreeAllLibraries();
327 * This will free list of external references to COM objects.
329 COM_ExternalLockFreeList();
333 /***********************************************************************
334 * CoGetMalloc16 [COMPOBJ.4]
336 * The current win16 IMalloc
338 HRESULT WINAPI
CoGetMalloc16(
339 DWORD dwMemContext
, /* [in] unknown */
340 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
343 currentMalloc16
= IMalloc16_Constructor();
344 *lpMalloc
= currentMalloc16
;
348 /******************************************************************************
349 * CoGetMalloc [OLE32.20]
352 * The current win32 IMalloc
354 HRESULT WINAPI
CoGetMalloc(
355 DWORD dwMemContext
, /* [in] unknown */
356 LPMALLOC
*lpMalloc
/* [out] current win32 malloc interface */
359 currentMalloc32
= IMalloc_Constructor();
360 *lpMalloc
= currentMalloc32
;
364 /***********************************************************************
365 * CoCreateStandardMalloc16 [COMPOBJ.71]
367 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
368 LPMALLOC16
*lpMalloc
)
370 /* FIXME: docu says we shouldn't return the same allocator as in
372 *lpMalloc
= IMalloc16_Constructor();
376 /******************************************************************************
377 * CoDisconnectObject [COMPOBJ.15]
379 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
381 TRACE("(%p, %lx)\n",lpUnk
,reserved
);
385 /***********************************************************************
386 * IsEqualGUID16 [COMPOBJ.18]
388 * Compares two Unique Identifiers.
393 BOOL16 WINAPI
IsEqualGUID16(
394 GUID
* g1
, /* [in] unique id 1 */
395 GUID
* g2
/* [in] unique id 2 */
397 return !memcmp( g1
, g2
, sizeof(GUID
) );
400 /******************************************************************************
401 * CLSIDFromString16 [COMPOBJ.20]
402 * Converts a unique identifier from its string representation into
405 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
410 HRESULT WINAPI
CLSIDFromString16(
411 LPCOLESTR16 idstr
, /* [in] string representation of guid */
412 CLSID
*id
/* [out] GUID converted from string */
414 BYTE
*s
= (BYTE
*) idstr
;
420 s
= "{00000000-0000-0000-0000-000000000000}";
421 else { /* validate the CLSID string */
424 return CO_E_CLASSSTRING
;
426 if ((s
[0]!='{') || (s
[9]!='-') || (s
[14]!='-') || (s
[19]!='-') || (s
[24]!='-') || (s
[37]!='}'))
427 return CO_E_CLASSSTRING
;
431 if ((i
== 9)||(i
== 14)||(i
== 19)||(i
== 24)) continue;
432 if (!(((s
[i
] >= '0') && (s
[i
] <= '9')) ||
433 ((s
[i
] >= 'a') && (s
[i
] <= 'f')) ||
434 ((s
[i
] >= 'A') && (s
[i
] <= 'F')))
436 return CO_E_CLASSSTRING
;
440 TRACE("%s -> %p\n", s
, id
);
442 /* quick lookup table */
443 memset(table
, 0, 256);
445 for (i
= 0; i
< 10; i
++) {
448 for (i
= 0; i
< 6; i
++) {
449 table
['A' + i
] = i
+10;
450 table
['a' + i
] = i
+10;
453 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
457 s
++; /* skip leading brace */
458 for (i
= 0; i
< 4; i
++) {
459 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
465 for (i
= 0; i
< 2; i
++) {
466 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
472 for (i
= 0; i
< 2; i
++) {
473 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
479 /* these are just sequential bytes */
480 for (i
= 0; i
< 2; i
++) {
481 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
486 for (i
= 0; i
< 6; i
++) {
487 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
494 /******************************************************************************
495 * CoCreateGuid[OLE32.6]
498 HRESULT WINAPI
CoCreateGuid(
499 GUID
*pguid
/* [out] points to the GUID to initialize */
501 return UuidCreate(pguid
);
504 /******************************************************************************
505 * CLSIDFromString [OLE32.3]
506 * Converts a unique identifier from its string representation into
510 * If idstr is not a valid CLSID string then it gets treated as a ProgID
515 HRESULT WINAPI
CLSIDFromString(
516 LPCOLESTR idstr
, /* [in] string representation of GUID */
517 CLSID
*id
/* [out] GUID represented by above string */
519 LPOLESTR16 xid
= HEAP_strdupWtoA(GetProcessHeap(),0,idstr
);
520 HRESULT ret
= CLSIDFromString16(xid
,id
);
522 HeapFree(GetProcessHeap(),0,xid
);
523 if(ret
!= S_OK
) { /* It appears a ProgID is also valid */
524 ret
= CLSIDFromProgID(idstr
, id
);
529 /******************************************************************************
530 * WINE_StringFromCLSID [Internal]
531 * Converts a GUID into the respective string representation.
536 * the string representation and HRESULT
538 static HRESULT
WINE_StringFromCLSID(
539 const CLSID
*id
, /* [in] GUID to be converted */
540 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
542 static const char *hex
= "0123456789ABCDEF";
547 { ERR("called with id=Null\n");
552 sprintf(idstr
, "{%08lX-%04X-%04X-%02X%02X-",
553 id
->Data1
, id
->Data2
, id
->Data3
,
554 id
->Data4
[0], id
->Data4
[1]);
558 for (i
= 2; i
< 8; i
++) {
559 *s
++ = hex
[id
->Data4
[i
]>>4];
560 *s
++ = hex
[id
->Data4
[i
] & 0xf];
566 TRACE("%p->%s\n", id
, idstr
);
571 /******************************************************************************
572 * StringFromCLSID16 [COMPOBJ.19]
573 * Converts a GUID into the respective string representation.
574 * The target string is allocated using the OLE IMalloc.
576 * the string representation and HRESULT
578 HRESULT WINAPI
StringFromCLSID16(
579 REFCLSID id
, /* [in] the GUID to be converted */
580 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
583 extern BOOL WINAPI
K32WOWCallback16Ex( DWORD vpfn16
, DWORD dwFlags
,
584 DWORD cbArgs
, LPVOID pArgs
, LPDWORD pdwRetCode
);
589 ret
= CoGetMalloc16(0,&mllc
);
592 args
[0] = (DWORD
)mllc
;
595 /* No need for a Callback entry, we have WOWCallback16Ex which does
596 * everything we need.
598 if (!K32WOWCallback16Ex(
599 (DWORD
)((ICOM_VTABLE(IMalloc16
)*)MapSL(
600 (SEGPTR
)ICOM_VTBL(((LPMALLOC16
)MapSL((SEGPTR
)mllc
))))
607 WARN("CallTo16 IMalloc16 failed\n");
610 return WINE_StringFromCLSID(id
,MapSL((SEGPTR
)*idstr
));
613 /******************************************************************************
614 * StringFromCLSID [OLE32.151]
615 * Converts a GUID into the respective string representation.
616 * The target string is allocated using the OLE IMalloc.
618 * the string representation and HRESULT
620 HRESULT WINAPI
StringFromCLSID(
621 REFCLSID id
, /* [in] the GUID to be converted */
622 LPOLESTR
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
628 if ((ret
=CoGetMalloc(0,&mllc
)))
631 ret
=WINE_StringFromCLSID(id
,buf
);
633 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, buf
, -1, NULL
, 0 );
634 *idstr
= IMalloc_Alloc( mllc
, len
* sizeof(WCHAR
) );
635 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, *idstr
, len
);
640 /******************************************************************************
641 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
643 * Converts a global unique identifier into a string of an API-
644 * specified fixed format. (The usual {.....} stuff.)
647 * The (UNICODE) string representation of the GUID in 'str'
648 * The length of the resulting string, 0 if there was any problem.
651 StringFromGUID2(REFGUID id
, LPOLESTR str
, INT cmax
)
655 if (WINE_StringFromCLSID(id
,xguid
))
657 return MultiByteToWideChar( CP_ACP
, 0, xguid
, -1, str
, cmax
);
660 /******************************************************************************
661 * ProgIDFromCLSID [OLE32.133]
662 * Converts a class id into the respective Program ID. (By using a registry lookup)
663 * RETURNS S_OK on success
664 * riid associated with the progid
667 HRESULT WINAPI
ProgIDFromCLSID(
668 REFCLSID clsid
, /* [in] class id as found in registry */
669 LPOLESTR
*lplpszProgID
/* [out] associated Prog ID */
672 char strCLSID
[50], *buf
, *buf2
;
678 WINE_StringFromCLSID(clsid
, strCLSID
);
680 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID
)+14);
681 sprintf(buf
,"CLSID\\%s\\ProgID", strCLSID
);
682 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
683 ret
= REGDB_E_CLASSNOTREG
;
685 HeapFree(GetProcessHeap(), 0, buf
);
689 buf2
= HeapAlloc(GetProcessHeap(), 0, 255);
691 if (RegQueryValueA(xhkey
, NULL
, buf2
, &buf2len
))
692 ret
= REGDB_E_CLASSNOTREG
;
696 if (CoGetMalloc(0,&mllc
))
700 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, buf2
, -1, NULL
, 0 );
701 *lplpszProgID
= IMalloc_Alloc(mllc
, len
* sizeof(WCHAR
) );
702 MultiByteToWideChar( CP_ACP
, 0, buf2
, -1, *lplpszProgID
, len
);
705 HeapFree(GetProcessHeap(), 0, buf2
);
712 /******************************************************************************
713 * CLSIDFromProgID16 [COMPOBJ.61]
714 * Converts a program id into the respective GUID. (By using a registry lookup)
716 * riid associated with the progid
718 HRESULT WINAPI
CLSIDFromProgID16(
719 LPCOLESTR16 progid
, /* [in] program id as found in registry */
720 LPCLSID riid
/* [out] associated CLSID */
727 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
728 sprintf(buf
,"%s\\CLSID",progid
);
729 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
730 HeapFree(GetProcessHeap(),0,buf
);
731 return CO_E_CLASSSTRING
;
733 HeapFree(GetProcessHeap(),0,buf
);
734 buf2len
= sizeof(buf2
);
735 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
737 return CO_E_CLASSSTRING
;
740 return CLSIDFromString16(buf2
,riid
);
743 /******************************************************************************
744 * CLSIDFromProgID [OLE32.2]
745 * Converts a program id into the respective GUID. (By using a registry lookup)
747 * riid associated with the progid
749 HRESULT WINAPI
CLSIDFromProgID(
750 LPCOLESTR progid
, /* [in] program id as found in registry */
751 LPCLSID riid
/* [out] associated CLSID */
753 LPOLESTR16 pid
= HEAP_strdupWtoA(GetProcessHeap(),0,progid
);
754 HRESULT ret
= CLSIDFromProgID16(pid
,riid
);
756 HeapFree(GetProcessHeap(),0,pid
);
762 /*****************************************************************************
763 * CoGetPSClsid [OLE32.22]
765 * This function returns the CLSID of the DLL that implements the proxy and stub
766 * for the specified interface.
768 * It determines this by searching the
769 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
770 * and any interface id registered by CoRegisterPSClsid within the current process.
772 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
774 HRESULT WINAPI
CoGetPSClsid(
775 REFIID riid
, /* [in] Interface whose proxy/stub CLSID is to be returned */
776 CLSID
*pclsid
) /* [out] Where to store returned proxy/stub CLSID */
782 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid
), pclsid
);
784 /* Get the input iid as a string */
785 WINE_StringFromCLSID(riid
, buf2
);
786 /* Allocate memory for the registry key we will construct.
787 (length of iid string plus constant length of static text */
788 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(buf2
)+27);
791 return (E_OUTOFMEMORY
);
794 /* Construct the registry key we want */
795 sprintf(buf
,"Interface\\%s\\ProxyStubClsid32", buf2
);
798 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
800 HeapFree(GetProcessHeap(),0,buf
);
801 return (E_INVALIDARG
);
803 HeapFree(GetProcessHeap(),0,buf
);
805 /* ... Once we have the key, query the registry to get the
806 value of CLSID as a string, and convert it into a
807 proper CLSID structure to be passed back to the app */
808 buf2len
= sizeof(buf2
);
809 if ( (RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
)) )
816 /* We have the CLSid we want back from the registry as a string, so
817 lets convert it into a CLSID structure */
818 if ( (CLSIDFromString16(buf2
,pclsid
)) != NOERROR
)
823 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid
));
829 /***********************************************************************
832 * This function write a CLSID on stream
834 HRESULT WINAPI
WriteClassStm(IStream
*pStm
,REFCLSID rclsid
)
836 TRACE("(%p,%p)\n",pStm
,rclsid
);
841 return IStream_Write(pStm
,rclsid
,sizeof(CLSID
),NULL
);
844 /***********************************************************************
847 * This function read a CLSID from a stream
849 HRESULT WINAPI
ReadClassStm(IStream
*pStm
,REFCLSID rclsid
)
854 TRACE("(%p,%p)\n",pStm
,rclsid
);
859 res
= IStream_Read(pStm
,(void*)rclsid
,sizeof(CLSID
),&nbByte
);
864 if (nbByte
!= sizeof(CLSID
))
870 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
871 /***********************************************************************
872 * LookupETask (COMPOBJ.94)
874 HRESULT WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
875 FIXME("(%p,%p),stub!\n",hTask
,p
);
876 if ((*hTask
= GetCurrentTask()) == hETask
) {
877 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
882 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
883 /***********************************************************************
884 * SetETask (COMPOBJ.95)
886 HRESULT WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
887 FIXME("(%04x,%p),stub!\n",hTask
,p
);
892 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
893 /***********************************************************************
894 * CallObjectInWOW (COMPOBJ.201)
896 HRESULT WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
897 FIXME("(%p,%p),stub!\n",p1
,p2
);
901 /******************************************************************************
902 * CoRegisterClassObject16 [COMPOBJ.5]
904 * Don't know where it registers it ...
906 HRESULT WINAPI
CoRegisterClassObject16(
909 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
910 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
915 WINE_StringFromCLSID(rclsid
,buf
);
917 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
918 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
924 /******************************************************************************
925 * CoRevokeClassObject16 [COMPOBJ.6]
928 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
) /* [in] token on class obj */
930 FIXME("(0x%08lx),stub!\n", dwRegister
);
936 * COM_GetRegisteredClassObject
938 * This internal method is used to scan the registered class list to
939 * find a class object.
942 * rclsid Class ID of the class to find.
943 * dwClsContext Class context to match.
944 * ppv [out] returns a pointer to the class object. Complying
945 * to normal COM usage, this method will increase the
946 * reference count on this object.
948 static HRESULT
COM_GetRegisteredClassObject(
953 RegisteredClass
* curClass
;
961 * Iterate through the whole list and try to match the class ID.
963 curClass
= firstRegisteredClass
;
965 while (curClass
!= 0)
968 * Check if we have a match on the class ID.
970 if (IsEqualGUID(&(curClass
->classIdentifier
), rclsid
))
973 * Since we don't do out-of process or DCOM just right away, let's ignore the
978 * We have a match, return the pointer to the class object.
980 *ppUnk
= curClass
->classObject
;
982 IUnknown_AddRef(curClass
->classObject
);
988 * Step to the next class in the list.
990 curClass
= curClass
->nextClass
;
994 * If we get to here, we haven't found our class.
999 /******************************************************************************
1000 * CoRegisterClassObject [OLE32.36]
1002 * This method will register the class object for a given class ID.
1004 * See the Windows documentation for more details.
1006 HRESULT WINAPI
CoRegisterClassObject(
1009 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
1010 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
1011 LPDWORD lpdwRegister
1014 RegisteredClass
* newClass
;
1015 LPUNKNOWN foundObject
;
1019 WINE_StringFromCLSID(rclsid
,buf
);
1021 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1022 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
);
1025 * Perform a sanity check on the parameters
1027 if ( (lpdwRegister
==0) || (pUnk
==0) )
1029 return E_INVALIDARG
;
1033 * Initialize the cookie (out parameter)
1038 * First, check if the class is already registered.
1039 * If it is, this should cause an error.
1041 hr
= COM_GetRegisteredClassObject(rclsid
, dwClsContext
, &foundObject
);
1046 * The COM_GetRegisteredClassObject increased the reference count on the
1047 * object so it has to be released.
1049 IUnknown_Release(foundObject
);
1051 return CO_E_OBJISREG
;
1055 * If it is not registered, we must create a new entry for this class and
1056 * append it to the registered class list.
1057 * We use the address of the chain node as the cookie since we are sure it's
1060 newClass
= HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass
));
1063 * Initialize the node.
1065 newClass
->classIdentifier
= *rclsid
;
1066 newClass
->runContext
= dwClsContext
;
1067 newClass
->connectFlags
= flags
;
1068 newClass
->dwCookie
= (DWORD
)newClass
;
1069 newClass
->nextClass
= firstRegisteredClass
;
1072 * Since we're making a copy of the object pointer, we have to increase its
1075 newClass
->classObject
= pUnk
;
1076 IUnknown_AddRef(newClass
->classObject
);
1078 firstRegisteredClass
= newClass
;
1081 * Assign the out parameter (cookie)
1083 *lpdwRegister
= newClass
->dwCookie
;
1086 * We're successful Yippee!
1091 /***********************************************************************
1092 * CoRevokeClassObject [OLE32.40]
1094 * This method will remove a class object from the class registry
1096 * See the Windows documentation for more details.
1098 HRESULT WINAPI
CoRevokeClassObject(
1101 RegisteredClass
** prevClassLink
;
1102 RegisteredClass
* curClass
;
1104 TRACE("(%08lx)\n",dwRegister
);
1107 * Iterate through the whole list and try to match the cookie.
1109 curClass
= firstRegisteredClass
;
1110 prevClassLink
= &firstRegisteredClass
;
1112 while (curClass
!= 0)
1115 * Check if we have a match on the cookie.
1117 if (curClass
->dwCookie
== dwRegister
)
1120 * Remove the class from the chain.
1122 *prevClassLink
= curClass
->nextClass
;
1125 * Release the reference to the class object.
1127 IUnknown_Release(curClass
->classObject
);
1130 * Free the memory used by the chain node.
1132 HeapFree(GetProcessHeap(), 0, curClass
);
1138 * Step to the next class in the list.
1140 prevClassLink
= &(curClass
->nextClass
);
1141 curClass
= curClass
->nextClass
;
1145 * If we get to here, we haven't found our class.
1147 return E_INVALIDARG
;
1150 /***********************************************************************
1151 * CoGetClassObject [COMPOBJ.7]
1153 HRESULT WINAPI
CoGetClassObject(
1154 REFCLSID rclsid
, DWORD dwClsContext
, COSERVERINFO
*pServerInfo
,
1155 REFIID iid
, LPVOID
*ppv
1157 LPUNKNOWN regClassObject
;
1158 HRESULT hres
= E_UNEXPECTED
;
1160 WCHAR dllName
[MAX_PATH
+1];
1161 DWORD dllNameLen
= sizeof(dllName
);
1163 typedef HRESULT
CALLBACK (*DllGetClassObjectFunc
)(REFCLSID clsid
,
1164 REFIID iid
, LPVOID
*ppv
);
1165 DllGetClassObjectFunc DllGetClassObject
;
1167 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
1169 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1170 debugstr_guid(rclsid
),
1175 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo
->pwszName
));
1176 FIXME("\t\tpAuthInfo=%p\n",pServerInfo
->pAuthInfo
);
1180 * First, try and see if we can't match the class ID with one of the
1181 * registered classes.
1183 if (S_OK
== COM_GetRegisteredClassObject(rclsid
, dwClsContext
, ®ClassObject
))
1186 * Get the required interface from the retrieved pointer.
1188 hres
= IUnknown_QueryInterface(regClassObject
, iid
, ppv
);
1191 * Since QI got another reference on the pointer, we want to release the
1192 * one we already have. If QI was unsuccessful, this will release the object. This
1193 * is good since we are not returning it in the "out" parameter.
1195 IUnknown_Release(regClassObject
);
1200 /* out of process and remote servers not supported yet */
1201 if ( ((CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
) & dwClsContext
)
1202 && !((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
)
1204 FIXME("%s %s not supported!\n",
1205 (dwClsContext
&CLSCTX_LOCAL_SERVER
)?"CLSCTX_LOCAL_SERVER":"",
1206 (dwClsContext
&CLSCTX_REMOTE_SERVER
)?"CLSCTX_REMOTE_SERVER":""
1208 return E_ACCESSDENIED
;
1211 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
1215 sprintf(buf
,"CLSID\\%s\\InprocServer32",xclsid
);
1216 hres
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, buf
, 0, KEY_READ
, &key
);
1218 if (hres
!= ERROR_SUCCESS
) {
1219 return REGDB_E_CLASSNOTREG
;
1222 memset(dllName
,0,sizeof(dllName
));
1223 hres
= RegQueryValueExW(key
,NULL
,NULL
,NULL
,(LPBYTE
)dllName
,&dllNameLen
);
1225 return REGDB_E_CLASSNOTREG
; /* FIXME: check retval */
1227 TRACE("found InprocServer32 dll %s\n", debugstr_w(dllName
));
1229 /* open dll, call DllGetClassObject */
1230 hLibrary
= CoLoadLibrary(dllName
, TRUE
);
1231 if (hLibrary
== 0) {
1232 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(dllName
));
1233 return E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
1235 DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject");
1236 if (!DllGetClassObject
) {
1237 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1238 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllName
));
1239 return E_ACCESSDENIED
;
1243 * Ask the DLL for its class object. (there was a note here about class
1244 * factories but this is good.
1246 return DllGetClassObject(rclsid
, iid
, ppv
);
1251 /***********************************************************************
1252 * CoResumeClassObjects
1254 * Resumes classobjects registered with REGCLS suspended
1256 HRESULT WINAPI
CoResumeClassObjects(void)
1262 /***********************************************************************
1265 * This function supplies the CLSID associated with the given filename.
1267 HRESULT WINAPI
GetClassFile(LPOLESTR filePathName
,CLSID
*pclsid
)
1271 int nbElm
=0,length
=0,i
=0;
1273 LPOLESTR
*pathDec
=0,absFile
=0,progId
=0;
1274 WCHAR extention
[100]={0};
1278 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1279 if((StgIsStorageFile(filePathName
))==S_OK
){
1281 res
=StgOpenStorage(filePathName
,NULL
,STGM_READ
| STGM_SHARE_DENY_WRITE
,NULL
,0,&pstg
);
1284 res
=ReadClassStg(pstg
,pclsid
);
1286 IStorage_Release(pstg
);
1290 /* if the file is not a storage object then attemps to match various bits in the file against a
1291 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1294 for(i=0;i<nFileTypes;i++)
1296 for(i=0;j<nPatternsForType;j++){
1301 pat=ReadPatternFromRegistry(i,j);
1302 hFile=CreateFileW(filePathName,,,,,,hFile);
1303 SetFilePosition(hFile,pat.offset);
1304 ReadFile(hFile,buf,pat.size,NULL,NULL);
1305 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1307 *pclsid=ReadCLSIDFromRegistry(i);
1313 /* if the obove strategies fail then search for the extension key in the registry */
1315 /* get the last element (absolute file) in the path name */
1316 nbElm
=FileMonikerImpl_DecomposePath(filePathName
,&pathDec
);
1317 absFile
=pathDec
[nbElm
-1];
1319 /* failed if the path represente a directory and not an absolute file name*/
1320 if (lstrcmpW(absFile
,(LPOLESTR
)"\\"))
1321 return MK_E_INVALIDEXTENSION
;
1323 /* get the extension of the file */
1324 length
=lstrlenW(absFile
);
1325 for(i
=length
-1; ( (i
>=0) && (extention
[i
]=absFile
[i
]) );i
--);
1327 /* get the progId associated to the extension */
1328 progId
=CoTaskMemAlloc(sizeProgId
);
1330 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1332 if (res
==ERROR_MORE_DATA
){
1334 progId
= CoTaskMemRealloc(progId
,sizeProgId
);
1335 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1337 if (res
==ERROR_SUCCESS
)
1338 /* return the clsid associated to the progId */
1339 res
= CLSIDFromProgID(progId
,pclsid
);
1341 for(i
=0; pathDec
[i
]!=NULL
;i
++)
1342 CoTaskMemFree(pathDec
[i
]);
1343 CoTaskMemFree(pathDec
);
1345 CoTaskMemFree(progId
);
1347 if (res
==ERROR_SUCCESS
)
1350 return MK_E_INVALIDEXTENSION
;
1352 /******************************************************************************
1353 * CoRegisterMessageFilter16 [COMPOBJ.27]
1355 HRESULT WINAPI
CoRegisterMessageFilter16(
1356 LPMESSAGEFILTER lpMessageFilter
,
1357 LPMESSAGEFILTER
*lplpMessageFilter
1359 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
1363 /***********************************************************************
1364 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1366 HRESULT WINAPI
CoCreateInstance(
1368 LPUNKNOWN pUnkOuter
,
1374 LPCLASSFACTORY lpclf
= 0;
1383 * Initialize the "out" parameter
1388 * Get a class factory to construct the object we want.
1390 hres
= CoGetClassObject(rclsid
,
1397 FIXME("no instance created for %s, hres is 0x%08lx\n",debugstr_guid(iid
),hres
);
1402 * Create the object and don't forget to release the factory
1404 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
1405 IClassFactory_Release(lpclf
);
1410 /***********************************************************************
1411 * CoCreateInstanceEx [OLE32.165]
1413 HRESULT WINAPI
CoCreateInstanceEx(
1415 LPUNKNOWN pUnkOuter
,
1417 COSERVERINFO
* pServerInfo
,
1421 IUnknown
* pUnk
= NULL
;
1424 int successCount
= 0;
1429 if ( (cmq
==0) || (pResults
==NULL
))
1430 return E_INVALIDARG
;
1432 if (pServerInfo
!=NULL
)
1433 FIXME("() non-NULL pServerInfo not supported!\n");
1436 * Initialize all the "out" parameters.
1438 for (index
= 0; index
< cmq
; index
++)
1440 pResults
[index
].pItf
= NULL
;
1441 pResults
[index
].hr
= E_NOINTERFACE
;
1445 * Get the object and get its IUnknown pointer.
1447 hr
= CoCreateInstance(rclsid
,
1457 * Then, query for all the interfaces requested.
1459 for (index
= 0; index
< cmq
; index
++)
1461 pResults
[index
].hr
= IUnknown_QueryInterface(pUnk
,
1462 pResults
[index
].pIID
,
1463 (VOID
**)&(pResults
[index
].pItf
));
1465 if (pResults
[index
].hr
== S_OK
)
1470 * Release our temporary unknown pointer.
1472 IUnknown_Release(pUnk
);
1474 if (successCount
== 0)
1475 return E_NOINTERFACE
;
1477 if (successCount
!=cmq
)
1478 return CO_S_NOTALLINTERFACES
;
1483 /***********************************************************************
1484 * CoFreeLibrary [COMPOBJ.13]
1486 void WINAPI
CoFreeLibrary(HINSTANCE hLibrary
)
1488 OpenDll
*ptr
, *prev
;
1491 /* lookup library in linked list */
1493 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
1494 if (ptr
->hLibrary
== hLibrary
) {
1501 /* shouldn't happen if user passed in a valid hLibrary */
1504 /* assert: ptr points to the library entry to free */
1506 /* free library and remove node from list */
1507 FreeLibrary(hLibrary
);
1508 if (ptr
== openDllList
) {
1509 tmp
= openDllList
->next
;
1510 HeapFree(GetProcessHeap(), 0, openDllList
);
1514 HeapFree(GetProcessHeap(), 0, ptr
);
1521 /***********************************************************************
1522 * CoFreeAllLibraries [COMPOBJ.12]
1524 void WINAPI
CoFreeAllLibraries(void)
1528 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1530 CoFreeLibrary(ptr
->hLibrary
);
1537 /***********************************************************************
1538 * CoFreeUnusedLibraries [COMPOBJ.17]
1540 void WINAPI
CoFreeUnusedLibraries(void)
1543 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
1544 DllCanUnloadNowFunc DllCanUnloadNow
;
1546 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1547 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
1548 GetProcAddress(ptr
->hLibrary
, "DllCanUnloadNow");
1550 if ( (DllCanUnloadNow
!= NULL
) &&
1551 (DllCanUnloadNow() == S_OK
) ) {
1553 CoFreeLibrary(ptr
->hLibrary
);
1561 /***********************************************************************
1562 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1564 * the current system time in lpFileTime
1566 HRESULT WINAPI
CoFileTimeNow( FILETIME
*lpFileTime
) /* [out] the current time */
1568 GetSystemTimeAsFileTime( lpFileTime
);
1572 /***********************************************************************
1573 * CoTaskMemAlloc (OLE32.43)
1575 * pointer to newly allocated block
1577 LPVOID WINAPI
CoTaskMemAlloc(
1578 ULONG size
/* [in] size of memoryblock to be allocated */
1581 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1586 return IMalloc_Alloc(lpmalloc
,size
);
1588 /***********************************************************************
1589 * CoTaskMemFree (OLE32.44)
1591 VOID WINAPI
CoTaskMemFree(
1592 LPVOID ptr
/* [in] pointer to be freed */
1595 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1600 IMalloc_Free(lpmalloc
, ptr
);
1603 /***********************************************************************
1604 * CoTaskMemRealloc (OLE32.45)
1606 * pointer to newly allocated block
1608 LPVOID WINAPI
CoTaskMemRealloc(
1610 ULONG size
) /* [in] size of memoryblock to be allocated */
1613 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1618 return IMalloc_Realloc(lpmalloc
, pvOld
, size
);
1621 /***********************************************************************
1622 * CoLoadLibrary (OLE32.30)
1624 HINSTANCE WINAPI
CoLoadLibrary(LPOLESTR lpszLibName
, BOOL bAutoFree
)
1630 TRACE("(%s, %d)\n", debugstr_w(lpszLibName
), bAutoFree
);
1632 hLibrary
= LoadLibraryExW(lpszLibName
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
1637 if (openDllList
== NULL
) {
1638 /* empty list -- add first node */
1639 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1640 openDllList
->hLibrary
=hLibrary
;
1641 openDllList
->next
= NULL
;
1643 /* search for this dll */
1645 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1646 if (ptr
->hLibrary
== hLibrary
) {
1652 /* dll not found, add it */
1654 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1655 openDllList
->hLibrary
= hLibrary
;
1656 openDllList
->next
= tmp
;
1663 /***********************************************************************
1664 * CoInitializeWOW (OLE32.27)
1666 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1667 FIXME("(0x%08lx,0x%08lx),stub!\n",x
,y
);
1671 /******************************************************************************
1672 * CoLockObjectExternal16 [COMPOBJ.63]
1674 HRESULT WINAPI
CoLockObjectExternal16(
1675 LPUNKNOWN pUnk
, /* [in] object to be locked */
1676 BOOL16 fLock
, /* [in] do lock */
1677 BOOL16 fLastUnlockReleases
/* [in] ? */
1679 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1683 /******************************************************************************
1684 * CoLockObjectExternal [OLE32.31]
1686 HRESULT WINAPI
CoLockObjectExternal(
1687 LPUNKNOWN pUnk
, /* [in] object to be locked */
1688 BOOL fLock
, /* [in] do lock */
1689 BOOL fLastUnlockReleases
) /* [in] unlock all */
1695 * Increment the external lock coutner, COM_ExternalLockAddRef also
1696 * increment the object's internal lock counter.
1698 COM_ExternalLockAddRef( pUnk
);
1703 * Decrement the external lock coutner, COM_ExternalLockRelease also
1704 * decrement the object's internal lock counter.
1706 COM_ExternalLockRelease( pUnk
, fLastUnlockReleases
);
1712 /***********************************************************************
1713 * CoGetState16 [COMPOBJ.115]
1715 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1717 FIXME("(%p),stub!\n", state
);
1721 /***********************************************************************
1722 * CoSetState [COM32.42]
1724 HRESULT WINAPI
CoSetState(LPDWORD state
)
1726 FIXME("(%p),stub!\n", state
);
1727 if (state
) *state
= 0;
1730 /***********************************************************************
1731 * CoCreateFreeThreadedMarshaler [OLE32.5]
1733 HRESULT WINAPI
CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter
, LPUNKNOWN
* ppunkMarshal
)
1735 FIXME ("(%p %p): stub\n", punkOuter
, ppunkMarshal
);
1741 /***********************************************************************
1742 * DllGetClassObject [OLE32.63]
1744 HRESULT WINAPI
OLE32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
1746 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid
),debugstr_guid(iid
));
1748 return CLASS_E_CLASSNOTAVAILABLE
;
1753 * COM_RevokeAllClasses
1755 * This method is called when the COM libraries are uninitialized to
1756 * release all the references to the class objects registered with
1759 static void COM_RevokeAllClasses()
1761 while (firstRegisteredClass
!=0)
1763 CoRevokeClassObject(firstRegisteredClass
->dwCookie
);
1767 /****************************************************************************
1768 * COM External Lock methods implementation
1771 /****************************************************************************
1772 * Public - Method that increments the count for a IUnknown* in the linked
1773 * list. The item is inserted if not already in the list.
1775 static void COM_ExternalLockAddRef(
1778 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1781 * Add an external lock to the object. If it was already externally
1782 * locked, just increase the reference count. If it was not.
1783 * add the item to the list.
1785 if ( externalLock
== EL_NOT_FOUND
)
1786 COM_ExternalLockInsert(pUnk
);
1788 externalLock
->uRefCount
++;
1791 * Add an internal lock to the object
1793 IUnknown_AddRef(pUnk
);
1796 /****************************************************************************
1797 * Public - Method that decrements the count for a IUnknown* in the linked
1798 * list. The item is removed from the list if its count end up at zero or if
1801 static void COM_ExternalLockRelease(
1805 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1807 if ( externalLock
!= EL_NOT_FOUND
)
1811 externalLock
->uRefCount
--; /* release external locks */
1812 IUnknown_Release(pUnk
); /* release local locks as well */
1814 if ( bRelAll
== FALSE
)
1815 break; /* perform single release */
1817 } while ( externalLock
->uRefCount
> 0 );
1819 if ( externalLock
->uRefCount
== 0 ) /* get rid of the list entry */
1820 COM_ExternalLockDelete(externalLock
);
1823 /****************************************************************************
1824 * Public - Method that frees the content of the list.
1826 static void COM_ExternalLockFreeList()
1828 COM_ExternalLock
*head
;
1830 head
= elList
.head
; /* grab it by the head */
1831 while ( head
!= EL_END_OF_LIST
)
1833 COM_ExternalLockDelete(head
); /* get rid of the head stuff */
1835 head
= elList
.head
; /* get the new head... */
1839 /****************************************************************************
1840 * Public - Method that dump the content of the list.
1842 void COM_ExternalLockDump()
1844 COM_ExternalLock
*current
= elList
.head
;
1846 DPRINTF("\nExternal lock list contains:\n");
1848 while ( current
!= EL_END_OF_LIST
)
1850 DPRINTF( "\t%p with %lu references count.\n", current
->pUnk
, current
->uRefCount
);
1852 /* Skip to the next item */
1853 current
= current
->next
;
1858 /****************************************************************************
1859 * Internal - Find a IUnknown* in the linked list
1861 static COM_ExternalLock
* COM_ExternalLockFind(
1864 return COM_ExternalLockLocate(elList
.head
, pUnk
);
1867 /****************************************************************************
1868 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1870 static COM_ExternalLock
* COM_ExternalLockLocate(
1871 COM_ExternalLock
*element
,
1874 if ( element
== EL_END_OF_LIST
)
1875 return EL_NOT_FOUND
;
1877 else if ( element
->pUnk
== pUnk
) /* We found it */
1880 else /* Not the right guy, keep on looking */
1881 return COM_ExternalLockLocate( element
->next
, pUnk
);
1884 /****************************************************************************
1885 * Internal - Insert a new IUnknown* to the linked list
1887 static BOOL
COM_ExternalLockInsert(
1890 COM_ExternalLock
*newLock
= NULL
;
1891 COM_ExternalLock
*previousHead
= NULL
;
1894 * Allocate space for the new storage object
1896 newLock
= HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock
));
1900 if ( elList
.head
== EL_END_OF_LIST
)
1902 elList
.head
= newLock
; /* The list is empty */
1907 * insert does it at the head
1909 previousHead
= elList
.head
;
1910 elList
.head
= newLock
;
1914 * Set new list item data member
1916 newLock
->pUnk
= pUnk
;
1917 newLock
->uRefCount
= 1;
1918 newLock
->next
= previousHead
;
1926 /****************************************************************************
1927 * Internal - Method that removes an item from the linked list.
1929 static void COM_ExternalLockDelete(
1930 COM_ExternalLock
*itemList
)
1932 COM_ExternalLock
*current
= elList
.head
;
1934 if ( current
== itemList
)
1937 * this section handles the deletion of the first node
1939 elList
.head
= itemList
->next
;
1940 HeapFree( GetProcessHeap(), 0, itemList
);
1946 if ( current
->next
== itemList
) /* We found the item to free */
1948 current
->next
= itemList
->next
; /* readjust the list pointers */
1950 HeapFree( GetProcessHeap(), 0, itemList
);
1954 /* Skip to the next item */
1955 current
= current
->next
;
1957 } while ( current
!= EL_END_OF_LIST
);
1961 /***********************************************************************
1962 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
1964 * Initialization code for the COMPOBJ DLL
1968 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
1970 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
,
1974 case DLL_PROCESS_ATTACH
:
1975 if (!COMPOBJ_Attach
++) COMPOBJ_hInstance
= hInst
;
1978 case DLL_PROCESS_DETACH
:
1979 if(!--COMPOBJ_Attach
)
1980 COMPOBJ_hInstance
= 0;
1986 /******************************************************************************
1987 * OleGetAutoConvert [OLE32.104]
1989 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
1997 sprintf(buf
,"CLSID\\");WINE_StringFromCLSID(clsidOld
,&buf
[6]);
1998 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&hkey
))
2000 res
= REGDB_E_CLASSNOTREG
;
2004 /* we can just query for the default value of AutoConvertTo key like that,
2005 without opening the AutoConvertTo key and querying for NULL (default) */
2006 if (RegQueryValueA(hkey
,"AutoConvertTo",buf
,&len
))
2008 res
= REGDB_E_KEYMISSING
;
2011 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, wbuf
, sizeof(wbuf
)/sizeof(WCHAR
) );
2012 CLSIDFromString(wbuf
,pClsidNew
);
2014 if (hkey
) RegCloseKey(hkey
);
2019 /******************************************************************************
2020 * OleSetAutoConvert [OLE32.126]
2022 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2024 HKEY hkey
= 0, hkeyConvert
= 0;
2025 char buf
[200], szClsidNew
[200];
2028 TRACE("(%p,%p);\n", clsidOld
, clsidNew
);
2029 sprintf(buf
,"CLSID\\");WINE_StringFromCLSID(clsidOld
,&buf
[6]);
2030 WINE_StringFromCLSID(clsidNew
, szClsidNew
);
2031 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&hkey
))
2033 res
= REGDB_E_CLASSNOTREG
;
2036 if (RegCreateKeyA(hkey
, "AutoConvertTo", &hkeyConvert
))
2038 res
= REGDB_E_WRITEREGDB
;
2041 if (RegSetValueExA(hkeyConvert
, NULL
, 0,
2042 REG_SZ
, (LPBYTE
)szClsidNew
, strlen(szClsidNew
)+1))
2044 res
= REGDB_E_WRITEREGDB
;
2049 if (hkeyConvert
) RegCloseKey(hkeyConvert
);
2050 if (hkey
) RegCloseKey(hkey
);
2055 /***********************************************************************
2056 * IsEqualGUID [OLE32.76]
2058 * Compares two Unique Identifiers.
2064 BOOL WINAPI
IsEqualGUID(
2065 REFGUID rguid1
, /* [in] unique id 1 */
2066 REFGUID rguid2
/* [in] unique id 2 */
2069 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));