Skip to content

Commit

Permalink
[OLE32] Sync with Wine Staging 3.9. CORE-14656
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineKhaldi committed Jun 4, 2018
1 parent 9ce306e commit 85037eb
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 195 deletions.
167 changes: 97 additions & 70 deletions dll/win32/ole32/compobj.c

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dll/win32/ole32/compobj_private.h
Expand Up @@ -142,6 +142,7 @@ struct apartment
DWORD host_apt_tid; /* thread ID of apartment hosting objects of differing threading model (CS cs) */
HWND host_apt_hwnd; /* handle to apartment window of host apartment (CS cs) */
LocalServer *local_server; /* A marshallable object exposing local servers (CS cs) */
BOOL being_destroyed; /* is currently being destroyed */

/* FIXME: OIDs should be given out by RPCSS */
OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
Expand Down Expand Up @@ -199,7 +200,7 @@ void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const
void stub_manager_disconnect(struct stub_manager *m) DECLSPEC_HIDDEN;
HRESULT ipid_get_dispatch_params(const IPID *ipid, APARTMENT **stub_apt, struct stub_manager **manager, IRpcStubBuffer **stub,
IRpcChannelBuffer **chan, IID *iid, IUnknown **iface) DECLSPEC_HIDDEN;
HRESULT start_apartment_remote_unknown(void) DECLSPEC_HIDDEN;
HRESULT start_apartment_remote_unknown(APARTMENT *apt) DECLSPEC_HIDDEN;

HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, DWORD dest_context, void *dest_context_data, MSHLFLAGS mshlflags) DECLSPEC_HIDDEN;

Expand All @@ -211,7 +212,7 @@ void RPC_StartRemoting(struct apartment *apt) DECLSPEC_HIDDEN;
HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid,
const OXID_INFO *oxid_info,
DWORD dest_context, void *dest_context_data,
IRpcChannelBuffer **chan) DECLSPEC_HIDDEN;
IRpcChannelBuffer **chan, APARTMENT *apt) DECLSPEC_HIDDEN;
HRESULT RPC_CreateServerChannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan) DECLSPEC_HIDDEN;
void RPC_ExecuteCall(struct dispatch_params *params) DECLSPEC_HIDDEN;
HRESULT RPC_RegisterInterface(REFIID riid) DECLSPEC_HIDDEN;
Expand Down Expand Up @@ -247,6 +248,7 @@ HRESULT apartment_createwindowifneeded(struct apartment *apt) DECLSPEC_HIDDEN;
HWND apartment_getwindow(const struct apartment *apt) DECLSPEC_HIDDEN;
HRESULT enter_apartment(struct oletls *info, DWORD model) DECLSPEC_HIDDEN;
void leave_apartment(struct oletls *info) DECLSPEC_HIDDEN;
APARTMENT *apartment_get_current_or_mta(void) DECLSPEC_HIDDEN;

/* DCOM messages used by the apartment window (not compatible with native) */
#define DM_EXECUTERPC (WM_USER + 0) /* WPARAM = 0, LPARAM = (struct dispatch_params *) */
Expand Down
225 changes: 153 additions & 72 deletions dll/win32/ole32/datacache.c
Expand Up @@ -547,6 +547,41 @@ static HRESULT open_pres_stream( IStorage *stg, int stream_number, IStream **stm
return IStorage_OpenStream( stg, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm );
}

static HRESULT synthesize_emf( HMETAFILEPICT data, STGMEDIUM *med )
{
METAFILEPICT *pict;
HRESULT hr = E_FAIL;
UINT size;
void *bits;

if (!(pict = GlobalLock( data ))) return hr;

size = GetMetaFileBitsEx( pict->hMF, 0, NULL );
if ((bits = HeapAlloc( GetProcessHeap(), 0, size )))
{
GetMetaFileBitsEx( pict->hMF, size, bits );
med->u.hEnhMetaFile = SetWinMetaFileBits( size, bits, NULL, pict );
HeapFree( GetProcessHeap(), 0, bits );
med->tymed = TYMED_ENHMF;
med->pUnkForRelease = NULL;
hr = S_OK;
}

GlobalUnlock( data );
return hr;
}
#include <pshpack2.h>
struct meta_placeable
{
DWORD key;
WORD hwmf;
WORD bounding_box[4];
WORD inch;
DWORD reserved;
WORD checksum;
};
#include <poppack.h>

