* Copyright 1999 Noel Borthwick <noel@macadamian.com>
* Copyright 2000 Abey George <abey@macadamian.com>
*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
* NOTES:
* This file contains the implementation for the OLE Clipboard and its
* internal interfaces. The OLE clipboard interacts with an IDataObject
*/
#include <assert.h>
+#include <stdarg.h>
+#include <string.h>
+
+#define COBJMACROS
+#define NONAMELESSUNION
+#define NONAMELESSSTRUCT
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winnls.h"
#include "ole2.h"
-#include "debugtools.h"
+#include "wine/debug.h"
#include "olestd.h"
#include "storage32.h"
/* For CoGetMalloc (MEMCTX_TASK is currently ignored) */
#ifndef MEMCTX_TASK
- #define MEMCTX_TASK -1
+# define MEMCTX_TASK -1
#endif
-DEFAULT_DEBUG_CHANNEL(ole);
+WINE_DEFAULT_DEBUG_CHANNEL(ole);
/****************************************************************************
* OLEClipbrd
/*
* List all interface VTables here
*/
- ICOM_VTABLE(IDataObject)* lpvtbl1; /* IDataObject VTable */
+ const IDataObjectVtbl* lpvtbl1; /* IDataObject VTable */
/*
- * The hidden OLE clipboard window. This window is used as the bridge between the
+ * The hidden OLE clipboard window. This window is used as the bridge between the
* the OLE and windows clipboard API. (Windows creates one such window per process)
*/
HWND hWndClipboard;
UINT cfDataObj;
/*
- * The handle to our ourself
+ * The handle to ourself
*/
- UINT hSelf;
+ HGLOBAL hSelf;
/*
* Reference count of this object
*/
- ULONG ref;
+ LONG ref;
};
typedef struct OLEClipbrd OLEClipbrd;
* IEnumFORMATETC implementation
* DO NOT add any members before the VTables declaration!
*/
-typedef struct
+typedef struct
{
/* IEnumFORMATETC VTable */
- ICOM_VFIELD(IEnumFORMATETC);
-
+ const IEnumFORMATETCVtbl *lpVtbl;
+
/* IEnumFORMATETC fields */
UINT posFmt; /* current enumerator position */
UINT countFmt; /* number of EnumFORMATETC's in array */
/*
* Reference count of this object
*/
- DWORD ref;
+ LONG ref;
/*
* IUnknown implementation of the parent data object.
*/
IUnknown* pUnkDataObj;
-
+
} IEnumFORMATETCImpl;
typedef struct PresentationDataHeader
/*
* Prototypes for the methods of the OLEClipboard class.
*/
-extern void OLEClipbrd_Initialize();
-extern void OLEClipbrd_UnInitialize();
-static OLEClipbrd* OLEClipbrd_Construct();
+void OLEClipbrd_Initialize(void);
+void OLEClipbrd_UnInitialize(void);
+static OLEClipbrd* OLEClipbrd_Construct(void);
static void OLEClipbrd_Destroy(OLEClipbrd* ptrToDestroy);
-static HWND OLEClipbrd_CreateWindow();
+static HWND OLEClipbrd_CreateWindow(void);
static void OLEClipbrd_DestroyWindow(HWND hwnd);
LRESULT CALLBACK OLEClipbrd_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static HRESULT OLEClipbrd_RenderFormat( IDataObject *pIDataObject, LPFORMATETC pFormatetc );
IDataObject* iface,
REFIID riid,
void** ppvObject);
-static ULONG WINAPI OLEClipbrd_IDataObject_AddRef(
+static ULONG WINAPI OLEClipbrd_IDataObject_AddRef(
IDataObject* iface);
-static ULONG WINAPI OLEClipbrd_IDataObject_Release(
+static ULONG WINAPI OLEClipbrd_IDataObject_Release(
IDataObject* iface);
static HRESULT WINAPI OLEClipbrd_IDataObject_GetData(
IDataObject* iface,
- LPFORMATETC pformatetcIn,
+ LPFORMATETC pformatetcIn,
STGMEDIUM* pmedium);
static HRESULT WINAPI OLEClipbrd_IDataObject_GetDataHere(
- IDataObject* iface,
+ IDataObject* iface,
LPFORMATETC pformatetc,
STGMEDIUM* pmedium);
static HRESULT WINAPI OLEClipbrd_IDataObject_QueryGetData(
IDataObject* iface,
LPFORMATETC pformatetc);
static HRESULT WINAPI OLEClipbrd_IDataObject_GetCanonicalFormatEtc(
- IDataObject* iface,
- LPFORMATETC pformatectIn,
+ IDataObject* iface,
+ LPFORMATETC pformatectIn,
LPFORMATETC pformatetcOut);
static HRESULT WINAPI OLEClipbrd_IDataObject_SetData(
IDataObject* iface,
- LPFORMATETC pformatetc,
- STGMEDIUM* pmedium,
+ LPFORMATETC pformatetc,
+ STGMEDIUM* pmedium,
BOOL fRelease);
static HRESULT WINAPI OLEClipbrd_IDataObject_EnumFormatEtc(
- IDataObject* iface,
+ IDataObject* iface,
DWORD dwDirection,
IEnumFORMATETC** ppenumFormatEtc);
static HRESULT WINAPI OLEClipbrd_IDataObject_DAdvise(
- IDataObject* iface,
- FORMATETC* pformatetc,
- DWORD advf,
- IAdviseSink* pAdvSink,
+ IDataObject* iface,
+ FORMATETC* pformatetc,
+ DWORD advf,
+ IAdviseSink* pAdvSink,
DWORD* pdwConnection);
static HRESULT WINAPI OLEClipbrd_IDataObject_DUnadvise(
IDataObject* iface,
/*
* Virtual function table for the OLEClipbrd's exposed IDataObject interface
*/
-static ICOM_VTABLE(IDataObject) OLEClipbrd_IDataObject_VTable =
+static const IDataObjectVtbl OLEClipbrd_IDataObject_VTable =
{
- ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
OLEClipbrd_IDataObject_QueryInterface,
OLEClipbrd_IDataObject_AddRef,
OLEClipbrd_IDataObject_Release,
/*
* Virtual function table for IEnumFORMATETC interface
*/
-static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
+static const IEnumFORMATETCVtbl efvt =
{
- ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
OLEClipbrd_IEnumFORMATETC_QueryInterface,
OLEClipbrd_IEnumFORMATETC_AddRef,
OLEClipbrd_IEnumFORMATETC_Release,
};
/*
- * Name of our registered OLE clipboard window class
+ * Name of our registered OLE clipboard window class
*/
CHAR OLEClipbrd_WNDCLASS[] = "CLIPBRDWNDCLASS";
/*
* If we need to store state info we can store it here.
- * For now we dont need this functionality.
+ * For now we don't need this functionality.
*
typedef struct tagClipboardWindowInfo
{
*/
/*---------------------------------------------------------------------*
- * Win32 OLE clipboard API
+ * Win32 OLE clipboard API
*---------------------------------------------------------------------*/
/***********************************************************************
- * OleSetClipboard [OLE32.127]
+ * OleSetClipboard [OLE32.@]
* Places a pointer to the specified data object onto the clipboard,
* making the data object accessible to the OleGetClipboard function.
*
- * RETURNS:
+ * RETURNS
*
* S_OK IDataObject pointer placed on the clipboard
- * CLIPBRD_E_CANT_OPEN OpenClipboard failed
- * CLIPBRD_E_CANT_EMPTY EmptyClipboard failed
+ * CLIPBRD_E_CANT_OPEN OpenClipboard failed
+ * CLIPBRD_E_CANT_EMPTY EmptyClipboard failed
* CLIPBRD_E_CANT_CLOSE CloseClipboard failed
* CLIPBRD_E_CANT_SET SetClipboard failed
*/
HGLOBAL hDataObject = 0;
OLEClipbrd **ppDataObject;
*/
-
+
TRACE("(%p)\n", pDataObj);
-
+
/*
* Make sure we have a clipboard object
*/
/*
* Empty the current clipboard and make our window the clipboard owner
- * NOTE: This will trigger a WM_DESTROYCLIPBOARD message
+ * NOTE: This will trigger a WM_DESTROYCLIPBOARD message
*/
if ( !EmptyClipboard() )
HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY );
}
/*
- * Enumerate all HGLOBAL formats supported by the source and make
+ * Enumerate all HGLOBAL formats supported by the source and make
* those formats available using delayed rendering using SetClipboardData.
- * Only global memory based data items may be made available to non-OLE
- * applications via the standard Windows clipboard API. Data based on other
+ * Only global memory based data items may be made available to non-OLE
+ * applications via the standard Windows clipboard API. Data based on other
* mediums(non TYMED_HGLOBAL) can only be accessed via the Ole Clipboard API.
*
* TODO: Do we need to additionally handle TYMED_IStorage media by copying
{
HANDLE_ERROR( hr );
}
-
+
while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) )
{
if ( rgelt.tymed == TYMED_HGLOBAL )
TRACE("(cfFormat=%d:%s)\n", rgelt.cfFormat,
GetClipboardFormatNameA(rgelt.cfFormat, szFmtName, sizeof(szFmtName)-1)
? szFmtName : "");
-
- SetClipboardData( rgelt.cfFormat, (HANDLE)NULL);
+
+ SetClipboardData( rgelt.cfFormat, NULL);
}
}
IEnumFORMATETC_Release(penumFormatetc);
/*
* Windows additionally creates a new "DataObject" clipboard format
- * and stores in on the clipboard. We could possibly store a pointer
+ * and stores in on the clipboard. We could possibly store a pointer
* to our internal IDataObject interface on the clipboard. I'm not
* sure what the use of this is though.
* Enable the code below for this functionality.
sizeof(OLEClipbrd *));
if (hDataObject==0)
HANDLE_ERROR( E_OUTOFMEMORY );
-
+
ppDataObject = (OLEClipbrd**)GlobalLock(hDataObject);
*ppDataObject = theOleClipboard;
GlobalUnlock(hDataObject);
if ( !SetClipboardData( theOleClipboard->cfDataObj, hDataObject ) )
HANDLE_ERROR( CLIPBRD_E_CANT_SET );
*/
-
+
hr = S_OK;
CLEANUP:
/***********************************************************************
- * OleGetClipboard [OLE32.105]
- * Returns a pointer to our internal IDataObject which represents the conceptual
- * state of the Windows clipboard. If the current clipboard already contains
+ * OleGetClipboard [OLE32.@]
+ * Returns a pointer to our internal IDataObject which represents the conceptual
+ * state of the Windows clipboard. If the current clipboard already contains
* an IDataObject, our internal IDataObject will delegate to this object.
*/
HRESULT WINAPI OleGetClipboard(IDataObject** ppDataObj)
{
HRESULT hr = S_OK;
TRACE("()\n");
-
+
/*
* Make sure we have a clipboard object
*/
return hr;
}
-/***********************************************************************
- * OleFlushClipboard [OLE2.76]
- */
-
-HRESULT WINAPI OleFlushClipboard16(void)
-{
- return OleFlushClipboard();
-}
-
-
/******************************************************************************
- * OleFlushClipboard [OLE32.103]
+ * OleFlushClipboard [OLE32.@]
* Renders the data from the source IDataObject into the windows clipboard
*
* TODO: OleFlushClipboard needs to additionally handle TYMED_IStorage media
HRESULT hr = S_OK;
BOOL bClipboardOpen = FALSE;
IDataObject* pIDataObjectSrc = NULL;
-
+
TRACE("()\n");
/*
*/
pIDataObjectSrc = theOleClipboard->pIDataObjectSrc;
IDataObject_AddRef(pIDataObjectSrc);
-
+
/*
* Open the Windows clipboard
*/
continue;
}
}
-
+
IEnumFORMATETC_Release(penumFormatetc);
-
+
/*
* Release the source data object we are holding on to
*/
/***********************************************************************
- * OleIsCurrentClipboard [OLE32.110]
+ * OleIsCurrentClipboard [OLE32.@]
*/
-HRESULT WINAPI OleIsCurrentClipboard ( IDataObject *pDataObject)
+HRESULT WINAPI OleIsCurrentClipboard ( IDataObject *pDataObject)
{
TRACE("()\n");
/*
/*---------------------------------------------------------------------*
- * Internal implementation methods for the OLE clipboard
+ * Internal implementation methods for the OLE clipboard
*---------------------------------------------------------------------*/
/***********************************************************************
* OLEClipbrd_Initialize()
- * Initializes the OLE clipboard.
+ * Initializes the OLE clipboard.
*/
-void OLEClipbrd_Initialize()
+void OLEClipbrd_Initialize(void)
{
/*
- * Create the clipboard if necessary
+ * Create the clipboard if necessary
*/
if ( !theOleClipboard )
{
/***********************************************************************
* OLEClipbrd_UnInitialize()
- * Un-Initializes the OLE clipboard
+ * Un-Initializes the OLE clipboard
*/
-void OLEClipbrd_UnInitialize()
+void OLEClipbrd_UnInitialize(void)
{
TRACE("()\n");
/*
{
OLEClipbrd* newObject = NULL;
HGLOBAL hNewObject = 0;
-
+
/*
* Allocate space for the object. We use GlobalAlloc since we need
* an HGLOBAL to expose our DataObject as a registered clipboard type.
* Lock the handle for the entire lifetime of the clipboard.
*/
newObject = GlobalLock(hNewObject);
-
+
/*
* Initialize the virtual function table.
*/
newObject->lpvtbl1 = &OLEClipbrd_IDataObject_VTable;
/*
- * Start with one reference count. The caller of this function
+ * Start with one reference count. The caller of this function
* must release the interface pointer when it is done.
*/
newObject->ref = 1;
newObject->hSelf = hNewObject;
-
+
/*
* The Ole clipboard is a singleton - save the global handle and pointer
*/
static void OLEClipbrd_Destroy(OLEClipbrd* ptrToDestroy)
{
TRACE("()\n");
-
+
if ( !ptrToDestroy )
return;
/*
- * Destroy the Ole clipboard window
+ * Destroy the Ole clipboard window
*/
if ( ptrToDestroy->hWndClipboard )
OLEClipbrd_DestroyWindow(ptrToDestroy->hWndClipboard);
/***********************************************************************
* OLEClipbrd_CreateWindow()
- * Create the clipboard window
+ * Create the clipboard window
*/
static HWND OLEClipbrd_CreateWindow()
{
HWND hwnd = 0;
WNDCLASSEXA wcex;
- /*
- * Register the clipboard window class if necessary
+ /*
+ * Register the clipboard window class if necessary
*/
ZeroMemory( &wcex, sizeof(WNDCLASSEXA));
wcex.cbSize = sizeof(WNDCLASSEXA);
/* Windows creates this class with a style mask of 0
- * We dont bother doing this since the FindClassByAtom code
- * would have to be changed to deal with this idiosyncracy. */
+ * We don't bother doing this since the FindClassByAtom code
+ * would have to be changed to deal with this idiosyncrasy. */
wcex.style = CS_GLOBALCLASS;
- wcex.lpfnWndProc = (WNDPROC)OLEClipbrd_WndProc;
+ wcex.lpfnWndProc = OLEClipbrd_WndProc;
wcex.hInstance = 0;
wcex.lpszClassName = OLEClipbrd_WNDCLASS;
RegisterClassExA(&wcex);
/*
- * Create a hidden window to receive OLE clipboard messages
+ * Create a hidden window to receive OLE clipboard messages
*/
/*
* If we need to store state info we can store it here.
- * For now we dont need this functionality.
+ * For now we don't need this functionality.
* ClipboardWindowInfo clipboardInfo;
* ZeroMemory( &trackerInfo, sizeof(ClipboardWindowInfo));
*/
- hwnd = CreateWindowA(OLEClipbrd_WNDCLASS,
+ hwnd = CreateWindowA(OLEClipbrd_WNDCLASS,
"ClipboardWindow",
WS_POPUP | WS_CLIPSIBLINGS | WS_OVERLAPPED,
CW_USEDEFAULT, CW_USEDEFAULT,
*/
static void OLEClipbrd_DestroyWindow(HWND hwnd)
{
- /*
- * Destroy clipboard window and unregister its WNDCLASS
+ /*
+ * Destroy clipboard window and unregister its WNDCLASS
*/
DestroyWindow(hwnd);
UnregisterClassA( OLEClipbrd_WNDCLASS, 0 );
/***********************************************************************
* OLEClipbrd_WndProc(HWND, unsigned, WORD, LONG)
- * Processes messages sent to the OLE clipboard window.
- * Note that we will intercept messages in our WndProc only when data
- * has been placed in the clipboard via OleSetClipboard().
+ * Processes messages sent to the OLE clipboard window.
+ * Note that we will intercept messages in our WndProc only when data
+ * has been placed in the clipboard via OleSetClipboard().
* i.e. Only when OLE owns the windows clipboard.
*/
LRESULT CALLBACK OLEClipbrd_WndProc
(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
+ switch (message)
{
/*
- * WM_RENDERFORMAT
+ * WM_RENDERFORMAT
* We receive this message to allow us to handle delayed rendering of
- * a specific clipboard format when an application requests data in
+ * a specific clipboard format when an application requests data in
* that format by calling GetClipboardData.
- * (Recall that in OleSetClipboard, we used SetClipboardData to
+ * (Recall that in OleSetClipboard, we used SetClipboardData to
* make all HGLOBAL formats supported by the source IDataObject
* available using delayed rendering)
- * On receiving this mesage we must actually render the data in the
- * specified format and place it on the clipboard by calling the
- * SetClipboardData function.
+ * On receiving this message we must actually render the data in the
+ * specified format and place it on the clipboard by calling the
+ * SetClipboardData function.
*/
case WM_RENDERFORMAT:
{
FORMATETC rgelt;
-
+
ZeroMemory( &rgelt, sizeof(FORMATETC));
/*
rgelt.tymed = TYMED_HGLOBAL;
TRACE("(): WM_RENDERFORMAT(cfFormat=%d)\n", rgelt.cfFormat);
-
+
/*
* Render the clipboard data.
* (We must have a source data object or we wouldn't be in this WndProc)
{
IEnumFORMATETC* penumFormatetc = NULL;
FORMATETC rgelt;
-
+
TRACE("(): WM_RENDERALLFORMATS\n");
-
+
/*
* Render all HGLOBAL formats supported by the source into
* the windows clipboard.
if ( rgelt.tymed == TYMED_HGLOBAL )
{
/*
- * Render the clipboard data.
+ * Render the clipboard data.
*/
if ( FAILED(OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt )) )
continue;
-
+
TRACE("(): WM_RENDERALLFORMATS(cfFormat=%d)\n", rgelt.cfFormat);
}
}
-
+
IEnumFORMATETC_Release(penumFormatetc);
break;
std.tymed = pFormatetc->tymed = TYMED_ISTORAGE;
hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0);
+ if (hStorage == NULL)
+ HANDLE_ERROR( E_OUTOFMEMORY );
hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes);
hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg);
if (FAILED(hr = IDataObject_GetDataHere(theOleClipboard->pIDataObjectSrc, pFormatetc, &std)))
{
WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%lx)\n", hr);
+ GlobalFree(hStorage);
return hr;
}
if (!FAILED(hr = IDataObject_GetData(theOleClipboard->pIDataObjectSrc, &fmt2, &std2)))
{
- mfp = (METAFILEPICT *)GlobalLock(std2.u.hMetaFilePict);
+ mfp = (METAFILEPICT *)GlobalLock(std2.u.hGlobal);
}
if (mfp)
IStream_Release(pStream);
HeapFree(GetProcessHeap(), 0, mfBits);
-
- GlobalUnlock(std2.u.hMetaFilePict);
+
+ GlobalUnlock(std2.u.hGlobal);
ReadClassStg(std.u.pstg, &clsID);
ProgIDFromCLSID(&clsID, &strProgID);
else
{
if (FAILED(hr = IDataObject_GetData(pIDataObject, pFormatetc, &std)))
- {
- WARN("() : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr);
- return hr;
- }
+ {
+ WARN("() : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr);
+ GlobalFree(hStorage);
+ return hr;
+ }
/* To put a copy back on the clipboard */
/*
* Put a copy of the rendered data back on the clipboard
*/
-
+
if ( !(hDup = OLEClipbrd_GlobalDupMem(hStorage)) )
HANDLE_ERROR( E_OUTOFMEMORY );
-
+
if ( !SetClipboardData( pFormatetc->cfFormat, hDup ) )
{
GlobalFree(hDup);
}
CLEANUP:
-
+
ReleaseStgMedium(&std);
-
+
return hr;
}
HGLOBAL hGlobalDest;
PVOID pGlobalSrc, pGlobalDest;
DWORD cBytes;
-
+
if ( !hGlobalSrc )
return 0;
cBytes = GlobalSize(hGlobalSrc);
if ( 0 == cBytes )
return 0;
-
+
hGlobalDest = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE,
cBytes );
if ( !hGlobalDest )
return 0;
-
+
pGlobalSrc = GlobalLock(hGlobalSrc);
pGlobalDest = GlobalLock(hGlobalDest);
if ( !pGlobalSrc || !pGlobalDest )
+ {
+ GlobalFree(hGlobalDest);
return 0;
+ }
memcpy(pGlobalDest, pGlobalSrc, cBytes);
-
+
GlobalUnlock(hGlobalSrc);
GlobalUnlock(hGlobalDest);
/*---------------------------------------------------------------------*
- * Implementation of the internal IDataObject interface exposed by
+ * Implementation of the internal IDataObject interface exposed by
* the OLE clipboard.
*---------------------------------------------------------------------*/
REFIID riid,
void** ppvObject)
{
- /*
- * Declare "This" pointer
+ /*
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
+ OLEClipbrd *This = (OLEClipbrd *)iface;
TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObject);
-
+
/*
* Perform a sanity check on the parameters.
*/
if ( (This==0) || (ppvObject==0) )
return E_INVALIDARG;
-
+
/*
* Initialize the return parameter.
*/
/*
* Compare the riid with the interface IDs implemented by this object.
*/
- if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
+ if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
{
*ppvObject = iface;
}
- else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0)
+ else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0)
{
*ppvObject = (IDataObject*)&(This->lpvtbl1);
}
WARN( "() : asking for unsupported interface %s\n", debugstr_guid(riid));
return E_NOINTERFACE;
}
-
+
/*
* Query Interface always increases the reference count by one when it is
- * successful.
+ * successful.
*/
IUnknown_AddRef((IUnknown*)*ppvObject);
*
* See Windows documentation for more details on IUnknown methods.
*/
-static ULONG WINAPI OLEClipbrd_IDataObject_AddRef(
+static ULONG WINAPI OLEClipbrd_IDataObject_AddRef(
IDataObject* iface)
{
- /*
- * Declare "This" pointer
+ /*
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
+ OLEClipbrd *This = (OLEClipbrd *)iface;
TRACE("(%p)->(count=%lu)\n",This, This->ref);
-
- This->ref++;
- return This->ref;
+ return InterlockedIncrement(&This->ref);
+
}
/************************************************************************
*
* See Windows documentation for more details on IUnknown methods.
*/
-static ULONG WINAPI OLEClipbrd_IDataObject_Release(
+static ULONG WINAPI OLEClipbrd_IDataObject_Release(
IDataObject* iface)
{
- /*
- * Declare "This" pointer
+ /*
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
+ OLEClipbrd *This = (OLEClipbrd *)iface;
+ ULONG ref;
TRACE("(%p)->(count=%lu)\n",This, This->ref);
-
+
/*
* Decrease the reference count on this object.
*/
- This->ref--;
+ ref = InterlockedDecrement(&This->ref);
/*
* If the reference count goes down to 0, perform suicide.
*/
- if (This->ref==0)
+ if (ref == 0)
{
OLEClipbrd_Destroy(This);
}
-
- return This->ref;
+
+ return ref;
}
-
+
/************************************************************************
* OLEClipbrd_IDataObject_GetData (IDataObject)
*
- * The OLE Clipboard's implementation of this method delegates to
+ * The OLE Clipboard's implementation of this method delegates to
* a data source if there is one or wraps around the windows clipboard
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI OLEClipbrd_IDataObject_GetData(
IDataObject* iface,
- LPFORMATETC pformatetcIn,
+ LPFORMATETC pformatetcIn,
STGMEDIUM* pmedium)
{
HANDLE hData = 0;
BOOL bClipboardOpen = FALSE;
HRESULT hr = S_OK;
+ LPVOID src;
/*
- * Declare "This" pointer
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
-
+ OLEClipbrd *This = (OLEClipbrd *)iface;
+
TRACE("(%p,%p,%p)\n", iface, pformatetcIn, pmedium);
if ( !pformatetcIn || !pmedium )
return DV_E_DVASPECT;
*/
- /*
+ /*
* Otherwise, get the data from the windows clipboard using GetClipboardData
*/
if ( !(bClipboardOpen = OpenClipboard(theOleClipboard->hWndClipboard)) )
hData = GetClipboardData(pformatetcIn->cfFormat);
- /*
+ /* Must make a copy of global handle returned by GetClipboardData; it
+ * is not valid after we call CloseClipboard
+ * Application is responsible for freeing the memory (Forte Agent does this)
+ */
+ src = GlobalLock(hData);
+ if(src) {
+ LPVOID dest;
+ ULONG size;
+ HANDLE hDest;
+
+ size = GlobalSize(hData);
+ hDest = GlobalAlloc(GHND, size);
+ dest = GlobalLock(hDest);
+ memcpy(dest, src, size);
+ GlobalUnlock(hDest);
+ GlobalUnlock(hData);
+ hData = hDest;
+ }
+
+ /*
* Return the clipboard data in the storage medium structure
*/
pmedium->tymed = (hData == 0) ? TYMED_NULL : TYMED_HGLOBAL;
pmedium->u.hGlobal = (HGLOBAL)hData;
pmedium->pUnkForRelease = NULL;
-
+
hr = S_OK;
-
+
CLEANUP:
/*
* Close Windows clipboard
}
static HRESULT WINAPI OLEClipbrd_IDataObject_GetDataHere(
- IDataObject* iface,
+ IDataObject* iface,
LPFORMATETC pformatetc,
STGMEDIUM* pmedium)
{
/************************************************************************
* OLEClipbrd_IDataObject_QueryGetData (IDataObject)
*
- * The OLE Clipboard's implementation of this method delegates to
+ * The OLE Clipboard's implementation of this method delegates to
* a data source if there is one or wraps around the windows clipboard
* function IsClipboardFormatAvailable() otherwise.
*
IDataObject* iface,
LPFORMATETC pformatetc)
{
- /*
- * Declare "This" pointer
+ /*
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
+ OLEClipbrd *This = (OLEClipbrd *)iface;
TRACE("(%p, %p)\n", iface, pformatetc);
*/
if ( pformatetc->tymed != TYMED_HGLOBAL )
return DV_E_TYMED;
-
+
/*
* Delegate to the Windows clipboard function IsClipboardFormatAvailable
*/
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI OLEClipbrd_IDataObject_GetCanonicalFormatEtc(
- IDataObject* iface,
- LPFORMATETC pformatectIn,
+ IDataObject* iface,
+ LPFORMATETC pformatectIn,
LPFORMATETC pformatetcOut)
{
TRACE("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut);
/************************************************************************
* OLEClipbrd_IDataObject_SetData (IDataObject)
*
- * The OLE Clipboard's does not implement this method
+ * The OLE Clipboard's does not implement this method
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI OLEClipbrd_IDataObject_SetData(
IDataObject* iface,
- LPFORMATETC pformatetc,
- STGMEDIUM* pmedium,
+ LPFORMATETC pformatetc,
+ STGMEDIUM* pmedium,
BOOL fRelease)
{
TRACE("\n");
int cfmt, i;
UINT format;
BOOL bClipboardOpen;
-
- /*
- * Declare "This" pointer
+
+ /*
+ * Declare "This" pointer
*/
- ICOM_THIS(OLEClipbrd, iface);
+ OLEClipbrd *This = (OLEClipbrd *)iface;
TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
* and create an IEnumFORMATETC enumerator from this list.
*/
cfmt = CountClipboardFormats();
- afmt = (FORMATETC *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+ afmt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(FORMATETC) * cfmt);
/*
* Open the Windows clipboard, associating it with our hidden window
ERR("EnumClipboardFormats failed to return format!\n");
HANDLE_ERROR( E_FAIL );
}
-
+
/* Init the FORMATETC struct */
afmt[i].cfFormat = format;
afmt[i].ptd = NULL;
if (FAILED( hr = IEnumFORMATETC_AddRef(*ppenumFormatEtc)))
HANDLE_ERROR( hr );
-
+
hr = S_OK;
-
+
CLEANUP:
/*
* Free the array of FORMATETC's
*/
- if (afmt)
- HeapFree(GetProcessHeap(), 0, afmt);
-
+ HeapFree(GetProcessHeap(), 0, afmt);
+
/*
* Close Windows clipboard
*/
/************************************************************************
* OLEClipbrd_IDataObject_DAdvise (IDataObject)
*
- * The OLE Clipboard's does not implement this method
+ * The OLE Clipboard's does not implement this method
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI OLEClipbrd_IDataObject_DAdvise(
- IDataObject* iface,
- FORMATETC* pformatetc,
- DWORD advf,
- IAdviseSink* pAdvSink,
+ IDataObject* iface,
+ FORMATETC* pformatetc,
+ DWORD advf,
+ IAdviseSink* pAdvSink,
DWORD* pdwConnection)
{
TRACE("\n");
/************************************************************************
* OLEClipbrd_IDataObject_DUnadvise (IDataObject)
*
- * The OLE Clipboard's does not implement this method
+ * The OLE Clipboard's does not implement this method
*
* See Windows documentation for more details on IDataObject methods.
*/
IEnumFORMATETCImpl* ef;
DWORD size=cfmt * sizeof(FORMATETC);
LPMALLOC pIMalloc;
-
- ef = (IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(IEnumFORMATETCImpl));
+
+ ef = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
if (!ef)
return NULL;
-
+
ef->ref = 0;
- ICOM_VTBL(ef) = &efvt;
+ ef->lpVtbl = &efvt;
ef->pUnkDataObj = pUnkDataObj;
-
+
ef->posFmt = 0;
ef->countFmt = cfmt;
- if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)))
+ if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) {
+ HeapFree(GetProcessHeap(), 0, ef);
return NULL;
+ }
ef->pFmt = (LPFORMATETC)IMalloc_Alloc(pIMalloc, size);
IMalloc_Release(pIMalloc);
-
+
if (ef->pFmt)
memcpy(ef->pFmt, afmt, size);
-
+
TRACE("(%p)->()\n",ef);
return (LPENUMFORMATETC)ef;
}
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_QueryInterface
(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
/*
- * Since enumerators are seperate objects from the parent data object
+ * Since enumerators are separate objects from the parent data object
* we only need to support the IUnknown and IEnumFORMATETC interfaces
*/
-
+
*ppvObj = NULL;
-
+
if(IsEqualIID(riid, &IID_IUnknown))
{
*ppvObj = This;
else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
{
*ppvObj = (IDataObject*)This;
- }
-
+ }
+
if(*ppvObj)
{
IEnumFORMATETC_AddRef((IEnumFORMATETC*)*ppvObj);
TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
return S_OK;
}
-
+
TRACE("-- Interface: E_NOINTERFACE\n");
return E_NOINTERFACE;
}
*/
static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
TRACE("(%p)->(count=%lu)\n",This, This->ref);
if (This->pUnkDataObj)
IUnknown_AddRef(This->pUnkDataObj);
-
- return ++(This->ref);
+
+ return InterlockedIncrement(&This->ref);
}
/************************************************************************
*/
static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
LPMALLOC pIMalloc;
+ ULONG ref;
TRACE("(%p)->(count=%lu)\n",This, This->ref);
if (This->pUnkDataObj)
IUnknown_Release(This->pUnkDataObj); /* Release parent data object */
-
- if (!--(This->ref))
+
+ ref = InterlockedDecrement(&This->ref);
+ if (!ref)
{
TRACE("() - destroying IEnumFORMATETC(%p)\n",This);
if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)))
IMalloc_Free(pIMalloc, This->pFmt);
IMalloc_Release(pIMalloc);
}
-
+
HeapFree(GetProcessHeap(),0,This);
- return 0;
}
-
- return This->ref;
+ return ref;
}
/************************************************************************
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Next
(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
UINT cfetch;
HRESULT hres = S_FALSE;
-
+
TRACE("(%p)->(pos=%u)\n", This, This->posFmt);
-
+
if (This->posFmt < This->countFmt)
{
cfetch = This->countFmt - This->posFmt;
cfetch = celt;
hres = S_OK;
}
-
+
memcpy(rgelt, &This->pFmt[This->posFmt], cfetch * sizeof(FORMATETC));
This->posFmt += cfetch;
}
{
cfetch = 0;
}
-
+
if (pceltFethed)
{
*pceltFethed = cfetch;
}
-
+
return hres;
}
*/
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface, ULONG celt)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
TRACE("(%p)->(num=%lu)\n", This, celt);
-
+
This->posFmt += celt;
if (This->posFmt > This->countFmt)
{
*/
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
TRACE("(%p)->()\n", This);
-
+
This->posFmt = 0;
return S_OK;
}
static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Clone
(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
{
- ICOM_THIS(IEnumFORMATETCImpl,iface);
+ IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
HRESULT hr = S_OK;
-
+
TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
if ( !ppenum )
if (FAILED( hr = IEnumFORMATETC_AddRef(*ppenum)))
return ( hr );
-
+
return (*ppenum) ? S_OK : E_OUTOFMEMORY;
}
-