msi: Split up resolve_folder.
[wine.git] / dlls / oleaut32 / oleaut.c
blobac2d6665e1ff5955e6e9f53a6580ea657d771d35
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"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44 static BOOL BSTR_bCache = TRUE; /* Cache allocations to minimise alloc calls? */
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 /******************************************************************************
74 * SysStringLen [OLEAUT32.7]
76 * Get the allocated length of a BSTR in wide characters.
78 * PARAMS
79 * str [I] BSTR to find the length of
81 * RETURNS
82 * The allocated length of str, or 0 if str is NULL.
84 * NOTES
85 * See BSTR.
86 * The returned length may be different from the length of the string as
87 * calculated by lstrlenW(), since it returns the length that was used to
88 * allocate the string by SysAllocStringLen().
90 UINT WINAPI SysStringLen(BSTR str)
92 DWORD* bufferPointer;
94 if (!str) return 0;
96 * The length of the string (in bytes) is contained in a DWORD placed
97 * just before the BSTR pointer
99 bufferPointer = (DWORD*)str;
101 bufferPointer--;
103 return (int)(*bufferPointer/sizeof(WCHAR));
106 /******************************************************************************
107 * SysStringByteLen [OLEAUT32.149]
109 * Get the allocated length of a BSTR in bytes.
111 * PARAMS
112 * str [I] BSTR to find the length of
114 * RETURNS
115 * The allocated length of str, or 0 if str is NULL.
117 * NOTES
118 * See SysStringLen(), BSTR().
120 UINT WINAPI SysStringByteLen(BSTR str)
122 DWORD* bufferPointer;
124 if (!str) return 0;
126 * The length of the string (in bytes) is contained in a DWORD placed
127 * just before the BSTR pointer
129 bufferPointer = (DWORD*)str;
131 bufferPointer--;
133 return (int)(*bufferPointer);
136 /******************************************************************************
137 * SysAllocString [OLEAUT32.2]
139 * Create a BSTR from an OLESTR.
141 * PARAMS
142 * str [I] Source to create BSTR from
144 * RETURNS
145 * Success: A BSTR allocated with SysAllocStringLen().
146 * Failure: NULL, if oleStr is NULL.
148 * NOTES
149 * See BSTR.
150 * MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
151 * a length of 0. Native Win32 and this implementation both return a valid
152 * empty BSTR in this case.
154 BSTR WINAPI SysAllocString(LPCOLESTR str)
156 if (!str) return 0;
158 /* Delegate this to the SysAllocStringLen32 method. */
159 return SysAllocStringLen(str, lstrlenW(str));
162 /******************************************************************************
163 * SysFreeString [OLEAUT32.6]
165 * Free a BSTR.
167 * PARAMS
168 * str [I] BSTR to free.
170 * RETURNS
171 * Nothing.
173 * NOTES
174 * See BSTR.
175 * str may be NULL, in which case this function does nothing.
177 void WINAPI SysFreeString(BSTR str)
179 DWORD* bufferPointer;
181 /* NULL is a valid parameter */
182 if(!str) return;
185 * We have to be careful when we free a BSTR pointer, it points to
186 * the beginning of the string but it skips the byte count contained
187 * before the string.
189 bufferPointer = (DWORD*)str;
191 bufferPointer--;
194 * Free the memory from its "real" origin.
196 HeapFree(GetProcessHeap(), 0, bufferPointer);
199 /******************************************************************************
200 * SysAllocStringLen [OLEAUT32.4]
202 * Create a BSTR from an OLESTR of a given wide character length.
204 * PARAMS
205 * str [I] Source to create BSTR from
206 * len [I] Length of oleStr in wide characters
208 * RETURNS
209 * Success: A newly allocated BSTR from SysAllocStringByteLen()
210 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
212 * NOTES
213 * See BSTR(), SysAllocStringByteLen().
215 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
217 DWORD bufferSize;
218 DWORD* newBuffer;
219 WCHAR* stringBuffer;
221 /* Detect integer overflow. */
222 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
223 return NULL;
225 * Find the length of the buffer passed-in, in bytes.
227 bufferSize = len * sizeof (WCHAR);
230 * Allocate a new buffer to hold the string.
231 * don't forget to keep an empty spot at the beginning of the
232 * buffer for the character count and an extra character at the
233 * end for the NULL.
235 newBuffer = HeapAlloc(GetProcessHeap(), 0,
236 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
239 * If the memory allocation failed, return a null pointer.
241 if (!newBuffer)
242 return NULL;
245 * Copy the length of the string in the placeholder.
247 *newBuffer = bufferSize;
250 * Skip the byte count.
252 newBuffer++;
255 * Copy the information in the buffer.
256 * Since it is valid to pass a NULL pointer here, we'll initialize the
257 * buffer to nul if it is the case.
259 if (str != 0)
260 memcpy(newBuffer, str, bufferSize);
261 else
262 memset(newBuffer, 0, bufferSize);
265 * Make sure that there is a nul character at the end of the
266 * string.
268 stringBuffer = (WCHAR*)newBuffer;
269 stringBuffer[len] = '\0';
271 return stringBuffer;
274 /******************************************************************************
275 * SysReAllocStringLen [OLEAUT32.5]
277 * Change the length of a previously created BSTR.
279 * PARAMS
280 * old [O] BSTR to change the length of
281 * str [I] New source for pbstr
282 * len [I] Length of oleStr in wide characters
284 * RETURNS
285 * Success: 1. The size of pbstr is updated.
286 * Failure: 0, if len >= 0x80000000 or memory allocation fails.
288 * NOTES
289 * See BSTR(), SysAllocStringByteLen().
290 * *old may be changed by this function.
292 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
294 /* Detect integer overflow. */
295 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
296 return 0;
298 if (*old!=NULL) {
299 BSTR old_copy = *old;
300 DWORD newbytelen = len*sizeof(WCHAR);
301 DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
302 *old = (BSTR)(ptr+1);
303 *ptr = newbytelen;
304 /* Subtle hidden feature: The old string data is still there
305 * when 'in' is NULL!
306 * Some Microsoft program needs it.
308 if (str && old_copy!=str) memmove(*old, str, newbytelen);
309 (*old)[len] = 0;
310 } else {
312 * Allocate the new string
314 *old = SysAllocStringLen(str, len);
317 return 1;
320 /******************************************************************************
321 * SysAllocStringByteLen [OLEAUT32.150]
323 * Create a BSTR from an OLESTR of a given byte length.
325 * PARAMS
326 * str [I] Source to create BSTR from
327 * len [I] Length of oleStr in bytes
329 * RETURNS
330 * Success: A newly allocated BSTR
331 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
333 * NOTES
334 * -If len is 0 or oleStr is NULL the resulting string is empty ("").
335 * -This function always NUL terminates the resulting BSTR.
336 * -oleStr may be either an LPCSTR or LPCOLESTR, since it is copied
337 * without checking for a terminating NUL.
338 * See BSTR.
340 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
342 DWORD* newBuffer;
343 char* stringBuffer;
345 /* Detect integer overflow. */
346 if (len >= (UINT_MAX-sizeof(WCHAR)-sizeof(DWORD)))
347 return NULL;
350 * Allocate a new buffer to hold the string.
351 * don't forget to keep an empty spot at the beginning of the
352 * buffer for the character count and an extra character at the
353 * end for the NULL.
355 newBuffer = HeapAlloc(GetProcessHeap(), 0,
356 len + sizeof(WCHAR) + sizeof(DWORD));
359 * If the memory allocation failed, return a null pointer.
361 if (newBuffer==0)
362 return 0;
365 * Copy the length of the string in the placeholder.
367 *newBuffer = len;
370 * Skip the byte count.
372 newBuffer++;
375 * Copy the information in the buffer.
376 * Since it is valid to pass a NULL pointer here, we'll initialize the
377 * buffer to nul if it is the case.
379 if (str != 0)
380 memcpy(newBuffer, str, len);
383 * Make sure that there is a nul character at the end of the
384 * string.
386 stringBuffer = (char *)newBuffer;
387 stringBuffer[len] = 0;
388 stringBuffer[len+1] = 0;
390 return (LPWSTR)stringBuffer;
393 /******************************************************************************
394 * SysReAllocString [OLEAUT32.3]
396 * Change the length of a previously created BSTR.
398 * PARAMS
399 * old [I/O] BSTR to change the length of
400 * str [I] New source for pbstr
402 * RETURNS
403 * Success: 1
404 * Failure: 0.
406 * NOTES
407 * See BSTR(), SysAllocStringStringLen().
409 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
412 * Sanity check
414 if (old==NULL)
415 return 0;
418 * Make sure we free the old string.
420 SysFreeString(*old);
423 * Allocate the new string
425 *old = SysAllocString(str);
427 return 1;
430 /******************************************************************************
431 * SetOaNoCache (OLEAUT32.327)
433 * Instruct Ole Automation not to cache BSTR allocations.
435 * PARAMS
436 * None.
438 * RETURNS
439 * Nothing.
441 * NOTES
442 * See BSTR.
444 void WINAPI SetOaNoCache(void)
446 BSTR_bCache = FALSE;
449 static const WCHAR _delimiter[2] = {'!',0}; /* default delimiter apparently */
450 static const WCHAR *pdelimiter = &_delimiter[0];
452 /***********************************************************************
453 * RegisterActiveObject (OLEAUT32.33)
455 * Registers an object in the global item table.
457 * PARAMS
458 * punk [I] Object to register.
459 * rcid [I] CLSID of the object.
460 * dwFlags [I] Flags.
461 * pdwRegister [O] Address to store cookie of object registration in.
463 * RETURNS
464 * Success: S_OK.
465 * Failure: HRESULT code.
467 HRESULT WINAPI RegisterActiveObject(
468 LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
470 WCHAR guidbuf[80];
471 HRESULT ret;
472 LPRUNNINGOBJECTTABLE runobtable;
473 LPMONIKER moniker;
475 StringFromGUID2(rcid,guidbuf,39);
476 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
477 if (FAILED(ret))
478 return ret;
479 ret = GetRunningObjectTable(0,&runobtable);
480 if (FAILED(ret)) {
481 IMoniker_Release(moniker);
482 return ret;
484 ret = IRunningObjectTable_Register(runobtable,dwFlags,punk,moniker,pdwRegister);
485 IRunningObjectTable_Release(runobtable);
486 IMoniker_Release(moniker);
487 return ret;
490 /***********************************************************************
491 * RevokeActiveObject (OLEAUT32.34)
493 * Revokes an object from the global item table.
495 * PARAMS
496 * xregister [I] Registration cookie.
497 * reserved [I] Reserved. Set to NULL.
499 * RETURNS
500 * Success: S_OK.
501 * Failure: HRESULT code.
503 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
505 LPRUNNINGOBJECTTABLE runobtable;
506 HRESULT ret;
508 ret = GetRunningObjectTable(0,&runobtable);
509 if (FAILED(ret)) return ret;
510 ret = IRunningObjectTable_Revoke(runobtable,xregister);
511 if (SUCCEEDED(ret)) ret = S_OK;
512 IRunningObjectTable_Release(runobtable);
513 return ret;
516 /***********************************************************************
517 * GetActiveObject (OLEAUT32.35)
519 * Gets an object from the global item table.
521 * PARAMS
522 * rcid [I] CLSID of the object.
523 * preserved [I] Reserved. Set to NULL.
524 * ppunk [O] Address to store object into.
526 * RETURNS
527 * Success: S_OK.
528 * Failure: HRESULT code.
530 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
532 WCHAR guidbuf[80];
533 HRESULT ret;
534 LPRUNNINGOBJECTTABLE runobtable;
535 LPMONIKER moniker;
537 StringFromGUID2(rcid,guidbuf,39);
538 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
539 if (FAILED(ret))
540 return ret;
541 ret = GetRunningObjectTable(0,&runobtable);
542 if (FAILED(ret)) {
543 IMoniker_Release(moniker);
544 return ret;
546 ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
547 IRunningObjectTable_Release(runobtable);
548 IMoniker_Release(moniker);
549 return ret;
553 /***********************************************************************
554 * OaBuildVersion [OLEAUT32.170]
556 * Get the Ole Automation build version.
558 * PARAMS
559 * None
561 * RETURNS
562 * The build version.
564 * NOTES
565 * Known oleaut32.dll versions:
566 *| OLE Ver. Comments Date Build Ver.
567 *| -------- ------------------------- ---- ---------
568 *| OLE 2.1 NT 1993-95 10 3023
569 *| OLE 2.1 10 3027
570 *| Win32s Ver 1.1e 20 4049
571 *| OLE 2.20 W95/NT 1993-96 20 4112
572 *| OLE 2.20 W95/NT 1993-96 20 4118
573 *| OLE 2.20 W95/NT 1993-96 20 4122
574 *| OLE 2.30 W95/NT 1993-98 30 4265
575 *| OLE 2.40 NT?? 1993-98 40 4267
576 *| OLE 2.40 W98 SE orig. file 1993-98 40 4275
577 *| OLE 2.40 W2K orig. file 1993-XX 40 4514
579 * Currently the versions returned are 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
580 * and 2.40 for all later versions. The build number is maximum, i.e. 0xffff.
582 ULONG WINAPI OaBuildVersion(void)
584 switch(GetVersion() & 0x8000ffff) /* mask off build number */
586 case 0x80000a03: /* WIN31 */
587 return MAKELONG(0xffff, 20);
588 case 0x00003303: /* NT351 */
589 return MAKELONG(0xffff, 30);
590 case 0x80000004: /* WIN95; I'd like to use the "standard" w95 minor
591 version here (30), but as we still use w95
592 as default winver (which is good IMHO), I better
593 play safe and use the latest value for w95 for now.
594 Change this as soon as default winver gets changed
595 to something more recent */
596 case 0x80000a04: /* WIN98 */
597 case 0x00000004: /* NT40 */
598 case 0x00000005: /* W2K */
599 case 0x00000105: /* WinXP */
600 return MAKELONG(0xffff, 40);
601 default:
602 FIXME("Version value not known yet. Please investigate it !\n");
603 return MAKELONG(0xffff, 40); /* for now return the same value as for w2k */
607 /******************************************************************************
608 * OleTranslateColor [OLEAUT32.421]
610 * Convert an OLE_COLOR to a COLORREF.
612 * PARAMS
613 * clr [I] Color to convert
614 * hpal [I] Handle to a palette for the conversion
615 * pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok
617 * RETURNS
618 * Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL.
619 * Failure: E_INVALIDARG, if any argument is invalid.
621 * FIXME
622 * Document the conversion rules.
624 HRESULT WINAPI OleTranslateColor(
625 OLE_COLOR clr,
626 HPALETTE hpal,
627 COLORREF* pColorRef)
629 COLORREF colorref;
630 BYTE b = HIBYTE(HIWORD(clr));
632 TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);
635 * In case pColorRef is NULL, provide our own to simplify the code.
637 if (pColorRef == NULL)
638 pColorRef = &colorref;
640 switch (b)
642 case 0x00:
644 if (hpal != 0)
645 *pColorRef = PALETTERGB(GetRValue(clr),
646 GetGValue(clr),
647 GetBValue(clr));
648 else
649 *pColorRef = clr;
651 break;
654 case 0x01:
656 if (hpal != 0)
658 PALETTEENTRY pe;
660 * Validate the palette index.
662 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
663 return E_INVALIDARG;
666 *pColorRef = clr;
668 break;
671 case 0x02:
672 *pColorRef = clr;
673 break;
675 case 0x80:
677 int index = LOBYTE(LOWORD(clr));
680 * Validate GetSysColor index.
682 if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
683 return E_INVALIDARG;
685 *pColorRef = GetSysColor(index);
687 break;
690 default:
691 return E_INVALIDARG;
694 return S_OK;
697 extern HRESULT WINAPI OLEAUTPS_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
698 extern BOOL WINAPI OLEAUTPS_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
699 extern HRESULT WINAPI OLEAUTPS_DllRegisterServer(void) DECLSPEC_HIDDEN;
700 extern HRESULT WINAPI OLEAUTPS_DllUnregisterServer(void) DECLSPEC_HIDDEN;
701 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
703 extern void _get_STDFONT_CF(LPVOID *);
704 extern void _get_STDPIC_CF(LPVOID *);
706 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
708 if (IsEqualIID(riid, &IID_IUnknown) ||
709 IsEqualIID(riid, &IID_IPSFactoryBuffer))
711 IUnknown_AddRef(iface);
712 *ppv = iface;
713 return S_OK;
715 return E_NOINTERFACE;
718 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
720 return 2;
723 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
725 return 1;
728 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
730 IPSFactoryBuffer *pPSFB;
731 HRESULT hr;
733 if (IsEqualIID(riid, &IID_IDispatch))
734 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
735 else
736 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
738 if (FAILED(hr)) return hr;
740 hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
742 IPSFactoryBuffer_Release(pPSFB);
743 return hr;
746 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
748 IPSFactoryBuffer *pPSFB;
749 HRESULT hr;
751 if (IsEqualIID(riid, &IID_IDispatch))
752 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
753 else
754 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
756 if (FAILED(hr)) return hr;
758 hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
760 IPSFactoryBuffer_Release(pPSFB);
761 return hr;
764 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
766 PSDispatchFacBuf_QueryInterface,
767 PSDispatchFacBuf_AddRef,
768 PSDispatchFacBuf_Release,
769 PSDispatchFacBuf_CreateProxy,
770 PSDispatchFacBuf_CreateStub
773 /* This is the whole PSFactoryBuffer object, just the vtableptr */
774 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
776 /***********************************************************************
777 * DllGetClassObject (OLEAUT32.@)
779 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
781 *ppv = NULL;
782 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
783 if (IsEqualGUID(iid,&IID_IClassFactory)) {
784 _get_STDFONT_CF(ppv);
785 IClassFactory_AddRef((IClassFactory*)*ppv);
786 return S_OK;
789 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
790 if (IsEqualGUID(iid,&IID_IClassFactory)) {
791 _get_STDPIC_CF(ppv);
792 IClassFactory_AddRef((IClassFactory*)*ppv);
793 return S_OK;
796 if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
797 *ppv = &pPSDispatchFacBuf;
798 IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
799 return S_OK;
801 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
802 if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
803 return S_OK;
804 /*FALLTHROUGH*/
806 if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
807 IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
808 IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
809 IsEqualCLSID(rclsid, &CLSID_PSEnumVariant))
810 return OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, iid, ppv);
812 return OLEAUTPS_DllGetClassObject(rclsid, iid, ppv);
815 /***********************************************************************
816 * DllCanUnloadNow (OLEAUT32.@)
818 * Determine if this dll can be unloaded from the callers address space.
820 * PARAMS
821 * None.
823 * RETURNS
824 * Always returns S_FALSE. This dll cannot be unloaded.
826 HRESULT WINAPI DllCanUnloadNow(void)
828 return S_FALSE;
831 /*****************************************************************************
832 * DllMain [OLEAUT32.@]
834 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
836 return OLEAUTPS_DllMain( hInstDll, fdwReason, lpvReserved );
840 static HRESULT register_typelib( const WCHAR *name )
842 static const WCHAR backslash[] = {'\\',0};
843 HRESULT hr;
844 ITypeLib *typelib;
845 WCHAR *path;
846 DWORD len;
848 len = GetSystemDirectoryW( NULL, 0 ) + strlenW( name ) + 1;
849 if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
850 GetSystemDirectoryW( path, len );
851 strcatW( path, backslash );
852 strcatW( path, name );
853 hr = LoadTypeLib( path, &typelib );
854 if (SUCCEEDED(hr))
856 hr = RegisterTypeLib( typelib, path, NULL );
857 ITypeLib_Release( typelib );
859 HeapFree( GetProcessHeap(), 0, path );
860 return hr;
863 /***********************************************************************
864 * DllRegisterServer (OLEAUT32.@)
866 HRESULT WINAPI DllRegisterServer(void)
868 HRESULT hr;
870 TRACE("\n");
872 hr = OLEAUTPS_DllRegisterServer();
873 if (SUCCEEDED(hr))
875 const WCHAR stdole32W[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
876 const WCHAR stdole2W[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
877 hr = register_typelib( stdole2W );
878 if (SUCCEEDED(hr)) hr = register_typelib( stdole32W );
880 return hr;
883 /***********************************************************************
884 * DllUnregisterServer (OLEAUT32.@)
886 HRESULT WINAPI DllUnregisterServer(void)
888 return OLEAUTPS_DllUnregisterServer();
891 /***********************************************************************
892 * OleIconToCursor (OLEAUT32.415)
894 HCURSOR WINAPI OleIconToCursor( HINSTANCE hinstExe, HICON hIcon)
896 FIXME("(%p,%p), partially implemented.\n",hinstExe,hIcon);
897 /* FIXME: make a extended conversation from HICON to HCURSOR */
898 return CopyCursor(hIcon);