ReactOS  0.4.12-dev-919-gfc3b8d5
hglobalstream.c File Reference
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "objbase.h"
#include "ole2.h"
#include "winerror.h"
#include "winternl.h"
#include "wine/debug.h"
Include dependency graph for hglobalstream.c:

Go to the source code of this file.

Classes

struct  handle_wrapper
 
struct  HGLOBALStreamImpl
 

Macros

#define COBJMACROS
 
#define NONAMELESSUNION
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (hglobalstream)
 
static void handle_addref (struct handle_wrapper *handle)
 
static void handle_release (struct handle_wrapper *handle)
 
static ULONG handle_read (struct handle_wrapper *handle, ULONG *pos, void *dest, ULONG len)
 
static ULONG handle_write (struct handle_wrapper *handle, ULONG *pos, const void *source, ULONG len)
 
static HGLOBAL handle_gethglobal (struct handle_wrapper *handle)
 
static HRESULT handle_setsize (struct handle_wrapper *handle, ULONG size)
 
static ULONG handle_getsize (struct handle_wrapper *handle)
 
static struct handle_wrapperhandle_create (HGLOBAL hglobal, BOOL delete_on_release)
 
static HGLOBALStreamImplimpl_from_IStream (IStream *iface)
 
static HRESULT WINAPI HGLOBALStreamImpl_QueryInterface (IStream *iface, REFIID riid, void **ppvObject)
 
static ULONG WINAPI HGLOBALStreamImpl_AddRef (IStream *iface)
 
static ULONG WINAPI HGLOBALStreamImpl_Release (IStream *iface)
 
