4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
8 * Copyright 2002 Marcus Meissner
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #include "wine/unicode.h"
42 #include "wine/obj_base.h"
43 #include "wine/obj_clientserver.h"
44 #include "wine/obj_misc.h"
45 #include "wine/obj_marshal.h"
46 #include "wine/obj_storage.h"
47 #include "wine/obj_channel.h"
48 #include "wine/winbase16.h"
49 #include "compobj_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
56 /****************************************************************************
57 * COM External Lock structures and methods declaration
59 * This api provides a linked list to managed external references to
62 * The public interface consists of three calls:
63 * COM_ExternalLockAddRef
64 * COM_ExternalLockRelease
65 * COM_ExternalLockFreeList
68 #define EL_END_OF_LIST 0
69 #define EL_NOT_FOUND 0
72 * Declaration of the static structure that manage the
73 * external lock to COM objects.
75 typedef struct COM_ExternalLock COM_ExternalLock
;
76 typedef struct COM_ExternalLockList COM_ExternalLockList
;
78 struct COM_ExternalLock
80 IUnknown
*pUnk
; /* IUnknown referenced */
81 ULONG uRefCount
; /* external lock counter to IUnknown object*/
82 COM_ExternalLock
*next
; /* Pointer to next element in list */
85 struct COM_ExternalLockList
87 COM_ExternalLock
*head
; /* head of list */
91 * Declaration and initialization of the static structure that manages
92 * the external lock to COM objects.
94 static COM_ExternalLockList elList
= { EL_END_OF_LIST
};
97 * Public Interface to the external lock list
99 static void COM_ExternalLockFreeList();
100 static void COM_ExternalLockAddRef(IUnknown
*pUnk
);
101 static void COM_ExternalLockRelease(IUnknown
*pUnk
, BOOL bRelAll
);
102 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
105 * Private methods used to managed the linked list
107 static BOOL
COM_ExternalLockInsert(
110 static void COM_ExternalLockDelete(
111 COM_ExternalLock
*element
);
113 static COM_ExternalLock
* COM_ExternalLockFind(
116 static COM_ExternalLock
* COM_ExternalLockLocate(
117 COM_ExternalLock
*element
,
120 /****************************************************************************
121 * This section defines variables internal to the COM module.
123 * TODO: Most of these things will have to be made thread-safe.
125 HINSTANCE16 COMPOBJ_hInstance
= 0;
126 HINSTANCE COMPOBJ_hInstance32
= 0;
127 static int COMPOBJ_Attach
= 0;
129 LPMALLOC16 currentMalloc16
=NULL
;
130 LPMALLOC currentMalloc32
=NULL
;
133 WORD Table_ETask
[62];
136 * This lock count counts the number of times CoInitialize is called. It is
137 * decreased every time CoUninitialize is called. When it hits 0, the COM
138 * libraries are freed
140 static LONG s_COMLockCount
= 0;
143 * This linked list contains the list of registered class objects. These
144 * are mostly used to register the factories for out-of-proc servers of OLE
147 * TODO: Make this data structure aware of inter-process communication. This
148 * means that parts of this will be exported to the Wine Server.
150 typedef struct tagRegisteredClass
152 CLSID classIdentifier
;
153 LPUNKNOWN classObject
;
157 HANDLE hThread
; /* only for localserver */
158 struct tagRegisteredClass
* nextClass
;
161 static CRITICAL_SECTION csRegisteredClassList
;
162 static RegisteredClass
* firstRegisteredClass
= NULL
;
164 /* this open DLL table belongs in a per process table, but my guess is that
165 * it shouldn't live in the kernel, so I'll put them out here in DLL
166 * space assuming that there is one OLE32 per process.
168 typedef struct tagOpenDll
{
170 struct tagOpenDll
*next
;
173 static CRITICAL_SECTION csOpenDllList
;
174 static OpenDll
*openDllList
= NULL
; /* linked list of open dlls */
176 /*****************************************************************************
177 * This section contains prototypes to internal methods for this
180 static HRESULT
COM_GetRegisteredClassObject(REFCLSID rclsid
,
184 static void COM_RevokeAllClasses();
187 /******************************************************************************
188 * Initialize/Uninitialize critical sections.
190 void COMPOBJ_InitProcess( void )
192 InitializeCriticalSection( &csRegisteredClassList
);
193 InitializeCriticalSection( &csOpenDllList
);
196 void COMPOBJ_UninitProcess( void )
198 DeleteCriticalSection( &csRegisteredClassList
);
199 DeleteCriticalSection( &csOpenDllList
);
202 /******************************************************************************
203 * CoBuildVersion [COMPOBJ.1]
204 * CoBuildVersion [OLE32.4]
207 * Current build version, hiword is majornumber, loword is minornumber
209 DWORD WINAPI
CoBuildVersion(void)
211 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
212 return (rmm
<<16)+rup
;
215 /******************************************************************************
216 * CoInitialize [COMPOBJ.2]
217 * Set the win16 IMalloc used for memory management
219 HRESULT WINAPI
CoInitialize16(
220 LPVOID lpReserved
/* [in] pointer to win16 malloc interface */
222 currentMalloc16
= (LPMALLOC16
)lpReserved
;
226 /******************************************************************************
227 * CoInitialize [OLE32.26]
229 * Initializes the COM libraries.
233 HRESULT WINAPI
CoInitialize(
234 LPVOID lpReserved
/* [in] pointer to win32 malloc interface
235 (obsolete, should be NULL) */
239 * Just delegate to the newer method.
241 return CoInitializeEx(lpReserved
, COINIT_APARTMENTTHREADED
);
244 /******************************************************************************
245 * CoInitializeEx [OLE32.163]
247 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
248 * used for memory management is obsolete.
251 * S_OK if successful,
252 * S_FALSE if this function was called already.
253 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
257 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
260 * See the windows documentation for more details.
262 HRESULT WINAPI
CoInitializeEx(
263 LPVOID lpReserved
, /* [in] pointer to win32 malloc interface
264 (obsolete, should be NULL) */
265 DWORD dwCoInit
/* [in] A value from COINIT specifies the threading model */
270 TRACE("(%p, %x)\n", lpReserved
, (int)dwCoInit
);
272 if (lpReserved
!=NULL
)
274 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved
, (int)dwCoInit
, lpReserved
);
278 * Check for unsupported features.
280 if (dwCoInit
!=COINIT_APARTMENTTHREADED
)
282 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved
, (int)dwCoInit
, (int)dwCoInit
);
283 /* Hope for the best and continue anyway */
287 * Check the lock count. If this is the first time going through the initialize
288 * process, we have to initialize the libraries.
290 * And crank-up that lock count.
292 if (InterlockedExchangeAdd(&s_COMLockCount
,1)==0)
295 * Initialize the various COM libraries and data structures.
297 TRACE("() - Initializing the COM libraries\n");
300 RunningObjectTableImpl_Initialize();
310 /***********************************************************************
311 * CoUninitialize [COMPOBJ.3]
312 * Don't know what it does.
313 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
314 * believe is the correct spelling
316 void WINAPI
CoUninitialize16(void)
319 CoFreeAllLibraries();
322 /***********************************************************************
323 * CoUninitialize [OLE32.47]
325 * This method will release the COM libraries.
327 * See the windows documentation for more details.
329 void WINAPI
CoUninitialize(void)
335 * Decrease the reference count.
336 * If we are back to 0 locks on the COM library, make sure we free
337 * all the associated data structures.
339 lCOMRefCnt
= InterlockedExchangeAdd(&s_COMLockCount
,-1);
343 * Release the various COM libraries and data structures.
345 TRACE("() - Releasing the COM libraries\n");
347 RunningObjectTableImpl_UnInitialize();
349 * Release the references to the registered class objects.
351 COM_RevokeAllClasses();
354 * This will free the loaded COM Dlls.
356 CoFreeAllLibraries();
359 * This will free list of external references to COM objects.
361 COM_ExternalLockFreeList();
364 else if (lCOMRefCnt
<1) {
365 ERR( "CoUninitialize() - not CoInitialized.\n" );
366 InterlockedExchangeAdd(&s_COMLockCount
,1); /* restore the lock count. */
370 /***********************************************************************
371 * CoGetMalloc [COMPOBJ.4]
373 * The current win16 IMalloc
375 HRESULT WINAPI
CoGetMalloc16(
376 DWORD dwMemContext
, /* [in] unknown */
377 LPMALLOC16
* lpMalloc
/* [out] current win16 malloc interface */
380 currentMalloc16
= IMalloc16_Constructor();
381 *lpMalloc
= currentMalloc16
;
385 /******************************************************************************
386 * CoGetMalloc [OLE32.20]
389 * The current win32 IMalloc
391 HRESULT WINAPI
CoGetMalloc(
392 DWORD dwMemContext
, /* [in] unknown */
393 LPMALLOC
*lpMalloc
/* [out] current win32 malloc interface */
396 currentMalloc32
= IMalloc_Constructor();
397 *lpMalloc
= currentMalloc32
;
401 /***********************************************************************
402 * CoCreateStandardMalloc [COMPOBJ.71]
404 HRESULT WINAPI
CoCreateStandardMalloc16(DWORD dwMemContext
,
405 LPMALLOC16
*lpMalloc
)
407 /* FIXME: docu says we shouldn't return the same allocator as in
409 *lpMalloc
= IMalloc16_Constructor();
413 /******************************************************************************
414 * CoDisconnectObject [COMPOBJ.15]
415 * CoDisconnectObject [OLE32.8]
417 HRESULT WINAPI
CoDisconnectObject( LPUNKNOWN lpUnk
, DWORD reserved
)
419 TRACE("(%p, %lx)\n",lpUnk
,reserved
);
423 /***********************************************************************
424 * IsEqualGUID [COMPOBJ.18]
426 * Compares two Unique Identifiers.
431 BOOL16 WINAPI
IsEqualGUID16(
432 GUID
* g1
, /* [in] unique id 1 */
433 GUID
* g2
/* [in] unique id 2 */
435 return !memcmp( g1
, g2
, sizeof(GUID
) );
438 /******************************************************************************
439 * CLSIDFromString [COMPOBJ.20]
440 * Converts a unique identifier from its string representation into
443 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
448 HRESULT WINAPI
CLSIDFromString16(
449 LPCOLESTR16 idstr
, /* [in] string representation of guid */
450 CLSID
*id
/* [out] GUID converted from string */
452 BYTE
*s
= (BYTE
*) idstr
;
457 s
= "{00000000-0000-0000-0000-000000000000}";
458 else { /* validate the CLSID string */
461 return CO_E_CLASSSTRING
;
463 if ((s
[0]!='{') || (s
[9]!='-') || (s
[14]!='-') || (s
[19]!='-') || (s
[24]!='-') || (s
[37]!='}'))
464 return CO_E_CLASSSTRING
;
468 if ((i
== 9)||(i
== 14)||(i
== 19)||(i
== 24)) continue;
469 if (!(((s
[i
] >= '0') && (s
[i
] <= '9')) ||
470 ((s
[i
] >= 'a') && (s
[i
] <= 'f')) ||
471 ((s
[i
] >= 'A') && (s
[i
] <= 'F')))
473 return CO_E_CLASSSTRING
;
477 TRACE("%s -> %p\n", s
, id
);
479 /* quick lookup table */
480 memset(table
, 0, 256);
482 for (i
= 0; i
< 10; i
++) {
485 for (i
= 0; i
< 6; i
++) {
486 table
['A' + i
] = i
+10;
487 table
['a' + i
] = i
+10;
490 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
492 id
->Data1
= (table
[s
[1]] << 28 | table
[s
[2]] << 24 | table
[s
[3]] << 20 | table
[s
[4]] << 16 |
493 table
[s
[5]] << 12 | table
[s
[6]] << 8 | table
[s
[7]] << 4 | table
[s
[8]]);
494 id
->Data2
= table
[s
[10]] << 12 | table
[s
[11]] << 8 | table
[s
[12]] << 4 | table
[s
[13]];
495 id
->Data3
= table
[s
[15]] << 12 | table
[s
[16]] << 8 | table
[s
[17]] << 4 | table
[s
[18]];
497 /* these are just sequential bytes */
498 id
->Data4
[0] = table
[s
[20]] << 4 | table
[s
[21]];
499 id
->Data4
[1] = table
[s
[22]] << 4 | table
[s
[23]];
500 id
->Data4
[2] = table
[s
[25]] << 4 | table
[s
[26]];
501 id
->Data4
[3] = table
[s
[27]] << 4 | table
[s
[28]];
502 id
->Data4
[4] = table
[s
[29]] << 4 | table
[s
[30]];
503 id
->Data4
[5] = table
[s
[31]] << 4 | table
[s
[32]];
504 id
->Data4
[6] = table
[s
[33]] << 4 | table
[s
[34]];
505 id
->Data4
[7] = table
[s
[35]] << 4 | table
[s
[36]];
510 /******************************************************************************
511 * CoCreateGuid[OLE32.6]
514 HRESULT WINAPI
CoCreateGuid(
515 GUID
*pguid
/* [out] points to the GUID to initialize */
517 return UuidCreate(pguid
);
520 /******************************************************************************
521 * CLSIDFromString [OLE32.3]
522 * IIDFromString [OLE32.74]
523 * Converts a unique identifier from its string representation into
527 * If idstr is not a valid CLSID string then it gets treated as a ProgID
532 HRESULT WINAPI
CLSIDFromString(
533 LPCOLESTR idstr
, /* [in] string representation of GUID */
534 CLSID
*id
) /* [out] GUID represented by above string */
539 if (!WideCharToMultiByte( CP_ACP
, 0, idstr
, -1, xid
, sizeof(xid
), NULL
, NULL
))
540 return CO_E_CLASSSTRING
;
541 ret
= CLSIDFromString16(xid
,id
);
542 if(ret
!= S_OK
) { /* It appears a ProgID is also valid */
543 ret
= CLSIDFromProgID(idstr
, id
);
548 /******************************************************************************
549 * WINE_StringFromCLSID [Internal]
550 * Converts a GUID into the respective string representation.
555 * the string representation and HRESULT
557 HRESULT
WINE_StringFromCLSID(
558 const CLSID
*id
, /* [in] GUID to be converted */
559 LPSTR idstr
/* [out] pointer to buffer to contain converted guid */
561 static const char *hex
= "0123456789ABCDEF";
566 { ERR("called with id=Null\n");
571 sprintf(idstr
, "{%08lX-%04X-%04X-%02X%02X-",
572 id
->Data1
, id
->Data2
, id
->Data3
,
573 id
->Data4
[0], id
->Data4
[1]);
577 for (i
= 2; i
< 8; i
++) {
578 *s
++ = hex
[id
->Data4
[i
]>>4];
579 *s
++ = hex
[id
->Data4
[i
] & 0xf];
585 TRACE("%p->%s\n", id
, idstr
);
590 /******************************************************************************
591 * StringFromCLSID [COMPOBJ.19]
592 * Converts a GUID into the respective string representation.
593 * The target string is allocated using the OLE IMalloc.
595 * the string representation and HRESULT
597 HRESULT WINAPI
StringFromCLSID16(
598 REFCLSID id
, /* [in] the GUID to be converted */
599 LPOLESTR16
*idstr
/* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
602 extern BOOL WINAPI
K32WOWCallback16Ex( DWORD vpfn16
, DWORD dwFlags
,
603 DWORD cbArgs
, LPVOID pArgs
, LPDWORD pdwRetCode
);
608 ret
= CoGetMalloc16(0,&mllc
);
611 args
[0] = (DWORD
)mllc
;
614 /* No need for a Callback entry, we have WOWCallback16Ex which does
615 * everything we need.
617 if (!K32WOWCallback16Ex(
618 (DWORD
)((ICOM_VTABLE(IMalloc16
)*)MapSL(
619 (SEGPTR
)ICOM_VTBL(((LPMALLOC16
)MapSL((SEGPTR
)mllc
))))
626 WARN("CallTo16 IMalloc16 failed\n");
629 return WINE_StringFromCLSID(id
,MapSL((SEGPTR
)*idstr
));
632 /******************************************************************************
633 * StringFromCLSID [OLE32.151]
634 * StringFromIID [OLE32.153]
635 * Converts a GUID into the respective string representation.
636 * The target string is allocated using the OLE IMalloc.
638 * the string representation and HRESULT
640 HRESULT WINAPI
StringFromCLSID(
641 REFCLSID id
, /* [in] the GUID to be converted */
642 LPOLESTR
*idstr
/* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
648 if ((ret
=CoGetMalloc(0,&mllc
)))
651 ret
=WINE_StringFromCLSID(id
,buf
);
653 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, buf
, -1, NULL
, 0 );
654 *idstr
= IMalloc_Alloc( mllc
, len
* sizeof(WCHAR
) );
655 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, *idstr
, len
);
660 /******************************************************************************
661 * StringFromGUID2 [COMPOBJ.76]
662 * StringFromGUID2 [OLE32.152]
664 * Converts a global unique identifier into a string of an API-
665 * specified fixed format. (The usual {.....} stuff.)
668 * The (UNICODE) string representation of the GUID in 'str'
669 * The length of the resulting string, 0 if there was any problem.
672 StringFromGUID2(REFGUID id
, LPOLESTR str
, INT cmax
)
676 if (WINE_StringFromCLSID(id
,xguid
))
678 return MultiByteToWideChar( CP_ACP
, 0, xguid
, -1, str
, cmax
);
681 /******************************************************************************
682 * ProgIDFromCLSID [OLE32.133]
683 * Converts a class id into the respective Program ID. (By using a registry lookup)
684 * RETURNS S_OK on success
685 * riid associated with the progid
688 HRESULT WINAPI
ProgIDFromCLSID(
689 REFCLSID clsid
, /* [in] class id as found in registry */
690 LPOLESTR
*lplpszProgID
/* [out] associated Prog ID */
693 char strCLSID
[50], *buf
, *buf2
;
699 WINE_StringFromCLSID(clsid
, strCLSID
);
701 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID
)+14);
702 sprintf(buf
,"CLSID\\%s\\ProgID", strCLSID
);
703 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
704 ret
= REGDB_E_CLASSNOTREG
;
706 HeapFree(GetProcessHeap(), 0, buf
);
710 buf2
= HeapAlloc(GetProcessHeap(), 0, 255);
712 if (RegQueryValueA(xhkey
, NULL
, buf2
, &buf2len
))
713 ret
= REGDB_E_CLASSNOTREG
;
717 if (CoGetMalloc(0,&mllc
))
721 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, buf2
, -1, NULL
, 0 );
722 *lplpszProgID
= IMalloc_Alloc(mllc
, len
* sizeof(WCHAR
) );
723 MultiByteToWideChar( CP_ACP
, 0, buf2
, -1, *lplpszProgID
, len
);
726 HeapFree(GetProcessHeap(), 0, buf2
);
733 /******************************************************************************
734 * CLSIDFromProgID [COMPOBJ.61]
735 * Converts a program id into the respective GUID. (By using a registry lookup)
737 * riid associated with the progid
739 HRESULT WINAPI
CLSIDFromProgID16(
740 LPCOLESTR16 progid
, /* [in] program id as found in registry */
741 LPCLSID riid
/* [out] associated CLSID */
748 buf
= HeapAlloc(GetProcessHeap(),0,strlen(progid
)+8);
749 sprintf(buf
,"%s\\CLSID",progid
);
750 if ((err
=RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&xhkey
))) {
751 HeapFree(GetProcessHeap(),0,buf
);
752 return CO_E_CLASSSTRING
;
754 HeapFree(GetProcessHeap(),0,buf
);
755 buf2len
= sizeof(buf2
);
756 if ((err
=RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))) {
758 return CO_E_CLASSSTRING
;
761 return CLSIDFromString16(buf2
,riid
);
764 /******************************************************************************
765 * CLSIDFromProgID [OLE32.2]
766 * Converts a program id into the respective GUID. (By using a registry lookup)
768 * riid associated with the progid
770 HRESULT WINAPI
CLSIDFromProgID(
771 LPCOLESTR progid
, /* [in] program id as found in registry */
772 LPCLSID riid
) /* [out] associated CLSID */
774 static const WCHAR clsidW
[] = { '\\','C','L','S','I','D',0 };
776 DWORD buf2len
= sizeof(buf2
);
779 WCHAR
*buf
= HeapAlloc( GetProcessHeap(),0,(strlenW(progid
)+8) * sizeof(WCHAR
) );
780 strcpyW( buf
, progid
);
781 strcatW( buf
, clsidW
);
782 if (RegOpenKeyW(HKEY_CLASSES_ROOT
,buf
,&xhkey
))
784 HeapFree(GetProcessHeap(),0,buf
);
785 return CO_E_CLASSSTRING
;
787 HeapFree(GetProcessHeap(),0,buf
);
789 if (RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
))
792 return CO_E_CLASSSTRING
;
795 return CLSIDFromString16(buf2
,riid
);
800 /*****************************************************************************
801 * CoGetPSClsid [OLE32.22]
803 * This function returns the CLSID of the DLL that implements the proxy and stub
804 * for the specified interface.
806 * It determines this by searching the
807 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
808 * and any interface id registered by CoRegisterPSClsid within the current process.
810 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
812 HRESULT WINAPI
CoGetPSClsid(
813 REFIID riid
, /* [in] Interface whose proxy/stub CLSID is to be returned */
814 CLSID
*pclsid
) /* [out] Where to store returned proxy/stub CLSID */
820 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid
), pclsid
);
822 /* Get the input iid as a string */
823 WINE_StringFromCLSID(riid
, buf2
);
824 /* Allocate memory for the registry key we will construct.
825 (length of iid string plus constant length of static text */
826 buf
= HeapAlloc(GetProcessHeap(), 0, strlen(buf2
)+27);
829 return (E_OUTOFMEMORY
);
832 /* Construct the registry key we want */
833 sprintf(buf
,"Interface\\%s\\ProxyStubClsid32", buf2
);
836 if (RegOpenKeyA(HKEY_CLASSES_ROOT
, buf
, &xhkey
))
838 HeapFree(GetProcessHeap(),0,buf
);
839 return (E_INVALIDARG
);
841 HeapFree(GetProcessHeap(),0,buf
);
843 /* ... Once we have the key, query the registry to get the
844 value of CLSID as a string, and convert it into a
845 proper CLSID structure to be passed back to the app */
846 buf2len
= sizeof(buf2
);
847 if ( (RegQueryValueA(xhkey
,NULL
,buf2
,&buf2len
)) )
854 /* We have the CLSid we want back from the registry as a string, so
855 lets convert it into a CLSID structure */
856 if ( (CLSIDFromString16(buf2
,pclsid
)) != NOERROR
)
861 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid
));
867 /***********************************************************************
868 * WriteClassStm (OLE32.159)
870 * This function write a CLSID on stream
872 HRESULT WINAPI
WriteClassStm(IStream
*pStm
,REFCLSID rclsid
)
874 TRACE("(%p,%p)\n",pStm
,rclsid
);
879 return IStream_Write(pStm
,rclsid
,sizeof(CLSID
),NULL
);
882 /***********************************************************************
883 * ReadClassStm (OLE32.135)
885 * This function read a CLSID from a stream
887 HRESULT WINAPI
ReadClassStm(IStream
*pStm
,CLSID
*pclsid
)
892 TRACE("(%p,%p)\n",pStm
,pclsid
);
897 res
= IStream_Read(pStm
,(void*)pclsid
,sizeof(CLSID
),&nbByte
);
902 if (nbByte
!= sizeof(CLSID
))
908 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
909 /***********************************************************************
910 * LookupETask (COMPOBJ.94)
912 HRESULT WINAPI
LookupETask16(HTASK16
*hTask
,LPVOID p
) {
913 FIXME("(%p,%p),stub!\n",hTask
,p
);
914 if ((*hTask
= GetCurrentTask()) == hETask
) {
915 memcpy(p
, Table_ETask
, sizeof(Table_ETask
));
920 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
921 /***********************************************************************
922 * SetETask (COMPOBJ.95)
924 HRESULT WINAPI
SetETask16(HTASK16 hTask
, LPVOID p
) {
925 FIXME("(%04x,%p),stub!\n",hTask
,p
);
930 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
931 /***********************************************************************
932 * CALLOBJECTINWOW (COMPOBJ.201)
934 HRESULT WINAPI
CallObjectInWOW(LPVOID p1
,LPVOID p2
) {
935 FIXME("(%p,%p),stub!\n",p1
,p2
);
939 /******************************************************************************
940 * CoRegisterClassObject [COMPOBJ.5]
942 * Don't know where it registers it ...
944 HRESULT WINAPI
CoRegisterClassObject16(
947 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
948 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
953 WINE_StringFromCLSID(rclsid
,buf
);
955 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
956 buf
,pUnk
,dwClsContext
,flags
,lpdwRegister
962 /******************************************************************************
963 * CoRevokeClassObject [COMPOBJ.6]
966 HRESULT WINAPI
CoRevokeClassObject16(DWORD dwRegister
) /* [in] token on class obj */
968 FIXME("(0x%08lx),stub!\n", dwRegister
);
972 /******************************************************************************
973 * CoFileTimeToDosDateTime [COMPOBJ.30]
975 BOOL16 WINAPI
CoFileTimeToDosDateTime16(const FILETIME
*ft
, LPWORD lpDosDate
, LPWORD lpDosTime
)
977 return FileTimeToDosDateTime(ft
, lpDosDate
, lpDosTime
);
980 /******************************************************************************
981 * CoDosDateTimeToFileTime [COMPOBJ.31]
983 BOOL16 WINAPI
CoDosDateTimeToFileTime16(WORD wDosDate
, WORD wDosTime
, FILETIME
*ft
)
985 return DosDateTimeToFileTime(wDosDate
, wDosTime
, ft
);
989 * COM_GetRegisteredClassObject
991 * This internal method is used to scan the registered class list to
992 * find a class object.
995 * rclsid Class ID of the class to find.
996 * dwClsContext Class context to match.
997 * ppv [out] returns a pointer to the class object. Complying
998 * to normal COM usage, this method will increase the
999 * reference count on this object.
1001 static HRESULT
COM_GetRegisteredClassObject(
1006 HRESULT hr
= S_FALSE
;
1007 RegisteredClass
* curClass
;
1009 EnterCriticalSection( &csRegisteredClassList
);
1017 * Iterate through the whole list and try to match the class ID.
1019 curClass
= firstRegisteredClass
;
1021 while (curClass
!= 0)
1024 * Check if we have a match on the class ID.
1026 if (IsEqualGUID(&(curClass
->classIdentifier
), rclsid
))
1029 * Since we don't do out-of process or DCOM just right away, let's ignore the
1034 * We have a match, return the pointer to the class object.
1036 *ppUnk
= curClass
->classObject
;
1038 IUnknown_AddRef(curClass
->classObject
);
1045 * Step to the next class in the list.
1047 curClass
= curClass
->nextClass
;
1051 LeaveCriticalSection( &csRegisteredClassList
);
1053 * If we get to here, we haven't found our class.
1059 _LocalServerThread(LPVOID param
) {
1062 RegisteredClass
*newClass
= (RegisteredClass
*)param
;
1066 unsigned char *buffer
;
1068 IClassFactory
*classfac
;
1069 LARGE_INTEGER seekto
;
1070 ULARGE_INTEGER newpos
;
1073 TRACE("Starting threader for %s.\n",debugstr_guid(&newClass
->classIdentifier
));
1074 strcpy(pipefn
,PIPEPREF
);
1075 WINE_StringFromCLSID(&newClass
->classIdentifier
,pipefn
+strlen(PIPEPREF
));
1077 hres
= IUnknown_QueryInterface(newClass
->classObject
,&IID_IClassFactory
,(LPVOID
*)&classfac
);
1078 if (hres
) return hres
;
1080 hres
= CreateStreamOnHGlobal(0,TRUE
,&pStm
);
1082 FIXME("Failed to create stream on hglobal.\n");
1085 hres
= CoMarshalInterface(pStm
,&IID_IClassFactory
,(LPVOID
)classfac
,0,NULL
,0);
1087 FIXME("CoMarshalInterface failed, %lx!\n",hres
);
1090 hres
= IStream_Stat(pStm
,&ststg
,0);
1091 if (hres
) return hres
;
1093 buflen
= ststg
.cbSize
.s
.LowPart
;
1094 buffer
= HeapAlloc(GetProcessHeap(),0,buflen
);
1095 seekto
.s
.LowPart
= 0;
1096 seekto
.s
.HighPart
= 0;
1097 hres
= IStream_Seek(pStm
,seekto
,SEEK_SET
,&newpos
);
1099 FIXME("IStream_Seek failed, %lx\n",hres
);
1102 hres
= IStream_Read(pStm
,buffer
,buflen
,&res
);
1104 FIXME("Stream Read failed, %lx\n",hres
);
1107 IStream_Release(pStm
);
1110 hPipe
= CreateNamedPipeA(
1113 PIPE_TYPE_BYTE
|PIPE_WAIT
,
1114 PIPE_UNLIMITED_INSTANCES
,
1117 NMPWAIT_USE_DEFAULT_WAIT
,
1120 if (hPipe
== INVALID_HANDLE_VALUE
) {
1121 FIXME("pipe creation failed for %s, le is %lx\n",pipefn
,GetLastError());
1124 if (!ConnectNamedPipe(hPipe
,NULL
)) {
1125 ERR("Failure during ConnectNamedPipe %lx, ABORT!\n",GetLastError());
1129 WriteFile(hPipe
,buffer
,buflen
,&res
,NULL
);
1135 /******************************************************************************
1136 * CoRegisterClassObject [OLE32.36]
1138 * This method will register the class object for a given class ID.
1140 * See the Windows documentation for more details.
1142 HRESULT WINAPI
CoRegisterClassObject(
1145 DWORD dwClsContext
, /* [in] CLSCTX flags indicating the context in which to run the executable */
1146 DWORD flags
, /* [in] REGCLS flags indicating how connections are made */
1147 LPDWORD lpdwRegister
1150 RegisteredClass
* newClass
;
1151 LPUNKNOWN foundObject
;
1154 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1155 debugstr_guid(rclsid
),pUnk
,dwClsContext
,flags
,lpdwRegister
);
1157 if ( (lpdwRegister
==0) || (pUnk
==0) )
1158 return E_INVALIDARG
;
1163 * First, check if the class is already registered.
1164 * If it is, this should cause an error.
1166 hr
= COM_GetRegisteredClassObject(rclsid
, dwClsContext
, &foundObject
);
1168 IUnknown_Release(foundObject
);
1169 return CO_E_OBJISREG
;
1172 newClass
= HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass
));
1173 if ( newClass
== NULL
)
1174 return E_OUTOFMEMORY
;
1176 EnterCriticalSection( &csRegisteredClassList
);
1178 newClass
->classIdentifier
= *rclsid
;
1179 newClass
->runContext
= dwClsContext
;
1180 newClass
->connectFlags
= flags
;
1182 * Use the address of the chain node as the cookie since we are sure it's
1185 newClass
->dwCookie
= (DWORD
)newClass
;
1186 newClass
->nextClass
= firstRegisteredClass
;
1189 * Since we're making a copy of the object pointer, we have to increase its
1192 newClass
->classObject
= pUnk
;
1193 IUnknown_AddRef(newClass
->classObject
);
1195 firstRegisteredClass
= newClass
;
1196 LeaveCriticalSection( &csRegisteredClassList
);
1198 *lpdwRegister
= newClass
->dwCookie
;
1200 if (dwClsContext
& CLSCTX_LOCAL_SERVER
) {
1204 newClass
->hThread
=CreateThread(NULL
,0,_LocalServerThread
,newClass
,0,&tid
);
1209 /***********************************************************************
1210 * CoRevokeClassObject [OLE32.40]
1212 * This method will remove a class object from the class registry
1214 * See the Windows documentation for more details.
1216 HRESULT WINAPI
CoRevokeClassObject(
1219 HRESULT hr
= E_INVALIDARG
;
1220 RegisteredClass
** prevClassLink
;
1221 RegisteredClass
* curClass
;
1223 TRACE("(%08lx)\n",dwRegister
);
1225 EnterCriticalSection( &csRegisteredClassList
);
1228 * Iterate through the whole list and try to match the cookie.
1230 curClass
= firstRegisteredClass
;
1231 prevClassLink
= &firstRegisteredClass
;
1233 while (curClass
!= 0)
1236 * Check if we have a match on the cookie.
1238 if (curClass
->dwCookie
== dwRegister
)
1241 * Remove the class from the chain.
1243 *prevClassLink
= curClass
->nextClass
;
1246 * Release the reference to the class object.
1248 IUnknown_Release(curClass
->classObject
);
1251 * Free the memory used by the chain node.
1253 HeapFree(GetProcessHeap(), 0, curClass
);
1260 * Step to the next class in the list.
1262 prevClassLink
= &(curClass
->nextClass
);
1263 curClass
= curClass
->nextClass
;
1267 LeaveCriticalSection( &csRegisteredClassList
);
1269 * If we get to here, we haven't found our class.
1274 /***********************************************************************
1275 * CoGetClassObject [COMPOBJ.7]
1276 * CoGetClassObject [OLE32.16]
1278 * FIXME. If request allows of several options and there is a failure
1279 * with one (other than not being registered) do we try the
1280 * others or return failure? (E.g. inprocess is registered but
1281 * the DLL is not found but the server version works)
1283 HRESULT WINAPI
CoGetClassObject(
1284 REFCLSID rclsid
, DWORD dwClsContext
, COSERVERINFO
*pServerInfo
,
1285 REFIID iid
, LPVOID
*ppv
1287 LPUNKNOWN regClassObject
;
1288 HRESULT hres
= E_UNEXPECTED
;
1290 WCHAR ProviderName
[MAX_PATH
+1];
1291 DWORD ProviderNameLen
= sizeof(ProviderName
);
1293 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
,
1294 REFIID iid
, LPVOID
*ppv
);
1295 DllGetClassObjectFunc DllGetClassObject
;
1297 WINE_StringFromCLSID((LPCLSID
)rclsid
,xclsid
);
1299 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1300 debugstr_guid(rclsid
),
1305 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo
->pwszName
));
1306 FIXME("\t\tpAuthInfo=%p\n",pServerInfo
->pAuthInfo
);
1310 * First, try and see if we can't match the class ID with one of the
1311 * registered classes.
1313 if (S_OK
== COM_GetRegisteredClassObject(rclsid
, dwClsContext
, ®ClassObject
))
1316 * Get the required interface from the retrieved pointer.
1318 hres
= IUnknown_QueryInterface(regClassObject
, iid
, ppv
);
1321 * Since QI got another reference on the pointer, we want to release the
1322 * one we already have. If QI was unsuccessful, this will release the object. This
1323 * is good since we are not returning it in the "out" parameter.
1325 IUnknown_Release(regClassObject
);
1330 if ((CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
) & dwClsContext
) {
1334 memset(ProviderName
,0,sizeof(ProviderName
));
1335 sprintf(buf
,"CLSID\\%s\\InprocServer32",xclsid
);
1336 if (((hres
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, buf
, 0, KEY_READ
, &key
)) != ERROR_SUCCESS
) ||
1337 ((hres
= RegQueryValueExW(key
,NULL
,NULL
,NULL
,(LPBYTE
)ProviderName
,&ProviderNameLen
)),
1339 hres
!= ERROR_SUCCESS
))
1341 hres
= REGDB_E_CLASSNOTREG
;
1343 /* Don't ask me. MSDN says that CoGetClassObject does NOT call CoLoadLibrary */
1344 else if ((hLibrary
= CoLoadLibrary(ProviderName
, TRUE
)) == 0)
1346 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(ProviderName
));
1347 hres
= E_ACCESSDENIED
; /* or should this be CO_E_DLLNOTFOUND? */
1349 else if (!(DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject")))
1351 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1352 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(ProviderName
));
1353 hres
= E_ACCESSDENIED
;
1357 /* Ask the DLL for its class object. (there was a note here about
1358 * class factories but this is good.
1360 return DllGetClassObject(rclsid
, iid
, ppv
);
1365 /* Next try out of process */
1366 if (CLSCTX_LOCAL_SERVER
& dwClsContext
)
1368 return create_marshalled_proxy(rclsid
,iid
,ppv
);
1371 /* Finally try remote */
1372 if (CLSCTX_REMOTE_SERVER
& dwClsContext
)
1374 FIXME ("CLSCTX_REMOTE_SERVER not supported\n");
1375 hres
= E_NOINTERFACE
;
1380 /***********************************************************************
1381 * CoResumeClassObjects (OLE32.173)
1383 * Resumes classobjects registered with REGCLS suspended
1385 HRESULT WINAPI
CoResumeClassObjects(void)
1391 /***********************************************************************
1392 * GetClassFile (OLE32.67)
1394 * This function supplies the CLSID associated with the given filename.
1396 HRESULT WINAPI
GetClassFile(LPCOLESTR filePathName
,CLSID
*pclsid
)
1400 int nbElm
=0,length
=0,i
=0;
1402 LPOLESTR
*pathDec
=0,absFile
=0,progId
=0;
1403 WCHAR extention
[100]={0};
1407 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1408 if((StgIsStorageFile(filePathName
))==S_OK
){
1410 res
=StgOpenStorage(filePathName
,NULL
,STGM_READ
| STGM_SHARE_DENY_WRITE
,NULL
,0,&pstg
);
1413 res
=ReadClassStg(pstg
,pclsid
);
1415 IStorage_Release(pstg
);
1419 /* if the file is not a storage object then attemps to match various bits in the file against a
1420 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1423 for(i=0;i<nFileTypes;i++)
1425 for(i=0;j<nPatternsForType;j++){
1430 pat=ReadPatternFromRegistry(i,j);
1431 hFile=CreateFileW(filePathName,,,,,,hFile);
1432 SetFilePosition(hFile,pat.offset);
1433 ReadFile(hFile,buf,pat.size,NULL,NULL);
1434 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1436 *pclsid=ReadCLSIDFromRegistry(i);
1442 /* if the obove strategies fail then search for the extension key in the registry */
1444 /* get the last element (absolute file) in the path name */
1445 nbElm
=FileMonikerImpl_DecomposePath(filePathName
,&pathDec
);
1446 absFile
=pathDec
[nbElm
-1];
1448 /* failed if the path represente a directory and not an absolute file name*/
1449 if (lstrcmpW(absFile
,(LPOLESTR
)"\\"))
1450 return MK_E_INVALIDEXTENSION
;
1452 /* get the extension of the file */
1453 length
=lstrlenW(absFile
);
1454 for(i
=length
-1; ( (i
>=0) && (extention
[i
]=absFile
[i
]) );i
--);
1456 /* get the progId associated to the extension */
1457 progId
=CoTaskMemAlloc(sizeProgId
);
1459 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1461 if (res
==ERROR_MORE_DATA
){
1463 progId
= CoTaskMemRealloc(progId
,sizeProgId
);
1464 res
=RegQueryValueW(HKEY_CLASSES_ROOT
,extention
,progId
,&sizeProgId
);
1466 if (res
==ERROR_SUCCESS
)
1467 /* return the clsid associated to the progId */
1468 res
= CLSIDFromProgID(progId
,pclsid
);
1470 for(i
=0; pathDec
[i
]!=NULL
;i
++)
1471 CoTaskMemFree(pathDec
[i
]);
1472 CoTaskMemFree(pathDec
);
1474 CoTaskMemFree(progId
);
1476 if (res
==ERROR_SUCCESS
)
1479 return MK_E_INVALIDEXTENSION
;
1481 /******************************************************************************
1482 * CoRegisterMessageFilter [COMPOBJ.27]
1484 HRESULT WINAPI
CoRegisterMessageFilter16(
1485 LPMESSAGEFILTER lpMessageFilter
,
1486 LPMESSAGEFILTER
*lplpMessageFilter
1488 FIXME("(%p,%p),stub!\n",lpMessageFilter
,lplpMessageFilter
);
1492 /***********************************************************************
1493 * CoCreateInstance [COMPOBJ.13]
1494 * CoCreateInstance [OLE32.7]
1496 HRESULT WINAPI
CoCreateInstance(
1498 LPUNKNOWN pUnkOuter
,
1504 LPCLASSFACTORY lpclf
= 0;
1513 * Initialize the "out" parameter
1518 * Get a class factory to construct the object we want.
1520 hres
= CoGetClassObject(rclsid
,
1527 FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
1528 debugstr_guid(rclsid
),hres
);
1533 * Create the object and don't forget to release the factory
1535 hres
= IClassFactory_CreateInstance(lpclf
, pUnkOuter
, iid
, ppv
);
1536 IClassFactory_Release(lpclf
);
1538 FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
1539 debugstr_guid(iid
), debugstr_guid(rclsid
),hres
);
1544 /***********************************************************************
1545 * CoCreateInstanceEx [OLE32.165]
1547 HRESULT WINAPI
CoCreateInstanceEx(
1549 LPUNKNOWN pUnkOuter
,
1551 COSERVERINFO
* pServerInfo
,
1555 IUnknown
* pUnk
= NULL
;
1558 int successCount
= 0;
1563 if ( (cmq
==0) || (pResults
==NULL
))
1564 return E_INVALIDARG
;
1566 if (pServerInfo
!=NULL
)
1567 FIXME("() non-NULL pServerInfo not supported!\n");
1570 * Initialize all the "out" parameters.
1572 for (index
= 0; index
< cmq
; index
++)
1574 pResults
[index
].pItf
= NULL
;
1575 pResults
[index
].hr
= E_NOINTERFACE
;
1579 * Get the object and get its IUnknown pointer.
1581 hr
= CoCreateInstance(rclsid
,
1591 * Then, query for all the interfaces requested.
1593 for (index
= 0; index
< cmq
; index
++)
1595 pResults
[index
].hr
= IUnknown_QueryInterface(pUnk
,
1596 pResults
[index
].pIID
,
1597 (VOID
**)&(pResults
[index
].pItf
));
1599 if (pResults
[index
].hr
== S_OK
)
1604 * Release our temporary unknown pointer.
1606 IUnknown_Release(pUnk
);
1608 if (successCount
== 0)
1609 return E_NOINTERFACE
;
1611 if (successCount
!=cmq
)
1612 return CO_S_NOTALLINTERFACES
;
1617 /***********************************************************************
1618 * CoFreeLibrary [OLE32.13]
1620 void WINAPI
CoFreeLibrary(HINSTANCE hLibrary
)
1622 OpenDll
*ptr
, *prev
;
1625 EnterCriticalSection( &csOpenDllList
);
1627 /* lookup library in linked list */
1629 for (ptr
= openDllList
; ptr
!= NULL
; ptr
=ptr
->next
) {
1630 if (ptr
->hLibrary
== hLibrary
) {
1637 /* shouldn't happen if user passed in a valid hLibrary */
1640 /* assert: ptr points to the library entry to free */
1642 /* free library and remove node from list */
1643 FreeLibrary(hLibrary
);
1644 if (ptr
== openDllList
) {
1645 tmp
= openDllList
->next
;
1646 HeapFree(GetProcessHeap(), 0, openDllList
);
1650 HeapFree(GetProcessHeap(), 0, ptr
);
1654 LeaveCriticalSection( &csOpenDllList
);
1658 /***********************************************************************
1659 * CoFreeAllLibraries [OLE32.12]
1661 void WINAPI
CoFreeAllLibraries(void)
1665 EnterCriticalSection( &csOpenDllList
);
1667 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1669 CoFreeLibrary(ptr
->hLibrary
);
1673 LeaveCriticalSection( &csOpenDllList
);
1678 /***********************************************************************
1679 * CoFreeUnusedLibraries [COMPOBJ.17]
1680 * CoFreeUnusedLibraries [OLE32.14]
1682 void WINAPI
CoFreeUnusedLibraries(void)
1685 typedef HRESULT(*DllCanUnloadNowFunc
)(void);
1686 DllCanUnloadNowFunc DllCanUnloadNow
;
1688 EnterCriticalSection( &csOpenDllList
);
1690 for (ptr
= openDllList
; ptr
!= NULL
; ) {
1691 DllCanUnloadNow
= (DllCanUnloadNowFunc
)
1692 GetProcAddress(ptr
->hLibrary
, "DllCanUnloadNow");
1694 if ( (DllCanUnloadNow
!= NULL
) &&
1695 (DllCanUnloadNow() == S_OK
) ) {
1697 CoFreeLibrary(ptr
->hLibrary
);
1704 LeaveCriticalSection( &csOpenDllList
);
1707 /***********************************************************************
1708 * CoFileTimeNow [COMPOBJ.82]
1709 * CoFileTimeNow [OLE32.10]
1712 * the current system time in lpFileTime
1714 HRESULT WINAPI
CoFileTimeNow( FILETIME
*lpFileTime
) /* [out] the current time */
1716 GetSystemTimeAsFileTime( lpFileTime
);
1720 /***********************************************************************
1721 * CoTaskMemAlloc (OLE32.43)
1723 * pointer to newly allocated block
1725 LPVOID WINAPI
CoTaskMemAlloc(
1726 ULONG size
/* [in] size of memoryblock to be allocated */
1729 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1734 return IMalloc_Alloc(lpmalloc
,size
);
1736 /***********************************************************************
1737 * CoTaskMemFree (OLE32.44)
1739 VOID WINAPI
CoTaskMemFree(
1740 LPVOID ptr
/* [in] pointer to be freed */
1743 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1748 IMalloc_Free(lpmalloc
, ptr
);
1751 /***********************************************************************
1752 * CoTaskMemRealloc (OLE32.45)
1754 * pointer to newly allocated block
1756 LPVOID WINAPI
CoTaskMemRealloc(
1758 ULONG size
) /* [in] size of memoryblock to be allocated */
1761 HRESULT ret
= CoGetMalloc(0,&lpmalloc
);
1766 return IMalloc_Realloc(lpmalloc
, pvOld
, size
);
1769 /***********************************************************************
1770 * CoLoadLibrary (OLE32.30)
1772 HINSTANCE WINAPI
CoLoadLibrary(LPOLESTR lpszLibName
, BOOL bAutoFree
)
1778 TRACE("(%s, %d)\n", debugstr_w(lpszLibName
), bAutoFree
);
1780 hLibrary
= LoadLibraryExW(lpszLibName
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
1785 EnterCriticalSection( &csOpenDllList
);
1787 if (openDllList
== NULL
) {
1788 /* empty list -- add first node */
1789 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1790 openDllList
->hLibrary
=hLibrary
;
1791 openDllList
->next
= NULL
;
1793 /* search for this dll */
1795 for (ptr
= openDllList
; ptr
->next
!= NULL
; ptr
=ptr
->next
) {
1796 if (ptr
->hLibrary
== hLibrary
) {
1802 /* dll not found, add it */
1804 openDllList
= (OpenDll
*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll
));
1805 openDllList
->hLibrary
= hLibrary
;
1806 openDllList
->next
= tmp
;
1810 LeaveCriticalSection( &csOpenDllList
);
1815 /***********************************************************************
1816 * CoInitializeWOW (OLE32.27)
1818 HRESULT WINAPI
CoInitializeWOW(DWORD x
,DWORD y
) {
1819 FIXME("(0x%08lx,0x%08lx),stub!\n",x
,y
);
1823 /******************************************************************************
1824 * CoLockObjectExternal [COMPOBJ.63]
1826 HRESULT WINAPI
CoLockObjectExternal16(
1827 LPUNKNOWN pUnk
, /* [in] object to be locked */
1828 BOOL16 fLock
, /* [in] do lock */
1829 BOOL16 fLastUnlockReleases
/* [in] ? */
1831 FIXME("(%p,%d,%d),stub!\n",pUnk
,fLock
,fLastUnlockReleases
);
1835 /******************************************************************************
1836 * CoLockObjectExternal [OLE32.31]
1838 HRESULT WINAPI
CoLockObjectExternal(
1839 LPUNKNOWN pUnk
, /* [in] object to be locked */
1840 BOOL fLock
, /* [in] do lock */
1841 BOOL fLastUnlockReleases
) /* [in] unlock all */
1847 * Increment the external lock coutner, COM_ExternalLockAddRef also
1848 * increment the object's internal lock counter.
1850 COM_ExternalLockAddRef( pUnk
);
1855 * Decrement the external lock coutner, COM_ExternalLockRelease also
1856 * decrement the object's internal lock counter.
1858 COM_ExternalLockRelease( pUnk
, fLastUnlockReleases
);
1864 /***********************************************************************
1865 * CoGetState [COMPOBJ.115]
1867 HRESULT WINAPI
CoGetState16(LPDWORD state
)
1869 FIXME("(%p),stub!\n", state
);
1873 /***********************************************************************
1874 * CoSetState [OLE32.42]
1876 HRESULT WINAPI
CoSetState(LPDWORD state
)
1878 FIXME("(%p),stub!\n", state
);
1879 if (state
) *state
= 0;
1882 /***********************************************************************
1883 * CoCreateFreeThreadedMarshaler [OLE32.5]
1885 HRESULT WINAPI
CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter
, LPUNKNOWN
* ppunkMarshal
)
1887 FIXME ("(%p %p): stub\n", punkOuter
, ppunkMarshal
);
1893 * COM_RevokeAllClasses
1895 * This method is called when the COM libraries are uninitialized to
1896 * release all the references to the class objects registered with
1899 static void COM_RevokeAllClasses()
1901 EnterCriticalSection( &csRegisteredClassList
);
1903 while (firstRegisteredClass
!=0)
1905 CoRevokeClassObject(firstRegisteredClass
->dwCookie
);
1908 LeaveCriticalSection( &csRegisteredClassList
);
1911 /****************************************************************************
1912 * COM External Lock methods implementation
1915 /****************************************************************************
1916 * Public - Method that increments the count for a IUnknown* in the linked
1917 * list. The item is inserted if not already in the list.
1919 static void COM_ExternalLockAddRef(
1922 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1925 * Add an external lock to the object. If it was already externally
1926 * locked, just increase the reference count. If it was not.
1927 * add the item to the list.
1929 if ( externalLock
== EL_NOT_FOUND
)
1930 COM_ExternalLockInsert(pUnk
);
1932 externalLock
->uRefCount
++;
1935 * Add an internal lock to the object
1937 IUnknown_AddRef(pUnk
);
1940 /****************************************************************************
1941 * Public - Method that decrements the count for a IUnknown* in the linked
1942 * list. The item is removed from the list if its count end up at zero or if
1945 static void COM_ExternalLockRelease(
1949 COM_ExternalLock
*externalLock
= COM_ExternalLockFind(pUnk
);
1951 if ( externalLock
!= EL_NOT_FOUND
)
1955 externalLock
->uRefCount
--; /* release external locks */
1956 IUnknown_Release(pUnk
); /* release local locks as well */
1958 if ( bRelAll
== FALSE
)
1959 break; /* perform single release */
1961 } while ( externalLock
->uRefCount
> 0 );
1963 if ( externalLock
->uRefCount
== 0 ) /* get rid of the list entry */
1964 COM_ExternalLockDelete(externalLock
);
1967 /****************************************************************************
1968 * Public - Method that frees the content of the list.
1970 static void COM_ExternalLockFreeList()
1972 COM_ExternalLock
*head
;
1974 head
= elList
.head
; /* grab it by the head */
1975 while ( head
!= EL_END_OF_LIST
)
1977 COM_ExternalLockDelete(head
); /* get rid of the head stuff */
1979 head
= elList
.head
; /* get the new head... */
1983 /****************************************************************************
1984 * Public - Method that dump the content of the list.
1986 void COM_ExternalLockDump()
1988 COM_ExternalLock
*current
= elList
.head
;
1990 DPRINTF("\nExternal lock list contains:\n");
1992 while ( current
!= EL_END_OF_LIST
)
1994 DPRINTF( "\t%p with %lu references count.\n", current
->pUnk
, current
->uRefCount
);
1996 /* Skip to the next item */
1997 current
= current
->next
;
2002 /****************************************************************************
2003 * Internal - Find a IUnknown* in the linked list
2005 static COM_ExternalLock
* COM_ExternalLockFind(
2008 return COM_ExternalLockLocate(elList
.head
, pUnk
);
2011 /****************************************************************************
2012 * Internal - Recursivity agent for IUnknownExternalLockList_Find
2014 static COM_ExternalLock
* COM_ExternalLockLocate(
2015 COM_ExternalLock
*element
,
2018 if ( element
== EL_END_OF_LIST
)
2019 return EL_NOT_FOUND
;
2021 else if ( element
->pUnk
== pUnk
) /* We found it */
2024 else /* Not the right guy, keep on looking */
2025 return COM_ExternalLockLocate( element
->next
, pUnk
);
2028 /****************************************************************************
2029 * Internal - Insert a new IUnknown* to the linked list
2031 static BOOL
COM_ExternalLockInsert(
2034 COM_ExternalLock
*newLock
= NULL
;
2035 COM_ExternalLock
*previousHead
= NULL
;
2038 * Allocate space for the new storage object
2040 newLock
= HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock
));
2044 if ( elList
.head
== EL_END_OF_LIST
)
2046 elList
.head
= newLock
; /* The list is empty */
2051 * insert does it at the head
2053 previousHead
= elList
.head
;
2054 elList
.head
= newLock
;
2058 * Set new list item data member
2060 newLock
->pUnk
= pUnk
;
2061 newLock
->uRefCount
= 1;
2062 newLock
->next
= previousHead
;
2070 /****************************************************************************
2071 * Internal - Method that removes an item from the linked list.
2073 static void COM_ExternalLockDelete(
2074 COM_ExternalLock
*itemList
)
2076 COM_ExternalLock
*current
= elList
.head
;
2078 if ( current
== itemList
)
2081 * this section handles the deletion of the first node
2083 elList
.head
= itemList
->next
;
2084 HeapFree( GetProcessHeap(), 0, itemList
);
2090 if ( current
->next
== itemList
) /* We found the item to free */
2092 current
->next
= itemList
->next
; /* readjust the list pointers */
2094 HeapFree( GetProcessHeap(), 0, itemList
);
2098 /* Skip to the next item */
2099 current
= current
->next
;
2101 } while ( current
!= EL_END_OF_LIST
);
2105 /***********************************************************************
2106 * DllEntryPoint [COMPOBJ.116]
2108 * Initialization code for the COMPOBJ DLL
2112 BOOL WINAPI
COMPOBJ_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
, WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
2114 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason
, hInst
, ds
, HeapSize
,
2118 case DLL_PROCESS_ATTACH
:
2119 if (!COMPOBJ_Attach
++) COMPOBJ_hInstance
= hInst
;
2122 case DLL_PROCESS_DETACH
:
2123 if(!--COMPOBJ_Attach
)
2124 COMPOBJ_hInstance
= 0;
2130 /******************************************************************************
2131 * OleGetAutoConvert [OLE32.104]
2133 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2141 sprintf(buf
,"CLSID\\");WINE_StringFromCLSID(clsidOld
,&buf
[6]);
2142 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&hkey
))
2144 res
= REGDB_E_CLASSNOTREG
;
2148 /* we can just query for the default value of AutoConvertTo key like that,
2149 without opening the AutoConvertTo key and querying for NULL (default) */
2150 if (RegQueryValueA(hkey
,"AutoConvertTo",buf
,&len
))
2152 res
= REGDB_E_KEYMISSING
;
2155 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, wbuf
, sizeof(wbuf
)/sizeof(WCHAR
) );
2156 CLSIDFromString(wbuf
,pClsidNew
);
2158 if (hkey
) RegCloseKey(hkey
);
2163 /******************************************************************************
2164 * OleSetAutoConvert [OLE32.126]
2166 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2169 char buf
[200], szClsidNew
[200];
2172 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2173 sprintf(buf
,"CLSID\\");WINE_StringFromCLSID(clsidOld
,&buf
[6]);
2174 WINE_StringFromCLSID(clsidNew
, szClsidNew
);
2175 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&hkey
))
2177 res
= REGDB_E_CLASSNOTREG
;
2180 if (RegSetValueA(hkey
, "AutoConvertTo", REG_SZ
, szClsidNew
, strlen(szClsidNew
)+1))
2182 res
= REGDB_E_WRITEREGDB
;
2187 if (hkey
) RegCloseKey(hkey
);
2191 /******************************************************************************
2192 * CoTreatAsClass [OLE32.46]
2194 HRESULT WINAPI
CoTreatAsClass(REFCLSID clsidOld
, REFCLSID clsidNew
)
2197 char buf
[200], szClsidNew
[200];
2200 FIXME("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2201 sprintf(buf
,"CLSID\\");WINE_StringFromCLSID(clsidOld
,&buf
[6]);
2202 WINE_StringFromCLSID(clsidNew
, szClsidNew
);
2203 if (RegOpenKeyA(HKEY_CLASSES_ROOT
,buf
,&hkey
))
2205 res
= REGDB_E_CLASSNOTREG
;
2208 if (RegSetValueA(hkey
, "AutoTreatAs", REG_SZ
, szClsidNew
, strlen(szClsidNew
)+1))
2210 res
= REGDB_E_WRITEREGDB
;
2215 if (hkey
) RegCloseKey(hkey
);
2220 /***********************************************************************
2221 * IsEqualGUID [OLE32.76]
2223 * Compares two Unique Identifiers.
2229 BOOL WINAPI
IsEqualGUID(
2230 REFGUID rguid1
, /* [in] unique id 1 */
2231 REFGUID rguid2
/* [in] unique id 2 */
2234 return !memcmp(rguid1
,rguid2
,sizeof(GUID
));
2237 /***********************************************************************
2238 * CoInitializeSecurity [OLE32.164]
2240 HRESULT WINAPI
CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc
, LONG cAuthSvc
,
2241 SOLE_AUTHENTICATION_SERVICE
* asAuthSvc
,
2242 void* pReserved1
, DWORD dwAuthnLevel
,
2243 DWORD dwImpLevel
, void* pReserved2
,
2244 DWORD dwCapabilities
, void* pReserved3
)
2246 FIXME("(%p,%ld,%p,%p,%ld,%ld,%p,%ld,%p) - stub!\n", pSecDesc
, cAuthSvc
,
2247 asAuthSvc
, pReserved1
, dwAuthnLevel
, dwImpLevel
, pReserved2
,
2248 dwCapabilities
, pReserved3
);