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