static HRESULT load_mf_pict( DataCacheEntry *cache_entry, IStream *stm )
{
HRESULT hr;
Expand All @@ -559,25 +594,26 @@ static HRESULT load_mf_pict( DataCacheEntry *cache_entry, IStream *stm )
CLIPFORMAT clipformat;
static const LARGE_INTEGER offset_zero;
ULONG read;

if (cache_entry->load_stream_num == STREAM_NUMBER_CONTENTS)
{
FIXME( "Unimplemented for CONTENTS stream\n" );
return E_FAIL;
}
struct meta_placeable mf_place;

hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
if (FAILED( hr )) return hr;

hr = read_clipformat( stm, &clipformat );
if (FAILED( hr )) return hr;

hr = IStream_Read( stm, &header, sizeof(header), &read );
if (hr != S_OK || read != sizeof(header)) return E_FAIL;
if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
{
hr = read_clipformat( stm, &clipformat );
if (hr != S_OK) return hr;
hr = IStream_Read( stm, &header, sizeof(header), &read );
if (hr != S_OK) return hr;
}
else
{
hr = IStream_Read( stm, &mf_place, sizeof(mf_place), &read );
if (hr != S_OK) return hr;
}

hr = IStream_Seek( stm, offset_zero, STREAM_SEEK_CUR, &current_pos );
if (FAILED( hr )) return hr;

stat.cbSize.QuadPart -= current_pos.QuadPart;

hmfpict = GlobalAlloc( GMEM_MOVEABLE, sizeof(METAFILEPICT) );
Expand All @@ -592,14 +628,23 @@ static HRESULT load_mf_pict( DataCacheEntry *cache_entry, IStream *stm )
}

hr = IStream_Read( stm, bits, stat.cbSize.u.LowPart, &read );
if (hr != S_OK || read != stat.cbSize.u.LowPart) hr = E_FAIL;

