1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* HGLOBAL Stream implementation
|
|
|
|
*
|
|
|
|
* This file contains the implementation of the stream interface
|
1999-12-27 06:26:00 +01:00
|
|
|
* for streams contained supported by an HGLOBAL pointer.
|
1999-04-24 14:00:31 +02:00
|
|
|
*
|
|
|
|
* Copyright 1999 Francis Beaudet
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
1999-04-24 14:00:31 +02:00
|
|
|
*/
|
2001-07-20 20:00:00 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-04-24 14:00:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "ole2.h"
|
1999-04-24 14:00:31 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(storage);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* HGLOBALStreamImpl definition.
|
|
|
|
*
|
|
|
|
* This class imlements the IStream inteface and represents a stream
|
|
|
|
* supported by an HGLOBAL pointer.
|
|
|
|
*/
|
|
|
|
struct HGLOBALStreamImpl
|
|
|
|
{
|
2004-08-12 21:52:49 +02:00
|
|
|
IStreamVtbl *lpVtbl; /* Needs to be the first item in the stuct
|
1999-10-31 02:59:23 +01:00
|
|
|
* since we want to cast this in a IStream pointer */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Reference count
|
|
|
|
*/
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for the stream
|
|
|
|
*/
|
|
|
|
HGLOBAL supportHandle;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This flag is TRUE if the HGLOBAL is destroyed when the stream
|
|
|
|
* is finally released.
|
|
|
|
*/
|
|
|
|
BOOL deleteOnRelease;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper variable that contains the size of the stream
|
|
|
|
*/
|
|
|
|
ULARGE_INTEGER streamSize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the current position of the cursor in the stream
|
|
|
|
*/
|
|
|
|
ULARGE_INTEGER currentPosition;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct HGLOBALStreamImpl HGLOBALStreamImpl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Method definition for the StgStreamImpl class.
|
|
|
|
*/
|
|
|
|
HGLOBALStreamImpl* HGLOBALStreamImpl_Construct(
|
|
|
|
HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease);
|
|
|
|
|
|
|
|
void HGLOBALStreamImpl_Destroy(
|
|
|
|
HGLOBALStreamImpl* This);
|
|
|
|
|
|
|
|
void HGLOBALStreamImpl_OpenBlockChain(
|
|
|
|
HGLOBALStreamImpl* This);
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(
|
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
REFIID riid, /* [in] */
|
|
|
|
void** ppvObject); /* [iid_is][out] */
|
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
ULONG WINAPI HGLOBALStreamImpl_AddRef(
|
|
|
|
IStream* iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
ULONG WINAPI HGLOBALStreamImpl_Release(
|
|
|
|
IStream* iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Read(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
|
|
|
void* pv, /* [length_is][size_is][out] */
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbRead); /* [out] */
|
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Write(
|
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const void* pv, /* [size_is][in] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbWritten); /* [out] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Seek(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
LARGE_INTEGER dlibMove, /* [in] */
|
|
|
|
DWORD dwOrigin, /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
ULARGE_INTEGER* plibNewPosition); /* [out] */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_SetSize(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libNewSize); /* [in] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_CopyTo(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
IStream* pstm, /* [unique][in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
ULARGE_INTEGER* pcbRead, /* [out] */
|
|
|
|
ULARGE_INTEGER* pcbWritten); /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Commit(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfCommitFlags); /* [in] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Revert(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_LockRegion(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType); /* [in] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType); /* [in] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Stat(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
|
|
|
STATSTG* pstatstg, /* [out] */
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfStatFlag); /* [in] */
|
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Clone(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
IStream** ppstm); /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual function table for the HGLOBALStreamImpl class.
|
|
|
|
*/
|
|
|
|
static ICOM_VTABLE(IStream) HGLOBALStreamImpl_Vtbl =
|
|
|
|
{
|
1999-05-22 13:41:38 +02:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
1999-04-24 14:00:31 +02:00
|
|
|
HGLOBALStreamImpl_QueryInterface,
|
|
|
|
HGLOBALStreamImpl_AddRef,
|
|
|
|
HGLOBALStreamImpl_Release,
|
|
|
|
HGLOBALStreamImpl_Read,
|
|
|
|
HGLOBALStreamImpl_Write,
|
|
|
|
HGLOBALStreamImpl_Seek,
|
|
|
|
HGLOBALStreamImpl_SetSize,
|
|
|
|
HGLOBALStreamImpl_CopyTo,
|
|
|
|
HGLOBALStreamImpl_Commit,
|
|
|
|
HGLOBALStreamImpl_Revert,
|
|
|
|
HGLOBALStreamImpl_LockRegion,
|
|
|
|
HGLOBALStreamImpl_UnlockRegion,
|
|
|
|
HGLOBALStreamImpl_Stat,
|
|
|
|
HGLOBALStreamImpl_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CreateStreamOnHGlobal [OLE32.@]
|
1999-04-24 14:00:31 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI CreateStreamOnHGlobal(
|
2002-06-01 01:06:46 +02:00
|
|
|
HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease,
|
1999-04-24 14:00:31 +02:00
|
|
|
LPSTREAM* ppstm)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* newStream;
|
|
|
|
|
|
|
|
newStream = HGLOBALStreamImpl_Construct(hGlobal,
|
|
|
|
fDeleteOnRelease);
|
|
|
|
|
|
|
|
if (newStream!=NULL)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
return IUnknown_QueryInterface((IUnknown*)newStream,
|
1999-04-24 14:00:31 +02:00
|
|
|
&IID_IStream,
|
|
|
|
(void**)ppstm);
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
1999-05-08 12:48:44 +02:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* GetHGlobalFromStream [OLE32.@]
|
1999-05-08 12:48:44 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI GetHGlobalFromStream(IStream* pstm, HGLOBAL* phglobal)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* pStream;
|
|
|
|
|
|
|
|
if (pstm == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
pStream = (HGLOBALStreamImpl*) pstm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the stream object was created with CreateStreamOnHGlobal.
|
|
|
|
*/
|
2003-04-10 20:17:34 +02:00
|
|
|
if (pStream->lpVtbl == &HGLOBALStreamImpl_Vtbl)
|
1999-05-08 12:48:44 +02:00
|
|
|
*phglobal = pStream->supportHandle;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*phglobal = 0;
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/******************************************************************************
|
|
|
|
** HGLOBALStreamImpl implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is the constructor for the HGLOBALStreamImpl class.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* hGlobal - Handle that will support the stream. can be NULL.
|
2002-06-01 01:06:46 +02:00
|
|
|
* fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released
|
1999-04-24 14:00:31 +02:00
|
|
|
* when the IStream object is destroyed.
|
|
|
|
*/
|
|
|
|
HGLOBALStreamImpl* HGLOBALStreamImpl_Construct(
|
|
|
|
HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* newStream;
|
|
|
|
|
|
|
|
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALStreamImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
if (newStream!=0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set-up the virtual function table and reference count.
|
|
|
|
*/
|
2003-04-10 20:17:34 +02:00
|
|
|
newStream->lpVtbl = &HGLOBALStreamImpl_Vtbl;
|
1999-04-24 14:00:31 +02:00
|
|
|
newStream->ref = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Initialize the support.
|
|
|
|
*/
|
|
|
|
newStream->supportHandle = hGlobal;
|
|
|
|
newStream->deleteOnRelease = fDeleteOnRelease;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method will allocate a handle if one is not supplied.
|
|
|
|
*/
|
2000-11-25 02:40:34 +01:00
|
|
|
if (!newStream->supportHandle)
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
2000-07-08 13:46:16 +02:00
|
|
|
newStream->supportHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD |
|
|
|
|
GMEM_SHARE, 0);
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
2001-10-22 21:04:32 +02:00
|
|
|
* Start the stream at the beginning.
|
1999-04-24 14:00:31 +02:00
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newStream->currentPosition.u.HighPart = 0;
|
|
|
|
newStream->currentPosition.u.LowPart = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Initialize the size of the stream to the size of the handle.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newStream->streamSize.u.HighPart = 0;
|
|
|
|
newStream->streamSize.u.LowPart = GlobalSize(newStream->supportHandle);
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return newStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is the destructor of the HGLOBALStreamImpl class.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method will clean-up all the resources used-up by the given HGLOBALStreamImpl
|
1999-04-24 14:00:31 +02:00
|
|
|
* class. The pointer passed-in to this function will be freed and will not
|
|
|
|
* be valid anymore.
|
|
|
|
*/
|
|
|
|
void HGLOBALStreamImpl_Destroy(HGLOBALStreamImpl* This)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n", This);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Release the HGlobal if the constructor asked for that.
|
|
|
|
*/
|
|
|
|
if (This->deleteOnRelease)
|
|
|
|
{
|
|
|
|
GlobalFree(This->supportHandle);
|
|
|
|
This->supportHandle=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, free the memory used-up by the class.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method QueryInterface for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(
|
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
REFIID riid, /* [in] */
|
|
|
|
void** ppvObject) /* [iid_is][out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if (ppvObject==0)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Initialize the return parameter.
|
|
|
|
*/
|
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Compare the riid with the interface IDs implemented by this object.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
*ppvObject = (IStream*)This;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0)
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
*ppvObject = (IStream*)This;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
return E_NOINTERFACE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
|
|
|
HGLOBALStreamImpl_AddRef(iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method AddRef for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
ULONG WINAPI HGLOBALStreamImpl_AddRef(
|
|
|
|
IStream* iface)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
This->ref++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return This->ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method Release for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
ULONG WINAPI HGLOBALStreamImpl_Release(
|
|
|
|
IStream* iface)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
ULONG newRef;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
This->ref--;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
newRef = This->ref;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
|
|
|
if (newRef==0)
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl_Destroy(This);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return newRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the ISequentialStream interface.
|
|
|
|
*
|
|
|
|
* If reads a block of information from the stream at the current
|
|
|
|
* position. It then moves the current position at the end of the
|
|
|
|
* read block
|
|
|
|
*
|
|
|
|
* See the documentation of ISequentialStream for more info.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Read(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
|
|
|
void* pv, /* [length_is][size_is][out] */
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbRead) /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
void* supportBuffer;
|
|
|
|
ULONG bytesReadBuffer;
|
|
|
|
ULONG bytesToReadFromBuffer;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p, %ld, %p)\n", iface,
|
1999-05-02 13:41:10 +02:00
|
|
|
pv, cb, pcbRead);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
/*
|
1999-04-24 14:00:31 +02:00
|
|
|
* If the caller is not interested in the nubmer of bytes read,
|
|
|
|
* we use another buffer to avoid "if" statements in the code.
|
|
|
|
*/
|
|
|
|
if (pcbRead==0)
|
|
|
|
pcbRead = &bytesReadBuffer;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Using the known size of the stream, calculate the number of bytes
|
|
|
|
* to read from the block chain
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the buffer in position and copy the data.
|
|
|
|
*/
|
|
|
|
supportBuffer = GlobalLock(This->supportHandle);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
memcpy(pv, (char *) supportBuffer+This->currentPosition.u.LowPart, bytesToReadFromBuffer);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the current position to the new position
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
This->currentPosition.u.LowPart+=bytesToReadFromBuffer;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of bytes read.
|
|
|
|
*/
|
|
|
|
*pcbRead = bytesToReadFromBuffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
|
|
|
GlobalUnlock(This->supportHandle);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* The function returns S_OK if the buffer was filled completely
|
|
|
|
* it returns S_FALSE if the end of the stream is reached before the
|
|
|
|
* buffer is filled
|
|
|
|
*/
|
|
|
|
if(*pcbRead == cb)
|
|
|
|
return S_OK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/***
|
|
|
|
* This method is part of the ISequentialStream interface.
|
|
|
|
*
|
|
|
|
* It writes a block of information to the stream at the current
|
|
|
|
* position. It then moves the current position at the end of the
|
|
|
|
* written block. If the stream is too small to fit the block,
|
|
|
|
* the stream is grown to fit.
|
|
|
|
*
|
|
|
|
* See the documentation of ISequentialStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Write(
|
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const void* pv, /* [size_is][in] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbWritten) /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
void* supportBuffer;
|
|
|
|
ULARGE_INTEGER newSize;
|
|
|
|
ULONG bytesWritten = 0;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p, %ld, %p)\n", iface,
|
1999-05-02 13:41:10 +02:00
|
|
|
pv, cb, pcbWritten);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* If the caller is not interested in the number of bytes written,
|
|
|
|
* we use another buffer to avoid "if" statements in the code.
|
|
|
|
*/
|
|
|
|
if (pcbWritten == 0)
|
|
|
|
pcbWritten = &bytesWritten;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
if (cb == 0)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
newSize.u.HighPart = 0;
|
|
|
|
newSize.u.LowPart = This->currentPosition.u.LowPart + cb;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Verify if we need to grow the stream
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart > This->streamSize.u.LowPart)
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
/* grow stream */
|
1999-05-02 13:41:10 +02:00
|
|
|
IStream_SetSize(iface, newSize);
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Lock the buffer in position and copy the data.
|
|
|
|
*/
|
|
|
|
supportBuffer = GlobalLock(This->supportHandle);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
memcpy((char *) supportBuffer+This->currentPosition.u.LowPart, pv, cb);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the current position to the new position
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
This->currentPosition.u.LowPart+=cb;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of bytes read.
|
|
|
|
*/
|
|
|
|
*pcbWritten = cb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
|
|
|
GlobalUnlock(This->supportHandle);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will move the current stream pointer according to the parameters
|
|
|
|
* given.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Seek(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
LARGE_INTEGER dlibMove, /* [in] */
|
|
|
|
DWORD dwOrigin, /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
ULARGE_INTEGER* plibNewPosition) /* [out] */
|
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
ULARGE_INTEGER newPosition;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
TRACE("(%p, %lx%08lx, %ld, %p)\n", iface, dlibMove.u.HighPart,
|
|
|
|
dlibMove.u.LowPart, dwOrigin, plibNewPosition);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* The file pointer is moved depending on the given "function"
|
|
|
|
* parameter.
|
|
|
|
*/
|
|
|
|
switch (dwOrigin)
|
|
|
|
{
|
|
|
|
case STREAM_SEEK_SET:
|
2004-01-23 02:51:33 +01:00
|
|
|
newPosition.u.HighPart = 0;
|
|
|
|
newPosition.u.LowPart = 0;
|
1999-04-24 14:00:31 +02:00
|
|
|
break;
|
|
|
|
case STREAM_SEEK_CUR:
|
2002-07-01 20:10:34 +02:00
|
|
|
newPosition = This->currentPosition;
|
1999-04-24 14:00:31 +02:00
|
|
|
break;
|
|
|
|
case STREAM_SEEK_END:
|
2002-07-01 20:10:34 +02:00
|
|
|
newPosition = This->streamSize;
|
1999-04-24 14:00:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the actual file pointer
|
|
|
|
* If the file pointer ends-up after the end of the stream, the next Write operation will
|
|
|
|
* make the file larger. This is how it is documented.
|
|
|
|
*/
|
2002-07-01 20:10:34 +02:00
|
|
|
newPosition.QuadPart = RtlLargeIntegerAdd(newPosition.QuadPart, dlibMove.QuadPart);
|
|
|
|
if (newPosition.QuadPart < 0) return STG_E_INVALIDFUNCTION;
|
|
|
|
|
|
|
|
if (plibNewPosition) *plibNewPosition = newPosition;
|
|
|
|
This->currentPosition = newPosition;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will change the size of a stream.
|
|
|
|
*
|
|
|
|
* TODO: Switch from small blocks to big blocks and vice versa.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_SetSize(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libNewSize) /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
2003-11-26 04:36:18 +01:00
|
|
|
HGLOBAL supportHandle;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
TRACE("(%p, %ld)\n", iface, libNewSize.u.LowPart);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
if (libNewSize.u.HighPart != 0)
|
1999-04-24 14:00:31 +02:00
|
|
|
return STG_E_INVALIDFUNCTION;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
|
1999-04-24 14:00:31 +02:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re allocate the HGlobal to fit the new size of the stream.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0);
|
2003-11-26 04:36:18 +01:00
|
|
|
|
|
|
|
if (supportHandle == 0)
|
|
|
|
return STG_E_MEDIUMFULL;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2003-11-26 04:36:18 +01:00
|
|
|
This->supportHandle = supportHandle;
|
2004-01-23 02:51:33 +01:00
|
|
|
This->streamSize.u.LowPart = libNewSize.u.LowPart;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will copy the 'cb' Bytes to 'pstm' IStream.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_CopyTo(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
IStream* pstm, /* [unique][in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
ULARGE_INTEGER* pcbRead, /* [out] */
|
|
|
|
ULARGE_INTEGER* pcbWritten) /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BYTE tmpBuffer[128];
|
|
|
|
ULONG bytesRead, bytesWritten, copySize;
|
|
|
|
ULARGE_INTEGER totalBytesRead;
|
|
|
|
ULARGE_INTEGER totalBytesWritten;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("(%p, %p, %ld, %p, %p)\n", iface, pstm,
|
2004-01-23 02:51:33 +01:00
|
|
|
cb.u.LowPart, pcbRead, pcbWritten);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-04-24 14:00:31 +02:00
|
|
|
/*
|
|
|
|
* Sanity check
|
|
|
|
*/
|
|
|
|
if ( pstm == 0 )
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
totalBytesRead.u.LowPart = totalBytesRead.u.HighPart = 0;
|
|
|
|
totalBytesWritten.u.LowPart = totalBytesWritten.u.HighPart = 0;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* use stack to store data temporarly
|
|
|
|
* there is surely more performant way of doing it, for now this basic
|
|
|
|
* implementation will do the job
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
while ( cb.u.LowPart > 0 )
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
if ( cb.u.LowPart >= 128 )
|
1999-04-24 14:00:31 +02:00
|
|
|
copySize = 128;
|
|
|
|
else
|
2004-01-23 02:51:33 +01:00
|
|
|
copySize = cb.u.LowPart;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
totalBytesRead.u.LowPart += bytesRead;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
|
1999-04-24 14:00:31 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
totalBytesWritten.u.LowPart += bytesWritten;
|
1999-04-24 14:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that read & write operations were succesfull
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
if (bytesRead != bytesWritten)
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
hr = STG_E_MEDIUMFULL;
|
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
if (bytesRead!=copySize)
|
2004-01-23 02:51:33 +01:00
|
|
|
cb.u.LowPart = 0;
|
1999-05-02 13:41:10 +02:00
|
|
|
else
|
2004-01-23 02:51:33 +01:00
|
|
|
cb.u.LowPart -= bytesRead;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update number of bytes read and written
|
|
|
|
*/
|
|
|
|
if (pcbRead)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
pcbRead->u.LowPart = totalBytesRead.u.LowPart;
|
|
|
|
pcbRead->u.HighPart = totalBytesRead.u.HighPart;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pcbWritten)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
pcbWritten->u.LowPart = totalBytesWritten.u.LowPart;
|
|
|
|
pcbWritten->u.HighPart = totalBytesWritten.u.HighPart;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* For streams supported by HGLOBALS, this function does nothing.
|
1999-04-24 14:00:31 +02:00
|
|
|
* This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Commit(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfCommitFlags) /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* For streams supported by HGLOBALS, this function does nothing.
|
1999-04-24 14:00:31 +02:00
|
|
|
* This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Revert(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* For streams supported by HGLOBALS, this function does nothing.
|
1999-04-24 14:00:31 +02:00
|
|
|
* This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_LockRegion(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* For streams supported by HGLOBALS, this function does nothing.
|
1999-04-24 14:00:31 +02:00
|
|
|
* This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* This method returns information about the current
|
|
|
|
* stream.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Stat(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
|
|
|
STATSTG* pstatstg, /* [out] */
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfStatFlag) /* [in] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
|
|
|
|
memset(pstatstg, 0, sizeof(STATSTG));
|
|
|
|
|
|
|
|
pstatstg->pwcsName = NULL;
|
|
|
|
pstatstg->type = STGTY_STREAM;
|
|
|
|
pstatstg->cbSize = This->streamSize;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI HGLOBALStreamImpl_Clone(
|
1999-04-24 14:00:31 +02:00
|
|
|
IStream* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
IStream** ppstm) /* [out] */
|
1999-04-24 14:00:31 +02:00
|
|
|
{
|
2002-11-12 03:13:49 +01:00
|
|
|
ULARGE_INTEGER dummy;
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
HRESULT hr;
|
|
|
|
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
|
|
|
|
TRACE(" Cloning %p (deleteOnRelease=%d seek position=%ld)\n",iface,This->deleteOnRelease,(long)This->currentPosition.QuadPart);
|
|
|
|
hr=CreateStreamOnHGlobal(This->supportHandle, FALSE, ppstm);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
offset.QuadPart=(LONGLONG)This->currentPosition.QuadPart;
|
|
|
|
HGLOBALStreamImpl_Seek(*ppstm,offset,STREAM_SEEK_SET,&dummy);
|
|
|
|
return S_OK;
|
1999-04-24 14:00:31 +02:00
|
|
|
}
|