4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
15 #include <ole32/ole32.h>
17 #include <storage32.h>
21 /****************************************************************************
22 * COM External Lock structures and methods declaration
24 * This api provides a linked list to managed external references to
27 * The public interface consists of three calls:
28 * COM_ExternalLockAddRef
29 * COM_ExternalLockRelease
30 * COM_ExternalLockFreeList
33 #define EL_END_OF_LIST 0
34 #define EL_NOT_FOUND 0
37 * Declaration of the static structure that manage the
38 * external lock to COM objects.
40 typedef struct COM_ExternalLock COM_ExternalLock;
41 typedef struct COM_ExternalLockList COM_ExternalLockList;
43 struct COM_ExternalLock
45 IUnknown *pUnk; /* IUnknown referenced */
46 ULONG uRefCount; /* external lock counter to IUnknown object*/
47 COM_ExternalLock *next; /* Pointer to next element in list */
50 struct COM_ExternalLockList
52 COM_ExternalLock *head; /* head of list */
56 * Declaration and initialization of the static structure that manages
57 * the external lock to COM objects.
59 static COM_ExternalLockList elList = { EL_END_OF_LIST };
62 * Public Interface to the external lock list
64 static void COM_ExternalLockFreeList();
65 static void COM_ExternalLockAddRef(IUnknown *pUnk);
66 static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
67 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
70 * Private methods used to managed the linked list
72 static BOOL COM_ExternalLockInsert(
75 static void COM_ExternalLockDelete(
76 COM_ExternalLock *element);
78 static COM_ExternalLock* COM_ExternalLockFind(
81 static COM_ExternalLock* COM_ExternalLockLocate(
82 COM_ExternalLock *element,
85 /****************************************************************************
86 * This section defines variables internal to the COM module.
88 * TODO: Most of these things will have to be made thread-safe.
90 HINSTANCE COMPOBJ_hInstance32 = 0;
91 static int COMPOBJ_Attach = 0;
93 LPMALLOC currentMalloc32=NULL;
98 * This lock count counts the number of times CoInitialize is called. It is
99 * decreased every time CoUninitialize is called. When it hits 0, the COM
100 * libraries are freed
102 static ULONG s_COMLockCount = 0;
105 * This linked list contains the list of registered class objects. These
106 * are mostly used to register the factories for out-of-proc servers of OLE
109 * TODO: Make this data structure aware of inter-process communication. This
110 * means that parts of this will be exported to the Wine Server.
112 typedef struct tagRegisteredClass
114 CLSID classIdentifier;
115 LPUNKNOWN classObject;
119 struct tagRegisteredClass* nextClass;
122 static RegisteredClass* firstRegisteredClass = NULL;
124 /* this open DLL table belongs in a per process table, but my guess is that
125 * it shouldn't live in the kernel, so I'll put them out here in DLL
126 * space assuming that there is one OLE32 per process.
128 typedef struct tagOpenDll {
130 struct tagOpenDll *next;
133 static OpenDll *openDllList = NULL; /* linked list of open dlls */
135 /*****************************************************************************
136 * This section contains prototypes to internal methods for this
139 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
143 static void COM_RevokeAllClasses();
146 /******************************************************************************
147 * CoBuildVersion [COMPOBJ.1]
150 * Current build version, hiword is majornumber, loword is minornumber
152 DWORD WINAPI CoBuildVersion(void)
154 Print(MAX_TRACE, ("Returning version %d, build %d.\n", 1, 0));
158 /******************************************************************************
159 * CoInitialize16 [COMPOBJ.2]
160 * Set the win16 IMalloc used for memory management
162 HRESULT WINAPI CoInitialize16(
163 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
169 /******************************************************************************
170 * CoInitialize [OLE32.26]
172 * Initializes the COM libraries.
176 HRESULT WINAPI CoInitialize(
177 LPVOID lpReserved /* [in] pointer to win32 malloc interface
178 (obsolete, should be NULL) */
183 * Just delegate to the newer method.
185 return CoInitializeEx(lpReserved, )COINIT_APARTMENTTHREADED);
191 /******************************************************************************
192 * CoInitializeEx [OLE32.163]
194 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
195 * used for memory management is obsolete.
198 * S_OK if successful,
199 * S_FALSE if this function was called already.
200 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
204 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
207 * See the windows documentation for more details.
209 HRESULT WINAPI CoInitializeEx(
210 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
211 (obsolete, should be NULL) */
212 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
217 Print(MAX_TRACE, ("(%p, %x)\n", lpReserved, (int)dwCoInit));
219 if (lpReserved!=NULL)
221 Print(MIN_TRACE, ("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved));
225 * Check for unsupported features.
227 if (dwCoInit!=COINIT_APARTMENTTHREADED)
229 Print(MAX_TRACE, (":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit));
230 /* Hope for the best and continue anyway */
234 * Check the lock count. If this is the first time going through the initialize
235 * process, we have to initialize the libraries.
237 if (s_COMLockCount==0)
240 * Initialize the various COM libraries and data structures.
242 Print(MAX_TRACE, ("() - Initializing the COM libraries\n"));
244 RunningObjectTableImpl_Initialize();
252 * Crank-up that lock count.
259 /***********************************************************************
260 * CoUninitialize16 [COMPOBJ.3]
261 * Don't know what it does.
262 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
263 * believe is the correct spelling
265 void WINAPI CoUninitialize16(void)
267 Print(MAX_TRACE, ("Called\n"));
268 CoFreeAllLibraries();
271 /***********************************************************************
272 * CoUninitialize [OLE32.47]
274 * This method will release the COM libraries.
276 * See the windows documentation for more details.
278 void WINAPI CoUninitialize(void)
280 Print(MAX_TRACE, ("Called\n"));
283 * Decrease the reference count.
288 * If we are back to 0 locks on the COM library, make sure we free
289 * all the associated data structures.
291 if (s_COMLockCount==0)
294 * Release the various COM libraries and data structures.
296 Print(MAX_TRACE, ("() - Releasing the COM libraries\n"));
298 RunningObjectTableImpl_UnInitialize();
300 * Release the references to the registered class objects.
302 COM_RevokeAllClasses();
305 * This will free the loaded COM Dlls.
307 CoFreeAllLibraries();
310 * This will free list of external references to COM objects.
312 COM_ExternalLockFreeList();
316 /***********************************************************************
317 * CoGetMalloc16 [COMPOBJ.4]
319 * The current win16 IMalloc
321 HRESULT WINAPI CoGetMalloc16(
322 DWORD dwMemContext, /* [in] unknown */
323 PVOID lpMalloc /* [out] current win16 malloc interface */
329 /******************************************************************************
330 * CoGetMalloc [OLE32.20]
333 * The current win32 IMalloc
335 HRESULT WINAPI CoGetMalloc(
336 DWORD dwMemContext, /* [in] unknown */
337 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
341 currentMalloc32 = IMalloc_Constructor();
342 *lpMalloc = currentMalloc32;
350 /***********************************************************************
351 * CoCreateStandardMalloc16 [COMPOBJ.71]
353 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
360 /******************************************************************************
361 * CoDisconnectObject [COMPOBJ.15]
363 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
365 Print(MAX_TRACE, ("(%p, %lx)\n",lpUnk,reserved));
369 /***********************************************************************
370 * IsEqualGUID16 [COMPOBJ.18]
372 * Compares two Unique Identifiers.
377 BOOL WINAPI IsEqualGUID16(
378 GUID* g1, /* [in] unique id 1 */
379 GUID* g2 /* [in] unique id 2 */
381 return !memcmp( g1, g2, sizeof(GUID) );
384 /******************************************************************************
385 * CLSIDFromString16 [COMPOBJ.20]
386 * Converts a unique identifier from its string representation into
389 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
394 HRESULT WINAPI CLSIDFromString16(
395 LPCOLESTR16 idstr, /* [in] string representation of guid */
396 CLSID *id /* [out] GUID converted from string */
398 BYTE *s = (BYTE *) idstr;
404 s = "{00000000-0000-0000-0000-000000000000}";
405 else { /* validate the CLSID string */
408 return CO_E_CLASSSTRING;
410 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
411 return CO_E_CLASSSTRING;
415 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
416 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
417 ((s[i] >= 'a') && (s[i] <= 'f')) ||
418 ((s[i] >= 'A') && (s[i] <= 'F')))
420 return CO_E_CLASSSTRING;
424 Print(MAX_TRACE, ("%s -> %p\n", s, id));
426 /* quick lookup table */
427 memset(table, 0, 256);
429 for (i = 0; i < 10; i++) {
432 for (i = 0; i < 6; i++) {
433 table['A' + i] = i+10;
434 table['a' + i] = i+10;
437 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
441 s++; /* skip leading brace */
442 for (i = 0; i < 4; i++) {
443 p[3 - i] = table[*s]<<4 | table[*(s+1)];
449 for (i = 0; i < 2; i++) {
450 p[1-i] = table[*s]<<4 | table[*(s+1)];
456 for (i = 0; i < 2; i++) {
457 p[1-i] = table[*s]<<4 | table[*(s+1)];
463 /* these are just sequential bytes */
464 for (i = 0; i < 2; i++) {
465 *p++ = table[*s]<<4 | table[*(s+1)];
470 for (i = 0; i < 6; i++) {
471 *p++ = table[*s]<<4 | table[*(s+1)];
478 /******************************************************************************
479 * CoCreateGuid[OLE32.6]
482 HRESULT WINAPI CoCreateGuid(
483 GUID *pguid /* [out] points to the GUID to initialize */
485 return UuidCreate(pguid);
488 /******************************************************************************
489 * CLSIDFromString [OLE32.3]
490 * Converts a unique identifier from its string representation into
494 * If idstr is not a valid CLSID string then it gets treated as a ProgID
499 HRESULT WINAPI CLSIDFromString(
500 LPCOLESTR idstr, /* [in] string representation of GUID */
501 CLSID *id /* [out] GUID represented by above string */
504 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
505 HRESULT ret = CLSIDFromString16(xid,id);
507 HeapFree(GetProcessHeap(),0,xid);
508 if(ret != S_OK) { /* It appears a ProgID is also valid */
509 ret = CLSIDFromProgID(idstr, id);
518 /******************************************************************************
519 * WINE_StringFromCLSID [Internal]
520 * Converts a GUID into the respective string representation.
525 * the string representation and HRESULT
527 static HRESULT WINE_StringFromCLSID(
528 const CLSID *id, /* [in] GUID to be converted */
529 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
531 static const char *hex = "0123456789ABCDEF";
536 { Print(MIN_TRACE, ("called with id=Null\n"));
541 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
542 id->Data1, id->Data2, id->Data3,
543 id->Data4[0], id->Data4[1]);
547 for (i = 2; i < 8; i++) {
548 *s++ = hex[id->Data4[i]>>4];
549 *s++ = hex[id->Data4[i] & 0xf];
555 Print(MAX_TRACE, ("%p->%s\n", id, idstr));
560 /******************************************************************************
561 * StringFromCLSID16 [COMPOBJ.19]
562 * Converts a GUID into the respective string representation.
563 * The target string is allocated using the OLE IMalloc.
565 * the string representation and HRESULT
567 HRESULT WINAPI StringFromCLSID16(
568 REFCLSID id, /* [in] the GUID to be converted */
569 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
573 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
574 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
579 ret = CoGetMalloc16(0,&mllc);
582 args[0] = (DWORD)mllc;
585 /* No need for a Callback entry, we have WOWCallback16Ex which does
586 * everything we need.
588 if (!K32WOWCallback16Ex(
589 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
590 (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
597 WARN("CallTo16 IMalloc16 failed\n");
600 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
607 /******************************************************************************
608 * StringFromCLSID [OLE32.151]
609 * Converts a GUID into the respective string representation.
610 * The target string is allocated using the OLE IMalloc.
612 * the string representation and HRESULT
614 HRESULT WINAPI StringFromCLSID(
615 REFCLSID id, /* [in] the GUID to be converted */
616 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
622 if ((ret=CoGetMalloc(0,&mllc)))
625 ret=WINE_StringFromCLSID(id,buf);
627 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
628 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
629 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
634 /******************************************************************************
635 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
637 * Converts a global unique identifier into a string of an API-
638 * specified fixed format. (The usual {.....} stuff.)
641 * The (UNICODE) string representation of the GUID in 'str'
642 * The length of the resulting string, 0 if there was any problem.
645 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
649 if (WINE_StringFromCLSID(id,xguid))
651 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
654 /******************************************************************************
655 * ProgIDFromCLSID [OLE32.133]
656 * Converts a class id into the respective Program ID. (By using a registry lookup)
657 * RETURNS S_OK on success
658 * riid associated with the progid
661 HRESULT WINAPI ProgIDFromCLSID(
662 REFCLSID clsid, /* [in] class id as found in registry */
663 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
666 char strCLSID[50], *buf, *buf2;
672 WINE_StringFromCLSID(clsid, strCLSID);
674 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
675 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
676 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
677 ret = REGDB_E_CLASSNOTREG;
679 HeapFree(GetProcessHeap(), 0, buf);
683 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
685 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
686 ret = REGDB_E_CLASSNOTREG;
690 if (CoGetMalloc(0,&mllc))
694 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
695 *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
696 MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
699 HeapFree(GetProcessHeap(), 0, buf2);
706 /******************************************************************************
707 * CLSIDFromProgID16 [COMPOBJ.61]
708 * Converts a program id into the respective GUID. (By using a registry lookup)
710 * riid associated with the progid
712 HRESULT WINAPI CLSIDFromProgID16(
713 LPCOLESTR16 progid, /* [in] program id as found in registry */
714 LPCLSID riid /* [out] associated CLSID */
721 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
722 sprintf(buf,"%s\\CLSID",progid);
723 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
724 HeapFree(GetProcessHeap(),0,buf);
725 return CO_E_CLASSSTRING;
727 HeapFree(GetProcessHeap(),0,buf);
728 buf2len = sizeof(buf2);
729 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
731 return CO_E_CLASSSTRING;
734 return CLSIDFromString16(buf2,riid);
737 /******************************************************************************
738 * CLSIDFromProgID [OLE32.2]
739 * Converts a program id into the respective GUID. (By using a registry lookup)
741 * riid associated with the progid
743 HRESULT WINAPI CLSIDFromProgID(
744 LPCOLESTR progid, /* [in] program id as found in registry */
745 LPCLSID riid /* [out] associated CLSID */
748 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
749 HRESULT ret = CLSIDFromProgID16(pid,riid);
751 HeapFree(GetProcessHeap(),0,pid);
761 /*****************************************************************************
762 * CoGetPSClsid [OLE32.22]
764 * This function returns the CLSID of the DLL that implements the proxy and stub
765 * for the specified interface.
767 * It determines this by searching the
768 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
769 * and any interface id registered by CoRegisterPSClsid within the current process.
771 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
773 HRESULT WINAPI CoGetPSClsid(
774 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
775 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
781 Print(MAX_TRACE, ("() riid=%s, pclsid=%p\n", PRINT_GUID(riid), pclsid));
783 /* Get the input iid as a string */
784 WINE_StringFromCLSID(riid, buf2);
785 /* Allocate memory for the registry key we will construct.
786 (length of iid string plus constant length of static text */
787 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
790 return (E_OUTOFMEMORY);
793 /* Construct the registry key we want */
794 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
797 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
799 HeapFree(GetProcessHeap(),0,buf);
800 return (E_INVALIDARG);
802 HeapFree(GetProcessHeap(),0,buf);
804 /* ... Once we have the key, query the registry to get the
805 value of CLSID as a string, and convert it into a
806 proper CLSID structure to be passed back to the app */
807 buf2len = sizeof(buf2);
808 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
815 /* We have the CLSid we want back from the registry as a string, so
816 lets convert it into a CLSID structure */
817 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
822 Print(MAX_TRACE, ("() Returning CLSID=%s\n", PRINT_GUID(pclsid)));
828 /***********************************************************************
831 * This function write a CLSID on stream
833 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
835 Print(MAX_TRACE, ("(%p,%p)\n",pStm,rclsid));
840 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
843 /***********************************************************************
846 * This function read a CLSID from a stream
848 HRESULT WINAPI ReadClassStm(IStream *pStm,REFCLSID rclsid)
853 Print(MAX_TRACE, ("(%p,%p)\n",pStm,rclsid));
858 res = IStream_Read(pStm,(void*)rclsid,sizeof(CLSID),&nbByte);
863 if (nbByte != sizeof(CLSID))
869 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
870 /***********************************************************************
871 * LookupETask (COMPOBJ.94)
873 HRESULT WINAPI LookupETask16(PVOID hTask,LPVOID p) {
878 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
879 /***********************************************************************
880 * SetETask (COMPOBJ.95)
882 HRESULT WINAPI SetETask16(DWORD hTask, LPVOID p) {
887 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
888 /***********************************************************************
889 * CallObjectInWOW (COMPOBJ.201)
891 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
896 /******************************************************************************
897 * CoRegisterClassObject16 [COMPOBJ.5]
899 * Don't know where it registers it ...
901 HRESULT WINAPI CoRegisterClassObject16(
904 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
905 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
913 /******************************************************************************
914 * CoRevokeClassObject16 [COMPOBJ.6]
917 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
925 * COM_GetRegisteredClassObject
927 * This internal method is used to scan the registered class list to
928 * find a class object.
931 * rclsid Class ID of the class to find.
932 * dwClsContext Class context to match.
933 * ppv [out] returns a pointer to the class object. Complying
934 * to normal COM usage, this method will increase the
935 * reference count on this object.
937 static HRESULT COM_GetRegisteredClassObject(
942 RegisteredClass* curClass;
950 * Iterate through the whole list and try to match the class ID.
952 curClass = firstRegisteredClass;
954 while (curClass != 0)
957 * Check if we have a match on the class ID.
959 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
962 * Since we don't do out-of process or DCOM just right away, let's ignore the
967 * We have a match, return the pointer to the class object.
969 *ppUnk = curClass->classObject;
971 IUnknown_AddRef(curClass->classObject);
977 * Step to the next class in the list.
979 curClass = curClass->nextClass;
983 * If we get to here, we haven't found our class.
988 /******************************************************************************
989 * CoRegisterClassObject [OLE32.36]
991 * This method will register the class object for a given class ID.
993 * See the Windows documentation for more details.
995 HRESULT WINAPI CoRegisterClassObject(
998 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
999 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1000 LPDWORD lpdwRegister
1003 RegisteredClass* newClass;
1004 LPUNKNOWN foundObject;
1008 WINE_StringFromCLSID(rclsid,buf);
1010 Print(MAX_TRACE, ("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1011 buf,pUnk,dwClsContext,flags,lpdwRegister));
1014 * Perform a sanity check on the parameters
1016 if ( (lpdwRegister==0) || (pUnk==0) )
1018 return E_INVALIDARG;
1022 * Initialize the cookie (out parameter)
1027 * First, check if the class is already registered.
1028 * If it is, this should cause an error.
1030 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1035 * The COM_GetRegisteredClassObject increased the reference count on the
1036 * object so it has to be released.
1038 IUnknown_Release(foundObject);
1040 return CO_E_OBJISREG;
1044 * If it is not registered, we must create a new entry for this class and
1045 * append it to the registered class list.
1046 * We use the address of the chain node as the cookie since we are sure it's
1049 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1052 * Initialize the node.
1054 newClass->classIdentifier = *rclsid;
1055 newClass->runContext = dwClsContext;
1056 newClass->connectFlags = flags;
1057 newClass->dwCookie = (DWORD)newClass;
1058 newClass->nextClass = firstRegisteredClass;
1061 * Since we're making a copy of the object pointer, we have to increase its
1064 newClass->classObject = pUnk;
1065 IUnknown_AddRef(newClass->classObject);
1067 firstRegisteredClass = newClass;
1070 * Assign the out parameter (cookie)
1072 *lpdwRegister = newClass->dwCookie;
1075 * We're successful Yippee!
1080 /***********************************************************************
1081 * CoRevokeClassObject [OLE32.40]
1083 * This method will remove a class object from the class registry
1085 * See the Windows documentation for more details.
1087 HRESULT WINAPI CoRevokeClassObject(
1090 RegisteredClass** prevClassLink;
1091 RegisteredClass* curClass;
1093 Print(MAX_TRACE, ("(%08lx)\n",dwRegister));
1096 * Iterate through the whole list and try to match the cookie.
1098 curClass = firstRegisteredClass;
1099 prevClassLink = &firstRegisteredClass;
1101 while (curClass != 0)
1104 * Check if we have a match on the cookie.
1106 if (curClass->dwCookie == dwRegister)
1109 * Remove the class from the chain.
1111 *prevClassLink = curClass->nextClass;
1114 * Release the reference to the class object.
1116 IUnknown_Release(curClass->classObject);
1119 * Free the memory used by the chain node.
1121 HeapFree(GetProcessHeap(), 0, curClass);
1127 * Step to the next class in the list.
1129 prevClassLink = &(curClass->nextClass);
1130 curClass = curClass->nextClass;
1134 * If we get to here, we haven't found our class.
1136 return E_INVALIDARG;
1139 /***********************************************************************
1140 * CoGetClassObject [COMPOBJ.7]
1142 HRESULT WINAPI CoGetClassObject(
1143 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1144 REFIID iid, LPVOID *ppv
1146 LPUNKNOWN regClassObject;
1147 HRESULT hres = E_UNEXPECTED;
1149 WCHAR dllName[MAX_PATH+1];
1150 DWORD dllNameLen = sizeof(dllName);
1152 typedef HRESULT CALLBACK (*DllGetClassObjectFunc)(REFCLSID clsid,
1153 REFIID iid, LPVOID *ppv);
1154 DllGetClassObjectFunc DllGetClassObject;
1156 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1158 Print(MIN_TRACE, ("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1164 Print(MIN_TRACE, ("\tpServerInfo: name=%S\n",pServerInfo->pwszName));
1165 Print(MIN_TRACE, ("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo));
1169 * First, try and see if we can't match the class ID with one of the
1170 * registered classes.
1172 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1175 * Get the required interface from the retrieved pointer.
1177 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1180 * Since QI got another reference on the pointer, we want to release the
1181 * one we already have. If QI was unsuccessful, this will release the object. This
1182 * is good since we are not returning it in the "out" parameter.
1184 IUnknown_Release(regClassObject);
1189 /* out of process and remote servers not supported yet */
1190 if ( ((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1191 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
1193 Print(MIN_TRACE, ("%s %s not supported!\n",
1194 (dwClsContext&CLSCTX_LOCAL_SERVER)?"CLSCTX_LOCAL_SERVER":"",
1195 (dwClsContext&CLSCTX_REMOTE_SERVER)?"CLSCTX_REMOTE_SERVER":""
1197 return E_ACCESSDENIED;
1200 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1204 sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
1205 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
1207 if (hres != ERROR_SUCCESS) {
1208 return REGDB_E_CLASSNOTREG;
1211 memset(dllName,0,sizeof(dllName));
1212 hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
1214 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1216 Print(MAX_TRACE, ("found InprocServer32 dll %S\n", dllName));
1218 /* open dll, call DllGetClassObject */
1219 hLibrary = CoLoadLibrary(dllName, TRUE);
1220 if (hLibrary == 0) {
1221 Print(MIN_TRACE, ("couldn't load InprocServer32 dll %S\n", dllName));
1222 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1224 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1225 if (!DllGetClassObject) {
1226 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1227 Print(MIN_TRACE, ("couldn't find function DllGetClassObject in %S\n", dllName));
1228 return E_ACCESSDENIED;
1232 * Ask the DLL for its class object. (there was a note here about class
1233 * factories but this is good.
1235 return DllGetClassObject(rclsid, iid, ppv);
1240 /***********************************************************************
1241 * CoResumeClassObjects
1243 * Resumes classobjects registered with REGCLS suspended
1245 HRESULT WINAPI CoResumeClassObjects(void)
1251 /***********************************************************************
1254 * This function supplies the CLSID associated with the given filename.
1256 HRESULT WINAPI GetClassFile(LPOLESTR filePathName,CLSID *pclsid)
1260 int nbElm=0,length=0,i=0;
1262 LPOLESTR *pathDec=0,absFile=0,progId=0;
1263 WCHAR extention[100]={0};
1265 Print(MAX_TRACE, ("()\n"));
1267 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1268 if((StgIsStorageFile(filePathName))==S_OK){
1270 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1273 res=ReadClassStg(pstg,pclsid);
1275 IStorage_Release(pstg);
1279 /* if the file is not a storage object then attemps to match various bits in the file against a
1280 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1283 for(i=0;i<nFileTypes;i++)
1285 for(i=0;j<nPatternsForType;j++){
1290 pat=ReadPatternFromRegistry(i,j);
1291 hFile=CreateFileW(filePathName,,,,,,hFile);
1292 SetFilePosition(hFile,pat.offset);
1293 ReadFile(hFile,buf,pat.size,NULL,NULL);
1294 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1296 *pclsid=ReadCLSIDFromRegistry(i);
1302 /* if the obove strategies fail then search for the extension key in the registry */
1304 /* get the last element (absolute file) in the path name */
1305 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1306 absFile=pathDec[nbElm-1];
1308 /* failed if the path represente a directory and not an absolute file name*/
1309 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1310 return MK_E_INVALIDEXTENSION;
1312 /* get the extension of the file */
1313 length=lstrlenW(absFile);
1314 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1316 /* get the progId associated to the extension */
1317 progId=CoTaskMemAlloc(sizeProgId);
1319 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1321 if (res==ERROR_MORE_DATA){
1323 progId = CoTaskMemRealloc(progId,sizeProgId);
1324 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1326 if (res==ERROR_SUCCESS)
1327 /* return the clsid associated to the progId */
1328 res= CLSIDFromProgID(progId,pclsid);
1330 for(i=0; pathDec[i]!=NULL;i++)
1331 CoTaskMemFree(pathDec[i]);
1332 CoTaskMemFree(pathDec);
1334 CoTaskMemFree(progId);
1336 if (res==ERROR_SUCCESS)
1339 return MK_E_INVALIDEXTENSION;
1341 /******************************************************************************
1342 * CoRegisterMessageFilter16 [COMPOBJ.27]
1344 HRESULT WINAPI CoRegisterMessageFilter16(
1345 DWORD lpMessageFilter,
1346 DWORD *lplpMessageFilter
1352 /***********************************************************************
1353 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1355 HRESULT WINAPI CoCreateInstance(
1357 LPUNKNOWN pUnkOuter,
1363 LPCLASSFACTORY lpclf = 0;
1372 * Initialize the "out" parameter
1377 * Get a class factory to construct the object we want.
1379 hres = CoGetClassObject(rclsid,
1386 Print(MIN_TRACE, ("no instance created for %s, hres is 0x%08lx\n",PRINT_GUID(iid),hres));
1391 * Create the object and don't forget to release the factory
1393 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1394 IClassFactory_Release(lpclf);
1399 /***********************************************************************
1400 * CoCreateInstanceEx [OLE32.165]
1402 HRESULT WINAPI CoCreateInstanceEx(
1404 LPUNKNOWN pUnkOuter,
1406 COSERVERINFO* pServerInfo,
1410 IUnknown* pUnk = NULL;
1413 int successCount = 0;
1418 if ( (cmq==0) || (pResults==NULL))
1419 return E_INVALIDARG;
1421 if (pServerInfo!=NULL)
1422 Print(MIN_TRACE, ("() non-NULL pServerInfo not supported!\n"));
1425 * Initialize all the "out" parameters.
1427 for (index = 0; index < cmq; index++)
1429 pResults[index].pItf = NULL;
1430 pResults[index].hr = E_NOINTERFACE;
1434 * Get the object and get its IUnknown pointer.
1436 hr = CoCreateInstance(rclsid,
1446 * Then, query for all the interfaces requested.
1448 for (index = 0; index < cmq; index++)
1450 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1451 pResults[index].pIID,
1452 (VOID**)&(pResults[index].pItf));
1454 if (pResults[index].hr == S_OK)
1459 * Release our temporary unknown pointer.
1461 IUnknown_Release(pUnk);
1463 if (successCount == 0)
1464 return E_NOINTERFACE;
1466 if (successCount!=cmq)
1467 return CO_S_NOTALLINTERFACES;
1472 /***********************************************************************
1473 * CoFreeLibrary [COMPOBJ.13]
1475 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1477 OpenDll *ptr, *prev;
1480 /* lookup library in linked list */
1482 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1483 if (ptr->hLibrary == hLibrary) {
1490 /* shouldn't happen if user passed in a valid hLibrary */
1493 /* assert: ptr points to the library entry to free */
1495 /* free library and remove node from list */
1496 FreeLibrary(hLibrary);
1497 if (ptr == openDllList) {
1498 tmp = openDllList->next;
1499 HeapFree(GetProcessHeap(), 0, openDllList);
1503 HeapFree(GetProcessHeap(), 0, ptr);
1510 /***********************************************************************
1511 * CoFreeAllLibraries [COMPOBJ.12]
1513 void WINAPI CoFreeAllLibraries(void)
1517 for (ptr = openDllList; ptr != NULL; ) {
1519 CoFreeLibrary(ptr->hLibrary);
1526 /***********************************************************************
1527 * CoFreeUnusedLibraries [COMPOBJ.17]
1529 void WINAPI CoFreeUnusedLibraries(void)
1532 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1533 DllCanUnloadNowFunc DllCanUnloadNow;
1535 for (ptr = openDllList; ptr != NULL; ) {
1536 DllCanUnloadNow = (DllCanUnloadNowFunc)
1537 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1539 if ( (DllCanUnloadNow != NULL) &&
1540 (DllCanUnloadNow() == S_OK) ) {
1542 CoFreeLibrary(ptr->hLibrary);
1550 /***********************************************************************
1551 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1553 * the current system time in lpFileTime
1555 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1557 GetSystemTimeAsFileTime( lpFileTime );
1561 /***********************************************************************
1562 * CoTaskMemAlloc (OLE32.43)
1564 * pointer to newly allocated block
1566 LPVOID WINAPI CoTaskMemAlloc(
1567 ULONG size /* [in] size of memoryblock to be allocated */
1570 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1575 return IMalloc_Alloc(lpmalloc,size);
1577 /***********************************************************************
1578 * CoTaskMemFree (OLE32.44)
1580 VOID WINAPI CoTaskMemFree(
1581 LPVOID ptr /* [in] pointer to be freed */
1584 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1589 IMalloc_Free(lpmalloc, ptr);
1592 /***********************************************************************
1593 * CoTaskMemRealloc (OLE32.45)
1595 * pointer to newly allocated block
1597 LPVOID WINAPI CoTaskMemRealloc(
1599 ULONG size) /* [in] size of memoryblock to be allocated */
1602 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1607 return IMalloc_Realloc(lpmalloc, pvOld, size);
1610 /***********************************************************************
1611 * CoLoadLibrary (OLE32.30)
1613 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1619 Print(MAX_TRACE, ("(%S, %d)\n", lpszLibName, bAutoFree));
1621 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1626 if (openDllList == NULL) {
1627 /* empty list -- add first node */
1628 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1629 openDllList->hLibrary=hLibrary;
1630 openDllList->next = NULL;
1632 /* search for this dll */
1634 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1635 if (ptr->hLibrary == hLibrary) {
1641 /* dll not found, add it */
1643 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1644 openDllList->hLibrary = hLibrary;
1645 openDllList->next = tmp;
1652 /***********************************************************************
1653 * CoInitializeWOW (OLE32.27)
1655 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1660 /******************************************************************************
1661 * CoLockObjectExternal16 [COMPOBJ.63]
1663 HRESULT WINAPI CoLockObjectExternal16(
1664 LPUNKNOWN pUnk, /* [in] object to be locked */
1665 BOOL fLock, /* [in] do lock */
1666 BOOL fLastUnlockReleases /* [in] ? */
1672 /******************************************************************************
1673 * CoLockObjectExternal [OLE32.31]
1675 HRESULT WINAPI CoLockObjectExternal(
1676 LPUNKNOWN pUnk, /* [in] object to be locked */
1677 BOOL fLock, /* [in] do lock */
1678 BOOL fLastUnlockReleases) /* [in] unlock all */
1684 * Increment the external lock coutner, COM_ExternalLockAddRef also
1685 * increment the object's internal lock counter.
1687 COM_ExternalLockAddRef( pUnk);
1692 * Decrement the external lock coutner, COM_ExternalLockRelease also
1693 * decrement the object's internal lock counter.
1695 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1701 /***********************************************************************
1702 * CoGetState16 [COMPOBJ.115]
1704 HRESULT WINAPI CoGetState16(LPDWORD state)
1709 /***********************************************************************
1710 * CoSetState [COM32.42]
1712 HRESULT WINAPI CoSetState(LPDWORD state)
1717 /***********************************************************************
1718 * CoCreateFreeThreadedMarshaler [OLE32.5]
1720 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1727 /***********************************************************************
1728 * DllGetClassObject [OLE32.63]
1730 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1734 return CLASS_E_CLASSNOTAVAILABLE;
1739 * COM_RevokeAllClasses
1741 * This method is called when the COM libraries are uninitialized to
1742 * release all the references to the class objects registered with
1745 static void COM_RevokeAllClasses()
1747 while (firstRegisteredClass!=0)
1749 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1753 /****************************************************************************
1754 * COM External Lock methods implementation
1757 /****************************************************************************
1758 * Public - Method that increments the count for a IUnknown* in the linked
1759 * list. The item is inserted if not already in the list.
1761 static void COM_ExternalLockAddRef(
1764 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1767 * Add an external lock to the object. If it was already externally
1768 * locked, just increase the reference count. If it was not.
1769 * add the item to the list.
1771 if ( externalLock == EL_NOT_FOUND )
1772 COM_ExternalLockInsert(pUnk);
1774 externalLock->uRefCount++;
1777 * Add an internal lock to the object
1779 IUnknown_AddRef(pUnk);
1782 /****************************************************************************
1783 * Public - Method that decrements the count for a IUnknown* in the linked
1784 * list. The item is removed from the list if its count end up at zero or if
1787 static void COM_ExternalLockRelease(
1791 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1793 if ( externalLock != EL_NOT_FOUND )
1797 externalLock->uRefCount--; /* release external locks */
1798 IUnknown_Release(pUnk); /* release local locks as well */
1800 if ( bRelAll == FALSE )
1801 break; /* perform single release */
1803 } while ( externalLock->uRefCount > 0 );
1805 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1806 COM_ExternalLockDelete(externalLock);
1809 /****************************************************************************
1810 * Public - Method that frees the content of the list.
1812 static void COM_ExternalLockFreeList()
1814 COM_ExternalLock *head;
1816 head = elList.head; /* grab it by the head */
1817 while ( head != EL_END_OF_LIST )
1819 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1821 head = elList.head; /* get the new head... */
1825 /****************************************************************************
1826 * Public - Method that dump the content of the list.
1828 void COM_ExternalLockDump()
1830 COM_ExternalLock *current = elList.head;
1832 Print(MAX_TRACE, ("\nExternal lock list contains:\n"));
1834 while ( current != EL_END_OF_LIST )
1836 Print(MAX_TRACE, ("\t%p with %lu references count.\n", current->pUnk, current->uRefCount));
1838 /* Skip to the next item */
1839 current = current->next;
1844 /****************************************************************************
1845 * Internal - Find a IUnknown* in the linked list
1847 static COM_ExternalLock* COM_ExternalLockFind(
1850 return COM_ExternalLockLocate(elList.head, pUnk);
1853 /****************************************************************************
1854 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1856 static COM_ExternalLock* COM_ExternalLockLocate(
1857 COM_ExternalLock *element,
1860 if ( element == EL_END_OF_LIST )
1861 return EL_NOT_FOUND;
1863 else if ( element->pUnk == pUnk ) /* We found it */
1866 else /* Not the right guy, keep on looking */
1867 return COM_ExternalLockLocate( element->next, pUnk);
1870 /****************************************************************************
1871 * Internal - Insert a new IUnknown* to the linked list
1873 static BOOL COM_ExternalLockInsert(
1876 COM_ExternalLock *newLock = NULL;
1877 COM_ExternalLock *previousHead = NULL;
1880 * Allocate space for the new storage object
1882 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
1886 if ( elList.head == EL_END_OF_LIST )
1888 elList.head = newLock; /* The list is empty */
1893 * insert does it at the head
1895 previousHead = elList.head;
1896 elList.head = newLock;
1900 * Set new list item data member
1902 newLock->pUnk = pUnk;
1903 newLock->uRefCount = 1;
1904 newLock->next = previousHead;
1912 /****************************************************************************
1913 * Internal - Method that removes an item from the linked list.
1915 static void COM_ExternalLockDelete(
1916 COM_ExternalLock *itemList)
1918 COM_ExternalLock *current = elList.head;
1920 if ( current == itemList )
1923 * this section handles the deletion of the first node
1925 elList.head = itemList->next;
1926 HeapFree( GetProcessHeap(), 0, itemList);
1932 if ( current->next == itemList ) /* We found the item to free */
1934 current->next = itemList->next; /* readjust the list pointers */
1936 HeapFree( GetProcessHeap(), 0, itemList);
1940 /* Skip to the next item */
1941 current = current->next;
1943 } while ( current != EL_END_OF_LIST );
1947 /***********************************************************************
1948 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
1950 * Initialization code for the COMPOBJ DLL
1954 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, DWORD hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
1956 Print(MAX_TRACE, ("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
1960 case DLL_PROCESS_ATTACH:
1962 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
1966 case DLL_PROCESS_DETACH:
1968 if(!--COMPOBJ_Attach)
1969 COMPOBJ_hInstance = 0;
1976 /******************************************************************************
1977 * OleGetAutoConvert [OLE32.104]
1979 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
1987 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
1988 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
1990 res = REGDB_E_CLASSNOTREG;
1994 /* we can just query for the default value of AutoConvertTo key like that,
1995 without opening the AutoConvertTo key and querying for NULL (default) */
1996 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
1998 res = REGDB_E_KEYMISSING;
2001 MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
2002 CLSIDFromString(wbuf,pClsidNew);
2004 if (hkey) RegCloseKey(hkey);
2009 /******************************************************************************
2010 * OleSetAutoConvert [OLE32.126]
2012 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2014 HKEY hkey = 0, hkeyConvert = 0;
2015 char buf[200], szClsidNew[200];
2018 Print(MAX_TRACE, ("(%p,%p);\n", clsidOld, clsidNew));
2019 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2020 WINE_StringFromCLSID(clsidNew, szClsidNew);
2021 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2023 res = REGDB_E_CLASSNOTREG;
2026 if (RegCreateKeyA(hkey, "AutoConvertTo", &hkeyConvert))
2028 res = REGDB_E_WRITEREGDB;
2031 if (RegSetValueExA(hkeyConvert, NULL, 0,
2032 REG_SZ, (LPBYTE)szClsidNew, strlen(szClsidNew)+1))
2034 res = REGDB_E_WRITEREGDB;
2039 if (hkeyConvert) RegCloseKey(hkeyConvert);
2040 if (hkey) RegCloseKey(hkey);
2045 /***********************************************************************
2046 * IsEqualGUID [OLE32.76]
2048 * Compares two Unique Identifiers.
2054 BOOL WINAPI IsEqualGUID(
2055 REFGUID rguid1, /* [in] unique id 1 */
2056 REFGUID rguid2 /* [in] unique id 2 */
2059 return !memcmp(rguid1,rguid2,sizeof(GUID));