if (SUCCEEDED( hr ))
{
/* FIXME: get this from the stream */
mfpict->mm = MM_ANISOTROPIC;
mfpict->xExt = header.dwObjectExtentX;
mfpict->yExt = header.dwObjectExtentY;
/* FIXME: get this from the stream */
if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
{
mfpict->xExt = header.dwObjectExtentX;
mfpict->yExt = header.dwObjectExtentY;
}
else
{
mfpict->xExt = ((mf_place.bounding_box[2] - mf_place.bounding_box[0])
* 2540) / mf_place.inch;
mfpict->yExt = ((mf_place.bounding_box[3] - mf_place.bounding_box[1])
* 2540) / mf_place.inch;
}
mfpict->hMF = SetMetaFileBitsEx( stat.cbSize.u.LowPart, bits );
if (!mfpict->hMF)
hr = E_FAIL;
Expand All @@ -623,48 +668,61 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
{
HRESULT hr;
STATSTG stat;
void *dib;
BYTE *dib;
HGLOBAL hglobal;
ULONG read, info_size, bi_size;
BITMAPFILEHEADER file;
BITMAPINFOHEADER *info;
CLIPFORMAT cf;
PresentationDataHeader pres;
ULARGE_INTEGER current_pos;
static const LARGE_INTEGER offset_zero;

hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
if (FAILED( hr )) return hr;

if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
{
FIXME( "Unimplemented for presentation stream\n" );
return E_FAIL;
hr = read_clipformat( stm, &cf );
if (hr != S_OK) return hr;
hr = IStream_Read( stm, &pres, sizeof(pres), &read );
if (hr != S_OK) return hr;
}
else
{
hr = IStream_Read( stm, &file, sizeof(BITMAPFILEHEADER), &read );
if (hr != S_OK) return hr;
}

hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
hr = IStream_Seek( stm, offset_zero, STREAM_SEEK_CUR, &current_pos );
if (FAILED( hr )) return hr;

if (stat.cbSize.QuadPart < sizeof(file) + sizeof(DWORD)) return E_FAIL;
hr = IStream_Read( stm, &file, sizeof(file), &read );
if (hr != S_OK || read != sizeof(file)) return E_FAIL;
stat.cbSize.QuadPart -= sizeof(file);
stat.cbSize.QuadPart -= current_pos.QuadPart;

hglobal = GlobalAlloc( GMEM_MOVEABLE, stat.cbSize.u.LowPart );
if (!hglobal) return E_OUTOFMEMORY;
dib = GlobalLock( hglobal );

/* read first DWORD of BITMAPINFOHEADER */
hr = IStream_Read( stm, dib, sizeof(DWORD), &read );
if (hr != S_OK || read != sizeof(DWORD)) goto fail;
if (hr != S_OK) goto fail;
bi_size = *(DWORD *)dib;
if (stat.cbSize.QuadPart < bi_size) goto fail;

hr = IStream_Read( stm, (char *)dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
if (hr != S_OK || read != bi_size - sizeof(DWORD)) goto fail;
/* read rest of BITMAPINFOHEADER */
hr = IStream_Read( stm, dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
if (hr != S_OK) goto fail;

info_size = bitmap_info_size( dib, DIB_RGB_COLORS );
info_size = bitmap_info_size( (BITMAPINFO *)dib, DIB_RGB_COLORS );
if (stat.cbSize.QuadPart < info_size) goto fail;
if (info_size > bi_size)
{
hr = IStream_Read( stm, (char *)dib + bi_size, info_size - bi_size, &read );
if (hr != S_OK || read != info_size - bi_size) goto fail;
hr = IStream_Read( stm, dib + bi_size, info_size - bi_size, &read );
if (hr != S_OK) goto fail;
}
stat.cbSize.QuadPart -= info_size;

if (file.bfOffBits)
/* set Stream pointer to beginning of bitmap bits */
if (cache_entry->load_stream_num == STREAM_NUMBER_CONTENTS && file.bfOffBits)
{
LARGE_INTEGER skip;

Expand All @@ -675,8 +733,8 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
stat.cbSize.QuadPart -= skip.QuadPart;
}

hr = IStream_Read( stm, (char *)dib + info_size, stat.cbSize.u.LowPart, &read );
if (hr != S_OK || read != stat.cbSize.QuadPart) goto fail;
hr = IStream_Read( stm, dib + info_size, stat.cbSize.u.LowPart, &read );
if (hr != S_OK) goto fail;

if (bi_size >= sizeof(*info))
{
Expand All @@ -695,15 +753,69 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
cache_entry->stgmedium.tymed = TYMED_HGLOBAL;
cache_entry->stgmedium.u.hGlobal = hglobal;

return S_OK;
return hr;

fail:
GlobalUnlock( hglobal );
GlobalFree( hglobal );
return E_FAIL;
return hr;

}

static HRESULT load_emf( DataCacheEntry *cache_entry, IStream *stm )
{
HRESULT hr;

if (cache_entry->load_stream_num != STREAM_NUMBER_CONTENTS)
{
STGMEDIUM stgmed;

hr = load_mf_pict( cache_entry, stm );
if (SUCCEEDED( hr ))
{
hr = synthesize_emf( cache_entry->stgmedium.u.hMetaFilePict, &stgmed );
ReleaseStgMedium( &cache_entry->stgmedium );
}
if (SUCCEEDED( hr ))
cache_entry->stgmedium = stgmed;
}
else
{
STATSTG stat;
BYTE *data;
ULONG read, size_bits;

hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );

if (SUCCEEDED( hr ))
{
data = HeapAlloc( GetProcessHeap(), 0, stat.cbSize.u.LowPart );
if (!data) return E_OUTOFMEMORY;

hr = IStream_Read( stm, data, stat.cbSize.u.LowPart, &read );
if (hr != S_OK)
{
HeapFree( GetProcessHeap(), 0, data );
return hr;
}

if (read <= sizeof(DWORD) + sizeof(ENHMETAHEADER))
{
HeapFree( GetProcessHeap(), 0, data );
return E_FAIL;
}
size_bits = read - sizeof(DWORD) - sizeof(ENHMETAHEADER);
cache_entry->stgmedium.u.hEnhMetaFile = SetEnhMetaFileBits( size_bits, data + (read - size_bits) );
cache_entry->stgmedium.tymed = TYMED_ENHMF;
cache_entry->stgmedium.pUnkForRelease = NULL;

HeapFree( GetProcessHeap(), 0, data );
}
}

return hr;
}

/************************************************************************
* DataCacheEntry_LoadData
*
Expand Down Expand Up @@ -736,6 +848,10 @@ static HRESULT DataCacheEntry_LoadData(DataCacheEntry *cache_entry, IStorage *st
hr = load_dib( cache_entry, stm );
break;

case CF_ENHMETAFILE:
hr = load_emf( cache_entry, stm );
break;

default:
FIXME( "Unimplemented clip format %x\n", cache_entry->fmtetc.cfFormat );
hr = E_NOTIMPL;
Expand Down Expand Up @@ -817,18 +933,6 @@ static HRESULT save_dib(DataCacheEntry *entry, BOOL contents, IStream *stream)
return hr;
}

#include <pshpack2.h>
struct meta_placeable
{
DWORD key;
WORD hwmf;
WORD bounding_box[4];
WORD inch;
DWORD reserved;
WORD checksum;
};
#include <poppack.h>

static HRESULT save_mfpict(DataCacheEntry *entry, BOOL contents, IStream *stream)
{
HRESULT hr = S_OK;
Expand Down Expand Up @@ -1118,30 +1222,6 @@ static HRESULT synthesize_bitmap( HGLOBAL dib, STGMEDIUM *med )
return hr;
}

static HRESULT synthesize_emf( HMETAFILEPICT data, STGMEDIUM *med )
{
METAFILEPICT *pict;
HRESULT hr = E_FAIL;
UINT size;
void *bits;

if (!(pict = GlobalLock( data ))) return hr;

size = GetMetaFileBitsEx( pict->hMF, 0, NULL );
if ((bits = HeapAlloc( GetProcessHeap(), 0, size )))
{
GetMetaFileBitsEx( pict->hMF, size, bits );
med->u.hEnhMetaFile = SetWinMetaFileBits( size, bits, NULL, pict );
HeapFree( GetProcessHeap(), 0, bits );
med->tymed = TYMED_ENHMF;
med->pUnkForRelease = NULL;
hr = S_OK;
}

GlobalUnlock( data );
return hr;
}

static HRESULT DataCacheEntry_SetData(DataCacheEntry *cache_entry,
const FORMATETC *formatetc,
STGMEDIUM *stgmedium,
Expand Down Expand Up @@ -1763,6 +1843,7 @@ static HRESULT WINAPI DataCache_Load( IPersistStorage *iface, IStorage *stg )

LIST_FOR_EACH_ENTRY_SAFE( entry, cursor2, &This->cache_list, DataCacheEntry, entry )
DataCacheEntry_Destroy( This, entry );
This->clsid = CLSID_NULL;

ReadClassStg( stg, &clsid );
hr = create_automatic_entry( This, &clsid );
Expand Down

1 comment on commit 85037eb

@JoachimHenze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention, this commit did introduce the following regression:
https://jira.reactos.org/browse/CORE-14696

Please sign in to comment.