d3d8/tests: Use a separate device for alpha_test().
[wine.git] / dlls / oleaut32 / oleaut.c
blob4cd5135ea2f538a86ce7f56bf7792a391a1ee079
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 #define BUCKET_SIZE 16
94 #define BUCKET_BUFFER_SIZE 6
96 typedef struct {
97 unsigned short head;
98 unsigned short cnt;
99 bstr_t *buf[BUCKET_BUFFER_SIZE];
100 } bstr_cache_entry_t;
102 #define ARENA_INUSE_FILLER 0x55
103 #define ARENA_TAIL_FILLER 0xab
104 #define ARENA_FREE_FILLER 0xfeeefeee
106 static bstr_cache_entry_t bstr_cache[0x10000/BUCKET_SIZE];
108 static inline size_t bstr_alloc_size(size_t size)
110 return (FIELD_OFFSET(bstr_t, u.ptr[size]) + sizeof(WCHAR) + BUCKET_SIZE-1) & ~(BUCKET_SIZE-1);
113 static inline bstr_t *bstr_from_str(BSTR str)
115 return CONTAINING_RECORD(str, bstr_t, u.str);
118 static inline bstr_cache_entry_t *get_cache_entry(size_t size)
120 unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size-1])/BUCKET_SIZE;
121 return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
122 ? bstr_cache + cache_idx
123 : NULL;
126 static bstr_t *alloc_bstr(size_t size)
128 bstr_cache_entry_t *cache_entry = get_cache_entry(size+sizeof(WCHAR));
129 bstr_t *ret;
131 if(cache_entry) {
132 EnterCriticalSection(&cs_bstr_cache);
134 if(!cache_entry->cnt) {
135 cache_entry = get_cache_entry(size+sizeof(WCHAR)+BUCKET_SIZE);
136 if(cache_entry && !cache_entry->cnt)
137 cache_entry = NULL;
140 if(cache_entry) {
141 ret = cache_entry->buf[cache_entry->head++];
142 cache_entry->head %= BUCKET_BUFFER_SIZE;
143 cache_entry->cnt--;
146 LeaveCriticalSection(&cs_bstr_cache);
148 if(cache_entry) {
149 if(WARN_ON(heap)) {
150 size_t tail;
152 memset(ret, ARENA_INUSE_FILLER, FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]));
153 tail = bstr_alloc_size(size) - FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]);
154 if(tail)
155 memset(ret->u.ptr+size+sizeof(WCHAR), ARENA_TAIL_FILLER, tail);
157 ret->size = size;
158 return ret;
162 ret = HeapAlloc(GetProcessHeap(), 0, bstr_alloc_size(size));
163 if(ret)
164 ret->size = size;
165 return ret;
168 /******************************************************************************
169 * SysStringLen [OLEAUT32.7]
171 * Get the allocated length of a BSTR in wide characters.
173 * PARAMS
174 * str [I] BSTR to find the length of
176 * RETURNS
177 * The allocated length of str, or 0 if str is NULL.
179 * NOTES
180 * See BSTR.
181 * The returned length may be different from the length of the string as
182 * calculated by lstrlenW(), since it returns the length that was used to
183 * allocate the string by SysAllocStringLen().
185 UINT WINAPI SysStringLen(BSTR str)
187 return str ? bstr_from_str(str)->size/sizeof(WCHAR) : 0;
190 /******************************************************************************
191 * SysStringByteLen [OLEAUT32.149]
193 * Get the allocated length of a BSTR in bytes.
195 * PARAMS
196 * str [I] BSTR to find the length of
198 * RETURNS
199 * The allocated length of str, or 0 if str is NULL.
201 * NOTES
202 * See SysStringLen(), BSTR().
204 UINT WINAPI SysStringByteLen(BSTR str)
206 return str ? bstr_from_str(str)->size : 0;
209 /******************************************************************************
210 * SysAllocString [OLEAUT32.2]
212 * Create a BSTR from an OLESTR.
214 * PARAMS
215 * str [I] Source to create BSTR from
217 * RETURNS
218 * Success: A BSTR allocated with SysAllocStringLen().
219 * Failure: NULL, if oleStr is NULL.
221 * NOTES
222 * See BSTR.
223 * MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
224 * a length of 0. Native Win32 and this implementation both return a valid
225 * empty BSTR in this case.
227 BSTR WINAPI SysAllocString(LPCOLESTR str)
229 if (!str) return 0;
231 /* Delegate this to the SysAllocStringLen32 method. */
232 return SysAllocStringLen(str, lstrlenW(str));
235 /******************************************************************************
236 * SysFreeString [OLEAUT32.6]
238 * Free a BSTR.
240 * PARAMS
241 * str [I] BSTR to free.
243 * RETURNS
244 * Nothing.
246 * NOTES
247 * See BSTR.
248 * str may be NULL, in which case this function does nothing.
250 void WINAPI SysFreeString(BSTR str)
252 bstr_cache_entry_t *cache_entry;
253 bstr_t *bstr;
255 if(!str)
256 return;
258 bstr = bstr_from_str(str);
259 cache_entry = get_cache_entry(bstr->size+sizeof(WCHAR));
260 if(cache_entry) {
261 unsigned i;
263 EnterCriticalSection(&cs_bstr_cache);
265 /* According to tests, freeing a string that's already in cache doesn't corrupt anything.
266 * For that to work we need to search the cache. */
267 for(i=0; i < cache_entry->cnt; i++) {
268 if(cache_entry->buf[(cache_entry->head+i) % BUCKET_BUFFER_SIZE] == bstr) {
269 WARN_(heap)("String already is in cache!\n");
270 LeaveCriticalSection(&cs_bstr_cache);
271 return;
275 if(cache_entry->cnt < sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)) {
276 cache_entry->buf[(cache_entry->head+cache_entry->cnt) % BUCKET_BUFFER_SIZE] = bstr;
277 cache_entry->cnt++;
279 if(WARN_ON(heap)) {
280 unsigned n = bstr_alloc_size(bstr->size) / sizeof(DWORD) - 1;
281 bstr->size = ARENA_FREE_FILLER;
282 for(i=0; i<n; i++)
283 bstr->u.dwptr[i] = ARENA_FREE_FILLER;
286 LeaveCriticalSection(&cs_bstr_cache);
287 return;
290 LeaveCriticalSection(&cs_bstr_cache);
293 HeapFree(GetProcessHeap(), 0, bstr);
296 /******************************************************************************
297 * SysAllocStringLen [OLEAUT32.4]
299 * Create a BSTR from an OLESTR of a given wide character length.
301 * PARAMS
302 * str [I] Source to create BSTR from
303 * len [I] Length of oleStr in wide characters
305 * RETURNS
306 * Success: A newly allocated BSTR from SysAllocStringByteLen()
307 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
309 * NOTES
310 * See BSTR(), SysAllocStringByteLen().
312 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
314 bstr_t *bstr;
315 DWORD size;
317 /* Detect integer overflow. */
318 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
319 return NULL;
321 TRACE("%s\n", debugstr_wn(str, len));
323 size = len*sizeof(WCHAR);
324 bstr = alloc_bstr(size);
325 if(!bstr)
326 return NULL;
328 if(str) {
329 memcpy(bstr->u.str, str, size);
330 bstr->u.str[len] = 0;
331 }else {
332 memset(bstr->u.str, 0, size+sizeof(WCHAR));
335 return bstr->u.str;
338 /******************************************************************************
339 * SysReAllocStringLen [OLEAUT32.5]
341 * Change the length of a previously created BSTR.
343 * PARAMS
344 * old [O] BSTR to change the length of
345 * str [I] New source for pbstr
346 * len [I] Length of oleStr in wide characters
348 * RETURNS
349 * Success: 1. The size of pbstr is updated.
350 * Failure: 0, if len >= 0x80000000 or memory allocation fails.
352 * NOTES
353 * See BSTR(), SysAllocStringByteLen().
354 * *old may be changed by this function.
356 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
358 /* Detect integer overflow. */
359 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
360 return 0;
362 if (*old!=NULL) {
363 BSTR old_copy = *old;
364 DWORD newbytelen = len*sizeof(WCHAR);
365 bstr_t *bstr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,bstr_alloc_size(newbytelen));
366 *old = bstr->u.str;
367 bstr->size = newbytelen;
368 /* Subtle hidden feature: The old string data is still there
369 * when 'in' is NULL!
370 * Some Microsoft program needs it.
371 * FIXME: Is it a sideeffect of BSTR caching?
373 if (str && old_copy!=str) memmove(*old, str, newbytelen);
374 (*old)[len] = 0;
375 } else {
377 * Allocate the new string
379 *old = SysAllocStringLen(str, len);
382 return 1;
385 /******************************************************************************
386 * SysAllocStringByteLen [OLEAUT32.150]
388 * Create a BSTR from an OLESTR of a given byte length.
390 * PARAMS
391 * str [I] Source to create BSTR from
392 * len [I] Length of oleStr in bytes
394 * RETURNS
395 * Success: A newly allocated BSTR
396 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
398 * NOTES
399 * -If len is 0 or oleStr is NULL the resulting string is empty ("").
400 * -This function always NUL terminates the resulting BSTR.
401 * -oleStr may be either an LPCSTR or LPCOLESTR, since it is copied
402 * without checking for a terminating NUL.
403 * See BSTR.
405 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
407 bstr_t *bstr;
409 /* Detect integer overflow. */
410 if (len >= (UINT_MAX-sizeof(WCHAR)-sizeof(DWORD)))
411 return NULL;
413 bstr = alloc_bstr(len);
414 if(!bstr)
415 return NULL;
417 if(str) {
418 memcpy(bstr->u.ptr, str, len);
419 bstr->u.ptr[len] = bstr->u.ptr[len+1] = 0;
420 }else {
421 memset(bstr->u.ptr, 0, len+sizeof(WCHAR));
424 return bstr->u.str;
427 /******************************************************************************
428 * SysReAllocString [OLEAUT32.3]
430 * Change the length of a previously created BSTR.
432 * PARAMS
433 * old [I/O] BSTR to change the length of
434 * str [I] New source for pbstr
436 * RETURNS
437 * Success: 1
438 * Failure: 0.
440 * NOTES
441 * See BSTR(), SysAllocStringStringLen().
443 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
446 * Sanity check
448 if (old==NULL)
449 return 0;
452 * Make sure we free the old string.
454 SysFreeString(*old);
457 * Allocate the new string
459 *old = SysAllocString(str);
461 return 1;
464 /******************************************************************************
465 * SetOaNoCache (OLEAUT32.327)
467 * Instruct Ole Automation not to cache BSTR allocations.
469 * PARAMS
470 * None.
472 * RETURNS
473 * Nothing.
475 * NOTES
476 * SetOaNoCache does not release cached strings, so it leaks by design.
478 void WINAPI SetOaNoCache(void)
480 TRACE("\n");
481 bstr_cache_enabled = FALSE;
484 static const WCHAR _delimiter[] = {'!',0}; /* default delimiter apparently */
485 static const WCHAR *pdelimiter = &_delimiter[0];
487 /***********************************************************************
488 * RegisterActiveObject (OLEAUT32.33)
490 * Registers an object in the global item table.
492 * PARAMS
493 * punk [I] Object to register.
494 * rcid [I] CLSID of the object.
495 * dwFlags [I] Flags.
496 * pdwRegister [O] Address to store cookie of object registration in.
498 * RETURNS
499 * Success: S_OK.
500 * Failure: HRESULT code.
502 HRESULT WINAPI RegisterActiveObject(
503 LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
505 WCHAR guidbuf[80];
506 HRESULT ret;
507 LPRUNNINGOBJECTTABLE runobtable;
508 LPMONIKER moniker;
509 DWORD rot_flags = ROTFLAGS_REGISTRATIONKEEPSALIVE; /* default registration is strong */
511 StringFromGUID2(rcid,guidbuf,39);
512 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
513 if (FAILED(ret))
514 return ret;
515 ret = GetRunningObjectTable(0,&runobtable);
516 if (FAILED(ret)) {
517 IMoniker_Release(moniker);
518 return ret;
520 if(dwFlags == ACTIVEOBJECT_WEAK)
521 rot_flags = 0;
522 ret = IRunningObjectTable_Register(runobtable,rot_flags,punk,moniker,pdwRegister);
523 IRunningObjectTable_Release(runobtable);
524 IMoniker_Release(moniker);
525 return ret;
528 /***********************************************************************
529 * RevokeActiveObject (OLEAUT32.34)
531 * Revokes an object from the global item table.
533 * PARAMS
534 * xregister [I] Registration cookie.
535 * reserved [I] Reserved. Set to NULL.
537 * RETURNS
538 * Success: S_OK.
539 * Failure: HRESULT code.
541 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
543 LPRUNNINGOBJECTTABLE runobtable;
544 HRESULT ret;
546 ret = GetRunningObjectTable(0,&runobtable);
547 if (FAILED(ret)) return ret;
548 ret = IRunningObjectTable_Revoke(runobtable,xregister);
549 if (SUCCEEDED(ret)) ret = S_OK;
550 IRunningObjectTable_Release(runobtable);
551 return ret;
554 /***********************************************************************
555 * GetActiveObject (OLEAUT32.35)
557 * Gets an object from the global item table.
559 * PARAMS
560 * rcid [I] CLSID of the object.
561 * preserved [I] Reserved. Set to NULL.
562 * ppunk [O] Address to store object into.
564 * RETURNS
565 * Success: S_OK.
566 * Failure: HRESULT code.
568 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
570 WCHAR guidbuf[80];
571 HRESULT ret;
572 LPRUNNINGOBJECTTABLE runobtable;
573 LPMONIKER moniker;
575 StringFromGUID2(rcid,guidbuf,39);
576 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
577 if (FAILED(ret))
578 return ret;
579 ret = GetRunningObjectTable(0,&runobtable);
580 if (FAILED(ret)) {
581 IMoniker_Release(moniker);
582 return ret;
584 ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
585 IRunningObjectTable_Release(runobtable);
586 IMoniker_Release(moniker);
587 return ret;
591 /***********************************************************************
592 * OaBuildVersion [OLEAUT32.170]
594 * Get the Ole Automation build version.
596 * PARAMS
597 * None
599 * RETURNS
600 * The build version.
602 * NOTES
603 * Known oleaut32.dll versions:
604 *| OLE Ver. Comments Date Build Ver.
605 *| -------- ------------------------- ---- ---------
606 *| OLE 2.1 NT 1993-95 10 3023
607 *| OLE 2.1 10 3027
608 *| Win32s Ver 1.1e 20 4049
609 *| OLE 2.20 W95/NT 1993-96 20 4112
610 *| OLE 2.20 W95/NT 1993-96 20 4118
611 *| OLE 2.20 W95/NT 1993-96 20 4122
612 *| OLE 2.30 W95/NT 1993-98 30 4265
613 *| OLE 2.40 NT?? 1993-98 40 4267
614 *| OLE 2.40 W98 SE orig. file 1993-98 40 4275
615 *| OLE 2.40 W2K orig. file 1993-XX 40 4514
617 * Currently the versions returned are 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
618 * and 2.40 for all later versions. The build number is maximum, i.e. 0xffff.
620 ULONG WINAPI OaBuildVersion(void)
622 switch(GetVersion() & 0x8000ffff) /* mask off build number */
624 case 0x80000a03: /* WIN31 */
625 return MAKELONG(0xffff, 20);
626 case 0x00003303: /* NT351 */
627 return MAKELONG(0xffff, 30);
628 case 0x80000004: /* WIN95; I'd like to use the "standard" w95 minor
629 version here (30), but as we still use w95
630 as default winver (which is good IMHO), I better
631 play safe and use the latest value for w95 for now.
632 Change this as soon as default winver gets changed
633 to something more recent */
634 case 0x80000a04: /* WIN98 */
635 case 0x00000004: /* NT40 */
636 case 0x00000005: /* W2K */
637 return MAKELONG(0xffff, 40);
638 case 0x00000105: /* WinXP */
639 case 0x00000006: /* Vista */
640 case 0x00000106: /* Win7 */
641 return MAKELONG(0xffff, 50);
642 default:
643 FIXME("Version value not known yet. Please investigate it !\n");
644 return MAKELONG(0xffff, 40); /* for now return the same value as for w2k */
648 /******************************************************************************
649 * OleTranslateColor [OLEAUT32.421]
651 * Convert an OLE_COLOR to a COLORREF.
653 * PARAMS
654 * clr [I] Color to convert
655 * hpal [I] Handle to a palette for the conversion
656 * pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok
658 * RETURNS
659 * Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL.
660 * Failure: E_INVALIDARG, if any argument is invalid.
662 * FIXME
663 * Document the conversion rules.
665 HRESULT WINAPI OleTranslateColor(
666 OLE_COLOR clr,
667 HPALETTE hpal,
668 COLORREF* pColorRef)
670 COLORREF colorref;
671 BYTE b = HIBYTE(HIWORD(clr));
673 TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);
676 * In case pColorRef is NULL, provide our own to simplify the code.
678 if (pColorRef == NULL)
679 pColorRef = &colorref;
681 switch (b)
683 case 0x00:
685 if (hpal != 0)
686 *pColorRef = PALETTERGB(GetRValue(clr),
687 GetGValue(clr),
688 GetBValue(clr));
689 else
690 *pColorRef = clr;
692 break;
695 case 0x01:
697 if (hpal != 0)
699 PALETTEENTRY pe;
701 * Validate the palette index.
703 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
704 return E_INVALIDARG;
707 *pColorRef = clr;
709 break;
712 case 0x02:
713 *pColorRef = clr;
714 break;
716 case 0x80:
718 int index = LOBYTE(LOWORD(clr));
721 * Validate GetSysColor index.
723 if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
724 return E_INVALIDARG;
726 *pColorRef = GetSysColor(index);
728 break;
731 default:
732 return E_INVALIDARG;
735 return S_OK;
738 extern HRESULT WINAPI OLEAUTPS_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
739 extern BOOL WINAPI OLEAUTPS_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
740 extern HRESULT WINAPI OLEAUTPS_DllRegisterServer(void) DECLSPEC_HIDDEN;
741 extern HRESULT WINAPI OLEAUTPS_DllUnregisterServer(void) DECLSPEC_HIDDEN;
743 extern void _get_STDFONT_CF(LPVOID *);
744 extern void _get_STDPIC_CF(LPVOID *);
746 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
748 if (IsEqualIID(riid, &IID_IUnknown) ||
749 IsEqualIID(riid, &IID_IPSFactoryBuffer))
751 IPSFactoryBuffer_AddRef(iface);
752 *ppv = iface;
753 return S_OK;
755 return E_NOINTERFACE;
758 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
760 return 2;
763 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
765 return 1;
768 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
770 IPSFactoryBuffer *pPSFB;
771 HRESULT hr;
773 if (IsEqualIID(riid, &IID_IDispatch))
774 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
775 else
776 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
778 if (FAILED(hr)) return hr;
780 hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
782 IPSFactoryBuffer_Release(pPSFB);
783 return hr;
786 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
788 IPSFactoryBuffer *pPSFB;
789 HRESULT hr;
791 if (IsEqualIID(riid, &IID_IDispatch))
792 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
793 else
794 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
796 if (FAILED(hr)) return hr;
798 hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
800 IPSFactoryBuffer_Release(pPSFB);
801 return hr;
804 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
806 PSDispatchFacBuf_QueryInterface,
807 PSDispatchFacBuf_AddRef,
808 PSDispatchFacBuf_Release,
809 PSDispatchFacBuf_CreateProxy,
810 PSDispatchFacBuf_CreateStub
813 /* This is the whole PSFactoryBuffer object, just the vtableptr */
814 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
816 /***********************************************************************
817 * DllGetClassObject (OLEAUT32.@)
819 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
821 *ppv = NULL;
822 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
823 if (IsEqualGUID(iid,&IID_IClassFactory)) {
824 _get_STDFONT_CF(ppv);
825 IClassFactory_AddRef((IClassFactory*)*ppv);
826 return S_OK;
829 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
830 if (IsEqualGUID(iid,&IID_IClassFactory)) {
831 _get_STDPIC_CF(ppv);
832 IClassFactory_AddRef((IClassFactory*)*ppv);
833 return S_OK;
836 if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
837 *ppv = &pPSDispatchFacBuf;
838 IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
839 return S_OK;
841 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
842 if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
843 return S_OK;
844 /*FALLTHROUGH*/
846 if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
847 IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
848 IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
849 IsEqualCLSID(rclsid, &CLSID_PSEnumVariant))
850 return OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, iid, ppv);
852 return OLEAUTPS_DllGetClassObject(rclsid, iid, ppv);
855 /***********************************************************************
856 * DllCanUnloadNow (OLEAUT32.@)
858 * Determine if this dll can be unloaded from the callers address space.
860 * PARAMS
861 * None.
863 * RETURNS
864 * Always returns S_FALSE. This dll cannot be unloaded.
866 HRESULT WINAPI DllCanUnloadNow(void)
868 return S_FALSE;
871 /*****************************************************************************
872 * DllMain [OLEAUT32.@]
874 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
876 static const WCHAR oanocacheW[] = {'o','a','n','o','c','a','c','h','e',0};
878 if(fdwReason == DLL_PROCESS_ATTACH)
879 bstr_cache_enabled = !GetEnvironmentVariableW(oanocacheW, NULL, 0);
881 return OLEAUTPS_DllMain( hInstDll, fdwReason, lpvReserved );
884 /***********************************************************************
885 * DllRegisterServer (OLEAUT32.@)
887 HRESULT WINAPI DllRegisterServer(void)
889 return OLEAUTPS_DllRegisterServer();
892 /***********************************************************************
893 * DllUnregisterServer (OLEAUT32.@)
895 HRESULT WINAPI DllUnregisterServer(void)
897 return OLEAUTPS_DllUnregisterServer();
900 /***********************************************************************
901 * OleIconToCursor (OLEAUT32.415)
903 HCURSOR WINAPI OleIconToCursor( HINSTANCE hinstExe, HICON hIcon)
905 FIXME("(%p,%p), partially implemented.\n",hinstExe,hIcon);
906 /* FIXME: make an extended conversation from HICON to HCURSOR */
907 return CopyCursor(hIcon);