ReactOS  0.4.14-dev-606-g14ebc0b
hglobalstream.c File Reference
#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 31 of file hglobalstream.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 32 of file hglobalstream.c.

Function Documentation

◆ CreateStreamOnHGlobal()

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

Definition at line 623 of file hglobalstream.c.

627 {
629 
630  if (!ppstm)
631  return E_INVALIDARG;
632 
634  if (!This) return E_OUTOFMEMORY;
635 
636  /* allocate a handle if one is not supplied */
637  if (!hGlobal)
639 
640  This->handle = handle_create(hGlobal, fDeleteOnRelease);
641 
642  /* start at the beginning */
643  This->currentPosition.u.HighPart = 0;
644  This->currentPosition.u.LowPart = 0;
645 
646  *ppstm = &This->IStream_iface;
647 
648  return S_OK;
649 }
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_dispinterface(), 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 654 of file hglobalstream.c.

655 {
656  HGLOBALStreamImpl* pStream;
657 
658  if (!pstm || !phglobal)
659  return E_INVALIDARG;
660 
661  pStream = impl_from_IStream(pstm);
662 
663  /*
664  * Verify that the stream object was created with CreateStreamOnHGlobal.
665  */
666  if (pStream->IStream_iface.lpVtbl == &HGLOBALStreamImplVtbl)
667  *phglobal = handle_gethglobal(pStream->handle);
668  else
669  {
670  *phglobal = 0;
671  return E_INVALIDARG;
672  }
673 
674  return S_OK;
675 }
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 55 of file hglobalstream.c.

56 {
58 }
#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 180 of file hglobalstream.c.

181 {
182  struct handle_wrapper *handle;
183 
184  handle = HeapAlloc(GetProcessHeap(), 0, sizeof(*handle));
185  if (handle)
186  {
187  handle->ref = 1;
188  handle->hglobal = hglobal;
189  handle->size = GlobalSize(hglobal);
190  handle->delete_on_release = delete_on_release;
192  handle->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": handle_wrapper.lock");
193  }
194  return handle;
195 }
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:751
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL delete_on_release
Definition: hglobalstream.c:51

Referenced by CreateStreamOnHGlobal().

◆ handle_gethglobal()

static HGLOBAL handle_gethglobal ( struct handle_wrapper handle)
static

Definition at line 148 of file hglobalstream.c.

149 {
150  return handle->hglobal;
151 }

Referenced by GetHGlobalFromStream().

◆ handle_getsize()

static ULONG handle_getsize ( struct handle_wrapper handle)
static

Definition at line 175 of file hglobalstream.c.

176 {
177  return handle->size;
178 }

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 78 of file hglobalstream.c.

79 {
80  void *source;
81 
83 
84  if (*pos < handle->size)
85  len = min(handle->size - *pos, len);
86  else
87  len = 0;
88 
89  source = GlobalLock(handle->hglobal);
90  if (source)
91  {
92  memcpy(dest, (char *)source + *pos, len);
93  *pos += len;
94  GlobalUnlock(handle->hglobal);
95  }
96  else
97  {
98  WARN("read from invalid hglobal %p\n", handle->hglobal);
99  len = 0;
100  }
101 
103  return len;
104 }
#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 60 of file hglobalstream.c.

61 {
63 
64  if (!ref)
65  {
66  if (handle->delete_on_release)
67  {
68  GlobalFree(handle->hglobal);
69  handle->hglobal = NULL;
70  }
71 
72  handle->lock.DebugInfo->Spare[0] = 0;
75  }
76 }
Definition: send.c:47
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
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:402

Referenced by HGLOBALStreamImpl_Release().

◆ handle_setsize()

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

Definition at line 153 of file hglobalstream.c.

154 {
155  HRESULT hr = S_OK;
156 
158 
159  if (handle->size != size)
160  {
162  if (hglobal)
163  {
164  handle->hglobal = hglobal;
165  handle->size = size;
166  }
167  else
168  hr = E_OUTOFMEMORY;
169  }
170 
172  return hr;
173 }
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 106 of file hglobalstream.c.

