📄 datacache.c
字号:
NULL);
streamInfo.cbSize.u.LowPart -= offset.u.LowPart;
/*
* Allocate a buffer for the metafile bits.
*/
metafileBits = HeapAlloc(GetProcessHeap(),
0,
streamInfo.cbSize.u.LowPart);
/*
* Read the metafile bits.
*/
hres = IStream_Read(
presStream,
metafileBits,
streamInfo.cbSize.u.LowPart,
NULL);
/*
* Create a metafile with those bits.
*/
if (SUCCEEDED(hres))
{
newMetafile = SetMetaFileBitsEx(streamInfo.cbSize.u.LowPart, metafileBits);
}
/*
* Cleanup.
*/
HeapFree(GetProcessHeap(), 0, metafileBits);
IStream_Release(presStream);
if (newMetafile==0)
hres = E_FAIL;
return newMetafile;
}
/*********************************************************
* Method implementation for the non delegating IUnknown
* part of the DataCache class.
*/
/************************************************************************
* DataCache_NDIUnknown_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*
* This version of QueryInterface will not delegate it's implementation
* to the outer unknown.
*/
static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface(
IUnknown* iface,
REFIID riid,
void** ppvObject)
{
DataCache *this = impl_from_NDIUnknown(iface);
/*
* Perform a sanity check on the parameters.
*/
if ( (this==0) || (ppvObject==0) )
return E_INVALIDARG;
/*
* Initialize the return parameter.
*/
*ppvObject = 0;
/*
* Compare the riid with the interface IDs implemented by this object.
*/
if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
{
*ppvObject = iface;
}
else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0)
{
*ppvObject = (IDataObject*)&(this->lpVtbl);
}
else if ( (memcmp(&IID_IPersistStorage, riid, sizeof(IID_IPersistStorage)) == 0) ||
(memcmp(&IID_IPersist, riid, sizeof(IID_IPersist)) == 0) )
{
*ppvObject = (IPersistStorage*)&(this->lpvtblIPersistStorage);
}
else if ( (memcmp(&IID_IViewObject, riid, sizeof(IID_IViewObject)) == 0) ||
(memcmp(&IID_IViewObject2, riid, sizeof(IID_IViewObject2)) == 0) )
{
*ppvObject = (IViewObject2*)&(this->lpvtblIViewObject);
}
else if ( (memcmp(&IID_IOleCache, riid, sizeof(IID_IOleCache)) == 0) ||
(memcmp(&IID_IOleCache2, riid, sizeof(IID_IOleCache2)) == 0) )
{
*ppvObject = (IOleCache2*)&(this->lpvtblIOleCache2);
}
else if (memcmp(&IID_IOleCacheControl, riid, sizeof(IID_IOleCacheControl)) == 0)
{
*ppvObject = (IOleCacheControl*)&(this->lpvtblIOleCacheControl);
}
/*
* Check that we obtained an interface.
*/
if ((*ppvObject)==0)
{
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.
*/
IUnknown_AddRef((IUnknown*)*ppvObject);
return S_OK;
}
/************************************************************************
* DataCache_NDIUnknown_AddRef (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*
* This version of QueryInterface will not delegate it's implementation
* to the outer unknown.
*/
static ULONG WINAPI DataCache_NDIUnknown_AddRef(
IUnknown* iface)
{
DataCache *this = impl_from_NDIUnknown(iface);
return InterlockedIncrement(&this->ref);
}
/************************************************************************
* DataCache_NDIUnknown_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*
* This version of QueryInterface will not delegate it's implementation
* to the outer unknown.
*/
static ULONG WINAPI DataCache_NDIUnknown_Release(
IUnknown* iface)
{
DataCache *this = impl_from_NDIUnknown(iface);
ULONG ref;
/*
* Decrease the reference count on this object.
*/
ref = InterlockedDecrement(&this->ref);
/*
* If the reference count goes down to 0, perform suicide.
*/
if (ref == 0) DataCache_Destroy(this);
return ref;
}
/*********************************************************
* Method implementation for the IDataObject
* part of the DataCache class.
*/
/************************************************************************
* DataCache_IDataObject_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI DataCache_IDataObject_QueryInterface(
IDataObject* iface,
REFIID riid,
void** ppvObject)
{
DataCache *this = impl_from_IDataObject(iface);
return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
}
/************************************************************************
* DataCache_IDataObject_AddRef (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI DataCache_IDataObject_AddRef(
IDataObject* iface)
{
DataCache *this = impl_from_IDataObject(iface);
return IUnknown_AddRef(this->outerUnknown);
}
/************************************************************************
* DataCache_IDataObject_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI DataCache_IDataObject_Release(
IDataObject* iface)
{
DataCache *this = impl_from_IDataObject(iface);
return IUnknown_Release(this->outerUnknown);
}
/************************************************************************
* DataCache_GetData
*
* Get Data from a source dataobject using format pformatetcIn->cfFormat
* See Windows documentation for more details on GetData.
* TODO: Currently only CF_METAFILEPICT is implemented
*/
static HRESULT WINAPI DataCache_GetData(
IDataObject* iface,
LPFORMATETC pformatetcIn,
STGMEDIUM* pmedium)
{
HRESULT hr = 0;
HRESULT hrRet = E_UNEXPECTED;
IPersistStorage *pPersistStorage = 0;
IStorage *pStorage = 0;
IStream *pStream = 0;
OLECHAR name[]={ 2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0};
HGLOBAL hGlobalMF = 0;
void *mfBits = 0;
PresentationDataHeader pdh;
METAFILEPICT *mfPict;
HMETAFILE hMetaFile = 0;
if (pformatetcIn->cfFormat == CF_METAFILEPICT)
{
/* Get the Persist Storage */
hr = IDataObject_QueryInterface(iface, &IID_IPersistStorage, (void**)&pPersistStorage);
if (hr != S_OK)
goto cleanup;
/* Create a doc file to copy the doc to a storage */
hr = StgCreateDocfile(NULL, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage);
if (hr != S_OK)
goto cleanup;
/* Save it to storage */
hr = OleSave(pPersistStorage, pStorage, FALSE);
if (hr != S_OK)
goto cleanup;
/* Open the Presentation data srteam */
hr = IStorage_OpenStream(pStorage, name, 0, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &pStream);
if (hr != S_OK)
goto cleanup;
/* Read the presentation header */
hr = IStream_Read(pStream, &pdh, sizeof(PresentationDataHeader), NULL);
if (hr != S_OK)
goto cleanup;
mfBits = HeapAlloc(GetProcessHeap(), 0, pdh.dwSize);
/* Read the Metafile bits */
hr = IStream_Read(pStream, mfBits, pdh.dwSize, NULL);
if (hr != S_OK)
goto cleanup;
/* Create the metafile and place it in the STGMEDIUM structure */
hMetaFile = SetMetaFileBitsEx(pdh.dwSize, mfBits);
hGlobalMF = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, sizeof(METAFILEPICT));
mfPict = (METAFILEPICT *)GlobalLock(hGlobalMF);
mfPict->hMF = hMetaFile;
GlobalUnlock(hGlobalMF);
pmedium->u.hGlobal = hGlobalMF;
pmedium->tymed = TYMED_MFPICT;
hrRet = S_OK;
cleanup:
HeapFree(GetProcessHeap(), 0, mfBits);
if (pStream)
IStream_Release(pStream);
if (pStorage)
IStorage_Release(pStorage);
if (pPersistStorage)
IPersistStorage_Release(pPersistStorage);
return hrRet;
}
/* TODO: Other formats are not implemented */
return E_NOTIMPL;
}
static HRESULT WINAPI DataCache_GetDataHere(
IDataObject* iface,
LPFORMATETC pformatetc,
STGMEDIUM* pmedium)
{
FIXME("stub\n");
return E_NOTIMPL;
}
static HRESULT WINAPI DataCache_QueryGetData(
IDataObject* iface,
LPFORMATETC pformatetc)
{
FIXME("stub\n");
return E_NOTIMPL;
}
/************************************************************************
* DataCache_EnumFormatEtc (IDataObject)
*
* The data cache doesn't implement this method.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_GetCanonicalFormatEtc(
IDataObject* iface,
LPFORMATETC pformatectIn,
LPFORMATETC pformatetcOut)
{
TRACE("()\n");
return E_NOTIMPL;
}
/************************************************************************
* DataCache_IDataObject_SetData (IDataObject)
*
* This method is delegated to the IOleCache2 implementation.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_IDataObject_SetData(
IDataObject* iface,
LPFORMATETC pformatetc,
STGMEDIUM* pmedium,
BOOL fRelease)
{
IOleCache2* oleCache = NULL;
HRESULT hres;
TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
hres = IDataObject_QueryInterface(iface, &IID_IOleCache2, (void**)&oleCache);
if (FAILED(hres))
return E_UNEXPECTED;
hres = IOleCache2_SetData(oleCache, pformatetc, pmedium, fRelease);
IOleCache2_Release(oleCache);
return hres;
}
/************************************************************************
* DataCache_EnumFormatEtc (IDataObject)
*
* The data cache doesn't implement this method.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_EnumFormatEtc(
IDataObject* iface,
DWORD dwDirection,
IEnumFORMATETC** ppenumFormatEtc)
{
TRACE("()\n");
return E_NOTIMPL;
}
/************************************************************************
* DataCache_DAdvise (IDataObject)
*
* The data cache doesn't support connections.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_DAdvise(
IDataObject* iface,
FORMATETC* pformatetc,
DWORD advf,
IAdviseSink* pAdvSink,
DWORD* pdwConnection)
{
TRACE("()\n");
return OLE_E_ADVISENOTSUPPORTED;
}
/************************************************************************
* DataCache_DUnadvise (IDataObject)
*
* The data cache doesn't support connections.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_DUnadvise(
IDataObject* iface,
DWORD dwConnection)
{
TRACE("()\n");
return OLE_E_NOCONNECTION;
}
/************************************************************************
* DataCache_EnumDAdvise (IDataObject)
*
* The data cache doesn't support connections.
*
* See Windows documentation for more details on IDataObject methods.
*/
static HRESULT WINAPI DataCache_EnumDAdvise(
IDataObject* iface,
IEnumSTATDATA** ppenumAdvise)
{
TRACE("()\n");
return OLE_E_ADVISENOTSUPPORTED;
}
/*********************************************************
* Method implementation for the IDataObject
* part of the DataCache class.
*/
/************************************************************************
* DataCache_IPersistStorage_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface(
IPersistStorage* iface,
REFIID riid,
void** ppvObject)
{
DataCache *this = impl_from_IPersistStorage(iface);
return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -