4 * Copyright 1999, 2000 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 #include "oleaut32_oaidl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44 WINE_DECLARE_DEBUG_CHANNEL(heap);
46 /******************************************************************************
50 * BSTR is a simple typedef for a wide-character string used as the principle
51 * string type in ole automation. When encapsulated in a Variant type they are
52 * automatically copied and destroyed as the variant is processed.
54 * The low level BSTR API allows manipulation of these strings and is used by
55 * higher level API calls to manage the strings transparently to the caller.
57 * Internally the BSTR type is allocated with space for a DWORD byte count before
58 * the string data begins. This is undocumented and non-system code should not
59 * access the count directly. Use SysStringLen() or SysStringByteLen()
60 * instead. Note that the byte count does not include the terminating NUL.
62 * To create a new BSTR, use SysAllocString(), SysAllocStringLen() or
63 * SysAllocStringByteLen(). To change the size of an existing BSTR, use SysReAllocString()
64 * or SysReAllocStringLen(). Finally to destroy a string use SysFreeString().
66 * BSTR's are cached by Ole Automation by default. To override this behaviour
67 * either set the environment variable 'OANOCACHE', or call SetOaNoCache().
70 * 'Inside OLE, second edition' by Kraig Brockshmidt.
73 static BOOL bstr_cache_enabled;
75 static CRITICAL_SECTION cs_bstr_cache;
76 static CRITICAL_SECTION_DEBUG cs_bstr_cache_dbg =
79 { &cs_bstr_cache_dbg.ProcessLocksList, &cs_bstr_cache_dbg.ProcessLocksList },
80 0, 0, { (DWORD_PTR)(__FILE__ ": bstr_cache") }
82 static CRITICAL_SECTION cs_bstr_cache = { &cs_bstr_cache_dbg, -1, 0, 0, 0, 0 };
99 #define BUCKET_SIZE 16
101 #define ARENA_INUSE_FILLER 0x55
102 #define ARENA_TAIL_FILLER 0xab
103 #define ARENA_FREE_FILLER 0xfeeefeee
105 static bstr_cache_entry_t bstr_cache[0x10000/BUCKET_SIZE];
107 static inline size_t bstr_alloc_size(size_t size)
109 return (FIELD_OFFSET(bstr_t, u.ptr[size]) + sizeof(WCHAR) + BUCKET_SIZE-1) & ~(BUCKET_SIZE-1);
112 static inline bstr_t *bstr_from_str(BSTR str)
114 return CONTAINING_RECORD(str, bstr_t, u.str);
117 static inline bstr_cache_entry_t *get_cache_entry(size_t size)
119 unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size-1])/BUCKET_SIZE;
120 return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
121 ? bstr_cache + cache_idx
125 static bstr_t *alloc_bstr(size_t size)
127 bstr_cache_entry_t *cache_entry = get_cache_entry(size+sizeof(WCHAR));
131 EnterCriticalSection(&cs_bstr_cache);
133 if(!cache_entry->cnt) {
134 cache_entry = get_cache_entry(size+sizeof(WCHAR)+BUCKET_SIZE);
135 if(cache_entry && !cache_entry->cnt)
140 ret = cache_entry->buf[cache_entry->head++];
141 cache_entry->head %= sizeof(cache_entry->buf)/sizeof(*cache_entry->buf);
145 LeaveCriticalSection(&cs_bstr_cache);
151 memset(ret, ARENA_INUSE_FILLER, FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]));
152 tail = bstr_alloc_size(size) - FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)]);
154 memset(ret->u.ptr+size+sizeof(WCHAR), ARENA_TAIL_FILLER, tail);
161 ret = HeapAlloc(GetProcessHeap(), 0, bstr_alloc_size(size));
167 /******************************************************************************
168 * SysStringLen [OLEAUT32.7]
170 * Get the allocated length of a BSTR in wide characters.
173 * str [I] BSTR to find the length of
176 * The allocated length of str, or 0 if str is NULL.
180 * The returned length may be different from the length of the string as
181 * calculated by lstrlenW(), since it returns the length that was used to
182 * allocate the string by SysAllocStringLen().
184 UINT WINAPI SysStringLen(BSTR str)
186 return str ? bstr_from_str(str)->size/sizeof(WCHAR) : 0;
189 /******************************************************************************
190 * SysStringByteLen [OLEAUT32.149]
192 * Get the allocated length of a BSTR in bytes.
195 * str [I] BSTR to find the length of
198 * The allocated length of str, or 0 if str is NULL.
201 * See SysStringLen(), BSTR().
203 UINT WINAPI SysStringByteLen(BSTR str)
205 return str ? bstr_from_str(str)->size : 0;
208 /******************************************************************************
209 * SysAllocString [OLEAUT32.2]
211 * Create a BSTR from an OLESTR.
214 * str [I] Source to create BSTR from
217 * Success: A BSTR allocated with SysAllocStringLen().
218 * Failure: NULL, if oleStr is NULL.
222 * MSDN (October 2001) incorrectly states that NULL is returned if oleStr has
223 * a length of 0. Native Win32 and this implementation both return a valid
224 * empty BSTR in this case.
226 BSTR WINAPI SysAllocString(LPCOLESTR str)
230 /* Delegate this to the SysAllocStringLen32 method. */
231 return SysAllocStringLen(str, lstrlenW(str));
234 /******************************************************************************
235 * SysFreeString [OLEAUT32.6]
240 * str [I] BSTR to free.
247 * str may be NULL, in which case this function does nothing.
249 void WINAPI SysFreeString(BSTR str)
251 bstr_cache_entry_t *cache_entry;
257 bstr = bstr_from_str(str);
258 cache_entry = get_cache_entry(bstr->size+sizeof(WCHAR));
260 EnterCriticalSection(&cs_bstr_cache);
262 if(cache_entry->cnt < sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)) {
263 cache_entry->buf[(cache_entry->head+cache_entry->cnt)%((sizeof(cache_entry->buf)/sizeof(*cache_entry->buf)))] = bstr;
267 unsigned i, n = bstr_alloc_size(bstr->size) / sizeof(DWORD) - 1;
268 bstr->size = ARENA_FREE_FILLER;
270 bstr->u.dwptr[i] = ARENA_FREE_FILLER;
273 LeaveCriticalSection(&cs_bstr_cache);
277 LeaveCriticalSection(&cs_bstr_cache);
280 HeapFree(GetProcessHeap(), 0, bstr);
283 /******************************************************************************
284 * SysAllocStringLen [OLEAUT32.4]
286 * Create a BSTR from an OLESTR of a given wide character length.
289 * str [I] Source to create BSTR from
290 * len [I] Length of oleStr in wide characters
293 * Success: A newly allocated BSTR from SysAllocStringByteLen()
294 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
297 * See BSTR(), SysAllocStringByteLen().
299 BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
304 /* Detect integer overflow. */
305 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
308 TRACE("%s\n", debugstr_wn(str, len));
310 size = len*sizeof(WCHAR);
311 bstr = alloc_bstr(size);
316 memcpy(bstr->u.str, str, size);
317 bstr->u.str[len] = 0;
319 memset(bstr->u.str, 0, size+sizeof(WCHAR));
325 /******************************************************************************
326 * SysReAllocStringLen [OLEAUT32.5]
328 * Change the length of a previously created BSTR.
331 * old [O] BSTR to change the length of
332 * str [I] New source for pbstr
333 * len [I] Length of oleStr in wide characters
336 * Success: 1. The size of pbstr is updated.
337 * Failure: 0, if len >= 0x80000000 or memory allocation fails.
340 * See BSTR(), SysAllocStringByteLen().
341 * *old may be changed by this function.
343 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* str, unsigned int len)
345 /* Detect integer overflow. */
346 if (len >= ((UINT_MAX-sizeof(WCHAR)-sizeof(DWORD))/sizeof(WCHAR)))
350 BSTR old_copy = *old;
351 DWORD newbytelen = len*sizeof(WCHAR);
352 bstr_t *bstr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,bstr_alloc_size(newbytelen));
354 bstr->size = newbytelen;
355 /* Subtle hidden feature: The old string data is still there
357 * Some Microsoft program needs it.
358 * FIXME: Is it a sideeffect of BSTR caching?
360 if (str && old_copy!=str) memmove(*old, str, newbytelen);
364 * Allocate the new string
366 *old = SysAllocStringLen(str, len);
372 /******************************************************************************
373 * SysAllocStringByteLen [OLEAUT32.150]
375 * Create a BSTR from an OLESTR of a given byte length.
378 * str [I] Source to create BSTR from
379 * len [I] Length of oleStr in bytes
382 * Success: A newly allocated BSTR
383 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
386 * -If len is 0 or oleStr is NULL the resulting string is empty ("").
387 * -This function always NUL terminates the resulting BSTR.
388 * -oleStr may be either an LPCSTR or LPCOLESTR, since it is copied
389 * without checking for a terminating NUL.
392 BSTR WINAPI SysAllocStringByteLen(LPCSTR str, UINT len)
396 /* Detect integer overflow. */
397 if (len >= (UINT_MAX-sizeof(WCHAR)-sizeof(DWORD)))
400 bstr = alloc_bstr(len);
405 memcpy(bstr->u.ptr, str, len);
406 bstr->u.ptr[len] = bstr->u.ptr[len+1] = 0;
408 memset(bstr->u.ptr, 0, len+sizeof(WCHAR));
414 /******************************************************************************
415 * SysReAllocString [OLEAUT32.3]
417 * Change the length of a previously created BSTR.
420 * old [I/O] BSTR to change the length of
421 * str [I] New source for pbstr
428 * See BSTR(), SysAllocStringStringLen().
430 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR str)
439 * Make sure we free the old string.
444 * Allocate the new string
446 *old = SysAllocString(str);
451 /******************************************************************************
452 * SetOaNoCache (OLEAUT32.327)
454 * Instruct Ole Automation not to cache BSTR allocations.
463 * SetOaNoCache does not release cached strings, so it leaks by design.
465 void WINAPI SetOaNoCache(void)
468 bstr_cache_enabled = FALSE;
471 static const WCHAR _delimiter[] = {'!',0}; /* default delimiter apparently */
472 static const WCHAR *pdelimiter = &_delimiter[0];
474 /***********************************************************************
475 * RegisterActiveObject (OLEAUT32.33)
477 * Registers an object in the global item table.
480 * punk [I] Object to register.
481 * rcid [I] CLSID of the object.
483 * pdwRegister [O] Address to store cookie of object registration in.
487 * Failure: HRESULT code.
489 HRESULT WINAPI RegisterActiveObject(
490 LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
494 LPRUNNINGOBJECTTABLE runobtable;
496 DWORD rot_flags = ROTFLAGS_REGISTRATIONKEEPSALIVE; /* default registration is strong */
498 StringFromGUID2(rcid,guidbuf,39);
499 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
502 ret = GetRunningObjectTable(0,&runobtable);
504 IMoniker_Release(moniker);
507 if(dwFlags == ACTIVEOBJECT_WEAK)
509 ret = IRunningObjectTable_Register(runobtable,rot_flags,punk,moniker,pdwRegister);
510 IRunningObjectTable_Release(runobtable);
511 IMoniker_Release(moniker);
515 /***********************************************************************
516 * RevokeActiveObject (OLEAUT32.34)
518 * Revokes an object from the global item table.
521 * xregister [I] Registration cookie.
522 * reserved [I] Reserved. Set to NULL.
526 * Failure: HRESULT code.
528 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
530 LPRUNNINGOBJECTTABLE runobtable;
533 ret = GetRunningObjectTable(0,&runobtable);
534 if (FAILED(ret)) return ret;
535 ret = IRunningObjectTable_Revoke(runobtable,xregister);
536 if (SUCCEEDED(ret)) ret = S_OK;
537 IRunningObjectTable_Release(runobtable);
541 /***********************************************************************
542 * GetActiveObject (OLEAUT32.35)
544 * Gets an object from the global item table.
547 * rcid [I] CLSID of the object.
548 * preserved [I] Reserved. Set to NULL.
549 * ppunk [O] Address to store object into.
553 * Failure: HRESULT code.
555 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
559 LPRUNNINGOBJECTTABLE runobtable;
562 StringFromGUID2(rcid,guidbuf,39);
563 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
566 ret = GetRunningObjectTable(0,&runobtable);
568 IMoniker_Release(moniker);
571 ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
572 IRunningObjectTable_Release(runobtable);
573 IMoniker_Release(moniker);
578 /***********************************************************************
579 * OaBuildVersion [OLEAUT32.170]
581 * Get the Ole Automation build version.
590 * Known oleaut32.dll versions:
591 *| OLE Ver. Comments Date Build Ver.
592 *| -------- ------------------------- ---- ---------
593 *| OLE 2.1 NT 1993-95 10 3023
595 *| Win32s Ver 1.1e 20 4049
596 *| OLE 2.20 W95/NT 1993-96 20 4112
597 *| OLE 2.20 W95/NT 1993-96 20 4118
598 *| OLE 2.20 W95/NT 1993-96 20 4122
599 *| OLE 2.30 W95/NT 1993-98 30 4265
600 *| OLE 2.40 NT?? 1993-98 40 4267
601 *| OLE 2.40 W98 SE orig. file 1993-98 40 4275
602 *| OLE 2.40 W2K orig. file 1993-XX 40 4514
604 * Currently the versions returned are 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
605 * and 2.40 for all later versions. The build number is maximum, i.e. 0xffff.
607 ULONG WINAPI OaBuildVersion(void)
609 switch(GetVersion() & 0x8000ffff) /* mask off build number */
611 case 0x80000a03: /* WIN31 */
612 return MAKELONG(0xffff, 20);
613 case 0x00003303: /* NT351 */
614 return MAKELONG(0xffff, 30);
615 case 0x80000004: /* WIN95; I'd like to use the "standard" w95 minor
616 version here (30), but as we still use w95
617 as default winver (which is good IMHO), I better
618 play safe and use the latest value for w95 for now.
619 Change this as soon as default winver gets changed
620 to something more recent */
621 case 0x80000a04: /* WIN98 */
622 case 0x00000004: /* NT40 */
623 case 0x00000005: /* W2K */
624 return MAKELONG(0xffff, 40);
625 case 0x00000105: /* WinXP */
626 case 0x00000006: /* Vista */
627 case 0x00000106: /* Win7 */
628 return MAKELONG(0xffff, 50);
630 FIXME("Version value not known yet. Please investigate it !\n");
631 return MAKELONG(0xffff, 40); /* for now return the same value as for w2k */
635 /******************************************************************************
636 * OleTranslateColor [OLEAUT32.421]
638 * Convert an OLE_COLOR to a COLORREF.
641 * clr [I] Color to convert
642 * hpal [I] Handle to a palette for the conversion
643 * pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok
646 * Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL.
647 * Failure: E_INVALIDARG, if any argument is invalid.
650 * Document the conversion rules.
652 HRESULT WINAPI OleTranslateColor(
658 BYTE b = HIBYTE(HIWORD(clr));
660 TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);
663 * In case pColorRef is NULL, provide our own to simplify the code.
665 if (pColorRef == NULL)
666 pColorRef = &colorref;
673 *pColorRef = PALETTERGB(GetRValue(clr),
688 * Validate the palette index.
690 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
705 int index = LOBYTE(LOWORD(clr));
708 * Validate GetSysColor index.
710 if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
713 *pColorRef = GetSysColor(index);
725 extern HRESULT WINAPI OLEAUTPS_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
726 extern BOOL WINAPI OLEAUTPS_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
727 extern HRESULT WINAPI OLEAUTPS_DllRegisterServer(void) DECLSPEC_HIDDEN;
728 extern HRESULT WINAPI OLEAUTPS_DllUnregisterServer(void) DECLSPEC_HIDDEN;
729 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
731 extern void _get_STDFONT_CF(LPVOID *);
732 extern void _get_STDPIC_CF(LPVOID *);
734 static HRESULT WINAPI PSDispatchFacBuf_QueryInterface(IPSFactoryBuffer *iface, REFIID riid, void **ppv)
736 if (IsEqualIID(riid, &IID_IUnknown) ||
737 IsEqualIID(riid, &IID_IPSFactoryBuffer))
739 IUnknown_AddRef(iface);
743 return E_NOINTERFACE;
746 static ULONG WINAPI PSDispatchFacBuf_AddRef(IPSFactoryBuffer *iface)
751 static ULONG WINAPI PSDispatchFacBuf_Release(IPSFactoryBuffer *iface)
756 static HRESULT WINAPI PSDispatchFacBuf_CreateProxy(IPSFactoryBuffer *iface, IUnknown *pUnkOuter, REFIID riid, IRpcProxyBuffer **ppProxy, void **ppv)
758 IPSFactoryBuffer *pPSFB;
761 if (IsEqualIID(riid, &IID_IDispatch))
762 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
764 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
766 if (FAILED(hr)) return hr;
768 hr = IPSFactoryBuffer_CreateProxy(pPSFB, pUnkOuter, riid, ppProxy, ppv);
770 IPSFactoryBuffer_Release(pPSFB);
774 static HRESULT WINAPI PSDispatchFacBuf_CreateStub(IPSFactoryBuffer *iface, REFIID riid, IUnknown *pUnkOuter, IRpcStubBuffer **ppStub)
776 IPSFactoryBuffer *pPSFB;
779 if (IsEqualIID(riid, &IID_IDispatch))
780 hr = OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, &IID_IPSFactoryBuffer, (void **)&pPSFB);
782 hr = TMARSHAL_DllGetClassObject(&CLSID_PSOAInterface, &IID_IPSFactoryBuffer, (void **)&pPSFB);
784 if (FAILED(hr)) return hr;
786 hr = IPSFactoryBuffer_CreateStub(pPSFB, riid, pUnkOuter, ppStub);
788 IPSFactoryBuffer_Release(pPSFB);
792 static const IPSFactoryBufferVtbl PSDispatchFacBuf_Vtbl =
794 PSDispatchFacBuf_QueryInterface,
795 PSDispatchFacBuf_AddRef,
796 PSDispatchFacBuf_Release,
797 PSDispatchFacBuf_CreateProxy,
798 PSDispatchFacBuf_CreateStub
801 /* This is the whole PSFactoryBuffer object, just the vtableptr */
802 static const IPSFactoryBufferVtbl *pPSDispatchFacBuf = &PSDispatchFacBuf_Vtbl;
804 /***********************************************************************
805 * DllGetClassObject (OLEAUT32.@)
807 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
810 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
811 if (IsEqualGUID(iid,&IID_IClassFactory)) {
812 _get_STDFONT_CF(ppv);
813 IClassFactory_AddRef((IClassFactory*)*ppv);
817 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
818 if (IsEqualGUID(iid,&IID_IClassFactory)) {
820 IClassFactory_AddRef((IClassFactory*)*ppv);
824 if (IsEqualCLSID(rclsid, &CLSID_PSDispatch) && IsEqualIID(iid, &IID_IPSFactoryBuffer)) {
825 *ppv = &pPSDispatchFacBuf;
826 IPSFactoryBuffer_AddRef((IPSFactoryBuffer *)*ppv);
829 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
830 if (S_OK==TMARSHAL_DllGetClassObject(rclsid,iid,ppv))
834 if (IsEqualCLSID(rclsid, &CLSID_PSTypeInfo) ||
835 IsEqualCLSID(rclsid, &CLSID_PSTypeLib) ||
836 IsEqualCLSID(rclsid, &CLSID_PSDispatch) ||
837 IsEqualCLSID(rclsid, &CLSID_PSEnumVariant))
838 return OLEAUTPS_DllGetClassObject(&CLSID_PSFactoryBuffer, iid, ppv);
840 return OLEAUTPS_DllGetClassObject(rclsid, iid, ppv);
843 /***********************************************************************
844 * DllCanUnloadNow (OLEAUT32.@)
846 * Determine if this dll can be unloaded from the callers address space.
852 * Always returns S_FALSE. This dll cannot be unloaded.
854 HRESULT WINAPI DllCanUnloadNow(void)
859 /*****************************************************************************
860 * DllMain [OLEAUT32.@]
862 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
864 static const WCHAR oanocacheW[] = {'o','a','n','o','c','a','c','h','e',0};
866 bstr_cache_enabled = !GetEnvironmentVariableW(oanocacheW, NULL, 0);
868 return OLEAUTPS_DllMain( hInstDll, fdwReason, lpvReserved );
871 /***********************************************************************
872 * DllRegisterServer (OLEAUT32.@)
874 HRESULT WINAPI DllRegisterServer(void)
876 return OLEAUTPS_DllRegisterServer();
879 /***********************************************************************
880 * DllUnregisterServer (OLEAUT32.@)
882 HRESULT WINAPI DllUnregisterServer(void)
884 return OLEAUTPS_DllUnregisterServer();
887 /***********************************************************************
888 * OleIconToCursor (OLEAUT32.415)
890 HCURSOR WINAPI OleIconToCursor( HINSTANCE hinstExe, HICON hIcon)
892 FIXME("(%p,%p), partially implemented.\n",hinstExe,hIcon);
893 /* FIXME: make a extended conversation from HICON to HCURSOR */
894 return CopyCursor(hIcon);