static HRESULT WINAPI HGLOBALStreamImpl_Read (IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
 
static HRESULT WINAPI HGLOBALStreamImpl_Write (IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
 
static HRESULT WINAPI HGLOBALStreamImpl_Seek (IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
 
static HRESULT WINAPI HGLOBALStreamImpl_SetSize (IStream *iface, ULARGE_INTEGER libNewSize)
 
static HRESULT WINAPI HGLOBALStreamImpl_CopyTo (IStream *iface, IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
 
static HRESULT WINAPI HGLOBALStreamImpl_Commit (IStream *iface, DWORD grfCommitFlags)
 
static HRESULT WINAPI HGLOBALStreamImpl_Revert (IStream *iface)
 
static HRESULT WINAPI HGLOBALStreamImpl_LockRegion (IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion (IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI HGLOBALStreamImpl_Stat (IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
 
static HGLOBALStreamImplHGLOBALStreamImpl_Create (void)
 
static HRESULT WINAPI HGLOBALStreamImpl_Clone (IStream *iface, IStream **ppstm)
 
HRESULT WINAPI CreateStreamOnHGlobal (HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
 
HRESULT WINAPI GetHGlobalFromStream (IStream *pstm, HGLOBAL *phglobal)
 

Variables

static const IStreamVtbl HGLOBALStreamImplVtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 33 of file hglobalstream.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 34 of file hglobalstream.c.

Function Documentation

◆ CreateStreamOnHGlobal()

HRESULT WINAPI CreateStreamOnHGlobal ( HGLOBAL  hGlobal,
BOOL  fDeleteOnRelease,
LPSTREAM ppstm 
)

Definition at line 625 of file hglobalstream.c.

629 {
631 
632  if (!ppstm)
633  return E_INVALIDARG;
634 
636  if (!This) return E_OUTOFMEMORY;
637 
638  /* allocate a handle if one is not supplied */
639  if (!hGlobal)
641 
642  This->handle = handle_create(hGlobal, fDeleteOnRelease);
643 
644  /* start at the beginning */
645  This->currentPosition.u.HighPart = 0;
646  This->currentPosition.u.LowPart = 0;
647 
648  *ppstm = &This->IStream_iface;
649 
650  return S_OK;
651 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define GMEM_NODISCARD
Definition: winbase.h:299
#define GMEM_SHARE
Definition: winbase.h:302
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
static HGLOBALStreamImpl * HGLOBALStreamImpl_Create(void)
#define S_OK
Definition: intsafe.h:59
static struct handle_wrapper * handle_create(HGLOBAL hglobal, BOOL delete_on_release)
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by apartment_hostobject_in_hostapt(), BindStatusCallback_OnStartBinding(), bsc_OnStartBinding(), CoMarshalInterThreadInterfaceInStream(), crash_couninitialize_proc(), create_decoder(), create_doc_with_string(), create_stream(), create_stream_from_map(), create_stream_from_string(), create_stream_on_data(), create_stream_on_file(), create_stream_on_mip_ro(), create_test_stream(), D3DXSaveSurfaceToFileInMemory(), DataObjectImpl_CreateComplex(), decode_base64(), decode_qp(), doc_load_string(), get_current_dataobject(), get_data_from_stream(), get_local_server_stream(), get_stgmed_for_stream(), get_travellog_stream(), HlinkClone(), init_memstream(), CTravelEntry::Invoke(), load_image(), load_string(), LresultFromObject(), marshal_stgmed(), marshal_WdtpInterfacePointer(), METAFILE_CreateCompressedImageStream(), MimeOleCreateVirtualStream(), BrowserNavigator::navigated(), ObjectFromLresult(), OLEClipbrd_Initialize(), RECORD_StreamFromFile(), RegisterDragDrop(), RPC_GetLocalClassObject(), RunningObjectTableImpl_Register(), StdGlobalInterfaceTable_RegisterInterfaceInGlobal(), test_apm(), test_bad_marshal_stream(), test_bom(), test_bsc_marshaling(), test_bufferrawformat(), test_call_from_message(), test_channel_hook(), test_client_security(), test_CoGetStandardMarshal(), test_CoMarshalInterface(), test_componentinfo(), test_copyto(), test_CoRegisterPSClsid(), test_CoUnmarshalInterface(), test_CoWaitForMultipleHandles_thread(), test_createfromstream(), test_data_cache_save(), test_decode_1bpp(), test_decode_24bpp(), test_decode_4bpp(), test_decode_adobe_cmyk(), test_decode_rle4(), test_decode_rle8(), test_DfMarshal_custom_marshaling(), test_disconnect_stub(), test_empty_image(), test_empty_image_2(), test_enhmetafile(), test_external_connection(), test_file_moniker(), test_freed_hglobal(), test_freethreadedmarshaler(), test_GdipLoadImageFromStream(), test_getdatahere(), test_GetDataHere_Proxy(), test_handler_marshaling(), test_hresult_marshaling(), test_implicit_mta(), test_InternetSecurityMarshalling(), test_interthread_marshal_and_unmarshal(), test_Invoke(), test_IPersistStream(), test_IStream_Clone(), test_load_save_bmp(), test_load_save_emf(), test_load_save_empty_picture(), test_load_save_icon(), test_loadwmf(), test_lock_object_external(), test_marshal(), test_marshal_and_unmarshal_invalid(), test_marshal_channel_buffer(), test_marshal_proxy_apartment_shutdown(), test_marshal_proxy_mta_apartment_shutdown(), test_marshal_stub_apartment_shutdown(), test_message_filter(), test_metafile(), test_moniker(), test_multi_encoder(), test_multiframegif(), test_mxwriter_encoding(), test_mxwriter_flush(), test_mxwriter_stream(), test_no_couninitialize_client(), test_no_couninitialize_server(), test_no_marshaler(), test_normal_marshal_and_release(), test_normal_marshal_and_unmarshal(), test_normal_marshal_and_unmarshal_twice(), test_OleDoAutoConvert(), test_persist_save_data(), test_persiststreaminit(), test_pic(), test_pointer_moniker(), test_proxy_interfaces(), test_proxy_marshal_and_unmarshal(), test_proxy_marshal_and_unmarshal2(), test_proxy_marshal_and_unmarshal_strong(), test_proxy_marshal_and_unmarshal_weak(), test_proxy_used_in_wrong_thread(), test_ReadClassStm(), test_readerinput(), test_same_apartment_unmarshal_failure(), test_save(), test_save_history(), test_save_load_filemoniker(), test_StdMarshal_custom_marshaling(), test_streamonhglobal(), test_StreamOnIStream(), test_StreamOnStreamRange(), test_supported_encoders(), test_tablestrong_marshal_and_unmarshal_twice(), test_tableweak_and_normal_marshal_and_releasedata(), test_tableweak_and_normal_marshal_and_unmarshal(), test_tableweak_marshal_and_unmarshal_twice(), test_tableweak_marshal_releasedata1(), test_tableweak_marshal_releasedata2(), test_two_tableweak_marshal_and_releasedata(), test_typelibmarshal(), test_writeroutput(), test_writestartdocument(), test_xsltemplate(), union_tests(), unmarshal_stgmed(), CTravelEntry::Update(), WdtpInterfacePointer_UserMarshal(), WdtpInterfacePointer_UserUnmarshal(), window_proc(), writer_set_output(), and xslprocessor_transform().

◆ GetHGlobalFromStream()

HRESULT WINAPI GetHGlobalFromStream ( IStream pstm,
HGLOBAL phglobal 
)

Definition at line 656 of file hglobalstream.c.

657 {
658  HGLOBALStreamImpl* pStream;
659 
660  if (!pstm || !phglobal)
661  return E_INVALIDARG;
662 
663  pStream = impl_from_IStream(pstm);
664 
665  /*
666  * Verify that the stream object was created with CreateStreamOnHGlobal.
667  */
668  if (pStream->IStream_iface.lpVtbl == &HGLOBALStreamImplVtbl)
669  *phglobal = handle_gethglobal(pStream->handle);
670  else
671  {
672  *phglobal = 0;
673  return E_INVALIDARG;
674  }
675 
676  return S_OK;
677 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
static const IStreamVtbl HGLOBALStreamImplVtbl
#define E_INVALIDARG
Definition: ddrawi.h:101
struct handle_wrapper * handle
#define S_OK
Definition: intsafe.h:59
static HGLOBAL handle_gethglobal(struct handle_wrapper *handle)

Referenced by bsc_OnStopBinding(), check_iml_data(), check_output(), check_output_raw(), create_map_from_stream(), D3DXSaveSurfaceToFileInMemory(), expose_marshalled_dataobject(), RunningObjectTableImpl_Register(), stream_info(), test_bom(), test_freethreadedmarshaldata(), test_IStream_Clone(), test_moniker(), test_mxwriter_encoding(), test_omitxmldeclaration(), test_persist_save_data(), test_save(), test_writeenddocument(), test_XMLHTTP(), CTravelEntry::Update(), and xslprocessor_transform().

◆ handle_addref()

static void handle_addref ( struct handle_wrapper handle)
static

Definition at line 57 of file hglobalstream.c.

58 {
60 }
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by HGLOBALStreamImpl_Clone().

◆ handle_create()

static struct handle_wrapper* handle_create ( HGLOBAL  hglobal,
BOOL  delete_on_release 
)
static

Definition at line 182 of file hglobalstream.c.

183 {
184  struct handle_wrapper *handle;
185 
186  handle = HeapAlloc(GetProcessHeap(), 0, sizeof(*handle));
187  if (handle)
188  {
189  handle->ref = 1;
190  handle->hglobal = hglobal;
191  handle->size = GlobalSize(hglobal);
192  handle->delete_on_release = delete_on_release;
194  handle->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": handle_wrapper.lock");
195  }
196  return handle;
197 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define DWORD_PTR
Definition: treelist.c:76
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL delete_on_release
Definition: hglobalstream.c:53

Referenced by CreateStreamOnHGlobal().

◆ handle_gethglobal()

static HGLOBAL handle_gethglobal ( struct handle_wrapper handle)
static

Definition at line 150 of file hglobalstream.c.

151 {
152  return handle->hglobal;
153 }

Referenced by GetHGlobalFromStream().

◆ handle_getsize()

static ULONG handle_getsize ( struct handle_wrapper handle)
static

Definition at line 177 of file hglobalstream.c.

178 {
179  return handle->size;
180 }

Referenced by HGLOBALStreamImpl_Seek(), and HGLOBALStreamImpl_Stat().

◆ handle_read()

static ULONG handle_read ( struct handle_wrapper handle,
ULONG pos,
void dest,
ULONG  len 
)
static

Definition at line 80 of file hglobalstream.c.

81 {
82  void *source;
83 
85 
86  if (*pos < handle->size)
87  len = min(handle->size - *pos, len);
88  else
89  len = 0;
90 
91  source = GlobalLock(handle->hglobal);
92  if (source)
93  {
94  memcpy(dest, (char *)source + *pos, len);
95  *pos += len;
96  GlobalUnlock(handle->hglobal);
97  }
98  else
99  {
100  WARN("read from invalid hglobal %p\n", handle->hglobal);
101  len = 0;
102  }
103 
105  return len;
106 }
#define WARN(fmt,...)
Definition: debug.h:111
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
GLsizeiptr size
Definition: glext.h:5919
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLsizei GLchar * source
Definition: glext.h:6048
#define min(a, b)
Definition: monoChain.cc:55
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
static char * dest
Definition: rtl.c:135
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by HGLOBALStreamImpl_Read().

◆ handle_release()

static void handle_release ( struct handle_wrapper handle)
static

Definition at line 62 of file hglobalstream.c.

63 {
65 
66  if (!ref)
67  {
68  if (handle->delete_on_release)
69  {
70  GlobalFree(handle->hglobal);
71  handle->hglobal = NULL;
72  }
73 
74  handle->lock.DebugInfo->Spare[0] = 0;
77  }
78 }
Definition: send.c:47
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define InterlockedDecrement
Definition: armddk.h:52
unsigned int ULONG
Definition: retypes.h:1
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by HGLOBALStreamImpl_Release().

◆ handle_setsize()

static HRESULT handle_setsize ( struct handle_wrapper handle,
ULONG  size 
)
static

Definition at line 155 of file hglobalstream.c.

156 {
157  HRESULT hr = S_OK;
158 
160 
161  if (handle->size != size)
162  {
164  if (hglobal)
165  {
166  handle->hglobal = hglobal;
167  handle->size = size;
168  }
169  else
170  hr = E_OUTOFMEMORY;
171  }
172 
174  return hr;
175 }
HRESULT hr
Definition: shlfolder.c:183
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by HGLOBALStreamImpl_SetSize().

◆ handle_write()

static ULONG handle_write ( struct handle_wrapper handle,
ULONG pos,
const void source,
ULONG  len 
)
static

Definition at line 108 of file hglobalstream.c.

109 {
110  void *dest;
111 
112  if (!len)
113  return 0;
114 
116 
117  if (*pos + len > handle->size)
118  {
120  if (hglobal)
121  {
122  handle->hglobal = hglobal;
123  handle->size = *pos + len;
124  }
125  else
126  {
127  len = 0;
128  goto done;
129  }
130  }
131 
132  dest = GlobalLock(handle->hglobal);
133  if (dest)
134  {
135  memcpy((char *)dest + *pos, source, len);
136  *pos += len;
137  GlobalUnlock(handle->hglobal);
138  }
139  else
140  {
141  WARN("write to invalid hglobal %p\n", handle->hglobal);
142  /* len = 0; */
143  }
144 
145 done:
147  return len;
148 }
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
#define WARN(fmt,...)
Definition: debug.h:111
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
static char * dest
Definition: rtl.c:135
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by HGLOBALStreamImpl_Write().

◆ HGLOBALStreamImpl_AddRef()

static ULONG WINAPI HGLOBALStreamImpl_AddRef ( IStream iface)
static

Definition at line 248 of file hglobalstream.c.

249 {
251  return InterlockedIncrement(&This->ref);
252 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
#define InterlockedIncrement
Definition: armddk.h:53

◆ HGLOBALStreamImpl_Clone()

static HRESULT WINAPI HGLOBALStreamImpl_Clone ( IStream iface,
IStream **  ppstm 
)
static

Definition at line 576 of file hglobalstream.c.

579 {
581  HGLOBALStreamImpl* clone;
584 
585  if (!ppstm) return E_INVALIDARG;
586 
587  *ppstm = NULL;
588 
589  TRACE(" Cloning %p (seek position=%d)\n", iface, This->currentPosition.u.LowPart);
590 
591  clone = HGLOBALStreamImpl_Create();
592  if (!clone) return E_OUTOFMEMORY;
593 
594  *ppstm = &clone->IStream_iface;
595 
596  handle_addref(This->handle);
597  clone->handle = This->handle;
598 
599  offset.QuadPart = (LONGLONG)This->currentPosition.QuadPart;
600  IStream_Seek(*ppstm, offset, STREAM_SEEK_SET, &dummy);
601  return S_OK;
602 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
GLintptr offset
Definition: glext.h:5920
static void handle_addref(struct handle_wrapper *handle)
Definition: hglobalstream.c:57
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
int64_t LONGLONG
Definition: typedefs.h:66
#define TRACE(s)
Definition: solgame.cpp:4
static HGLOBALStreamImpl * HGLOBALStreamImpl_Create(void)
struct handle_wrapper * handle
#define S_OK
Definition: intsafe.h:59
unsigned char dummy
Definition: maze.c:118

◆ HGLOBALStreamImpl_Commit()

static HRESULT WINAPI HGLOBALStreamImpl_Commit ( IStream iface,
DWORD  grfCommitFlags 
)
static

Definition at line 482 of file hglobalstream.c.

485 {
486  return S_OK;
487 }
#define S_OK
Definition: intsafe.h:59

◆ HGLOBALStreamImpl_CopyTo()

static HRESULT WINAPI HGLOBALStreamImpl_CopyTo ( IStream iface,
IStream pstm,
ULARGE_INTEGER  cb,
ULARGE_INTEGER pcbRead,
ULARGE_INTEGER pcbWritten 
)
static

Definition at line 418 of file hglobalstream.c.

424 {
425  HRESULT hr = S_OK;
426  BYTE tmpBuffer[128];
427  ULONG bytesRead, bytesWritten, copySize;
428  ULARGE_INTEGER totalBytesRead;
429  ULARGE_INTEGER totalBytesWritten;
430 
431  TRACE("(%p, %p, %d, %p, %p)\n", iface, pstm,
432  cb.u.LowPart, pcbRead, pcbWritten);
433 
434  if ( pstm == 0 )
435  return STG_E_INVALIDPOINTER;
436 
437  totalBytesRead.QuadPart = 0;
438  totalBytesWritten.QuadPart = 0;
439 
440  while ( cb.QuadPart > 0 )
441  {
442  if ( cb.QuadPart >= sizeof(tmpBuffer) )
443  copySize = sizeof(tmpBuffer);
444  else
445  copySize = cb.u.LowPart;
446 
447  hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
448  if (FAILED(hr))
449  break;
450 
451  totalBytesRead.QuadPart += bytesRead;
452 
453  if (bytesRead)
454  {
455  hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
456  if (FAILED(hr))
457  break;
458 
459  totalBytesWritten.QuadPart += bytesWritten;
460  }
461 
462  if (bytesRead!=copySize)
463  cb.QuadPart = 0;
464  else
465  cb.QuadPart -= bytesRead;
466  }
467 
468  if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
469  if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
470 
471  return hr;
472 }
HRESULT hr
Definition: shlfolder.c:183
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static DWORD cb
Definition: integrity.c:41
unsigned char BYTE
Definition: mem.h:68
GLenum GLsizei GLuint GLint * bytesWritten
Definition: glext.h:11123
#define S_OK
Definition: intsafe.h:59
unsigned int ULONG
Definition: retypes.h:1

◆ HGLOBALStreamImpl_Create()

static HGLOBALStreamImpl* HGLOBALStreamImpl_Create ( void  )
static

Definition at line 563 of file hglobalstream.c.

564 {
566 
567  This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
568  if (This)
569  {
570  This->IStream_iface.lpVtbl = &HGLOBALStreamImplVtbl;
571  This->ref = 1;
572  }
573  return This;
574 }
static const IStreamVtbl HGLOBALStreamImplVtbl
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)

Referenced by CreateStreamOnHGlobal(), and HGLOBALStreamImpl_Clone().

◆ HGLOBALStreamImpl_LockRegion()

static HRESULT WINAPI HGLOBALStreamImpl_LockRegion ( IStream iface,
ULARGE_INTEGER  libOffset,
ULARGE_INTEGER  cb,
DWORD  dwLockType 
)
static

Definition at line 511 of file hglobalstream.c.

516 {
517  return STG_E_INVALIDFUNCTION;
518 }
#define STG_E_INVALIDFUNCTION
Definition: winerror.h:2564

◆ HGLOBALStreamImpl_QueryInterface()

static HRESULT WINAPI HGLOBALStreamImpl_QueryInterface ( IStream iface,
REFIID  riid,
void **  ppvObject 
)
static

Definition at line 221 of file hglobalstream.c.

225 {
227 
228  if (ppvObject==0)
229  return E_INVALIDARG;
230 
231  *ppvObject = 0;
232 
233  if (IsEqualIID(&IID_IUnknown, riid) ||
234  IsEqualIID(&IID_ISequentialStream, riid) ||
235  IsEqualIID(&IID_IStream, riid))
236  {
237  *ppvObject = &This->IStream_iface;
238  }
239 
240  if ((*ppvObject)==0)
241  return E_NOINTERFACE;
242 
243  IStream_AddRef(iface);
244 
245  return S_OK;
246 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
#define E_INVALIDARG
Definition: ddrawi.h:101
const GUID IID_IUnknown
REFIID LPVOID * ppvObject
Definition: precomp.h:44
#define S_OK
Definition: intsafe.h:59
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:90

◆ HGLOBALStreamImpl_Read()

static HRESULT WINAPI HGLOBALStreamImpl_Read ( IStream iface,
void pv,
ULONG  cb,
ULONG pcbRead 
)
static

Definition at line 278 of file hglobalstream.c.

283 {
286 
287  TRACE("(%p, %p, %d, %p)\n", iface, pv, cb, pcbRead);
288 
289  num_bytes = handle_read(This->handle, &This->currentPosition.u.LowPart, pv, cb);
290  if (pcbRead) *pcbRead = num_bytes;
291 
292  return S_OK;
293 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
#define TRACE(s)
Definition: solgame.cpp:4
ed2 num_bytes
Definition: write.c:2854
static DWORD cb
Definition: integrity.c:41
static ULONG handle_read(struct handle_wrapper *handle, ULONG *pos, void *dest, ULONG len)
Definition: hglobalstream.c:80
#define S_OK
Definition: intsafe.h:59
unsigned int ULONG
Definition: retypes.h:1

◆ HGLOBALStreamImpl_Release()

static ULONG WINAPI HGLOBALStreamImpl_Release ( IStream iface)
static

Definition at line 254 of file hglobalstream.c.

256 {
259 
260  if (!ref)
261  {
262  handle_release(This->handle);
264  }
265 
266  return ref;
267 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
#define GetProcessHeap()
Definition: compat.h:395
#define InterlockedDecrement
Definition: armddk.h:52
static void handle_release(struct handle_wrapper *handle)
Definition: hglobalstream.c:62
unsigned int ULONG
Definition: retypes.h:1
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ HGLOBALStreamImpl_Revert()

static HRESULT WINAPI HGLOBALStreamImpl_Revert ( IStream iface)
static

Definition at line 497 of file hglobalstream.c.

499 {
500  return S_OK;
501 }
#define S_OK
Definition: intsafe.h:59

◆ HGLOBALStreamImpl_Seek()

static HRESULT WINAPI HGLOBALStreamImpl_Seek ( IStream iface,
LARGE_INTEGER  dlibMove,
DWORD  dwOrigin,
ULARGE_INTEGER plibNewPosition 
)
static

Definition at line 330 of file hglobalstream.c.

335 {
337 
338  ULARGE_INTEGER newPosition = This->currentPosition;
339  HRESULT hr = S_OK;
340 
341  TRACE("(%p, %x%08x, %d, %p)\n", iface, dlibMove.u.HighPart,
342  dlibMove.u.LowPart, dwOrigin, plibNewPosition);
343 
344  /*
345  * The file pointer is moved depending on the given "function"
346  * parameter.
347  */
348  switch (dwOrigin)
349  {
350  case STREAM_SEEK_SET:
351  newPosition.u.HighPart = 0;
352  newPosition.u.LowPart = 0;
353  break;
354  case STREAM_SEEK_CUR:
355  break;
356  case STREAM_SEEK_END:
357  newPosition.QuadPart = handle_getsize(This->handle);
358  break;
359  default:
361  goto end;
362  }
363 
364  /*
365  * Move the actual file pointer
366  * If the file pointer ends-up after the end of the stream, the next Write operation will
367  * make the file larger. This is how it is documented.
368  */
369  newPosition.u.HighPart = 0;
370  newPosition.u.LowPart += dlibMove.QuadPart;
371 
372  if (dlibMove.u.LowPart >= 0x80000000 &&
373  newPosition.u.LowPart >= dlibMove.u.LowPart)
374  {
375  /* We tried to seek backwards and went past the start. */
377  goto end;
378  }
379 
380  This->currentPosition = newPosition;
381 
382 end:
383  if (plibNewPosition) *plibNewPosition = This->currentPosition;
384 
385  return hr;
386 }
struct _ULARGE_INTEGER::@3736 u
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
HRESULT hr
Definition: shlfolder.c:183
GLuint GLuint end
Definition: gl.h:1545
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
static ULONG handle_getsize(struct handle_wrapper *handle)
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
struct _LARGE_INTEGER::@2192 u
#define STG_E_SEEKERROR
Definition: winerror.h:2574
LONGLONG QuadPart
Definition: typedefs.h:112

◆ HGLOBALStreamImpl_SetSize()

static HRESULT WINAPI HGLOBALStreamImpl_SetSize ( IStream iface,
ULARGE_INTEGER  libNewSize 
)
static

Definition at line 397 of file hglobalstream.c.

400 {
402 
403  TRACE("(%p, %d)\n", iface, libNewSize.u.LowPart);
404 
405  /*
406  * HighPart is ignored as shown in tests
407  */
408  return handle_setsize(This->handle, libNewSize.u.LowPart);
409 }
struct _ULARGE_INTEGER::@3736 u
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
static HRESULT handle_setsize(struct handle_wrapper *handle, ULONG size)
#define TRACE(s)
Definition: solgame.cpp:4

◆ HGLOBALStreamImpl_Stat()

static HRESULT WINAPI HGLOBALStreamImpl_Stat ( IStream iface,
STATSTG *  pstatstg,
DWORD  grfStatFlag 
)
static

Definition at line 545 of file hglobalstream.c.

549 {
551 
552  memset(pstatstg, 0, sizeof(STATSTG));
553 
554  pstatstg->pwcsName = NULL;
555  pstatstg->type = STGTY_STREAM;
556  pstatstg->cbSize.QuadPart = handle_getsize(This->handle);
557 
558  return S_OK;
559 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
static ULONG handle_getsize(struct handle_wrapper *handle)
smooth NULL
Definition: ftsmooth.c:416
#define S_OK
Definition: intsafe.h:59
#define memset(x, y, z)
Definition: compat.h:39

◆ HGLOBALStreamImpl_UnlockRegion()

static HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion ( IStream iface,
ULARGE_INTEGER  libOffset,
ULARGE_INTEGER  cb,
DWORD  dwLockType 
)
static

Definition at line 528 of file hglobalstream.c.

533 {
534  return S_OK;
535 }
#define S_OK
Definition: intsafe.h:59

◆ HGLOBALStreamImpl_Write()

static HRESULT WINAPI HGLOBALStreamImpl_Write ( IStream iface,
const void pv,
ULONG  cb,
ULONG pcbWritten 
)
static

Definition at line 305 of file hglobalstream.c.

310 {
313 
314  TRACE("(%p, %p, %d, %p)\n", iface, pv, cb, pcbWritten);
315 
316  num_bytes = handle_write(This->handle, &This->currentPosition.u.LowPart, pv, cb);
317  if (pcbWritten) *pcbWritten = num_bytes;
318 
319  return (num_bytes < cb) ? E_OUTOFMEMORY : S_OK;
320 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
static ULONG handle_write(struct handle_wrapper *handle, ULONG *pos, const void *source, ULONG len)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define TRACE(s)
Definition: solgame.cpp:4
ed2 num_bytes
Definition: write.c:2854
static DWORD cb
Definition: integrity.c:41
#define S_OK
Definition: intsafe.h:59
unsigned int ULONG
Definition: retypes.h:1

◆ impl_from_IStream()

static HGLOBALStreamImpl* impl_from_IStream ( IStream iface)
inlinestatic

Definition at line 216 of file hglobalstream.c.

217 {
218  return CONTAINING_RECORD(iface, HGLOBALStreamImpl, IStream_iface);
219 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by GetHGlobalFromStream(), HGLOBALStreamImpl_AddRef(), HGLOBALStreamImpl_Clone(), HGLOBALStreamImpl_QueryInterface(), HGLOBALStreamImpl_Read(), HGLOBALStreamImpl_Release(), HGLOBALStreamImpl_Seek(), HGLOBALStreamImpl_SetSize(), HGLOBALStreamImpl_Stat(), and HGLOBALStreamImpl_Write().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( hglobalstream  )

Variable Documentation

◆ HGLOBALStreamImplVtbl

static const IStreamVtbl HGLOBALStreamImplVtbl
static
Initial value:
=
{
}
static ULONG WINAPI HGLOBALStreamImpl_AddRef(IStream *iface)
static HRESULT WINAPI HGLOBALStreamImpl_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
static HRESULT WINAPI HGLOBALStreamImpl_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
static HRESULT WINAPI HGLOBALStreamImpl_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
static HRESULT WINAPI HGLOBALStreamImpl_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
static HRESULT WINAPI HGLOBALStreamImpl_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
static HRESULT WINAPI HGLOBALStreamImpl_Commit(IStream *iface, DWORD grfCommitFlags)
static HRESULT WINAPI HGLOBALStreamImpl_LockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static HRESULT WINAPI HGLOBALStreamImpl_Clone(IStream *iface, IStream **ppstm)
static HRESULT WINAPI HGLOBALStreamImpl_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
static HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
static HRESULT WINAPI HGLOBALStreamImpl_Revert(IStream *iface)
static ULONG WINAPI HGLOBALStreamImpl_Release(IStream *iface)

Definition at line 561 of file hglobalstream.c.

Referenced by GetHGlobalFromStream(), and HGLOBALStreamImpl_Create().