1999-05-01 12:36:07 +02:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Global memory implementation of ILockBytes.
|
|
|
|
*
|
|
|
|
* Copyright 1999 Thuy Nguyen
|
|
|
|
*
|
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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-05-01 12:36:07 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-01-05 02:04:34 +01:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-05-01 12:36:07 +02:00
|
|
|
#include <string.h>
|
2001-07-20 20:00:00 +02:00
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
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-05-01 12:36:07 +02:00
|
|
|
#include "winerror.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* HGLOBALLockBytesImpl definition.
|
|
|
|
*
|
2006-11-21 21:44:54 +01:00
|
|
|
* This class implements the ILockBytes interface and represents a byte array
|
1999-05-01 12:36:07 +02:00
|
|
|
* object supported by an HGLOBAL pointer.
|
|
|
|
*/
|
|
|
|
struct HGLOBALLockBytesImpl
|
|
|
|
{
|
|
|
|
/*
|
2005-03-23 14:15:18 +01:00
|
|
|
* Needs to be the first item in the struct
|
1999-05-01 12:36:07 +02:00
|
|
|
* since we want to cast this in an ILockBytes pointer
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
const ILockBytesVtbl *lpVtbl;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reference count
|
|
|
|
*/
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for the LockBytes object
|
|
|
|
*/
|
|
|
|
HGLOBAL supportHandle;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This flag is TRUE if the HGLOBAL is destroyed when the object
|
|
|
|
* is finally released.
|
|
|
|
*/
|
|
|
|
BOOL deleteOnRelease;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper variable that contains the size of the byte array
|
|
|
|
*/
|
|
|
|
ULARGE_INTEGER byteArraySize;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct HGLOBALLockBytesImpl HGLOBALLockBytesImpl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Method definition for the HGLOBALLockBytesImpl class.
|
|
|
|
*/
|
|
|
|
HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct(
|
|
|
|
HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease);
|
|
|
|
|
|
|
|
void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This);
|
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_SetSize( ILockBytes* iface, ULARGE_INTEGER libNewSize );
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static const ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CreateILockBytesOnHGlobal [OLE32.@]
|
2005-07-07 19:21:44 +02:00
|
|
|
*
|
|
|
|
* Create a byte array object which is intended to be the compound file foundation.
|
|
|
|
* This object supports a COM implementation of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hGlobal [ I] Global memory handle
|
|
|
|
* fDeleteOnRelease [ I] Whether the handle should be freed when the object is released.
|
|
|
|
* ppLkbyt [ O] Address of ILockBytes pointer that receives
|
|
|
|
* the interface pointer to the new byte array object.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The supplied ILockBytes pointer can be used by the StgCreateDocfileOnILockBytes
|
|
|
|
* function to build a compound file on top of this byte array object.
|
|
|
|
* The ILockBytes interface instance calls the GlobalReAlloc function to grow
|
|
|
|
* the memory block as required.
|
1999-05-01 12:36:07 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease,
|
|
|
|
LPLOCKBYTES* ppLkbyt)
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* newLockBytes;
|
|
|
|
|
|
|
|
newLockBytes = HGLOBALLockBytesImpl_Construct(hGlobal, fDeleteOnRelease);
|
|
|
|
|
|
|
|
if (newLockBytes != NULL)
|
|
|
|
{
|
|
|
|
return IUnknown_QueryInterface((IUnknown*)newLockBytes,
|
|
|
|
&IID_ILockBytes,
|
|
|
|
(void**)ppLkbyt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* GetHGlobalFromILockBytes [OLE32.@]
|
2005-07-07 19:21:44 +02:00
|
|
|
*
|
|
|
|
* Retrieve a global memory handle to a byte array object created
|
|
|
|
* using the CreateILockBytesOnHGlobal function.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* plkbyt [ I] Pointer to the ILockBytes interface on byte array object
|
|
|
|
* phglobal [ O] Address to store a global memory handle
|
|
|
|
* RETURNS
|
|
|
|
* S_OK if *phglobal has a correct value
|
|
|
|
* E_INVALIDARG if any parameters are invalid
|
|
|
|
*
|
1999-05-01 12:36:07 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* plkbyt, HGLOBAL* phglobal)
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const pMemLockBytes = (HGLOBALLockBytesImpl*)plkbyt;
|
2002-07-05 23:19:55 +02:00
|
|
|
STATSTG stbuf;
|
|
|
|
HRESULT hres;
|
|
|
|
ULARGE_INTEGER start;
|
|
|
|
ULONG xread;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2002-07-05 23:19:55 +02:00
|
|
|
*phglobal = 0;
|
2003-04-10 20:17:34 +02:00
|
|
|
if (pMemLockBytes->lpVtbl == &HGLOBALLockBytesImpl_Vtbl) {
|
1999-05-08 12:05:08 +02:00
|
|
|
*phglobal = pMemLockBytes->supportHandle;
|
2002-07-05 23:19:55 +02:00
|
|
|
if (*phglobal == 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
/* It is not our lockbytes implementation, so use a more generic way */
|
|
|
|
hres = ILockBytes_Stat(plkbyt,&stbuf,0);
|
|
|
|
if (hres != S_OK) {
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Cannot ILockBytes_Stat, %x\n",hres);
|
2002-07-05 23:19:55 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("cbSize is %d\n",stbuf.cbSize.u.LowPart);
|
2004-01-23 02:51:33 +01:00
|
|
|
*phglobal = GlobalAlloc( GMEM_MOVEABLE|GMEM_SHARE, stbuf.cbSize.u.LowPart);
|
2002-07-05 23:19:55 +02:00
|
|
|
if (!*phglobal)
|
1999-05-01 12:36:07 +02:00
|
|
|
return E_INVALIDARG;
|
2002-07-05 23:19:55 +02:00
|
|
|
memset(&start,0,sizeof(start));
|
2004-01-23 02:51:33 +01:00
|
|
|
hres = ILockBytes_ReadAt(plkbyt, start, GlobalLock(*phglobal), stbuf.cbSize.u.LowPart, &xread);
|
2002-07-05 23:19:55 +02:00
|
|
|
GlobalUnlock(*phglobal);
|
|
|
|
if (hres != S_OK) {
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("%p->ReadAt failed with %x\n",plkbyt,hres);
|
2002-07-05 23:19:55 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2004-01-23 02:51:33 +01:00
|
|
|
if (stbuf.cbSize.u.LowPart != xread) {
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("Read size is not requested size %d vs %d?\n",stbuf.cbSize.u.LowPart, xread);
|
2002-07-05 23:19:55 +02:00
|
|
|
}
|
1999-05-01 12:36:07 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* HGLOBALLockBytesImpl implementation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This is the constructor for the HGLOBALLockBytesImpl class.
|
|
|
|
*
|
2005-07-07 19:21:44 +02:00
|
|
|
* PARAMS
|
|
|
|
* hGlobal [ I] Handle that will support the stream. can be NULL.
|
|
|
|
* fDeleteOnRelease [ I] Flag set to TRUE if the HGLOBAL will be released
|
|
|
|
* when the IStream object is destroyed.
|
1999-05-01 12:36:07 +02:00
|
|
|
*/
|
|
|
|
HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct(HGLOBAL hGlobal,
|
|
|
|
BOOL fDeleteOnRelease)
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* newLockBytes;
|
|
|
|
newLockBytes = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALLockBytesImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-01 12:36:07 +02:00
|
|
|
if (newLockBytes!=0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set up the virtual function table and reference count.
|
|
|
|
*/
|
2003-04-10 20:17:34 +02:00
|
|
|
newLockBytes->lpVtbl = &HGLOBALLockBytesImpl_Vtbl;
|
1999-05-01 12:36:07 +02:00
|
|
|
newLockBytes->ref = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-01 12:36:07 +02:00
|
|
|
/*
|
|
|
|
* Initialize the support.
|
|
|
|
*/
|
|
|
|
newLockBytes->supportHandle = hGlobal;
|
|
|
|
newLockBytes->deleteOnRelease = fDeleteOnRelease;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method will allocate a handle if one is not supplied.
|
|
|
|
*/
|
|
|
|
if (newLockBytes->supportHandle == 0)
|
|
|
|
{
|
|
|
|
newLockBytes->supportHandle = GlobalAlloc(GMEM_MOVEABLE |
|
|
|
|
GMEM_NODISCARD,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the size of the array to the size of the handle.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newLockBytes->byteArraySize.u.HighPart = 0;
|
|
|
|
newLockBytes->byteArraySize.u.LowPart = GlobalSize(
|
1999-05-01 12:36:07 +02:00
|
|
|
newLockBytes->supportHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newLockBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This is the destructor of the HGLOBALStreamImpl class.
|
|
|
|
*
|
|
|
|
* This method will clean-up all the resources used-up by the given
|
|
|
|
* HGLOBALLockBytesImpl class. The pointer passed-in to this function will be
|
|
|
|
* freed and will not be valid anymore.
|
|
|
|
*/
|
|
|
|
void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This implements the IUnknown method QueryInterface for this
|
|
|
|
* class
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
REFIID riid, /* [in] */
|
|
|
|
void** ppvObject) /* [iid_is][out] */
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if (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 = (ILockBytes*)This;
|
|
|
|
}
|
|
|
|
else if (memcmp(&IID_ILockBytes, riid, sizeof(IID_ILockBytes)) == 0)
|
|
|
|
{
|
|
|
|
*ppvObject = (ILockBytes*)This;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
IUnknown_AddRef(iface);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
1999-05-01 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This implements the IUnknown method AddRef for this
|
|
|
|
* class
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
|
1999-05-01 12:36:07 +02:00
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-05-01 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This implements the IUnknown method Release for this
|
|
|
|
* class
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI HGLOBALLockBytesImpl_Release(ILockBytes* iface)
|
1999-05-01 12:36:07 +02:00
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
2004-09-24 03:16:53 +02:00
|
|
|
if (ref==0)
|
1999-05-01 12:36:07 +02:00
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl_Destroy(This);
|
|
|
|
}
|
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1999-05-01 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* It reads a block of information from the byte array at the specified
|
|
|
|
* offset.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_ReadAt(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
ULARGE_INTEGER ulOffset, /* [in] */
|
|
|
|
void* pv, /* [length_is][size_is][out] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbRead) /* [out] */
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
|
|
|
|
|
|
|
void* supportBuffer;
|
|
|
|
ULONG bytesReadBuffer = 0;
|
|
|
|
ULONG bytesToReadFromBuffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the caller is not interested in the number of bytes read,
|
|
|
|
* we use another buffer to avoid "if" statements in the code.
|
|
|
|
*/
|
|
|
|
if (pcbRead == 0)
|
|
|
|
pcbRead = &bytesReadBuffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the offset is valid.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
if (ulOffset.u.LowPart > This->byteArraySize.u.LowPart)
|
1999-05-01 12:36:07 +02:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Using the known size of the array, calculate the number of bytes
|
|
|
|
* to read.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
bytesToReadFromBuffer = min(This->byteArraySize.u.LowPart -
|
|
|
|
ulOffset.u.LowPart, cb);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the buffer in position and copy the data.
|
|
|
|
*/
|
|
|
|
supportBuffer = GlobalLock(This->supportHandle);
|
|
|
|
|
|
|
|
memcpy(pv,
|
2004-01-23 02:51:33 +01:00
|
|
|
(char *) supportBuffer + ulOffset.u.LowPart,
|
1999-05-01 12:36:07 +02:00
|
|
|
bytesToReadFromBuffer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of bytes read.
|
|
|
|
*/
|
|
|
|
*pcbRead = bytesToReadFromBuffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
|
|
|
GlobalUnlock(This->supportHandle);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The function returns S_OK if the specified number of bytes were read
|
|
|
|
* or the end of the array was reached.
|
2002-06-01 01:06:46 +02:00
|
|
|
* It returns STG_E_READFAULT if the number of bytes to read does not equal
|
1999-05-01 12:36:07 +02:00
|
|
|
* the number of bytes actually read.
|
|
|
|
*/
|
|
|
|
if(*pcbRead == cb)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return STG_E_READFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* It writes the specified bytes at the specified offset.
|
|
|
|
* position. If the array is too small, it will be resized.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_WriteAt(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
ULARGE_INTEGER ulOffset, /* [in] */
|
|
|
|
const void* pv, /* [size_is][in] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbWritten) /* [out] */
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
|
|
|
|
|
|
|
void* supportBuffer;
|
|
|
|
ULARGE_INTEGER newSize;
|
|
|
|
ULONG bytesWritten = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
if (cb == 0)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
newSize.u.HighPart = 0;
|
|
|
|
newSize.u.LowPart = ulOffset.u.LowPart + cb;
|
1999-05-01 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify if we need to grow the stream
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart > This->byteArraySize.u.LowPart)
|
1999-05-01 12:36:07 +02:00
|
|
|
{
|
|
|
|
/* grow stream */
|
|
|
|
if (HGLOBALLockBytesImpl_SetSize(iface, newSize) == STG_E_MEDIUMFULL)
|
|
|
|
return STG_E_MEDIUMFULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the buffer in position and copy the data.
|
|
|
|
*/
|
|
|
|
supportBuffer = GlobalLock(This->supportHandle);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
memcpy((char *) supportBuffer + ulOffset.u.LowPart, pv, cb);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of bytes written.
|
|
|
|
*/
|
|
|
|
*pcbWritten = cb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
|
|
|
GlobalUnlock(This->supportHandle);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_Flush(ILockBytes* iface)
|
1999-05-01 12:36:07 +02:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* It will change the size of the byte array.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_SetSize(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
ULARGE_INTEGER libNewSize) /* [in] */
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
2003-11-26 04:36:18 +01:00
|
|
|
HGLOBAL supportHandle;
|
1999-05-01 12:36:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
if (libNewSize.u.HighPart != 0)
|
1999-05-01 12:36:07 +02:00
|
|
|
return STG_E_INVALIDFUNCTION;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (This->byteArraySize.u.LowPart == libNewSize.u.LowPart)
|
1999-05-01 12:36:07 +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);
|
1999-05-01 12:36:07 +02:00
|
|
|
|
2003-11-26 04:36:18 +01:00
|
|
|
if (supportHandle == 0)
|
1999-05-01 12:36:07 +02:00
|
|
|
return STG_E_MEDIUMFULL;
|
|
|
|
|
2003-11-26 04:36:18 +01:00
|
|
|
This->supportHandle = supportHandle;
|
2004-01-23 02:51:33 +01:00
|
|
|
This->byteArraySize.u.LowPart = libNewSize.u.LowPart;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-01 12:36:07 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* The global memory implementation of ILockBytes does not support locking.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_LockRegion(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
|
|
|
{
|
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* The global memory implementation of ILockBytes does not support locking.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_UnlockRegion(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
|
|
|
{
|
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* This method is part of the ILockBytes interface.
|
|
|
|
*
|
|
|
|
* This method returns information about the current
|
|
|
|
* byte array object.
|
|
|
|
*
|
|
|
|
* See the documentation of ILockBytes for more info.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI HGLOBALLockBytesImpl_Stat(
|
1999-05-01 12:36:07 +02:00
|
|
|
ILockBytes* iface,
|
|
|
|
STATSTG* pstatstg, /* [out] */
|
|
|
|
DWORD grfStatFlag) /* [in] */
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
|
|
|
|
|
|
|
|
memset(pstatstg, 0, sizeof(STATSTG));
|
|
|
|
|
|
|
|
pstatstg->pwcsName = NULL;
|
|
|
|
pstatstg->type = STGTY_LOCKBYTES;
|
|
|
|
pstatstg->cbSize = This->byteArraySize;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-06-10 11:59:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual function table for the HGLOBALLockBytesImpl class.
|
|
|
|
*/
|
|
|
|
static const ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl =
|
|
|
|
{
|
|
|
|
HGLOBALLockBytesImpl_QueryInterface,
|
|
|
|
HGLOBALLockBytesImpl_AddRef,
|
|
|
|
HGLOBALLockBytesImpl_Release,
|
|
|
|
HGLOBALLockBytesImpl_ReadAt,
|
|
|
|
HGLOBALLockBytesImpl_WriteAt,
|
|
|
|
HGLOBALLockBytesImpl_Flush,
|
|
|
|
HGLOBALLockBytesImpl_SetSize,
|
|
|
|
HGLOBALLockBytesImpl_LockRegion,
|
|
|
|
HGLOBALLockBytesImpl_UnlockRegion,
|
|
|
|
HGLOBALLockBytesImpl_Stat,
|
|
|
|
};
|