comctl32/monthcal: Copy SYSTEMTIME with a simple assignment.
[wine] / dlls / oleaut32 / oleaut.c
1 /*
2  *      OLEAUT32
3  *
4  * Copyright 1999, 2000 Marcus Meissner
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include <limits.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winerror.h"
32
33 #include "ole2.h"
34 #include "olectl.h"
35 #include "oleauto.h"
36 #include "typelib.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41
42 static BOOL BSTR_bCache = TRUE; /* Cache allocations to minimise alloc calls? */
43
44 /******************************************************************************
45  * BSTR  {OLEAUT32}
46  *
47  * NOTES
48  *  BSTR is a simple typedef for a wide-character string used as the principle
49  *  string type in ole automation. When encapsulated in a Variant type they are
50  *  automatically copied and destroyed as the variant is processed.
51  *
52  *  The low level BSTR Api allows manipulation of these strings and is used by
53  *  higher level Api calls to manage the strings transparently to the caller.
54  *
55  *  Internally the BSTR type is allocated with space for a DWORD byte count before
56  *  the string data begins. This is undocumented and non-system code should not
57  *  access the count directly. Use SysStringLen() or SysStringByteLen()
58  *  instead. Note that the byte count does not include the terminating NUL.
59  *
60  *  To create a new BSTR, use SysAllocString(), SysAllocStringLen() or
61  *  SysAllocStringByteLen(). To change the size of an existing BSTR, use SysReAllocString()
62  *  or SysReAllocStringLen(). Finally to destroy a string use SysFreeString().
63  *
64  *  BSTR's are cached by Ole Automation by default. To override this behaviour
65  *  either set the environment variable 'OANOCACHE', or call SetOaNoCache().
66  *
67  * SEE ALSO
68  *  'Inside OLE, second edition' by Kraig Brockshmidt.
69  */
70
71 /******************************************************************************
72  *             SysStringLen  [OLEAUT32.7]
73  *
74  * Get the allocated length of a BSTR in wide characters.
75  *
76  * PARAMS
77  *  str [I] BSTR to find the length of
78  *
79  * RETURNS
80  *  The allocated length of str, or 0 if str is NULL.
81  *
82  * NOTES
83  *  See BSTR.
84  *  The returned length may be different from the length of the string as
85  *  calculated by lstrlenW(), since it returns the length that was used to
86  *  allocate the string by SysAllocStringLen().
87  */
88 UINT WINAPI SysStringLen(BSTR str)
89 {
90     DWORD* bufferPointer;
91
92      if (!str) return 0;
93     /*
94      * The length of the string (in bytes) is contained in a DWORD placed
95      * just before the BSTR pointer
96      */
97     bufferPointer = (DWORD*)str;
98
99     bufferPointer--;
100
101     return (int)(*bufferPointer/sizeof(WCHAR));
102 }
103
104 /******************************************************************************
105  *             SysStringByteLen  [OLEAUT32.149]
106  *
107  * Get the allocated length of a BSTR in bytes.
108  *
109  * PARAMS
110  *  str [I] BSTR to find the length of
111  *
112  * RETURNS
113  *  The allocated length of str, or 0 if str is NULL.
114  *
115  * NOTES
116  *  See SysStringLen(), BSTR().
117  */
118 UINT WINAPI SysStringByteLen(BSTR str)
119 {
120     DWORD* bufferPointer;
121
122      if (!str) return 0;
123     /*
124      * The length of the string (in bytes) is contained in a DWORD placed
125      * just before the BSTR pointer
126      */
127     bufferPointer = (DWORD*)str;
128
129     bufferPointer--;
130
131     return (int)(*bufferPointer);
132 }
133
134 /******************************************************************************
135  *              SysAllocString  [OLEAUT32.2]
136  *
137  * Create a BSTR from an OLESTR.
138  *
139  * PARAMS
140  *  str [I] Source to create BSTR from
141  *
142  * RETURNS
143  *  Success: A BSTR allocated with SysAllocStringLen().
144  *  Failure: NULL, if oleStr is NULL.
145  *
146  * NOTES
147  *  See BSTR.
148  *  MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
149  *  a length of 0. Native Win32 and this implementation both return a valid
150  *  empty BSTR in this case.
151  */
152 BSTR WINAPI SysAllocString(LPCOLESTR str)
153 {
154     if (!str) return 0;
155
156     /* Delegate this to the SysAllocStringLen32 method. */
157     return SysAllocStringLen(str, lstrlenW(str));
158 }
159
160 /******************************************************************************
161  *              SysFreeString   [OLEAUT32.6]
162  *
163  * Free a BSTR.
164  *
165  * PARAMS
166  *  str [I] BSTR to free.
167  *
168  * RETURNS
169  *  Nothing.
170  *
171  * NOTES
172  *  See BSTR.
173  *  str may be NULL, in which case this function does nothing.
174  */
175 void WINAPI SysFreeString(BSTR str)
176 {
177     DWORD* bufferPointer;
178
179     /* NULL is a valid parameter */
180     if(!str) return;
181
182     /*
183      * We have to be careful when we free a BSTR pointer, it points to
184      * the beginning of the string but it skips the byte count contained
185      * before the string.
186      */
187     bufferPointer = (DWORD*)str;
188
189     bufferPointer--;
190
191     /*
192      * Free the memory from its "real" origin.
193      */
194     HeapFree(GetProcessHeap(), 0, bufferPointer);
195 }
196
197 /******************************************************************************
198  *             SysAllocStringLen     [OLEAUT32.4]
199  *
200  * Create a BSTR from an OLESTR of a given wide character length.
201  *
202  * PARAMS
203  *  str [I] Source to create BSTR from
204  *  len [I] Length of oleStr in wide characters
205  *
206  * RETURNS
207  *  Success: A newly allocated BSTR from SysAllocStringByteLen()
208  *  Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
209  *
210  * NOTES
211  *  See BSTR(), SysAllocStringByteLen().
212  */
213 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
214 {
215     DWORD  bufferSize;
216     DWORD* newBuffer;
217     WCHAR* stringBuffer;
218
219     /* Detect integer overflow. */
220     if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
221         return NULL;
222     /*
223      * Find the length of the buffer passed-in, in bytes.
224      */
225     bufferSize = len * sizeof (WCHAR);
226
227     /*
228      * Allocate a new buffer to hold the string.
229      * don't forget to keep an empty spot at the beginning of the
230      * buffer for the character count and an extra character at the
231      * end for the NULL.
232      */
233     newBuffer = HeapAlloc(GetProcessHeap(), 0,
234                           bufferSize + sizeof(WCHAR) + sizeof(DWORD));
235
236     /*
237      * If the memory allocation failed, return a null pointer.
238      */
239     if (!newBuffer)
240       return NULL;
241
242     /*
243      * Copy the length of the string in the placeholder.
244      */
245     *newBuffer = bufferSize;
246
247     /*
248      * Skip the byte count.
249      */
250     newBuffer++;
251
252     /*
253      * Copy the information in the buffer.
254      * Since it is valid to pass a NULL pointer here, we'll initialize the
255      * buffer to nul if it is the case.
256      */
257     if (str != 0)
258       memcpy(newBuffer, str, bufferSize);
259     else
260       memset(newBuffer, 0, bufferSize);
261
262     /*
263      * Make sure that there is a nul character at the end of the
264      * string.
265      */
266     stringBuffer = (WCHAR*)newBuffer;
267     stringBuffer[len] = '\0';
268
269     return stringBuffer;
270 }
271
272 /******************************************************************************
273  *             SysReAllocStringLen   [OLEAUT32.5]
274  *
275  * Change the length of a previously created BSTR.
276  *
277  * PARAMS
278  *  old [O] BSTR to change the length of
279  *  str [I] New source for pbstr
280  *  len [I] Length of oleStr in wide characters
281  *
282  * RETURNS
283  *  Success: 1. The size of pbstr is updated.
284  *  Failure: 0, if len >= 0x80000000 or memory allocation fails.
285  *
286  * NOTES
287  *  See BSTR(), SysAllocStringByteLen().
288  *  *old may be changed by this function.
289  */
290 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
291 {
292     /* Detect integer overflow. */
293     if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
294         return 0;
295
296     if (*old!=NULL) {
297       DWORD newbytelen = len*sizeof(WCHAR);
298       DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
299       *old = (BSTR)(ptr+1);
300       *ptr = newbytelen;
301       if (str) {
302         memmove(*old, str, newbytelen);
303         (*old)[len] = 0;
304       } else {
305         /* Subtle hidden feature: The old string data is still there
306          * when 'in' is NULL!
307          * Some Microsoft program needs it.
308          */
309       }
310     } else {
311       /*
312        * Allocate the new string
313        */
314       *old = SysAllocStringLen(str, len);
315     }
316
317     return 1;
318 }
319
320 /******************************************************************************
321  *             SysAllocStringByteLen     [OLEAUT32.150]
322  *
323  * Create a BSTR from an OLESTR of a given byte length.
324  *
325  * PARAMS
326  *  str [I] Source to create BSTR from
327  *  len [I] Length of oleStr in bytes
328  *
329  * RETURNS
330  *  Success: A newly allocated BSTR
331  *  Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
332  *
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.
339  */
340 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
341 {
342     DWORD* newBuffer;
343     char* stringBuffer;
344
345     /* Detect integer overflow. */
346     if (len >= (UINT_MAX-sizeof(WCHAR)-sizeof(DWORD)))
347         return NULL;
348
349     /*
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.
354      */
355     newBuffer = HeapAlloc(GetProcessHeap(), 0,
356                           len + sizeof(WCHAR) + sizeof(DWORD));
357
358     /*
359      * If the memory allocation failed, return a null pointer.
360      */
361     if (newBuffer==0)
362       return 0;
363
364     /*
365      * Copy the length of the string in the placeholder.
366      */
367     *newBuffer = len;
368
369     /*
370      * Skip the byte count.
371      */
372     newBuffer++;
373
374     /*
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.
378      */
379     if (str != 0)
380       memcpy(newBuffer, str, len);
381
382     /*
383      * Make sure that there is a nul character at the end of the
384      * string.
385      */
386     stringBuffer = (char *)newBuffer;
387     stringBuffer[len] = 0;
388     stringBuffer[len+1] = 0;
389
390     return (LPWSTR)stringBuffer;
391 }
392
393 /******************************************************************************
394  *              SysReAllocString        [OLEAUT32.3]
395  *
396  * Change the length of a previously created BSTR.
397  *
398  * PARAMS
399  *  old [I/O] BSTR to change the length of
400  *  str [I]   New source for pbstr
401  *
402  * RETURNS
403  *  Success: 1
404  *  Failure: 0.
405  *
406  * NOTES
407  *  See BSTR(), SysAllocStringStringLen().
408  */
409 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
410 {
411     /*
412      * Sanity check
413      */
414     if (old==NULL)
415       return 0;
416
417     /*
418      * Make sure we free the old string.
419      */
420     SysFreeString(*old);
421
422     /*
423      * Allocate the new string
424      */
425     *old = SysAllocString(str);
426
427      return 1;
428 }
429
430 /******************************************************************************
431  *              SetOaNoCache (OLEAUT32.327)
432  *
433  * Instruct Ole Automation not to cache BSTR allocations.
434  *
435  * PARAMS
436  *  None.
437  *
438  * RETURNS
439  *  Nothing.
440  *
441  * NOTES
442  *  See BSTR.
443  */
444 void WINAPI SetOaNoCache(void)
445 {
446   BSTR_bCache = FALSE;
447 }
448
449 static const WCHAR      _delimiter[2] = {'!',0}; /* default delimiter apparently */
450 static const WCHAR      *pdelimiter = &_delimiter[0];
451
452 /***********************************************************************
453  *              RegisterActiveObject (OLEAUT32.33)
454  *
455  * Registers an object in the global item table.
456  *
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.
462  *
463  * RETURNS
464  *  Success: S_OK.
465  *  Failure: HRESULT code.
466  */
467 HRESULT WINAPI RegisterActiveObject(
468         LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
469 ) {
470         WCHAR                   guidbuf[80];
471         HRESULT                 ret;
472         LPRUNNINGOBJECTTABLE    runobtable;
473         LPMONIKER               moniker;
474
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;
483         }
484         ret = IRunningObjectTable_Register(runobtable,dwFlags,punk,moniker,pdwRegister);
485         IRunningObjectTable_Release(runobtable);
486         IMoniker_Release(moniker);
487         return ret;
488 }
489
490 /***********************************************************************
491  *              RevokeActiveObject (OLEAUT32.34)
492  *
493  * Revokes an object from the global item table.
494  *
495  * PARAMS
496  *  xregister [I] Registration cookie.
497  *  reserved  [I] Reserved. Set to NULL.
498  *
499  * RETURNS
500  *  Success: S_OK.
501  *  Failure: HRESULT code.
502  */
503 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
504 {
505         LPRUNNINGOBJECTTABLE    runobtable;
506         HRESULT                 ret;
507
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;
514 }
515
516 /***********************************************************************
517  *              GetActiveObject (OLEAUT32.35)
518  *
519  * Gets an object from the global item table.
520  *
521  * PARAMS
522  *  rcid        [I] CLSID of the object.
523  *  preserved   [I] Reserved. Set to NULL.
524  *  ppunk       [O] Address to store object into.
525  *
526  * RETURNS
527  *  Success: S_OK.
528  *  Failure: HRESULT code.
529  */
530 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
531 {
532         WCHAR                   guidbuf[80];
533         HRESULT                 ret;
534         LPRUNNINGOBJECTTABLE    runobtable;
535         LPMONIKER               moniker;
536
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;
545         }
546         ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
547         IRunningObjectTable_Release(runobtable);
548         IMoniker_Release(moniker);
549         return ret;
550 }
551
552
553 /***********************************************************************
554  *           OaBuildVersion           [OLEAUT32.170]
555  *
556  * Get the Ole Automation build version.
557  *
558  * PARAMS
559  *  None
560  *
561  * RETURNS
562  *  The build version.
563  *
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
578  *
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.
581  */
582 ULONG WINAPI OaBuildVersion(void)
583 {
584     switch(GetVersion() & 0x8000ffff)  /* mask off build number */
585     {
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 */
604     }
605 }
606
607 /******************************************************************************
608  *              OleTranslateColor       [OLEAUT32.421]
609  *
610  * Convert an OLE_COLOR to a COLORREF.
611  *
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
616  *
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.
620  *
621  * FIXME
622  *  Document the conversion rules.
623  */
624 HRESULT WINAPI OleTranslateColor(
625   OLE_COLOR clr,
626   HPALETTE  hpal,
627   COLORREF* pColorRef)
628 {
629   COLORREF colorref;
630   BYTE b = HIBYTE(HIWORD(clr));
631
632   TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);
633
634   /*
635    * In case pColorRef is NULL, provide our own to simplify the code.
636    */
637   if (pColorRef == NULL)
638     pColorRef = &colorref;
639
640   switch (b)
641   {
642     case 0x00:
643     {
644       if (hpal != 0)
645         *pColorRef =  PALETTERGB(GetRValue(clr),
646                                  GetGValue(clr),
647                                  GetBValue(clr));
648       else
649         *pColorRef = clr;
650
651       break;
652     }
653
654     case 0x01:
655     {
656       if (hpal != 0)
657       {
658         PALETTEENTRY pe;
659         /*
660          * Validate the palette index.
661          */
662         if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
663           return E_INVALIDARG;
664       }
665
666       *pColorRef = clr;
667
668       break;
669     }
670
671     case 0x02:
672       *pColorRef = clr;
673       break;
674
675     case 0x80:
676     {
677       int index = LOBYTE(LOWORD(clr));
678
679       /*
680        * Validate GetSysColor index.
681        */
682       if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
683         return E_INVALIDARG;
684
685       *pColorRef =  GetSysColor(index);
686
687       break;
688     }
689
690     default:
691       return E_INVALIDARG;
692   }
693
694   return S_OK;
695 }
696
697 extern HRESULT WINAPI OLEAUTPS_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
698 extern BOOL WINAPI OLEAUTPS_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
699 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
700
701 extern void _get_STDFONT_CF(LPVOID *);
702 extern void _get_STDPIC_CF(LPVOID *);
703
704 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
705 {
706     if (IsEqualIID(riid, &IID_IUnknown) ||
707         IsEqualIID(riid, &IID_IPSFactoryBuffer))
708     {
709         IUnknown_AddRef(iface);
710         *ppv = iface;
711         return S_OK;
712     }
713     return E_NOINTERFACE;
714 }
715
716 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
717 {
718     return 2;
719 }
720
721 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
722 {
723     return 1;
724 }
725
726 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
727 {
728     IPSFactoryBuffer *pPSFB;
729     HRESULT hr;
730
731     if (IsEqualIID(riid, &IID_IDispatch))
732         hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
733     else
734         hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
735
736     if (FAILED(hr)) return hr;
737
738     hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
739
740     IPSFactoryBuffer_Release(pPSFB);
741     return hr;
742 }
743
744 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
745 {
746     IPSFactoryBuffer *pPSFB;
747     HRESULT hr;
748
749     if (IsEqualIID(riid, &IID_IDispatch))
750         hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
751     else
752         hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
753
754     if (FAILED(hr)) return hr;
755
756     hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
757
758     IPSFactoryBuffer_Release(pPSFB);
759     return hr;
760 }
761
762 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
763 {
764     PSDispatchFacBuf_QueryInterface,
765     PSDispatchFacBuf_AddRef,
766     PSDispatchFacBuf_Release,
767     PSDispatchFacBuf_CreateProxy,
768     PSDispatchFacBuf_CreateStub
769 };
770
771 /* This is the whole PSFactoryBuffer object, just the vtableptr */
772 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
773
774 /***********************************************************************
775  *              DllGetClassObject (OLEAUT32.@)
776  */
777 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
778 {
779     *ppv = NULL;
780     if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
781         if (IsEqualGUID(iid,&IID_IClassFactory)) {
782             _get_STDFONT_CF(ppv);
783             IClassFactory_AddRef((IClassFactory*)*ppv);
784             return S_OK;
785         }
786     }
787     if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
788         if (IsEqualGUID(iid,&IID_IClassFactory)) {
789             _get_STDPIC_CF(ppv);
790             IClassFactory_AddRef((IClassFactory*)*ppv);
791             return S_OK;
792         }
793     }
794     if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
795         *ppv = &pPSDispatchFacBuf;
796         IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
797         return S_OK;
798     }
799     if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
800         if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
801             return S_OK;
802         /*FALLTHROUGH*/
803     }
804     if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
805         IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
806         IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
807         IsEqualCLSID(rclsid, &CLSID_PSEnumVariant))
808         return OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, iid, ppv);
809
810     return OLEAUTPS_DllGetClassObject(rclsid, iid, ppv);
811 }
812
813 /***********************************************************************
814  *              DllCanUnloadNow (OLEAUT32.@)
815  *
816  * Determine if this dll can be unloaded from the callers address space.
817  *
818  * PARAMS
819  *  None.
820  *
821  * RETURNS
822  *  Always returns S_FALSE. This dll cannot be unloaded.
823  */
824 HRESULT WINAPI DllCanUnloadNow(void)
825 {
826     return S_FALSE;
827 }
828
829 /*****************************************************************************
830  *              DllMain         [OLEAUT32.@]
831  */
832 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
833 {
834     return OLEAUTPS_DllMain( hInstDll, fdwReason, lpvReserved );
835 }
836
837 /***********************************************************************
838  *              OleIconToCursor (OLEAUT32.415)
839  */
840 HCURSOR WINAPI OleIconToCursor( HINSTANCE hinstExe, HICON hIcon)
841 {
842     FIXME("(%p,%p), partially implemented.\n",hinstExe,hIcon);
843     /* FIXME: make a extended conversation from HICON to HCURSOR */
844     return CopyCursor(hIcon);
845 }