reshuffling of dlls
[reactos.git] / reactos / dll / win32 / 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdarg.h>
22 #include <string.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.h"
31
32 #include "ole2.h"
33 #include "olectl.h"
34 #include "oleauto.h"
35 #include "typelib.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40
41 /* The OLE Automation ProxyStub Interface Class (aka Typelib Marshaler) */
42 extern const GUID CLSID_PSOAInterface;
43
44 extern const GUID CLSID_PSDispatch;
45 extern const GUID CLSID_PSEnumVariant;
46 extern const GUID CLSID_PSTypeInfo;
47 extern const GUID CLSID_PSTypeLib;
48 extern const GUID CLSID_PSTypeComp;
49
50 static BOOL BSTR_bCache = TRUE; /* Cache allocations to minimise alloc calls? */
51
52 HMODULE OLEAUT32_hModule = NULL;
53
54 /******************************************************************************
55 * BSTR {OLEAUT32}
56 *
57 * NOTES
58 * BSTR is a simple typedef for a wide-character string used as the principle
59 * string type in ole automation. When encapsulated in a Variant type they are
60 * automatically copied and destroyed as the variant is processed.
61 *
62 * The low level BSTR Api allows manipulation of these strings and is used by
63 * higher level Api calls to manage the strings transparently to the caller.
64 *
65 * Internally the BSTR type is allocated with space for a DWORD byte count before
66 * the string data begins. This is undocumented and non-system code should not
67 * access the count directly. Use SysStringLen() or SysStringByteLen()
68 * instead. Note that the byte count does not include the terminating NUL.
69 *
70 * To create a new BSTR, use SysAllocString(), SysAllocStringLen() or
71 * SysAllocStringByteLen(). To change the size of an existing BSTR, use SysReAllocString()
72 * or SysReAllocStringLen(). Finally to destroy a string use SysFreeString().
73 *
74 * BSTR's are cached by Ole Automation by default. To override this behaviour
75 * either set the environment variable 'OANOCACHE', or call SetOaNoCache().
76 *
77 * SEE ALSO
78 * 'Inside OLE, second edition' by Kraig Brockshmidt.
79 */
80
81 /******************************************************************************
82 * SysStringLen [OLEAUT32.7]
83 *
84 * Get the allocated length of a BSTR in wide characters.
85 *
86 * PARAMS
87 * str [I] BSTR to find the length of
88 *
89 * RETURNS
90 * The allocated length of str, or 0 if str is NULL.
91 *
92 * NOTES
93 * See BSTR.
94 * The returned length may be different from the length of the string as
95 * calculated by lstrlenW(), since it returns the length that was used to
96 * allocate the string by SysAllocStringLen().
97 */
98 UINT WINAPI SysStringLen(BSTR str)
99 {
100 DWORD* bufferPointer;
101
102 if (!str) return 0;
103 /*
104 * The length of the string (in bytes) is contained in a DWORD placed
105 * just before the BSTR pointer
106 */
107 bufferPointer = (DWORD*)str;
108
109 bufferPointer--;
110
111 return (int)(*bufferPointer/sizeof(WCHAR));
112 }
113
114 /******************************************************************************
115 * SysStringByteLen [OLEAUT32.149]
116 *
117 * Get the allocated length of a BSTR in bytes.
118 *
119 * PARAMS
120 * str [I] BSTR to find the length of
121 *
122 * RETURNS
123 * The allocated length of str, or 0 if str is NULL.
124 *
125 * NOTES
126 * See SysStringLen(), BSTR().
127 */
128 UINT WINAPI SysStringByteLen(BSTR str)
129 {
130 DWORD* bufferPointer;
131
132 if (!str) return 0;
133 /*
134 * The length of the string (in bytes) is contained in a DWORD placed
135 * just before the BSTR pointer
136 */
137 bufferPointer = (DWORD*)str;
138
139 bufferPointer--;
140
141 return (int)(*bufferPointer);
142 }
143
144 /******************************************************************************
145 * SysAllocString [OLEAUT32.2]
146 *
147 * Create a BSTR from an OLESTR.
148 *
149 * PARAMS
150 * str [I] Source to create BSTR from
151 *
152 * RETURNS
153 * Success: A BSTR allocated with SysAllocStringLen().
154 * Failure: NULL, if oleStr is NULL.
155 *
156 * NOTES
157 * See BSTR.
158 * MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
159 * a length of 0. Native Win32 and this implementation both return a valid
160 * empty BSTR in this case.
161 */
162 BSTR WINAPI SysAllocString(LPCOLESTR str)
163 {
164 if (!str) return 0;
165
166 /* Delegate this to the SysAllocStringLen32 method. */
167 return SysAllocStringLen(str, lstrlenW(str));
168 }
169
170 /******************************************************************************
171 * SysFreeString [OLEAUT32.6]
172 *
173 * Free a BSTR.
174 *
175 * PARAMS
176 * str [I] BSTR to free.
177 *
178 * RETURNS
179 * Nothing.
180 *
181 * NOTES
182 * See BSTR.
183 * str may be NULL, in which case this function does nothing.
184 */
185 void WINAPI SysFreeString(BSTR str)
186 {
187 DWORD* bufferPointer;
188
189 /* NULL is a valid parameter */
190 if(!str) return;
191
192 /*
193 * We have to be careful when we free a BSTR pointer, it points to
194 * the beginning of the string but it skips the byte count contained
195 * before the string.
196 */
197 bufferPointer = (DWORD*)str;
198
199 bufferPointer--;
200
201 /*
202 * Free the memory from its "real" origin.
203 */
204 HeapFree(GetProcessHeap(), 0, bufferPointer);
205 }
206
207 /******************************************************************************
208 * SysAllocStringLen [OLEAUT32.4]
209 *
210 * Create a BSTR from an OLESTR of a given wide character length.
211 *
212 * PARAMS
213 * str [I] Source to create BSTR from
214 * len [I] Length of oleStr in wide characters
215 *
216 * RETURNS
217 * Success: A newly allocated BSTR from SysAllocStringByteLen()
218 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
219 *
220 * NOTES
221 * See BSTR(), SysAllocStringByteLen().
222 */
223 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
224 {
225 DWORD bufferSize;
226 DWORD* newBuffer;
227 WCHAR* stringBuffer;
228
229 /*
230 * Find the length of the buffer passed-in in bytes.
231 */
232 bufferSize = len * sizeof (WCHAR);
233
234 /*
235 * Allocate a new buffer to hold the string.
236 * don't forget to keep an empty spot at the beginning of the
237 * buffer for the character count and an extra character at the
238 * end for the NULL.
239 */
240 newBuffer = HeapAlloc(GetProcessHeap(), 0,
241 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
242
243 /*
244 * If the memory allocation failed, return a null pointer.
245 */
246 if (newBuffer==0)
247 return 0;
248
249 /*
250 * Copy the length of the string in the placeholder.
251 */
252 *newBuffer = bufferSize;
253
254 /*
255 * Skip the byte count.
256 */
257 newBuffer++;
258
259 /*
260 * Copy the information in the buffer.
261 * Since it is valid to pass a NULL pointer here, we'll initialize the
262 * buffer to nul if it is the case.
263 */
264 if (str != 0)
265 memcpy(newBuffer, str, bufferSize);
266 else
267 memset(newBuffer, 0, bufferSize);
268
269 /*
270 * Make sure that there is a nul character at the end of the
271 * string.
272 */
273 stringBuffer = (WCHAR*)newBuffer;
274 stringBuffer[len] = L'\0';
275
276 return (LPWSTR)stringBuffer;
277 }
278
279 /******************************************************************************
280 * SysReAllocStringLen [OLEAUT32.5]
281 *
282 * Change the length of a previously created BSTR.
283 *
284 * PARAMS
285 * old [O] BSTR to change the length of
286 * str [I] New source for pbstr
287 * len [I] Length of oleStr in wide characters
288 *
289 * RETURNS
290 * Success: 1. The size of pbstr is updated.
291 * Failure: 0, if len >= 0x80000000 or memory allocation fails.
292 *
293 * NOTES
294 * See BSTR(), SysAllocStringByteLen().
295 * *pbstr may be changed by this function.
296 */
297 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
298 {
299 if (*old!=NULL) {
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 if (str) {
305 memcpy(*old, str, newbytelen);
306 (*old)[len] = 0;
307 } else {
308 /* Subtle hidden feature: The old string data is still there
309 * when 'in' is NULL!
310 * Some Microsoft program needs it.
311 */
312 }
313 } else {
314 /*
315 * Allocate the new string
316 */
317 *old = SysAllocStringLen(str, len);
318 }
319
320 return 1;
321 }
322
323 /******************************************************************************
324 * SysAllocStringByteLen [OLEAUT32.150]
325 *
326 * Create a BSTR from an OLESTR of a given byte length.
327 *
328 * PARAMS
329 * str [I] Source to create BSTR from
330 * len [I] Length of oleStr in bytes
331 *
332 * RETURNS
333 * Success: A newly allocated BSTR
334 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
335 *
336 * NOTES
337 * -If len is 0 or oleStr is NULL the resulting string is empty ("").
338 * -This function always NUL terminates the resulting BSTR.
339 * -oleStr may be either an LPCSTR or LPCOLESTR, since it is copied
340 * without checking for a terminating NUL.
341 * See BSTR.
342 */
343 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
344 {
345 DWORD* newBuffer;
346 char* stringBuffer;
347
348 /*
349 * Allocate a new buffer to hold the string.
350 * don't forget to keep an empty spot at the beginning of the
351 * buffer for the character count and an extra character at the
352 * end for the NULL.
353 */
354 newBuffer = HeapAlloc(GetProcessHeap(), 0,
355 len + sizeof(WCHAR) + sizeof(DWORD));
356
357 /*
358 * If the memory allocation failed, return a null pointer.
359 */
360 if (newBuffer==0)
361 return 0;
362
363 /*
364 * Copy the length of the string in the placeholder.
365 */
366 *newBuffer = len;
367
368 /*
369 * Skip the byte count.
370 */
371 newBuffer++;
372
373 /*
374 * Copy the information in the buffer.
375 * Since it is valid to pass a NULL pointer here, we'll initialize the
376 * buffer to nul if it is the case.
377 */
378 if (str != 0)
379 memcpy(newBuffer, str, len);
380
381 /*
382 * Make sure that there is a nul character at the end of the
383 * string.
384 */
385 stringBuffer = (char *)newBuffer;
386 stringBuffer[len] = 0;
387 stringBuffer[len+1] = 0;
388
389 return (LPWSTR)stringBuffer;
390 }
391
392 /******************************************************************************
393 * SysReAllocString [OLEAUT32.3]
394 *
395 * Change the length of a previously created BSTR.
396 *
397 * PARAMS
398 * old [I/O] BSTR to change the length of
399 * str [I] New source for pbstr
400 *
401 * RETURNS
402 * Success: 1
403 * Failure: 0.
404 *
405 * NOTES
406 * See BSTR(), SysAllocStringStringLen().
407 */
408 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
409 {
410 /*
411 * Sanity check
412 */
413 if (old==NULL)
414 return 0;
415
416 /*
417 * Make sure we free the old string.
418 */
419 if (*old!=NULL)
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 WCHAR _delimiter[2] = {'!',0}; /* default delimiter apparently */
450 static 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()
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("(%08lx, %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 OLEAUTPS_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
698
699 extern void _get_STDFONT_CF(LPVOID);
700 extern void _get_STDPIC_CF(LPVOID);
701
702 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
703 {
704 if (IsEqualIID(riid, &IID_IUnknown) ||
705 IsEqualIID(riid, &IID_IPSFactoryBuffer))
706 {
707 IUnknown_AddRef(iface);
708 *ppv = (void *)iface;
709 return S_OK;
710 }
711 return E_NOINTERFACE;
712 }
713
714 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
715 {
716 return 2;
717 }
718
719 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
720 {
721 return 1;
722 }
723
724 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
725 {
726 IPSFactoryBuffer *pPSFB;
727 HRESULT hr;
728
729 if (IsEqualIID(riid, &IID_IDispatch))
730 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, &IID_IPSFactoryBuffer, (void **)&pPSFB);
731 else
732 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
733
734 if (FAILED(hr)) return hr;
735
736 hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
737
738 IPSFactoryBuffer_Release(pPSFB);
739 return hr;
740 }
741
742 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
743 {
744 IPSFactoryBuffer *pPSFB;
745 HRESULT hr;
746
747 if (IsEqualIID(riid, &IID_IDispatch))
748 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, &IID_IPSFactoryBuffer, (void **)&pPSFB);
749 else
750 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
751
752 if (FAILED(hr)) return hr;
753
754 hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
755
756 IPSFactoryBuffer_Release(pPSFB);
757 return hr;
758 }
759
760 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
761 {
762 PSDispatchFacBuf_QueryInterface,
763 PSDispatchFacBuf_AddRef,
764 PSDispatchFacBuf_Release,
765 PSDispatchFacBuf_CreateProxy,
766 PSDispatchFacBuf_CreateStub
767 };
768
769 /* This is the whole PSFactoryBuffer object, just the vtableptr */
770 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
771
772 /***********************************************************************
773 * DllGetClassObject (OLEAUT32.@)
774 */
775 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
776 {
777 *ppv = NULL;
778 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
779 if (IsEqualGUID(iid,&IID_IClassFactory)) {
780 _get_STDFONT_CF(ppv);
781 IClassFactory_AddRef((IClassFactory*)*ppv);
782 return S_OK;
783 }
784 }
785 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
786 if (IsEqualGUID(iid,&IID_IClassFactory)) {
787 _get_STDPIC_CF(ppv);
788 IClassFactory_AddRef((IClassFactory*)*ppv);
789 return S_OK;
790 }
791 }
792 if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
793 IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
794 IsEqualCLSID(rclsid, &CLSID_PSEnumVariant)) {
795 return OLEAUTPS_DllGetClassObject(&CLSID_PSDispatch, iid, ppv);
796 }
797 if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
798 *ppv = &pPSDispatchFacBuf;
799 IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
800 return S_OK;
801 }
802 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
803 if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
804 return S_OK;
805 /*FALLTHROUGH*/
806 }
807 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
808 return CLASS_E_CLASSNOTAVAILABLE;
809 }
810
811 /***********************************************************************
812 * DllCanUnloadNow (OLEAUT32.@)
813 *
814 * Determine if this dll can be unloaded from the callers address space.
815 *
816 * PARAMS
817 * None.
818 *
819 * RETURNS
820 * Always returns S_FALSE. This dll cannot be unloaded.
821 */
822 HRESULT WINAPI DllCanUnloadNow(void)
823 {
824 return S_FALSE;
825 }
826
827 /*****************************************************************************
828 * DllMain [OLEAUT32.@]
829 */
830 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
831 {
832 TRACE("(%p,%ld,%p)\n", hInstDll, fdwReason, lpvReserved);
833
834 switch (fdwReason) {
835 case DLL_PROCESS_ATTACH:
836 DisableThreadLibraryCalls(hInstDll);
837 OLEAUT32_hModule = (HMODULE)hInstDll;
838 break;
839 case DLL_PROCESS_DETACH:
840 break;
841 };
842
843 return TRUE;
844 }