107 {
108  void *dest;
109 
110  if (!len)
111  return 0;
112 
114 
115  if (*pos + len > handle->size)
116  {
118  if (hglobal)
119  {
120  handle->hglobal = hglobal;
121  handle->size = *pos + len;
122  }
123  else
124  {
125  len = 0;
126  goto done;
127  }
128  }
129 
130  dest = GlobalLock(handle->hglobal);
131  if (dest)
132  {
133  memcpy((char *)dest + *pos, source, len);
134  *pos += len;
135  GlobalUnlock(handle->hglobal);
136  }
137  else
138  {
139  WARN("write to invalid hglobal %p\n", handle->hglobal);
140  /* len = 0; */
141  }
142 
143 done:
145  return len;
146 }
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 246 of file hglobalstream.c.

247 {
249  return InterlockedIncrement(&This->ref);
250 }
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 574 of file hglobalstream.c.

577 {
579  HGLOBALStreamImpl* clone;
582 
583  if (!ppstm) return E_INVALIDARG;
584 
585  *ppstm = NULL;
586 
587  TRACE(" Cloning %p (seek position=%d)\n", iface, This->currentPosition.u.LowPart);
588 
589  clone = HGLOBALStreamImpl_Create();
590  if (!clone) return E_OUTOFMEMORY;
591 
592  *ppstm = &clone->IStream_iface;
593 
594  handle_addref(This->handle);
595  clone->handle = This->handle;
596 
597  offset.QuadPart = (LONGLONG)This->currentPosition.QuadPart;
598  IStream_Seek(*ppstm, offset, STREAM_SEEK_SET, &dummy);
599  return S_OK;
600 }
static HGLOBALStreamImpl * impl_from_IStream(IStream *iface)
GLintptr offset
Definition: glext.h:5920
static void handle_addref(struct handle_wrapper *handle)
Definition: hglobalstream.c:55
#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 480 of file hglobalstream.c.

483 {
484  return S_OK;
485 }
#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 416 of file hglobalstream.c.

422 {
423  HRESULT hr = S_OK;
424  BYTE tmpBuffer[128];
425  ULONG bytesRead, bytesWritten, copySize;
426  ULARGE_INTEGER totalBytesRead;
427  ULARGE_INTEGER totalBytesWritten;
428 
429  TRACE("(%p, %p, %d, %p, %p)\n", iface, pstm,
430  cb.u.LowPart, pcbRead, pcbWritten);
431 
432  if ( pstm == 0 )
433  return STG_E_INVALIDPOINTER;
434 
435  totalBytesRead.QuadPart = 0;
436  totalBytesWritten.QuadPart = 0;
437 
438  while ( cb.QuadPart > 0 )
439  {
440  if ( cb.QuadPart >= sizeof(tmpBuffer) )
441  copySize = sizeof(tmpBuffer);
442  else
443  copySize = cb.u.LowPart;
444 
445  hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
446  if (FAILED(hr))
447  break;
448 
449  totalBytesRead.QuadPart += bytesRead;
450 
451  if (bytesRead)
452  {
453  hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
454  if (FAILED(hr))
455  break;
456 
457  totalBytesWritten.QuadPart += bytesWritten;
458  }
459 
460  if (bytesRead!=copySize)
461  cb.QuadPart = 0;
462  else
463  cb.QuadPart -= bytesRead;
464  }
465 
466  if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
467  if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
468 
469  return hr;
470 }
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
unsigned char BYTE
Definition: mem.h:68
GLenum GLsizei GLuint GLint * bytesWritten
Definition: glext.h:11123
#define S_OK
Definition: intsafe.h:59
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
unsigned int ULONG
Definition: retypes.h:1

◆ HGLOBALStreamImpl_Create()

static HGLOBALStreamImpl* HGLOBALStreamImpl_Create ( void  )
static

Definition at line 561 of file hglobalstream.c.

562 {
564 
565  This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
566  if (This)
567  {
568  This->IStream_iface.lpVtbl = &HGLOBALStreamImplVtbl;
569  This->ref = 1;
570  }
571  return This;
572 }
static const IStreamVtbl HGLOBALStreamImplVtbl
#define GetProcessHeap()
Definition: compat.h:403
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 509 of file hglobalstream.c.

514 {
515  return STG_E_INVALIDFUNCTION;
516 }
#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 219 of file hglobalstream.c.

