windowscodecs: Add support for more types of IFD fields.
[wine/multimedia.git] / dlls / oleaut32 / oleaut.c
blob371873db6b1e4bfcbc1096c49538aa9b0db2c707
1 /*
2 * OLEAUT32
4 * Copyright 1999, 2000 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include <limits.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winerror.h"
33 #include "ole2.h"
34 #include "olectl.h"
35 #include "oleauto.h"
36 #include "initguid.h"
37 #include "typelib.h"
38 #include "oleaut32_oaidl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44 WINE_DECLARE_DEBUG_CHANNEL(heap);
46 /******************************************************************************
47 * BSTR {OLEAUT32}
49 * NOTES
50 * BSTR is a simple typedef for a wide-character string used as the principle
51 * string type in ole automation. When encapsulated in a Variant type they are
52 * automatically copied and destroyed as the variant is processed.
54 * The low level BSTR API allows manipulation of these strings and is used by
55 * higher level API calls to manage the strings transparently to the caller.
57 * Internally the BSTR type is allocated with space for a DWORD byte count before
58 * the string data begins. This is undocumented and non-system code should not
59 * access the count directly. Use SysStringLen() or SysStringByteLen()
60 * instead. Note that the byte count does not include the terminating NUL.
62 * To create a new BSTR, use SysAllocString(), SysAllocStringLen() or
63 * SysAllocStringByteLen(). To change the size of an existing BSTR, use SysReAllocString()
64 * or SysReAllocStringLen(). Finally to destroy a string use SysFreeString().
66 * BSTR's are cached by Ole Automation by default. To override this behaviour
67 * either set the environment variable 'OANOCACHE', or call SetOaNoCache().
69 * SEE ALSO
70 * 'Inside OLE, second edition' by Kraig Brockshmidt.
73 static BOOL bstr_cache_enabled;
75 static CRITICAL_SECTION cs_bstr_cache;
76 static CRITICAL_SECTION_DEBUG cs_bstr_cache_dbg =
78 0, 0, &cs_bstr_cache,
79 { &cs_bstr_cache_dbg.ProcessLocksList, &cs_bstr_cache_dbg.ProcessLocksList },
80 0, 0, { (DWORD_PTR)(__FILE__ ": bstr_cache") }
82 static CRITICAL_SECTION cs_bstr_cache = { &cs_bstr_cache_dbg, -1, 0, 0, 0, 0 };
84 typedef struct {
85 DWORD size;
86 union {
87 char ptr[1];
88 WCHAR str[1];
89 DWORD dwptr[1];
90 } u;
91 } bstr_t;
93 typedef struct {
94 unsigned short head;
95 unsigned short cnt;
96 bstr_t *buf[6];
97 } bstr_cache_entry_t;
99 #define BUCKET_SIZE 16
101 #define ARENA_INUSE_FILLER 0x55
102 #define ARENA_TAIL_FILLER 0xab
103 #define ARENA_FREE_FILLER 0xfeeefeee
105 static bstr_cache_entry_t bstr_cache[0x10000/BUCKET_SIZE];
107 static inline size_t bstr_alloc_size(size_t size)
109 return (FIELD_OFFSET(bstr_t, u.ptr[size]) + sizeof(WCHAR) + BUCKET_SIZE-1) & ~(BUCKET_SIZE-1);
112 static inline bstr_t *bstr_from_str(BSTR str)
114 return CONTAINING_RECORD(str, bstr_t, u.str);
117 static inline bstr_cache_entry_t *get_cache_entry(size_t size)
119 unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size-1])/BUCKET_SIZE;
120 return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
121 ? bstr_cache + cache_idx
122 : NULL;
125 static bstr_t *alloc_bstr(size_t size)
127 bstr_cache_entry_t *cache_entry = get_cache_entry(size+sizeof(WCHAR));
128 bstr_t *ret;
130 if(cache_entry) {
131 EnterCriticalSection(&cs_bstr_cache);
133 if(!cache_entry->cnt) {
134 cache_entry = get_cache_entry(size+sizeof(WCHAR)+BUCKET_SIZE);
135 if(cache_entry && !cache_entry->cnt)
136 cache_entry = NULL;
139 if(cache_entry) {
140 ret = cache_entry->buf[cache_entry->head++];
141 cache_entry->head %= sizeof(cache_entry->buf)/sizeof(*cache_entry->buf);
142 cache_entry->cnt--;
145 LeaveCriticalSection(&cs_bstr_cache);
147 if(cache_entry) {
148 if(WARN_ON(heap)) {
149 size_t tail;
151 memset(ret, ARENA_INUSE_FILLER, FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]));
152 tail = bstr_alloc_size(size) - FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]);
153 if(tail)
154 memset(ret->u.ptr+size+sizeof(WCHAR), ARENA_TAIL_FILLER, tail);
156 ret->size = size;
157 return ret;
161 ret = HeapAlloc(GetProcessHeap(), 0, bstr_alloc_size(size));
162 if(ret)
163 ret->size = size;
164 return ret;
167 /******************************************************************************
168 * SysStringLen [OLEAUT32.7]
170 * Get the allocated length of a BSTR in wide characters.
172 * PARAMS
173 * str [I] BSTR to find the length of
175 * RETURNS
176 * The allocated length of str, or 0 if str is NULL.
178 * NOTES
179 * See BSTR.
180 * The returned length may be different from the length of the string as
181 * calculated by lstrlenW(), since it returns the length that was used to
182 * allocate the string by SysAllocStringLen().
184 UINT WINAPI SysStringLen(BSTR str)
186 return str ? bstr_from_str(str)->size/sizeof(WCHAR) : 0;
189 /******************************************************************************
190 * SysStringByteLen [OLEAUT32.149]
192 * Get the allocated length of a BSTR in bytes.
194 * PARAMS
195 * str [I] BSTR to find the length of
197 * RETURNS
198 * The allocated length of str, or 0 if str is NULL.
200 * NOTES
201 * See SysStringLen(), BSTR().
203 UINT WINAPI SysStringByteLen(BSTR str)
205 return str ? bstr_from_str(str)->size : 0;
208 /******************************************************************************
209 * SysAllocString [OLEAUT32.2]
211 * Create a BSTR from an OLESTR.
213 * PARAMS
214 * str [I] Source to create BSTR from
216 * RETURNS
217 * Success: A BSTR allocated with SysAllocStringLen().
218 * Failure: NULL, if oleStr is NULL.
220 * NOTES
221 * See BSTR.
222 * MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
223 * a length of 0. Native Win32 and this implementation both return a valid
224 * empty BSTR in this case.
226 BSTR WINAPI SysAllocString(LPCOLESTR str)
228 if (!str) return 0;
230 /* Delegate this to the SysAllocStringLen32 method. */
231 return SysAllocStringLen(str, lstrlenW(str));
234 /******************************************************************************
235 * SysFreeString [OLEAUT32.6]
237 * Free a BSTR.
239 * PARAMS
240 * str [I] BSTR to free.
242 * RETURNS
243 * Nothing.
245 * NOTES
246 * See BSTR.
247 * str may be NULL, in which case this function does nothing.
249 void WINAPI SysFreeString(BSTR str)
251 bstr_cache_entry_t *cache_entry;
252 bstr_t *bstr;
254 if(!str)
255 return;
257 bstr = bstr_from_str(str);
258 cache_entry = get_cache_entry(bstr->size+sizeof(WCHAR));
259 if(cache_entry) {
260 EnterCriticalSection(&cs_bstr_cache);
262 if(cache_entry->cnt < sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)) {
263 cache_entry->buf[(cache_entry->head+cache_entry->cnt)%((sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)))] = bstr;
264 cache_entry->cnt++;
266 if(WARN_ON(heap)) {
267 unsigned i, n = bstr_alloc_size(bstr->size) / sizeof(DWORD) - 1;
268 bstr->size = ARENA_FREE_FILLER;
269 for(i=0; i<n; i++)
270 bstr->u.dwptr[i] = ARENA_FREE_FILLER;
273 LeaveCriticalSection(&cs_bstr_cache);
274 return;
277 LeaveCriticalSection(&cs_bstr_cache);
280 HeapFree(GetProcessHeap(), 0, bstr);
283 /******************************************************************************
284 * SysAllocStringLen [OLEAUT32.4]
286 * Create a BSTR from an OLESTR of a given wide character length.
288 * PARAMS
289 * str [I] Source to create BSTR from
290 * len [I] Length of oleStr in wide characters
292 * RETURNS
293 * Success: A newly allocated BSTR from SysAllocStringByteLen()
294 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
296 * NOTES
297 * See BSTR(), SysAllocStringByteLen().
299 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
301 bstr_t *bstr;
302 DWORD size;
304 /* Detect integer overflow. */
305 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
306 return NULL;
308 TRACE("%s\n", debugstr_wn(str, len));
310 size = len*sizeof(WCHAR);
311 bstr = alloc_bstr(size);
312 if(!bstr)
313 return NULL;
315 if(str) {
316 memcpy(bstr->u.str, str, size);
317 bstr->u.str[len] = 0;
318 }else {
319 memset(bstr->u.str, 0, size+sizeof(WCHAR));
322 return bstr->u.str;
325 /******************************************************************************
326 * SysReAllocStringLen [OLEAUT32.5]
328 * Change the length of a previously created BSTR.
330 * PARAMS
331 * old [O] BSTR to change the length of
332 * str [I] New source for pbstr
333 * len [I] Length of oleStr in wide characters
335 * RETURNS
336 * Success: 1. The size of pbstr is updated.
337 * Failure: 0, if len >= 0x80000000 or memory allocation fails.
339 * NOTES
340 * See BSTR(), SysAllocStringByteLen().
341 * *old may be changed by this function.
343 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
345 /* Detect integer overflow. */
346 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
347 return 0;
349 if (*old!=NULL) {
350 BSTR old_copy = *old;
351 DWORD newbytelen = len*sizeof(WCHAR);
352 bstr_t *bstr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,bstr_alloc_size(newbytelen));
353 *old = bstr->u.str;
354 bstr->size = newbytelen;
355 /* Subtle hidden feature: The old string data is still there
356 * when 'in' is NULL!
357 * Some Microsoft program needs it.
358 * FIXME: Is it a sideeffect of BSTR caching?
360 if (str && old_copy!=str) memmove(*old, str, newbytelen);
361 (*old)[len] = 0;
362 } else {
364 * Allocate the new string
366 *old = SysAllocStringLen(str, len);
369 return 1;
372 /******************************************************************************
373 * SysAllocStringByteLen [OLEAUT32.150]
375 * Create a BSTR from an OLESTR of a given byte length.
377 * PARAMS
378 * str [I] Source to create BSTR from
379 * len [I] Length of oleStr in bytes
381 * RETURNS
382 * Success: A newly allocated BSTR
383 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
385 * NOTES
386 * -If len is 0 or oleStr is NULL the resulting string is empty ("").
387 * -This function always NUL terminates the resulting BSTR.
388 * -oleStr may be either an LPCSTR or LPCOLESTR, since it is copied
389 * without checking for a terminating NUL.
390 * See BSTR.
392 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
394 bstr_t *bstr;
396 /* Detect integer overflow. */
397 if (len >= (UINT_MAX-sizeof(WCHAR)-sizeof(DWORD)))
398 return NULL;
400 bstr = alloc_bstr(len);
401 if(!bstr)
402 return NULL;
404 if(str) {
405 memcpy(bstr->u.ptr, str, len);
406 bstr->u.ptr[len] = bstr->u.ptr[len+1] = 0;
407 }else {
408 memset(bstr->u.ptr, 0, len+sizeof(WCHAR));
411 return bstr->u.str;
414 /******************************************************************************
415 * SysReAllocString [OLEAUT32.3]
417 * Change the length of a previously created BSTR.
419 * PARAMS
420 * old [I/O] BSTR to change the length of
421 * str [I] New source for pbstr
423 * RETURNS
424 * Success: 1
425 * Failure: 0.
427 * NOTES
428 * See BSTR(), SysAllocStringStringLen().
430 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
433 * Sanity check
435 if (old==NULL)
436 return 0;
439 * Make sure we free the old string.
441 SysFreeString(*old);
444 * Allocate the new string
446 *old = SysAllocString(str);
448 return 1;
451 /******************************************************************************
452 * SetOaNoCache (OLEAUT32.327)
454 * Instruct Ole Automation not to cache BSTR allocations.
456 * PARAMS
457 * None.
459 * RETURNS
460 * Nothing.
462 * NOTES
463 * SetOaNoCache does not release cached strings, so it leaks by design.
465 void WINAPI SetOaNoCache(void)
467 TRACE("\n");
468 bstr_cache_enabled = FALSE;
471 static const WCHAR _delimiter[] = {'!',0}; /* default delimiter apparently */
472 static const WCHAR *pdelimiter = &_delimiter[0];
474 /***********************************************************************
475 * RegisterActiveObject (OLEAUT32.33)
477 * Registers an object in the global item table.
479 * PARAMS
480 * punk [I] Object to register.
481 * rcid [I] CLSID of the object.
482 * dwFlags [I] Flags.
483 * pdwRegister [O] Address to store cookie of object registration in.
485 * RETURNS
486 * Success: S_OK.
487 * Failure: HRESULT code.
489 HRESULT WINAPI RegisterActiveObject(
490 LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
492 WCHAR guidbuf[80];
493 HRESULT ret;
494 LPRUNNINGOBJECTTABLE runobtable;
495 LPMONIKER moniker;
496 DWORD rot_flags = ROTFLAGS_REGISTRATIONKEEPSALIVE; /* default registration is strong */
498 StringFromGUID2(rcid,guidbuf,39);
499 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
500 if (FAILED(ret))
501 return ret;
502 ret = GetRunningObjectTable(0,&runobtable);
503 if (FAILED(ret)) {
504 IMoniker_Release(moniker);
505 return ret;
507 if(dwFlags == ACTIVEOBJECT_WEAK)
508 rot_flags = 0;
509 ret = IRunningObjectTable_Register(runobtable,rot_flags,punk,moniker,pdwRegister);
510 IRunningObjectTable_Release(runobtable);
511 IMoniker_Release(moniker);
512 return ret;
515 /***********************************************************************
516 * RevokeActiveObject (OLEAUT32.34)
518 * Revokes an object from the global item table.
520 * PARAMS
521 * xregister [I] Registration cookie.
522 * reserved [I] Reserved. Set to NULL.
524 * RETURNS
525 * Success: S_OK.
526 * Failure: HRESULT code.
528 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
530 LPRUNNINGOBJECTTABLE runobtable;
531 HRESULT ret;
533 ret = GetRunningObjectTable(0,&runobtable);
534 if (FAILED(ret)) return ret;
535 ret = IRunningObjectTable_Revoke(runobtable,xregister);
536 if (SUCCEEDED(ret)) ret = S_OK;
537 IRunningObjectTable_Release(runobtable);
538 return ret;
541 /***********************************************************************
542 * GetActiveObject (OLEAUT32.35)
544 * Gets an object from the global item table.
546 * PARAMS
547 * rcid [I] CLSID of the object.
548 * preserved [I] Reserved. Set to NULL.
549 * ppunk [O] Address to store object into.
551 * RETURNS
552 * Success: S_OK.
553 * Failure: HRESULT code.
555 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
557 WCHAR guidbuf[80];
558 HRESULT ret;
559 LPRUNNINGOBJECTTABLE runobtable;
560 LPMONIKER moniker;
562 StringFromGUID2(rcid,guidbuf,39);
563 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
564 if (FAILED(ret))
565 return ret;
566 ret = GetRunningObjectTable(0,&runobtable);
567 if (FAILED(ret)) {
568 IMoniker_Release(moniker);
569 return ret;
571 ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
572 IRunningObjectTable_Release(runobtable);
573 IMoniker_Release(moniker);
574 return ret;
578 /***********************************************************************
579 * OaBuildVersion [OLEAUT32.170]
581 * Get the Ole Automation build version.
583 * PARAMS
584 * None
586 * RETURNS
587 * The build version.
589 * NOTES
590 * Known oleaut32.dll versions:
591 *| OLE Ver. Comments Date Build Ver.
592 *| -------- ------------------------- ---- ---------
593 *| OLE 2.1 NT 1993-95 10 3023
594 *| OLE 2.1 10 3027
595 *| Win32s Ver 1.1e 20 4049
596 *| OLE 2.20 W95/NT 1993-96 20 4112
597 *| OLE 2.20 W95/NT 1993-96 20 4118
598 *| OLE 2.20 W95/NT 1993-96 20 4122
599 *| OLE 2.30 W95/NT 1993-98 30 4265
600 *| OLE 2.40 NT?? 1993-98 40 4267
601 *| OLE 2.40 W98 SE orig. file 1993-98 40 4275
602 *| OLE 2.40 W2K orig. file 1993-XX 40 4514
604 * Currently the versions returned are 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
605 * and 2.40 for all later versions. The build number is maximum, i.e. 0xffff.
607 ULONG WINAPI OaBuildVersion(void)
609 switch(GetVersion() & 0x8000ffff) /* mask off build number */
611 case 0x80000a03: /* WIN31 */
612 return MAKELONG(0xffff, 20);
613 case 0x00003303: /* NT351 */
614 return MAKELONG(0xffff, 30);
615 case 0x80000004: /* WIN95; I'd like to use the "standard" w95 minor
616 version here (30), but as we still use w95
617 as default winver (which is good IMHO), I better
618 play safe and use the latest value for w95 for now.
619 Change this as soon as default winver gets changed
620 to something more recent */
621 case 0x80000a04: /* WIN98 */
622 case 0x00000004: /* NT40 */
623 case 0x00000005: /* W2K */
624 return MAKELONG(0xffff, 40);
625 case 0x00000105: /* WinXP */
626 case 0x00000006: /* Vista */
627 case 0x00000106: /* Win7 */
628 return MAKELONG(0xffff, 50);
629 default:
630 FIXME("Version value not known yet. Please investigate it !\n");
631 return MAKELONG(0xffff, 40); /* for now return the same value as for w2k */
635 /******************************************************************************
636 * OleTranslateColor [OLEAUT32.421]
638 * Convert an OLE_COLOR to a COLORREF.
640 * PARAMS
641 * clr [I] Color to convert
642 * hpal [I] Handle to a palette for the conversion
643 * pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok
645 * RETURNS
646 * Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL.
647 * Failure: E_INVALIDARG, if any argument is invalid.
649 * FIXME
650 * Document the conversion rules.
652 HRESULT WINAPI OleTranslateColor(
653 OLE_COLOR clr,
654 HPALETTE hpal,
655 COLORREF* pColorRef)
657 COLORREF colorref;
658 BYTE b = HIBYTE(HIWORD(clr));
660 TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);
663 * In case pColorRef is NULL, provide our own to simplify the code.
665 if (pColorRef == NULL)
666 pColorRef = &colorref;
668 switch (b)
670 case 0x00:
672 if (hpal != 0)
673 *pColorRef = PALETTERGB(GetRValue(clr),
674 GetGValue(clr),
675 GetBValue(clr));
676 else
677 *pColorRef = clr;
679 break;
682 case 0x01:
684 if (hpal != 0)
686 PALETTEENTRY pe;
688 * Validate the palette index.
690 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
691 return E_INVALIDARG;
694 *pColorRef = clr;
696 break;
699 case 0x02:
700 *pColorRef = clr;
701 break;
703 case 0x80:
705 int index = LOBYTE(LOWORD(clr));
708 * Validate GetSysColor index.
710 if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
711 return E_INVALIDARG;
713 *pColorRef = GetSysColor(index);
715 break;
718 default:
719 return E_INVALIDARG;
722 return S_OK;
725 extern HRESULT WINAPI OLEAUTPS_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
726 extern BOOL WINAPI OLEAUTPS_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
727 extern HRESULT WINAPI OLEAUTPS_DllRegisterServer(void) DECLSPEC_HIDDEN;
728 extern HRESULT WINAPI OLEAUTPS_DllUnregisterServer(void) DECLSPEC_HIDDEN;
729 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
731 extern void _get_STDFONT_CF(LPVOID *);
732 extern void _get_STDPIC_CF(LPVOID *);
734 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
736 if (IsEqualIID(riid, &IID_IUnknown) ||
737 IsEqualIID(riid, &IID_IPSFactoryBuffer))
739 IUnknown_AddRef(iface);
740 *ppv = iface;
741 return S_OK;
743 return E_NOINTERFACE;
746 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
748 return 2;
751 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
753 return 1;
756 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
758 IPSFactoryBuffer *pPSFB;
759 HRESULT hr;
761 if (IsEqualIID(riid, &IID_IDispatch))
762 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
763 else
764 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
766 if (FAILED(hr)) return hr;
768 hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
770 IPSFactoryBuffer_Release(pPSFB);
771 return hr;
774 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
776 IPSFactoryBuffer *pPSFB;
777 HRESULT hr;
779 if (IsEqualIID(riid, &IID_IDispatch))
780 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
781 else
782 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
784 if (FAILED(hr)) return hr;
786 hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
788 IPSFactoryBuffer_Release(pPSFB);
789 return hr;
792 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
794 PSDispatchFacBuf_QueryInterface,
795 PSDispatchFacBuf_AddRef,
796 PSDispatchFacBuf_Release,
797 PSDispatchFacBuf_CreateProxy,
798 PSDispatchFacBuf_CreateStub
801 /* This is the whole PSFactoryBuffer object, just the vtableptr */
802 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
804 /***********************************************************************
805 * DllGetClassObject (OLEAUT32.@)
807 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
809 *ppv = NULL;
810 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
811 if (IsEqualGUID(iid,&IID_IClassFactory)) {
812 _get_STDFONT_CF(ppv);
813 IClassFactory_AddRef((IClassFactory*)*ppv);
814 return S_OK;
817 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
818 if (IsEqualGUID(iid,&IID_IClassFactory)) {
819 _get_STDPIC_CF(ppv);
820 IClassFactory_AddRef((IClassFactory*)*ppv);
821 return S_OK;
824 if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
825 *ppv = &pPSDispatchFacBuf;
826 IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
827 return S_OK;
829 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
830 if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
831 return S_OK;
832 /*FALLTHROUGH*/
834 if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
835 IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
836 IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
837 IsEqualCLSID(rclsid, &CLSID_PSEnumVariant))
838 return OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, iid, ppv);
840 return OLEAUTPS_DllGetClassObject(rclsid, iid, ppv);
843 /***********************************************************************
844 * DllCanUnloadNow (OLEAUT32.@)
846 * Determine if this dll can be unloaded from the callers address space.
848 * PARAMS
849 * None.
851 * RETURNS
852 * Always returns S_FALSE. This dll cannot be unloaded.
854 HRESULT WINAPI DllCanUnloadNow(void)
856 return S_FALSE;
859 /*****************************************************************************
860 * DllMain [OLEAUT32.@]
862 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
864 static const WCHAR oanocacheW[] = {'o','a','n','o','c','a','c','h','e',0};
866 bstr_cache_enabled = !GetEnvironmentVariableW(oanocacheW, NULL, 0);
868 return OLEAUTPS_DllMain( hInstDll, fdwReason, lpvReserved );
871 /***********************************************************************
872 * DllRegisterServer (OLEAUT32.@)
874 HRESULT WINAPI DllRegisterServer(void)
876 return OLEAUTPS_DllRegisterServer();
879 /***********************************************************************
880 * DllUnregisterServer (OLEAUT32.@)
882 HRESULT WINAPI DllUnregisterServer(void)
884 return OLEAUTPS_DllUnregisterServer();
887 /***********************************************************************
888 * OleIconToCursor (OLEAUT32.415)
890 HCURSOR WINAPI OleIconToCursor( HINSTANCE hinstExe, HICON hIcon)
892 FIXME("(%p,%p), partially implemented.\n",hinstExe,hIcon);
893 /* FIXME: make a extended conversation from HICON to HCURSOR */
894 return CopyCursor(hIcon);