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