223 {
225 
226  if (ppvObject==0)
227  return E_INVALIDARG;
228 
229  *ppvObject = 0;
230 
231  if (IsEqualIID(&IID_IUnknown, riid) ||
232  IsEqualIID(&IID_ISequentialStream, riid) ||
233  IsEqualIID(&IID_IStream, riid))
234  {
235  *ppvObject = &This->IStream_iface;
236  }
237 
238  if ((*ppvObject)==0)
239  return E_NOINTERFACE;
240 
241  IStream_AddRef(iface);
242 
243  return S_OK;
244 }
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:95

◆ HGLOBALStreamImpl_Read()

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

Definition at line 276 of file hglobalstream.c.

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

◆ HGLOBALStreamImpl_Release()

static ULONG WINAPI HGLOBALStreamImpl_Release ( IStream iface)
static

Definition at line 252 of file hglobalstream.c.

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

◆ HGLOBALStreamImpl_Revert()

static HRESULT WINAPI HGLOBALStreamImpl_Revert ( IStream iface)
static

Definition at line 495 of file hglobalstream.c.

497 {
498  return S_OK;
499 }
#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 328 of file hglobalstream.c.

333 {
335 
336  ULARGE_INTEGER newPosition = This->currentPosition;
337  HRESULT hr = S_OK;
338 
339  TRACE("(%p, %x%08x, %d, %p)\n", iface, dlibMove.u.HighPart,
340  dlibMove.u.LowPart, dwOrigin, plibNewPosition);
341 
342  /*
343  * The file pointer is moved depending on the given "function"
344  * parameter.
345  */
346  switch (dwOrigin)
347  {
348  case STREAM_SEEK_SET:
349  newPosition.u.HighPart = 0;
350  newPosition.u.LowPart = 0;
351  break;
352  case STREAM_SEEK_CUR:
353  break;
354  case STREAM_SEEK_END:
355  newPosition.QuadPart = handle_getsize(This->handle);
356  break;
357  default:
359  goto end;
360  }
361 
362  /*
363  * Move the actual file pointer
364  * If the file pointer ends-up after the end of the stream, the next Write operation will
365  * make the file larger. This is how it is documented.
366  */
367  newPosition.u.HighPart = 0;
368  newPosition.u.LowPart += dlibMove.QuadPart;
369 
370  if (dlibMove.u.LowPart >= 0x80000000 &&
371  newPosition.u.LowPart >= dlibMove.u.LowPart)
372  {
373  /* We tried to seek backwards and went past the start. */
375  goto end;
376  }
377 
378  This->currentPosition = newPosition;
379 
380 end:
381  if (plibNewPosition) *plibNewPosition = This->currentPosition;
382 
383  return hr;
384 }
struct _LARGE_INTEGER::@2220 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 _ULARGE_INTEGER::@3769 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 395 of file hglobalstream.c.

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

◆ HGLOBALStreamImpl_Stat()

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

Definition at line 543 of file hglobalstream.c.

547 {
549 
550  memset(pstatstg, 0, sizeof(STATSTG));
551 
552  pstatstg->pwcsName = NULL;
553  pstatstg->type = STGTY_STREAM;
554  pstatstg->cbSize.QuadPart = handle_getsize(This->handle);
555 
556  return S_OK;
557 }
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 526 of file hglobalstream.c.

531 {
532  return S_OK;
533 }
#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 303 of file hglobalstream.c.

308 {
311 
312  TRACE("(%p, %p, %d, %p)\n", iface, pv, cb, pcbWritten);
313 
314  num_bytes = handle_write(This->handle, &This->currentPosition.u.LowPart, pv, cb);
315  if (pcbWritten) *pcbWritten = num_bytes;
316 
317  return (num_bytes < cb) ? E_OUTOFMEMORY : S_OK;
318 }
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:2846
#define S_OK
Definition: intsafe.h:59
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
unsigned int ULONG
Definition: retypes.h:1

◆ impl_from_IStream()

static HGLOBALStreamImpl* impl_from_IStream ( IStream iface)
inlinestatic

Definition at line 214 of file hglobalstream.c.

215 {
216  return CONTAINING_RECORD(iface, HGLOBALStreamImpl, IStream_iface);
217 }
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 559 of file hglobalstream.c.

Referenced by GetHGlobalFromStream(), and HGLOBALStreamImpl_Create().