2 * OLE 2 clipboard support
4 * Copyright 1999 Noel Borthwick <noel@macadamian.com>
7 * This file contains the implementation for the OLE Clipboard and its
8 * internal interfaces. The OLE clipboard interacts with an IDataObject
9 * interface via the OleSetClipboard, OleGetClipboard and
10 * OleIsCurrentClipboard API's. An internal IDataObject delegates
11 * to a client supplied IDataObject or the WIN32 clipboard API depending
12 * on whether OleSetClipboard has been invoked.
13 * Here are some operating scenarios:
15 * 1. OleSetClipboard called: In this case the internal IDataObject
16 * delegates to the client supplied IDataObject. Additionally OLE takes
17 * ownership of the Windows clipboard and any HGLOCBAL IDataObject
18 * items are placed on the Windows clipboard. This allows non OLE aware
19 * applications to access these. A local WinProc fields WM_RENDERFORMAT
20 * and WM_RENDERALLFORMATS messages in this case.
22 * 2. OleGetClipboard called without previous OleSetClipboard. Here the internal
23 * IDataObject functionality wraps around the WIN32 clipboard API.
25 * 3. OleGetClipboard called after previous OleSetClipboard. Here the internal
26 * IDataObject delegates to the source IDataObjects functionality directly,
27 * thereby bypassing the Windows clipboard.
29 * Implementation references : Inside OLE 2'nd edition by Kraig Brockschmidt
32 * - Support for pasting between different processes. OLE clipboard support
33 * currently works only for in process copy and paste. Since we internally
34 * store a pointer to the source's IDataObject and delegate to that, this
35 * will fail if the IDataObject client belongs to a different process.
36 * - IDataObject::GetDataHere is not implemented
37 * - OleFlushClipboard needs to additionally handle TYMED_IStorage media
38 * by copying the storage into global memory. Subsequently the default
39 * data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL
40 * back to TYMED_IStorage.
41 * - OLE1 compatibility formats to be synthesized from OLE2 formats and put on
42 * clipboard in OleSetClipboard.
52 #include "debugtools.h"
55 #define HANDLE_ERROR(err) { hr = err; TRACE("(HRESULT=%lx)\n", (HRESULT)err); goto CLEANUP; }
57 /* For CoGetMalloc (MEMCTX_TASK is currently ignored) */
59 #define MEMCTX_TASK -1
62 DEFAULT_DEBUG_CHANNEL(ole
)
64 /****************************************************************************
66 * DO NOT add any members before the VTables declaration!
71 * List all interface VTables here
73 ICOM_VTABLE(IDataObject
)* lpvtbl1
; /* IDataObject VTable */
76 * The hidden OLE clipboard window. This window is used as the bridge between the
77 * the OLE and windows clipboard API. (Windows creates one such window per process)
82 * Pointer to the source data object (via OleSetClipboard)
84 IDataObject
* pIDataObjectSrc
;
87 * The registered DataObject clipboard format
92 * The handle to our ourself
97 * Reference count of this object
102 typedef struct OLEClipbrd OLEClipbrd
;
105 /****************************************************************************
106 * IEnumFORMATETC implementation
107 * DO NOT add any members before the VTables declaration!
111 /* IEnumFORMATETC VTable */
112 ICOM_VFIELD(IEnumFORMATETC
);
114 /* IEnumFORMATETC fields */
115 UINT posFmt
; /* current enumerator position */
116 UINT countFmt
; /* number of EnumFORMATETC's in array */
117 LPFORMATETC pFmt
; /* array of EnumFORMATETC's */
120 * Reference count of this object
125 * IUnknown implementation of the parent data object.
127 IUnknown
* pUnkDataObj
;
129 } IEnumFORMATETCImpl
;
133 * The one and only OLEClipbrd object which is created by OLEClipbrd_Initialize()
135 static HGLOBAL hTheOleClipboard
= 0;
136 static OLEClipbrd
* theOleClipboard
= NULL
;
140 * Prototypes for the methods of the OLEClipboard class.
142 extern void OLEClipbrd_Initialize();
143 extern void OLEClipbrd_UnInitialize();
144 static OLEClipbrd
* OLEClipbrd_Construct();
145 static void OLEClipbrd_Destroy(OLEClipbrd
* ptrToDestroy
);
146 static HWND
OLEClipbrd_CreateWindow();
147 static void OLEClipbrd_DestroyWindow(HWND hwnd
);
148 LRESULT CALLBACK
OLEClipbrd_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
149 static HRESULT
OLEClipbrd_RenderFormat( IDataObject
*pIDataObject
, LPFORMATETC pFormatetc
);
150 static HGLOBAL
OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc
);
153 * Prototypes for the methods of the OLEClipboard class
154 * that implement IDataObject methods.
156 static HRESULT WINAPI
OLEClipbrd_IDataObject_QueryInterface(
160 static ULONG WINAPI
OLEClipbrd_IDataObject_AddRef(
162 static ULONG WINAPI
OLEClipbrd_IDataObject_Release(
164 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetData(
166 LPFORMATETC pformatetcIn
,
168 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetDataHere(
170 LPFORMATETC pformatetc
,
172 static HRESULT WINAPI
OLEClipbrd_IDataObject_QueryGetData(
174 LPFORMATETC pformatetc
);
175 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetCanonicalFormatEtc(
177 LPFORMATETC pformatectIn
,
178 LPFORMATETC pformatetcOut
);
179 static HRESULT WINAPI
OLEClipbrd_IDataObject_SetData(
181 LPFORMATETC pformatetc
,
184 static HRESULT WINAPI
OLEClipbrd_IDataObject_EnumFormatEtc(
187 IEnumFORMATETC
** ppenumFormatEtc
);
188 static HRESULT WINAPI
OLEClipbrd_IDataObject_DAdvise(
190 FORMATETC
* pformatetc
,
192 IAdviseSink
* pAdvSink
,
193 DWORD
* pdwConnection
);
194 static HRESULT WINAPI
OLEClipbrd_IDataObject_DUnadvise(
197 static HRESULT WINAPI
OLEClipbrd_IDataObject_EnumDAdvise(
199 IEnumSTATDATA
** ppenumAdvise
);
202 * Prototypes for the IEnumFORMATETC methods.
204 static LPENUMFORMATETC
OLEClipbrd_IEnumFORMATETC_Construct(UINT cfmt
, const FORMATETC afmt
[],
205 LPUNKNOWN pUnkDataObj
);
206 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_QueryInterface(LPENUMFORMATETC iface
, REFIID riid
,
208 static ULONG WINAPI
OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface
);
209 static ULONG WINAPI
OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface
);
210 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Next(LPENUMFORMATETC iface
, ULONG celt
,
211 FORMATETC
* rgelt
, ULONG
* pceltFethed
);
212 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface
, ULONG celt
);
213 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface
);
214 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Clone(LPENUMFORMATETC iface
, LPENUMFORMATETC
* ppenum
);
218 * Virtual function table for the OLEClipbrd's exposed IDataObject interface
220 static ICOM_VTABLE(IDataObject
) OLEClipbrd_IDataObject_VTable
=
222 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
223 OLEClipbrd_IDataObject_QueryInterface
,
224 OLEClipbrd_IDataObject_AddRef
,
225 OLEClipbrd_IDataObject_Release
,
226 OLEClipbrd_IDataObject_GetData
,
227 OLEClipbrd_IDataObject_GetDataHere
,
228 OLEClipbrd_IDataObject_QueryGetData
,
229 OLEClipbrd_IDataObject_GetCanonicalFormatEtc
,
230 OLEClipbrd_IDataObject_SetData
,
231 OLEClipbrd_IDataObject_EnumFormatEtc
,
232 OLEClipbrd_IDataObject_DAdvise
,
233 OLEClipbrd_IDataObject_DUnadvise
,
234 OLEClipbrd_IDataObject_EnumDAdvise
238 * Virtual function table for IEnumFORMATETC interface
240 static struct ICOM_VTABLE(IEnumFORMATETC
) efvt
=
242 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
243 OLEClipbrd_IEnumFORMATETC_QueryInterface
,
244 OLEClipbrd_IEnumFORMATETC_AddRef
,
245 OLEClipbrd_IEnumFORMATETC_Release
,
246 OLEClipbrd_IEnumFORMATETC_Next
,
247 OLEClipbrd_IEnumFORMATETC_Skip
,
248 OLEClipbrd_IEnumFORMATETC_Reset
,
249 OLEClipbrd_IEnumFORMATETC_Clone
253 * Name of our registered OLE clipboard window class
255 CHAR OLEClipbrd_WNDCLASS
[] = "CLIPBRDWNDCLASS";
258 * If we need to store state info we can store it here.
259 * For now we dont need this functionality.
261 typedef struct tagClipboardWindowInfo
263 } ClipboardWindowInfo;
266 /*---------------------------------------------------------------------*
267 * Win32 OLE clipboard API
268 *---------------------------------------------------------------------*/
270 /***********************************************************************
271 * OleSetClipboard [OLE32.127]
272 * Places a pointer to the specified data object onto the clipboard,
273 * making the data object accessible to the OleGetClipboard function.
277 * S_OK IDataObject pointer placed on the clipboard
278 * CLIPBRD_E_CANT_OPEN OpenClipboard failed
279 * CLIPBRD_E_CANT_EMPTY EmptyClipboard failed
280 * CLIPBRD_E_CANT_CLOSE CloseClipboard failed
281 * CLIPBRD_E_CANT_SET SetClipboard failed
284 HRESULT WINAPI
OleSetClipboard(IDataObject
* pDataObj
)
287 IEnumFORMATETC
* penumFormatetc
= NULL
;
289 BOOL bClipboardOpen
= FALSE
;
291 HGLOBAL hDataObject = 0;
292 OLEClipbrd **ppDataObject;
295 TRACE("(%p)\n", pDataObj
);
298 * Make sure we have a clipboard object
300 OLEClipbrd_Initialize();
303 * If the Ole clipboard window hasn't been created yet, create it now.
305 if ( !theOleClipboard
->hWndClipboard
)
306 theOleClipboard
->hWndClipboard
= OLEClipbrd_CreateWindow();
308 if ( !theOleClipboard
->hWndClipboard
) /* sanity check */
309 HANDLE_ERROR( E_FAIL
);
312 * Open the Windows clipboard, associating it with our hidden window
314 if ( !(bClipboardOpen
= OpenClipboard(theOleClipboard
->hWndClipboard
)) )
315 HANDLE_ERROR( CLIPBRD_E_CANT_OPEN
);
318 * Empty the current clipboard and make our window the clipboard owner
319 * NOTE: This will trigger a WM_DESTROYCLIPBOARD message
321 if ( !EmptyClipboard() )
322 HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY
);
325 * If we are already holding on to an IDataObject first release that.
327 if ( theOleClipboard
->pIDataObjectSrc
)
329 IDataObject_Release(theOleClipboard
->pIDataObjectSrc
);
330 theOleClipboard
->pIDataObjectSrc
= NULL
;
334 * AddRef the data object passed in and save its pointer.
335 * A NULL value indicates that the clipboard should be emptied.
337 theOleClipboard
->pIDataObjectSrc
= pDataObj
;
340 IDataObject_AddRef(theOleClipboard
->pIDataObjectSrc
);
344 * Enumerate all HGLOBAL formats supported by the source and make
345 * those formats available using delayed rendering using SetClipboardData.
346 * Only global memory based data items may be made available to non-OLE
347 * applications via the standard Windows clipboard API. Data based on other
348 * mediums(non TYMED_HGLOBAL) can only be accessed via the Ole Clipboard API.
350 * TODO: Do we need to additionally handle TYMED_IStorage media by copying
351 * the storage into global memory?
355 if ( FAILED(hr
= IDataObject_EnumFormatEtc( pDataObj
,
362 while ( S_OK
== IEnumFORMATETC_Next(penumFormatetc
, 1, &rgelt
, NULL
) )
364 if ( rgelt
.tymed
== TYMED_HGLOBAL
)
367 TRACE("(cfFormat=%d:%s)\n", rgelt
.cfFormat
,
368 GetClipboardFormatNameA(rgelt
.cfFormat
, szFmtName
, sizeof(szFmtName
)-1)
371 SetClipboardData( rgelt
.cfFormat
, (HANDLE
)NULL
);
374 IEnumFORMATETC_Release(penumFormatetc
);
378 * Windows additionally creates a new "DataObject" clipboard format
379 * and stores in on the clipboard. We could possibly store a pointer
380 * to our internal IDataObject interface on the clipboard. I'm not
381 * sure what the use of this is though.
382 * Enable the code below for this functionality.
385 theOleClipboard->cfDataObj = RegisterClipboardFormatA("DataObject");
386 hDataObject = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT,
387 sizeof(OLEClipbrd *));
389 HANDLE_ERROR( E_OUTOFMEMORY );
391 ppDataObject = (OLEClipbrd**)GlobalLock(hDataObject);
392 *ppDataObject = theOleClipboard;
393 GlobalUnlock(hDataObject);
395 if ( !SetClipboardData( theOleClipboard->cfDataObj, hDataObject ) )
396 HANDLE_ERROR( CLIPBRD_E_CANT_SET );
404 * Close Windows clipboard (It remains associated with our window)
406 if ( bClipboardOpen
&& !CloseClipboard() )
407 hr
= CLIPBRD_E_CANT_CLOSE
;
410 * Release the source IDataObject if something failed
414 if (theOleClipboard
->pIDataObjectSrc
)
416 IDataObject_Release(theOleClipboard
->pIDataObjectSrc
);
417 theOleClipboard
->pIDataObjectSrc
= NULL
;
425 /***********************************************************************
426 * OleGetClipboard32 [OLE32.105]
427 * Returns a pointer to our internal IDataObject which represents the conceptual
428 * state of the Windows clipboard. If the current clipboard already contains
429 * an IDataObject, our internal IDataObject will delegate to this object.
431 HRESULT WINAPI
OleGetClipboard(IDataObject
** ppDataObj
)
437 * Make sure we have a clipboard object
439 OLEClipbrd_Initialize();
441 if (!theOleClipboard
)
442 return E_OUTOFMEMORY
;
444 /* Return a reference counted IDataObject */
445 hr
= IDataObject_QueryInterface( (IDataObject
*)&(theOleClipboard
->lpvtbl1
),
446 &IID_IDataObject
, (void**)ppDataObj
);
450 /***********************************************************************
451 * OleFlushClipboard [OLE2.76]
454 HRESULT WINAPI
OleFlushClipboard16(void)
457 return OleFlushClipboard();
461 /******************************************************************************
462 * OleFlushClipboard [OLE32.103]
463 * Renders the data from the source IDataObject into the windows clipboard
465 * TODO: OleFlushClipboard needs to additionally handle TYMED_IStorage media
466 * by copying the storage into global memory. Subsequently the default
467 * data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL
468 * back to TYMED_IStorage.
470 HRESULT WINAPI
OleFlushClipboard()
472 IEnumFORMATETC
* penumFormatetc
= NULL
;
475 BOOL bClipboardOpen
= FALSE
;
476 IDataObject
* pIDataObjectSrc
= NULL
;
481 * Make sure we have a clipboard object
483 OLEClipbrd_Initialize();
486 * Already flushed or no source DataObject? Nothing to do.
488 if (!theOleClipboard
->pIDataObjectSrc
)
492 * Addref and save the source data object we are holding on to temporarily,
493 * since it will be released when we empty the clipboard.
495 pIDataObjectSrc
= theOleClipboard
->pIDataObjectSrc
;
496 IDataObject_AddRef(pIDataObjectSrc
);
499 * Open the Windows clipboard
501 if ( !(bClipboardOpen
= OpenClipboard(theOleClipboard
->hWndClipboard
)) )
502 HANDLE_ERROR( CLIPBRD_E_CANT_OPEN
);
505 * Empty the current clipboard
507 if ( !EmptyClipboard() )
508 HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY
);
511 * Render all HGLOBAL formats supported by the source into
512 * the windows clipboard.
514 if ( FAILED( hr
= IDataObject_EnumFormatEtc( pIDataObjectSrc
,
521 while ( S_OK
== IEnumFORMATETC_Next(penumFormatetc
, 1, &rgelt
, NULL
) )
523 if ( rgelt
.tymed
== TYMED_HGLOBAL
)
526 TRACE("(cfFormat=%d:%s)\n", rgelt
.cfFormat
,
527 GetClipboardFormatNameA(rgelt
.cfFormat
, szFmtName
, sizeof(szFmtName
)-1)
531 * Render the clipboard data
533 if ( FAILED(OLEClipbrd_RenderFormat( pIDataObjectSrc
, &rgelt
)) )
538 IEnumFORMATETC_Release(penumFormatetc
);
541 * Release the source data object we are holding on to
543 IDataObject_Release(pIDataObjectSrc
);
548 * Close Windows clipboard (It remains associated with our window)
550 if ( bClipboardOpen
&& !CloseClipboard() )
551 hr
= CLIPBRD_E_CANT_CLOSE
;
557 /***********************************************************************
558 * OleIsCurrentClipboard32 [OLE32.110]
560 HRESULT WINAPI
OleIsCurrentClipboard ( IDataObject
*pDataObject
)
564 * Make sure we have a clipboard object
566 OLEClipbrd_Initialize();
568 if (!theOleClipboard
)
569 return E_OUTOFMEMORY
;
571 return (pDataObject
== theOleClipboard
->pIDataObjectSrc
) ? S_OK
: S_FALSE
;
575 /*---------------------------------------------------------------------*
576 * Internal implementation methods for the OLE clipboard
577 *---------------------------------------------------------------------*/
579 /***********************************************************************
580 * OLEClipbrd_Initialize()
581 * Initializes the OLE clipboard.
583 void OLEClipbrd_Initialize()
586 * Create the clipboard if necesary
588 if ( !theOleClipboard
)
591 theOleClipboard
= OLEClipbrd_Construct();
596 /***********************************************************************
597 * OLEClipbrd_UnInitialize()
598 * Un-Initializes the OLE clipboard
600 void OLEClipbrd_UnInitialize()
604 * Destroy the clipboard if no one holds a reference to us.
605 * Note that the clipboard was created with a reference count of 1.
607 if ( theOleClipboard
&& (theOleClipboard
->ref
<= 1) )
609 OLEClipbrd_Destroy( theOleClipboard
);
613 WARN( "() : OLEClipbrd_UnInitialize called while client holds an IDataObject reference!\n");
618 /*********************************************************
619 * Construct the OLEClipbrd class.
621 static OLEClipbrd
* OLEClipbrd_Construct()
623 OLEClipbrd
* newObject
= NULL
;
624 HGLOBAL hNewObject
= 0;
627 * Allocate space for the object. We use GlobalAlloc since we need
628 * an HGLOBAL to expose our DataObject as a registered clipboard type.
630 hNewObject
= GlobalAlloc( GMEM_DDESHARE
|GMEM_MOVEABLE
|GMEM_ZEROINIT
,
636 * Lock the handle for the entire lifetime of the clipboard.
638 newObject
= GlobalLock(hNewObject
);
641 * Initialize the virtual function table.
643 newObject
->lpvtbl1
= &OLEClipbrd_IDataObject_VTable
;
646 * Start with one reference count. The caller of this function
647 * must release the interface pointer when it is done.
651 newObject
->hSelf
= hNewObject
;
654 * The Ole clipboard is a singleton - save the global handle and pointer
656 theOleClipboard
= newObject
;
657 hTheOleClipboard
= hNewObject
;
659 return theOleClipboard
;
662 static void OLEClipbrd_Destroy(OLEClipbrd
* ptrToDestroy
)
670 * Destroy the Ole clipboard window
672 if ( ptrToDestroy
->hWndClipboard
)
673 OLEClipbrd_DestroyWindow(ptrToDestroy
->hWndClipboard
);
676 * Free the actual OLE Clipboard structure.
678 TRACE("() - Destroying clipboard data object.\n");
679 GlobalUnlock(ptrToDestroy
->hSelf
);
680 GlobalFree(ptrToDestroy
->hSelf
);
683 * The Ole clipboard is a singleton (ptrToDestroy == theOleClipboard)
685 theOleClipboard
= NULL
;
686 hTheOleClipboard
= 0;
690 /***********************************************************************
691 * OLEClipbrd_CreateWindow()
692 * Create the clipboard window
694 static HWND
OLEClipbrd_CreateWindow()
701 * Register the clipboard window class if necessary
704 if ( !( atom
= GlobalFindAtomA(OLEClipbrd_WNDCLASS
) ) ||
705 !( CLASS_FindClassByAtom(atom
, 0) ) )
707 ZeroMemory( &wcex
, sizeof(WNDCLASSEXA
));
709 wcex
.cbSize
= sizeof(WNDCLASSEXA
);
710 /* Windows creates this class with a style mask of 0
711 * We dont bother doing this since the FindClassByAtom code
712 * would have to be changed to deal with this idiosyncracy. */
713 wcex
.style
= CS_GLOBALCLASS
;
714 wcex
.lpfnWndProc
= (WNDPROC
)OLEClipbrd_WndProc
;
716 wcex
.lpszClassName
= OLEClipbrd_WNDCLASS
;
718 RegisterClassExA(&wcex
);
722 * Create a hidden window to receive OLE clipboard messages
726 * If we need to store state info we can store it here.
727 * For now we dont need this functionality.
728 * ClipboardWindowInfo clipboardInfo;
729 * ZeroMemory( &trackerInfo, sizeof(ClipboardWindowInfo));
732 hwnd
= CreateWindowA(OLEClipbrd_WNDCLASS
,
734 WS_POPUP
| WS_CLIPSIBLINGS
| WS_OVERLAPPED
,
735 CW_USEDEFAULT
, CW_USEDEFAULT
,
736 CW_USEDEFAULT
, CW_USEDEFAULT
,
740 0 /*(LPVOID)&clipboardInfo */);
745 /***********************************************************************
746 * OLEClipbrd_DestroyWindow(HWND)
747 * Destroy the clipboard window and unregister its class
749 static void OLEClipbrd_DestroyWindow(HWND hwnd
)
752 * Destroy clipboard window and unregister its WNDCLASS
755 UnregisterClassA( OLEClipbrd_WNDCLASS
, 0 );
758 /***********************************************************************
759 * OLEClipbrd_WndProc(HWND, unsigned, WORD, LONG)
760 * Processes messages sent to the OLE clipboard window.
761 * Note that we will intercept messages in our WndProc only when data
762 * has been placed in the clipboard via OleSetClipboard().
763 * i.e. Only when OLE owns the windows clipboard.
765 LRESULT CALLBACK OLEClipbrd_WndProc
766 (HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
772 * We receive this message to allow us to handle delayed rendering of
773 * a specific clipboard format when an application requests data in
774 * that format by calling GetClipboardData.
775 * (Recall that in OleSetClipboard, we used SetClipboardData to
776 * make all HGLOBAL formats supported by the source IDataObject
777 * available using delayed rendering)
778 * On receiving this mesage we must actually render the data in the
779 * specified format and place it on the clipboard by calling the
780 * SetClipboardData function.
782 case WM_RENDERFORMAT
:
786 ZeroMemory( &rgelt
, sizeof(FORMATETC
));
789 * Initialize FORMATETC to a Windows clipboard friendly format
791 rgelt
.cfFormat
= (UINT
) wParam
;
792 rgelt
.dwAspect
= DVASPECT_CONTENT
;
794 rgelt
.tymed
= TYMED_HGLOBAL
;
796 TRACE("(): WM_RENDERFORMAT(cfFormat=%d)\n", rgelt
.cfFormat
);
799 * Render the clipboard data.
800 * (We must have a source data object or we wouldn't be in this WndProc)
802 OLEClipbrd_RenderFormat( (IDataObject
*)&(theOleClipboard
->lpvtbl1
), &rgelt
);
808 * WM_RENDERALLFORMATS
809 * Sent before the clipboard owner window is destroyed.
810 * We should receive this message only when OleUninitialize is called
811 * while we have an IDataObject in the clipboard.
812 * For the content of the clipboard to remain available to other
813 * applications, we must render data in all the formats the source IDataObject
814 * is capable of generating, and place the data on the clipboard by calling
817 case WM_RENDERALLFORMATS
:
819 IEnumFORMATETC
* penumFormatetc
= NULL
;
822 TRACE("(): WM_RENDERALLFORMATS\n");
825 * Render all HGLOBAL formats supported by the source into
826 * the windows clipboard.
828 if ( FAILED( IDataObject_EnumFormatEtc( (IDataObject
*)&(theOleClipboard
->lpvtbl1
),
829 DATADIR_GET
, &penumFormatetc
) ) )
831 WARN("(): WM_RENDERALLFORMATS failed to retrieve EnumFormatEtc!\n");
835 while ( S_OK
== IEnumFORMATETC_Next(penumFormatetc
, 1, &rgelt
, NULL
) )
837 if ( rgelt
.tymed
== TYMED_HGLOBAL
)
840 * Render the clipboard data.
842 if ( FAILED(OLEClipbrd_RenderFormat( (IDataObject
*)&(theOleClipboard
->lpvtbl1
), &rgelt
)) )
845 TRACE("(): WM_RENDERALLFORMATS(cfFormat=%d)\n", rgelt
.cfFormat
);
849 IEnumFORMATETC_Release(penumFormatetc
);
855 * WM_DESTROYCLIPBOARD
856 * This is sent by EmptyClipboard before the clipboard is emptied.
857 * We should release any IDataObject we are holding onto when we receive
858 * this message, since it indicates that the OLE clipboard should be empty
859 * from this point on.
861 case WM_DESTROYCLIPBOARD
:
863 TRACE("(): WM_DESTROYCLIPBOARD\n");
865 * Release the data object we are holding on to
867 if ( theOleClipboard
->pIDataObjectSrc
)
869 IDataObject_Release(theOleClipboard
->pIDataObjectSrc
);
870 theOleClipboard
->pIDataObjectSrc
= NULL
;
876 case WM_ASKCBFORMATNAME:
877 case WM_CHANGECBCHAIN:
878 case WM_DRAWCLIPBOARD:
879 case WM_SIZECLIPBOARD:
880 case WM_HSCROLLCLIPBOARD:
881 case WM_VSCROLLCLIPBOARD:
882 case WM_PAINTCLIPBOARD:
885 return DefWindowProcA(hWnd
, message
, wParam
, lParam
);
892 /***********************************************************************
893 * OLEClipbrd_RenderFormat(LPFORMATETC)
894 * Render the clipboard data. Note that this call will delegate to the
895 * source data object.
896 * Note: This function assumes it is passed an HGLOBAL format to render.
898 static HRESULT
OLEClipbrd_RenderFormat(IDataObject
*pIDataObject
, LPFORMATETC pFormatetc
)
904 if ( FAILED(hr
= IDataObject_GetData(pIDataObject
, pFormatetc
, &medium
)) )
906 WARN("() : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr
);
911 * Put a copy of the rendered data back on the clipboard
914 if ( !(hDup
= OLEClipbrd_GlobalDupMem(medium
.u
.hGlobal
)) )
915 HANDLE_ERROR( E_OUTOFMEMORY
);
917 if ( !SetClipboardData( pFormatetc
->cfFormat
, hDup
) )
920 WARN("() : Failed to set rendered clipboard data into clipboard!\n");
925 ReleaseStgMedium(&medium
);
931 /***********************************************************************
932 * OLEClipbrd_GlobalDupMem( HGLOBAL )
933 * Helper method to duplicate an HGLOBAL chunk of memory
935 static HGLOBAL
OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc
)
938 PVOID pGlobalSrc
, pGlobalDest
;
944 cBytes
= GlobalSize(hGlobalSrc
);
948 hGlobalDest
= GlobalAlloc( GMEM_DDESHARE
|GMEM_MOVEABLE
,
953 pGlobalSrc
= GlobalLock(hGlobalSrc
);
954 pGlobalDest
= GlobalLock(hGlobalDest
);
955 if ( !pGlobalSrc
|| !pGlobalDest
)
958 memcpy(pGlobalDest
, pGlobalSrc
, cBytes
);
960 GlobalUnlock(hGlobalSrc
);
961 GlobalUnlock(hGlobalDest
);
967 /*---------------------------------------------------------------------*
968 * Implementation of the internal IDataObject interface exposed by
970 *---------------------------------------------------------------------*/
973 /************************************************************************
974 * OLEClipbrd_IDataObject_QueryInterface (IUnknown)
976 * See Windows documentation for more details on IUnknown methods.
978 static HRESULT WINAPI
OLEClipbrd_IDataObject_QueryInterface(
984 * Declare "This" pointer
986 ICOM_THIS(OLEClipbrd
, iface
);
989 WINE_StringFromCLSID((LPCLSID
)riid
,xriid
);
990 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,xriid
,ppvObject
);
993 * Perform a sanity check on the parameters.
995 if ( (This
==0) || (ppvObject
==0) )
999 * Initialize the return parameter.
1004 * Compare the riid with the interface IDs implemented by this object.
1006 if (memcmp(&IID_IUnknown
, riid
, sizeof(IID_IUnknown
)) == 0)
1010 else if (memcmp(&IID_IDataObject
, riid
, sizeof(IID_IDataObject
)) == 0)
1012 *ppvObject
= (IDataObject
*)&(This
->lpvtbl1
);
1014 else /* We only support IUnknown and IDataObject */
1018 WINE_StringFromCLSID((LPCLSID
)riid
,clsid
);
1019 WARN( "() : asking for unsupported interface %s\n", clsid
);
1021 return E_NOINTERFACE
;
1025 * Query Interface always increases the reference count by one when it is
1028 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1033 /************************************************************************
1034 * OLEClipbrd_IDataObject_AddRef (IUnknown)
1036 * See Windows documentation for more details on IUnknown methods.
1038 static ULONG WINAPI
OLEClipbrd_IDataObject_AddRef(
1042 * Declare "This" pointer
1044 ICOM_THIS(OLEClipbrd
, iface
);
1046 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
1053 /************************************************************************
1054 * OLEClipbrd_IDataObject_Release (IUnknown)
1056 * See Windows documentation for more details on IUnknown methods.
1058 static ULONG WINAPI
OLEClipbrd_IDataObject_Release(
1062 * Declare "This" pointer
1064 ICOM_THIS(OLEClipbrd
, iface
);
1066 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
1069 * Decrease the reference count on this object.
1074 * If the reference count goes down to 0, perform suicide.
1078 OLEClipbrd_Destroy(This
);
1085 /************************************************************************
1086 * OLEClipbrd_IDataObject_GetData (IDataObject)
1088 * The OLE Clipboard's implementation of this method delegates to
1089 * a data source if there is one or wraps around the windows clipboard
1091 * See Windows documentation for more details on IDataObject methods.
1093 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetData(
1095 LPFORMATETC pformatetcIn
,
1099 BOOL bClipboardOpen
= FALSE
;
1103 * Declare "This" pointer
1105 ICOM_THIS(OLEClipbrd
, iface
);
1107 if ( !pformatetcIn
|| !pformatetcIn
|| !pmedium
)
1108 return E_INVALIDARG
;
1110 TRACE("(%p, %p)\n", iface
, pformatetcIn
);
1113 * If we have a data source placed on the clipboard (via OleSetClipboard)
1114 * simply delegate to the source object's QueryGetData
1115 * NOTE: This code assumes that the IDataObject is in the same address space!
1116 * We will need to add marshalling support when Wine handles multiple processes.
1118 if ( This
->pIDataObjectSrc
)
1120 return IDataObject_GetData(This
->pIDataObjectSrc
, pformatetcIn
, pmedium
);
1123 if ( pformatetcIn
->lindex
!= -1 )
1125 if ( (pformatetcIn
->tymed
& TYMED_HGLOBAL
) != TYMED_HGLOBAL
)
1128 if ( pformatetcIn->dwAspect != DVASPECT_CONTENT )
1129 return DV_E_DVASPECT;
1133 * Otherwise, get the data from the windows clipboard using GetClipboardData
1135 if ( !(bClipboardOpen
= OpenClipboard(theOleClipboard
->hWndClipboard
)) )
1136 HANDLE_ERROR( CLIPBRD_E_CANT_OPEN
);
1138 hData
= GetClipboardData(pformatetcIn
->cfFormat
);
1141 * Return the clipboard data in the storage medium structure
1143 pmedium
->tymed
= (hData
== 0) ? TYMED_NULL
: TYMED_HGLOBAL
;
1144 pmedium
->u
.hGlobal
= (HGLOBAL
)hData
;
1145 pmedium
->pUnkForRelease
= NULL
;
1151 * Close Windows clipboard
1153 if ( bClipboardOpen
&& !CloseClipboard() )
1154 hr
= CLIPBRD_E_CANT_CLOSE
;
1158 return (hData
== 0) ? DV_E_FORMATETC
: S_OK
;
1161 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetDataHere(
1163 LPFORMATETC pformatetc
,
1170 /************************************************************************
1171 * OLEClipbrd_IDataObject_QueryGetData (IDataObject)
1173 * The OLE Clipboard's implementation of this method delegates to
1174 * a data source if there is one or wraps around the windows clipboard
1175 * function IsClipboardFormatAvailable() otherwise.
1177 * See Windows documentation for more details on IDataObject methods.
1179 static HRESULT WINAPI
OLEClipbrd_IDataObject_QueryGetData(
1181 LPFORMATETC pformatetc
)
1184 * Declare "This" pointer
1186 ICOM_THIS(OLEClipbrd
, iface
);
1188 TRACE("(%p, %p)\n", iface
, pformatetc
);
1191 * If we have a data source placed on the clipboard (via OleSetClipboard)
1192 * simply delegate to the source object's QueryGetData
1194 if ( This
->pIDataObjectSrc
)
1196 return IDataObject_QueryGetData(This
->pIDataObjectSrc
, pformatetc
);
1200 return E_INVALIDARG
;
1202 if ( pformatetc->dwAspect != DVASPECT_CONTENT )
1203 return DV_E_DVASPECT;
1205 if ( pformatetc
->lindex
!= -1 )
1208 /* TODO: Handle TYMED_IStorage media which were put on the clipboard
1209 * by copying the storage into global memory. We must convert this
1210 * TYMED_HGLOBAL back to TYMED_IStorage.
1212 if ( pformatetc
->tymed
!= TYMED_HGLOBAL
)
1216 * Delegate to the Windows clipboard function IsClipboardFormatAvailable
1218 return (IsClipboardFormatAvailable(pformatetc
->cfFormat
)) ? S_OK
: DV_E_FORMATETC
;
1221 /************************************************************************
1222 * OLEClipbrd_IDataObject_GetCanonicalFormatEtc (IDataObject)
1224 * See Windows documentation for more details on IDataObject methods.
1226 static HRESULT WINAPI
OLEClipbrd_IDataObject_GetCanonicalFormatEtc(
1228 LPFORMATETC pformatectIn
,
1229 LPFORMATETC pformatetcOut
)
1231 TRACE("(%p, %p, %p)\n", iface
, pformatectIn
, pformatetcOut
);
1233 if ( !pformatectIn
|| !pformatetcOut
)
1234 return E_INVALIDARG
;
1236 memcpy(pformatetcOut
, pformatectIn
, sizeof(FORMATETC
));
1237 return DATA_S_SAMEFORMATETC
;
1240 /************************************************************************
1241 * OLEClipbrd_IDataObject_SetData (IDataObject)
1243 * The OLE Clipboard's does not implement this method
1245 * See Windows documentation for more details on IDataObject methods.
1247 static HRESULT WINAPI
OLEClipbrd_IDataObject_SetData(
1249 LPFORMATETC pformatetc
,
1256 /************************************************************************
1257 * OLEClipbrd_IDataObject_EnumFormatEtc (IDataObject)
1259 * See Windows documentation for more details on IDataObject methods.
1261 static HRESULT WINAPI
OLEClipbrd_IDataObject_EnumFormatEtc(
1264 IEnumFORMATETC
** ppenumFormatEtc
)
1267 FORMATETC
*afmt
= NULL
;
1270 BOOL bClipboardOpen
;
1273 * Declare "This" pointer
1275 ICOM_THIS(OLEClipbrd
, iface
);
1277 TRACE("(%p, %lx, %p)\n", iface
, dwDirection
, ppenumFormatEtc
);
1280 * If we have a data source placed on the clipboard (via OleSetClipboard)
1281 * simply delegate to the source object's EnumFormatEtc
1283 if ( This
->pIDataObjectSrc
)
1285 return IDataObject_EnumFormatEtc(This
->pIDataObjectSrc
,
1286 dwDirection
, ppenumFormatEtc
);
1290 * Otherwise we must provide our own enumerator which wraps around the
1291 * Windows clipboard function EnumClipboardFormats
1293 if ( !ppenumFormatEtc
)
1294 return E_INVALIDARG
;
1296 if ( dwDirection
!= DATADIR_GET
) /* IDataObject_SetData not implemented */
1300 * Store all current clipboard formats in an array of FORMATETC's,
1301 * and create an IEnumFORMATETC enumerator from this list.
1303 cfmt
= CountClipboardFormats();
1304 afmt
= (FORMATETC
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1305 sizeof(FORMATETC
) * cfmt
);
1307 * Open the Windows clipboard, associating it with our hidden window
1309 if ( !(bClipboardOpen
= OpenClipboard(This
->hWndClipboard
)) )
1310 HANDLE_ERROR( CLIPBRD_E_CANT_OPEN
);
1313 * Store all current clipboard formats in an array of FORMATETC's
1314 * TODO: Handle TYMED_IStorage media which were put on the clipboard
1315 * by copying the storage into global memory. We must convert this
1316 * TYMED_HGLOBAL back to TYMED_IStorage.
1318 for (i
= 0, format
= 0; i
< cfmt
; i
++)
1320 format
= EnumClipboardFormats(format
);
1321 if (!format
) /* Failed! */
1323 ERR("EnumClipboardFormats failed to return format!\n");
1324 HANDLE_ERROR( E_FAIL
);
1327 /* Init the FORMATETC struct */
1328 afmt
[i
].cfFormat
= format
;
1330 afmt
[i
].dwAspect
= DVASPECT_CONTENT
;
1331 afmt
[i
].lindex
= -1;
1332 afmt
[i
].tymed
= TYMED_HGLOBAL
;
1336 * Create an EnumFORMATETC enumerator and return an
1337 * EnumFORMATETC after bumping up its ref count
1339 *ppenumFormatEtc
= OLEClipbrd_IEnumFORMATETC_Construct( cfmt
, afmt
, (LPUNKNOWN
)iface
);
1340 if (!(*ppenumFormatEtc
))
1341 HANDLE_ERROR( E_OUTOFMEMORY
);
1343 if (FAILED( hr
= IEnumFORMATETC_AddRef(*ppenumFormatEtc
)))
1350 * Free the array of FORMATETC's
1353 HeapFree(GetProcessHeap(), 0, afmt
);
1356 * Close Windows clipboard
1358 if ( bClipboardOpen
&& !CloseClipboard() )
1359 hr
= CLIPBRD_E_CANT_CLOSE
;
1364 /************************************************************************
1365 * OLEClipbrd_IDataObject_DAdvise (IDataObject)
1367 * The OLE Clipboard's does not implement this method
1369 * See Windows documentation for more details on IDataObject methods.
1371 static HRESULT WINAPI
OLEClipbrd_IDataObject_DAdvise(
1373 FORMATETC
* pformatetc
,
1375 IAdviseSink
* pAdvSink
,
1376 DWORD
* pdwConnection
)
1381 /************************************************************************
1382 * OLEClipbrd_IDataObject_DUnadvise (IDataObject)
1384 * The OLE Clipboard's does not implement this method
1386 * See Windows documentation for more details on IDataObject methods.
1388 static HRESULT WINAPI
OLEClipbrd_IDataObject_DUnadvise(
1395 /************************************************************************
1396 * OLEClipbrd_IDataObject_EnumDAdvise (IDataObject)
1398 * The OLE Clipboard does not implement this method
1400 * See Windows documentation for more details on IDataObject methods.
1402 static HRESULT WINAPI
OLEClipbrd_IDataObject_EnumDAdvise(
1404 IEnumSTATDATA
** ppenumAdvise
)
1410 /*---------------------------------------------------------------------*
1411 * Implementation of the internal IEnumFORMATETC interface returned by
1412 * the OLE clipboard's IDataObject.
1413 *---------------------------------------------------------------------*/
1415 /************************************************************************
1416 * OLEClipbrd_IEnumFORMATETC_Construct (UINT, const FORMATETC, LPUNKNOWN)
1418 * Creates an IEnumFORMATETC enumerator from an array of FORMATETC
1419 * Structures. pUnkOuter is the outer unknown for reference counting only.
1420 * NOTE: this does not AddRef the interface.
1423 LPENUMFORMATETC
OLEClipbrd_IEnumFORMATETC_Construct(UINT cfmt
, const FORMATETC afmt
[],
1424 LPUNKNOWN pUnkDataObj
)
1426 IEnumFORMATETCImpl
* ef
;
1427 DWORD size
=cfmt
* sizeof(FORMATETC
);
1430 ef
= (IEnumFORMATETCImpl
*)HeapAlloc(GetProcessHeap(),
1432 sizeof(IEnumFORMATETCImpl
));
1437 ICOM_VTBL(ef
) = &efvt
;
1438 ef
->pUnkDataObj
= pUnkDataObj
;
1441 ef
->countFmt
= cfmt
;
1442 if (FAILED(CoGetMalloc(MEMCTX_TASK
, &pIMalloc
)))
1444 ef
->pFmt
= (LPFORMATETC
)IMalloc_Alloc(pIMalloc
, size
);
1445 IMalloc_Release(pIMalloc
);
1448 memcpy(ef
->pFmt
, afmt
, size
);
1450 TRACE("(%p)->()\n",ef
);
1451 return (LPENUMFORMATETC
)ef
;
1455 /************************************************************************
1456 * OLEClipbrd_IEnumFORMATETC_QueryInterface (IUnknown)
1458 * See Windows documentation for more details on IUnknown methods.
1460 static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_QueryInterface
1461 (LPENUMFORMATETC iface
, REFIID riid
, LPVOID
* ppvObj
)
1463 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1466 WINE_StringFromCLSID((LPCLSID
)riid
,xriid
);
1467 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,xriid
,ppvObj
);
1470 * Since enumerators are seperate objects from the parent data object
1471 * we only need to support the IUnknown and IEnumFORMATETC interfaces
1476 if(IsEqualIID(riid
, &IID_IUnknown
))
1480 else if(IsEqualIID(riid
, &IID_IEnumFORMATETC
))
1482 *ppvObj
= (IDataObject
*)This
;
1487 IEnumFORMATETC_AddRef((IEnumFORMATETC
*)*ppvObj
);
1488 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
1492 TRACE("-- Interface: E_NOINTERFACE\n");
1493 return E_NOINTERFACE
;
1496 /************************************************************************
1497 * OLEClipbrd_IEnumFORMATETC_AddRef (IUnknown)
1499 * Since enumerating formats only makes sense when our data object is around,
1500 * we insure that it stays as long as we stay by calling our parents IUnknown
1501 * for AddRef and Release. But since we are not controlled by the lifetime of
1502 * the outer object, we still keep our own reference count in order to
1505 static ULONG WINAPI
OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface
)
1507 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1508 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
1510 if (This
->pUnkDataObj
)
1511 IUnknown_AddRef(This
->pUnkDataObj
);
1513 return ++(This
->ref
);
1516 /************************************************************************
1517 * OLEClipbrd_IEnumFORMATETC_Release (IUnknown)
1519 * See Windows documentation for more details on IUnknown methods.
1521 static ULONG WINAPI
OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface
)
1523 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1526 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
1528 if (This
->pUnkDataObj
)
1529 IUnknown_Release(This
->pUnkDataObj
); /* Release parent data object */
1533 TRACE("() - destroying IEnumFORMATETC(%p)\n",This
);
1534 if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK
, &pIMalloc
)))
1536 IMalloc_Free(pIMalloc
, This
->pFmt
);
1537 IMalloc_Release(pIMalloc
);
1540 HeapFree(GetProcessHeap(),0,This
);
1547 /************************************************************************
1548 * OLEClipbrd_IEnumFORMATETC_Next (IEnumFORMATETC)
1550 * Standard enumerator members for IEnumFORMATETC
1552 static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Next
1553 (LPENUMFORMATETC iface
, ULONG celt
, FORMATETC
*rgelt
, ULONG
*pceltFethed
)
1555 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1557 HRESULT hres
= S_FALSE
;
1559 TRACE("(%p)->(pos=%u)\n", This
, This
->posFmt
);
1561 if (This
->posFmt
< This
->countFmt
)
1563 cfetch
= This
->countFmt
- This
->posFmt
;
1570 memcpy(rgelt
, &This
->pFmt
[This
->posFmt
], cfetch
* sizeof(FORMATETC
));
1571 This
->posFmt
+= cfetch
;
1580 *pceltFethed
= cfetch
;
1586 /************************************************************************
1587 * OLEClipbrd_IEnumFORMATETC_Skip (IEnumFORMATETC)
1589 * Standard enumerator members for IEnumFORMATETC
1591 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface
, ULONG celt
)
1593 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1594 TRACE("(%p)->(num=%lu)\n", This
, celt
);
1596 This
->posFmt
+= celt
;
1597 if (This
->posFmt
> This
->countFmt
)
1599 This
->posFmt
= This
->countFmt
;
1605 /************************************************************************
1606 * OLEClipbrd_IEnumFORMATETC_Reset (IEnumFORMATETC)
1608 * Standard enumerator members for IEnumFORMATETC
1610 static HRESULT WINAPI
OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface
)
1612 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1613 TRACE("(%p)->()\n", This
);
1619 /************************************************************************
1620 * OLEClipbrd_IEnumFORMATETC_Clone (IEnumFORMATETC)
1622 * Standard enumerator members for IEnumFORMATETC
1624 static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Clone
1625 (LPENUMFORMATETC iface
, LPENUMFORMATETC
* ppenum
)
1627 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
1630 TRACE("(%p)->(ppenum=%p)\n", This
, ppenum
);
1633 return E_INVALIDARG
;
1635 *ppenum
= OLEClipbrd_IEnumFORMATETC_Construct(This
->countFmt
,
1639 if (FAILED( hr
= IEnumFORMATETC_AddRef(*ppenum
)))
1642 return (*ppenum
) ? S_OK
: E_OUTOFMEMORY
;