From 05aeafcb9c58a0e9e9a05c06ebc85c920600ef5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 5 Sep 2005 21:56:14 +0000 Subject: [PATCH] Sync to Wine-20050830: Francois Gouget - Use LPSTORAGE to better match the PSDK. Document the real SEGPTR type using the standard documentation mechanisms. Fixes winapi_check warnings. Robert Shearman - Remove unused thread handle entry from the apartment structure. - Implement IMarshal on proxies so that we don't end up with proxies to proxies, causing potential deadlock issues and performance problems. - Add a test for this situation and remove the todo_wine from another test that now succeeds. - Add stub for CoAllowSetForegroundWindow. Vincent Beron - Remove local declarations already in included public headers. - Correct mismatches between spec files and comments about export number. Alexandre Julliard - Uncomment the typedef in the DECLARE_INTERFACE macro, and get rid of duplicate typedefs. - Use the proper WOW functions everywhere instead of the K32WOW variant. - Don't prefix the functions DllCanUnloadNow, DllGetClassObject and Dll(Un)RegisterServer with the dll name so that the compiler can check the prototypes. - Remove duplicate definition of FILE_BEGIN. - Replace the _ICOM_THIS_From macros by inline functions the way it's already done in shelllink.c. Mike McCormack - Warning fixes for gcc 4.0. - Fix some gcc 4.0 warnings. - return a precomputed result for a NULL string - pass strlen an LPSTR to eliminate a sign warning Marcus Meissner - Implemented ILockBytes16 (memorystream) support for the 16bit compound storage implementation. - Added ReadClassStg, OleDoAutoConvert, GetConvertStg implementations/stubs. Marcus Meissner - Added CoCreateInstance16, CoGetClassObject16, OleLoad16 stubs. svn path=/trunk/; revision=17678 --- reactos/lib/ole32/antimoniker.c | 11 +- reactos/lib/ole32/compobj.c | 93 +++- reactos/lib/ole32/compobj.spec | 4 +- reactos/lib/ole32/compobj_private.h | 4 +- reactos/lib/ole32/compositemoniker.c | 10 +- reactos/lib/ole32/datacache.c | 127 +++-- reactos/lib/ole32/defaulthandler.c | 118 +++-- reactos/lib/ole32/errorinfo.c | 60 ++- reactos/lib/ole32/filemoniker.c | 13 +- reactos/lib/ole32/ftmarshal.c | 16 +- reactos/lib/ole32/ifs.h | 8 + reactos/lib/ole32/itemmoniker.c | 13 +- reactos/lib/ole32/marshal.c | 103 +++- reactos/lib/ole32/moniker.c | 21 +- reactos/lib/ole32/moniker.h | 2 - reactos/lib/ole32/ole16.c | 6 +- reactos/lib/ole32/ole2.c | 11 +- reactos/lib/ole32/ole2.spec | 8 +- reactos/lib/ole32/ole2_16.c | 17 + reactos/lib/ole32/ole32.spec | 3 +- reactos/lib/ole32/oleproxy.c | 2 +- reactos/lib/ole32/stg_prop.c | 27 +- reactos/lib/ole32/storage.c | 728 ++++++++++++++++++--------- reactos/lib/ole32/storage.spec | 2 +- reactos/lib/ole32/storage32.c | 4 +- 25 files changed, 939 insertions(+), 472 deletions(-) diff --git a/reactos/lib/ole32/antimoniker.c b/reactos/lib/ole32/antimoniker.c index 6993b42f722..c01552510e0 100644 --- a/reactos/lib/ole32/antimoniker.c +++ b/reactos/lib/ole32/antimoniker.c @@ -53,6 +53,11 @@ typedef struct AntiMonikerImpl{ } AntiMonikerImpl; +static inline IMoniker *impl_from_IROTData( IROTData *iface ) +{ + return (IMoniker *)((char*)iface - FIELD_OFFSET(AntiMonikerImpl, lpvtbl2)); +} + /******************************************************************************* * AntiMoniker_QueryInterface @@ -485,7 +490,7 @@ AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys) static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p,%p,%p)\n",iface,riid,ppvObject); @@ -497,7 +502,7 @@ AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObje */ static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); @@ -509,7 +514,7 @@ static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface) */ static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); diff --git a/reactos/lib/ole32/compobj.c b/reactos/lib/ole32/compobj.c index f0a72d40975..8c7a8bd0441 100644 --- a/reactos/lib/ole32/compobj.c +++ b/reactos/lib/ole32/compobj.c @@ -224,9 +224,6 @@ static APARTMENT *apartment_construct(DWORD model) apt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*apt)); apt->tid = GetCurrentThreadId(); - DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), &apt->thread, - THREAD_ALL_ACCESS, FALSE, 0); list_init(&apt->proxies); list_init(&apt->stubmgrs); @@ -360,7 +357,6 @@ DWORD apartment_release(struct apartment *apt) DEBUG_CLEAR_CRITSEC_NAME(&apt->cs); DeleteCriticalSection(&apt->cs); - CloseHandle(apt->thread); HeapFree(GetProcessHeap(), 0, apt); } @@ -813,27 +809,29 @@ HRESULT WINAPI CoCreateGuid(GUID *pguid) */ HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id) { - const BYTE *s = (const BYTE *) idstr; + const BYTE *s; int i; BYTE table[256]; - if (!s) - s = "{00000000-0000-0000-0000-000000000000}"; - else { /* validate the CLSID string */ + if (!idstr) { + memset( id, 0, sizeof (CLSID) ); + return S_OK; + } - if (strlen(s) != 38) - return CO_E_CLASSSTRING; + /* validate the CLSID string */ + if (strlen(idstr) != 38) + return CO_E_CLASSSTRING; - if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}')) - return CO_E_CLASSSTRING; + s = (const BYTE *) idstr; + if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}')) + return CO_E_CLASSSTRING; - for (i=1; i<37; i++) { - if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue; - if (!(((s[i] >= '0') && (s[i] <= '9')) || - ((s[i] >= 'a') && (s[i] <= 'f')) || - ((s[i] >= 'A') && (s[i] <= 'F')))) - return CO_E_CLASSSTRING; - } + for (i=1; i<37; i++) { + if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue; + if (!(((s[i] >= '0') && (s[i] <= '9')) || + ((s[i] >= 'a') && (s[i] <= 'f')) || + ((s[i] >= 'A') && (s[i] <= 'F')))) + return CO_E_CLASSSTRING; } TRACE("%s -> %p\n", s, id); @@ -1026,7 +1024,7 @@ HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID) if (ret == S_OK) { - DWORD progidlen = 0; + LONG progidlen = 0; if (RegQueryValueW(hkey, NULL, NULL, &progidlen)) ret = REGDB_E_CLASSNOTREG; @@ -1064,7 +1062,7 @@ HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID) HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid) { char *buf,buf2[80]; - DWORD buf2len; + LONG buf2len; HRESULT err; HKEY xhkey; @@ -1101,7 +1099,7 @@ HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid) { static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 }; WCHAR buf2[CHARS_IN_GUID]; - DWORD buf2len = sizeof(buf2); + LONG buf2len = sizeof(buf2); HKEY xhkey; WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) ); @@ -1166,7 +1164,7 @@ HRESULT WINAPI CoGetPSClsid(REFIID riid, CLSID *pclsid) static const WCHAR wszPSC[] = {'\\','P','r','o','x','y','S','t','u','b','C','l','s','i','d','3','2',0}; WCHAR path[ARRAYSIZE(wszInterface) - 1 + CHARS_IN_GUID - 1 + ARRAYSIZE(wszPSC)]; WCHAR value[CHARS_IN_GUID]; - DWORD len; + LONG len; HKEY hkey; TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid); @@ -1562,7 +1560,6 @@ HRESULT COM_RegReadPath(HKEY hkeyroot, const WCHAR *keyname, const WCHAR *valuen } /*********************************************************************** - * CoGetClassObject [COMPOBJ.7] * CoGetClassObject [OLE32.@] * * FIXME. If request allows of several options and there is a failure @@ -1664,6 +1661,23 @@ HRESULT WINAPI CoGetClassObject( return hres; } + +/*********************************************************************** + * CoGetClassObject [COMPOBJ.7] + * + */ +HRESULT WINAPI CoGetClassObject16( + REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo, + REFIID iid, LPVOID *ppv) +{ + FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid)); + + if (pServerInfo) { + FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName)); + FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo); + } + return E_NOTIMPL; +} /*********************************************************************** * CoResumeClassObjects (OLE32.@) * @@ -1772,8 +1786,8 @@ HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid) return MK_E_INVALIDEXTENSION; } + /*********************************************************************** - * CoCreateInstance [COMPOBJ.13] * CoCreateInstance [OLE32.@] */ HRESULT WINAPI CoCreateInstance( @@ -1840,6 +1854,23 @@ HRESULT WINAPI CoCreateInstance( return hres; } +/*********************************************************************** + * CoCreateInstance [COMPOBJ.13] + */ +HRESULT WINAPI CoCreateInstance16( + REFCLSID rclsid, + LPUNKNOWN pUnkOuter, + DWORD dwClsContext, + REFIID iid, + LPVOID *ppv) +{ + FIXME("(%s, %p, %lx, %s, %p), stub!\n", + debugstr_guid(rclsid), pUnkOuter, dwClsContext, debugstr_guid(iid), + ppv + ); + return E_NOTIMPL; +} + /*********************************************************************** * CoCreateInstanceEx [OLE32.@] */ @@ -2173,7 +2204,7 @@ HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew) static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0}; HKEY hkey = NULL; WCHAR buf[CHARS_IN_GUID]; - DWORD len; + LONG len; HRESULT res = S_OK; if (ERROR_SUCCESS != COM_OpenKeyForCLSID(clsidOld, KEY_READ, &hkey)) @@ -2459,6 +2490,16 @@ BOOL WINAPI CoIsHandlerConnected(IUnknown *pUnk) return TRUE; } + +/*********************************************************************** + * CoAllowSetForegroundWindow [OLE32.@] + * + */ +HRESULT WINAPI CoAllowSetForegroundWindow(IUnknown *pUnk, void *pvReserved) +{ + FIXME("(%p, %p): stub\n", pUnk, pvReserved); + return S_OK; +} /*********************************************************************** * CoQueryProxyBlanket [OLE32.@] diff --git a/reactos/lib/ole32/compobj.spec b/reactos/lib/ole32/compobj.spec index f218cceefb1..af946920192 100644 --- a/reactos/lib/ole32/compobj.spec +++ b/reactos/lib/ole32/compobj.spec @@ -4,13 +4,13 @@ 4 pascal CoGetMalloc(long ptr) CoGetMalloc16 5 pascal CoRegisterClassObject(ptr ptr long long ptr) CoRegisterClassObject16 6 pascal CoRevokeClassObject(long) CoRevokeClassObject16 -7 pascal CoGetClassObject(ptr long ptr ptr ptr) CoGetClassObject +7 pascal CoGetClassObject(ptr long ptr ptr ptr) CoGetClassObject16 8 stub COMARSHALINTERFACE 9 stub COUNMARSHALINTERFACE 10 stub COLOADLIBRARY 11 stub COFREELIBRARY 12 stub COFREEALLLIBRARIES -13 pascal CoCreateInstance(ptr ptr long ptr ptr) CoCreateInstance +13 pascal CoCreateInstance(ptr ptr long ptr ptr) CoCreateInstance16 14 stub STRINGFROMIID 15 pascal CoDisconnectObject(ptr long) CoDisconnectObject 16 stub CORELEASEMARSHALDATA diff --git a/reactos/lib/ole32/compobj_private.h b/reactos/lib/ole32/compobj_private.h index 3289b118948..04231e34909 100644 --- a/reactos/lib/ole32/compobj_private.h +++ b/reactos/lib/ole32/compobj_private.h @@ -96,8 +96,8 @@ struct ifproxy struct list entry; /* entry in proxy_manager list (CS parent->cs) */ struct proxy_manager *parent; /* owning proxy_manager (RO) */ LPVOID iface; /* interface pointer (RO) */ + STDOBJREF stdobjref; /* marshal data that represents this object (RO) */ IID iid; /* interface ID (RO) */ - IPID ipid; /* imported interface ID (RO) */ LPRPCPROXYBUFFER proxy; /* interface proxy (RO) */ DWORD refs; /* imported (public) references (MUTEX parent->remoting_mutex) */ IRpcChannelBuffer *chan; /* channel to object (CS parent->cs) */ @@ -107,6 +107,7 @@ struct ifproxy struct proxy_manager { const IMultiQIVtbl *lpVtbl; + const IMarshalVtbl *lpVtblMarshal; struct apartment *parent; /* owning apartment (RO) */ struct list entry; /* entry in apartment (CS parent->cs) */ OXID oxid; /* object exported ID (RO) */ @@ -127,7 +128,6 @@ struct apartment LONG refs; /* refcount of the apartment (LOCK) */ DWORD model; /* threading model (RO) */ DWORD tid; /* thread id (RO) */ - HANDLE thread; /* thread handle (RO) */ OXID oxid; /* object exporter ID (RO) */ LONG ipidc; /* interface pointer ID counter, starts at 1 (LOCK) */ HWND win; /* message window (RO) */ diff --git a/reactos/lib/ole32/compositemoniker.c b/reactos/lib/ole32/compositemoniker.c index 87c483ad4ce..c6510abefc5 100644 --- a/reactos/lib/ole32/compositemoniker.c +++ b/reactos/lib/ole32/compositemoniker.c @@ -80,6 +80,10 @@ typedef struct EnumMonikerImpl{ } EnumMonikerImpl; +static inline IMoniker *impl_from_IROTData( IROTData *iface ) +{ + return (IMoniker *)((char*)iface - FIELD_OFFSET(CompositeMonikerImpl, lpvtbl2)); +} static HRESULT EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker,ULONG tabSize,ULONG currentPos,BOOL leftToRigth,IEnumMoniker ** ppmk); @@ -1208,7 +1212,7 @@ CompositeMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid, VOID** ppvObject) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p,%p,%p)\n",iface,riid,ppvObject); @@ -1221,7 +1225,7 @@ CompositeMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid, static ULONG WINAPI CompositeMonikerROTDataImpl_AddRef(IROTData *iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); @@ -1233,7 +1237,7 @@ CompositeMonikerROTDataImpl_AddRef(IROTData *iface) */ static ULONG WINAPI CompositeMonikerROTDataImpl_Release(IROTData* iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); diff --git a/reactos/lib/ole32/datacache.c b/reactos/lib/ole32/datacache.c index f53fdb1345e..6079bb55e99 100644 --- a/reactos/lib/ole32/datacache.c +++ b/reactos/lib/ole32/datacache.c @@ -93,12 +93,12 @@ struct DataCache /* * List all interface VTables here */ - const IDataObjectVtbl* lpvtbl1; - const IUnknownVtbl* lpvtbl2; - const IPersistStorageVtbl* lpvtbl3; - const IViewObject2Vtbl* lpvtbl4; - const IOleCache2Vtbl* lpvtbl5; - const IOleCacheControlVtbl* lpvtbl6; + const IDataObjectVtbl* lpVtbl; + const IUnknownVtbl* lpvtblNDIUnknown; + const IPersistStorageVtbl* lpvtblIPersistStorage; + const IViewObject2Vtbl* lpvtblIViewObject; + const IOleCache2Vtbl* lpvtblIOleCache2; + const IOleCacheControlVtbl* lpvtblIOleCacheControl; /* * Reference count of this object @@ -136,12 +136,37 @@ typedef struct DataCache DataCache; * There is a version to accommodate all of the VTables implemented * by this object. */ -#define _ICOM_THIS_From_IDataObject(class,name) class* this = (class*)name -#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*)) -#define _ICOM_THIS_From_IPersistStorage(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*)) -#define _ICOM_THIS_From_IViewObject2(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*)) -#define _ICOM_THIS_From_IOleCache2(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*)) -#define _ICOM_THIS_From_IOleCacheControl(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*)) + +static inline DataCache *impl_from_IDataObject( IDataObject *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpVtbl)); +} + +static inline DataCache *impl_from_NDIUnknown( IUnknown *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblNDIUnknown)); +} + +static inline DataCache *impl_from_IPersistStorage( IPersistStorage *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIPersistStorage)); +} + +static inline DataCache *impl_from_IViewObject2( IViewObject2 *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIViewObject)); +} + +static inline DataCache *impl_from_IOleCache2( IOleCache2 *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIOleCache2)); +} + +static inline DataCache *impl_from_IOleCacheControl( IOleCacheControl *iface ) +{ + return (DataCache *)((char*)iface - FIELD_OFFSET(DataCache, lpvtblIOleCacheControl)); +} + /* * Prototypes for the methods of the DataCache class. @@ -489,7 +514,7 @@ static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_NDIUnknown(DataCache, iface); + DataCache *this = impl_from_NDIUnknown(iface); /* * Perform a sanity check on the parameters. @@ -511,26 +536,26 @@ static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface( } else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) { - *ppvObject = (IDataObject*)&(this->lpvtbl1); + *ppvObject = (IDataObject*)&(this->lpVtbl); } else if ( (memcmp(&IID_IPersistStorage, riid, sizeof(IID_IPersistStorage)) == 0) || (memcmp(&IID_IPersist, riid, sizeof(IID_IPersist)) == 0) ) { - *ppvObject = (IPersistStorage*)&(this->lpvtbl3); + *ppvObject = (IPersistStorage*)&(this->lpvtblIPersistStorage); } else if ( (memcmp(&IID_IViewObject, riid, sizeof(IID_IViewObject)) == 0) || (memcmp(&IID_IViewObject2, riid, sizeof(IID_IViewObject2)) == 0) ) { - *ppvObject = (IViewObject2*)&(this->lpvtbl4); + *ppvObject = (IViewObject2*)&(this->lpvtblIViewObject); } else if ( (memcmp(&IID_IOleCache, riid, sizeof(IID_IOleCache)) == 0) || (memcmp(&IID_IOleCache2, riid, sizeof(IID_IOleCache2)) == 0) ) { - *ppvObject = (IOleCache2*)&(this->lpvtbl5); + *ppvObject = (IOleCache2*)&(this->lpvtblIOleCache2); } else if (memcmp(&IID_IOleCacheControl, riid, sizeof(IID_IOleCacheControl)) == 0) { - *ppvObject = (IOleCacheControl*)&(this->lpvtbl6); + *ppvObject = (IOleCacheControl*)&(this->lpvtblIOleCacheControl); } /* @@ -562,7 +587,7 @@ static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface( static ULONG WINAPI DataCache_NDIUnknown_AddRef( IUnknown* iface) { - _ICOM_THIS_From_NDIUnknown(DataCache, iface); + DataCache *this = impl_from_NDIUnknown(iface); return InterlockedIncrement(&this->ref); } @@ -577,7 +602,7 @@ static ULONG WINAPI DataCache_NDIUnknown_AddRef( static ULONG WINAPI DataCache_NDIUnknown_Release( IUnknown* iface) { - _ICOM_THIS_From_NDIUnknown(DataCache, iface); + DataCache *this = impl_from_NDIUnknown(iface); ULONG ref; /* @@ -608,7 +633,7 @@ static HRESULT WINAPI DataCache_IDataObject_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IDataObject(DataCache, iface); + DataCache *this = impl_from_IDataObject(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -621,7 +646,7 @@ static HRESULT WINAPI DataCache_IDataObject_QueryInterface( static ULONG WINAPI DataCache_IDataObject_AddRef( IDataObject* iface) { - _ICOM_THIS_From_IDataObject(DataCache, iface); + DataCache *this = impl_from_IDataObject(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -634,7 +659,7 @@ static ULONG WINAPI DataCache_IDataObject_AddRef( static ULONG WINAPI DataCache_IDataObject_Release( IDataObject* iface) { - _ICOM_THIS_From_IDataObject(DataCache, iface); + DataCache *this = impl_from_IDataObject(iface); return IUnknown_Release(this->outerUnknown); } @@ -886,7 +911,7 @@ static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -899,7 +924,7 @@ static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface( static ULONG WINAPI DataCache_IPersistStorage_AddRef( IPersistStorage* iface) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -912,7 +937,7 @@ static ULONG WINAPI DataCache_IPersistStorage_AddRef( static ULONG WINAPI DataCache_IPersistStorage_Release( IPersistStorage* iface) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); return IUnknown_Release(this->outerUnknown); } @@ -979,7 +1004,7 @@ static HRESULT WINAPI DataCache_Load( IPersistStorage* iface, IStorage* pStg) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); TRACE("(%p, %p)\n", iface, pStg); @@ -1012,7 +1037,7 @@ static HRESULT WINAPI DataCache_Save( IStorage* pStg, BOOL fSameAsLoad) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); TRACE("(%p, %p, %d)\n", iface, pStg, fSameAsLoad); @@ -1072,7 +1097,7 @@ static HRESULT WINAPI DataCache_SaveCompleted( static HRESULT WINAPI DataCache_HandsOffStorage( IPersistStorage* iface) { - _ICOM_THIS_From_IPersistStorage(DataCache, iface); + DataCache *this = impl_from_IPersistStorage(iface); TRACE("(%p)\n", iface); @@ -1100,7 +1125,7 @@ static HRESULT WINAPI DataCache_IViewObject2_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -1113,7 +1138,7 @@ static HRESULT WINAPI DataCache_IViewObject2_QueryInterface( static ULONG WINAPI DataCache_IViewObject2_AddRef( IViewObject2* iface) { - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -1126,7 +1151,7 @@ static ULONG WINAPI DataCache_IViewObject2_AddRef( static ULONG WINAPI DataCache_IViewObject2_Release( IViewObject2* iface) { - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); return IUnknown_Release(this->outerUnknown); } @@ -1156,7 +1181,7 @@ static HRESULT WINAPI DataCache_Draw( HMETAFILE presMetafile = 0; HRESULT hres; - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); TRACE("(%p, %lx, %ld, %p, %p, %p, %p, %p, %p, %lx)\n", iface, @@ -1295,7 +1320,7 @@ static HRESULT WINAPI DataCache_SetAdvise( DWORD advf, IAdviseSink* pAdvSink) { - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); TRACE("(%p, %lx, %lx, %p)\n", iface, aspects, advf, pAdvSink); @@ -1350,7 +1375,7 @@ static HRESULT WINAPI DataCache_GetAdvise( DWORD* pAdvf, IAdviseSink** ppAdvSink) { - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); TRACE("(%p, %p, %p, %p)\n", iface, pAspects, pAdvf, ppAdvSink); @@ -1390,7 +1415,7 @@ static HRESULT WINAPI DataCache_GetExtent( PresentationDataHeader presData; HRESULT hres = E_FAIL; - _ICOM_THIS_From_IViewObject2(DataCache, iface); + DataCache *this = impl_from_IViewObject2(iface); TRACE("(%p, %lx, %ld, %p, %p)\n", iface, dwDrawAspect, lindex, ptd, lpsizel); @@ -1459,7 +1484,7 @@ static HRESULT WINAPI DataCache_IOleCache2_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IOleCache2(DataCache, iface); + DataCache *this = impl_from_IOleCache2(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -1472,7 +1497,7 @@ static HRESULT WINAPI DataCache_IOleCache2_QueryInterface( static ULONG WINAPI DataCache_IOleCache2_AddRef( IOleCache2* iface) { - _ICOM_THIS_From_IOleCache2(DataCache, iface); + DataCache *this = impl_from_IOleCache2(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -1485,7 +1510,7 @@ static ULONG WINAPI DataCache_IOleCache2_AddRef( static ULONG WINAPI DataCache_IOleCache2_Release( IOleCache2* iface) { - _ICOM_THIS_From_IOleCache2(DataCache, iface); + DataCache *this = impl_from_IOleCache2(iface); return IUnknown_Release(this->outerUnknown); } @@ -1568,7 +1593,7 @@ static HRESULT WINAPI DataCache_IOleCacheControl_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); + DataCache *this = impl_from_IOleCacheControl(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -1581,7 +1606,7 @@ static HRESULT WINAPI DataCache_IOleCacheControl_QueryInterface( static ULONG WINAPI DataCache_IOleCacheControl_AddRef( IOleCacheControl* iface) { - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); + DataCache *this = impl_from_IOleCacheControl(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -1594,7 +1619,7 @@ static ULONG WINAPI DataCache_IOleCacheControl_AddRef( static ULONG WINAPI DataCache_IOleCacheControl_Release( IOleCacheControl* iface) { - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); + DataCache *this = impl_from_IOleCacheControl(iface); return IUnknown_Release(this->outerUnknown); } @@ -1735,13 +1760,13 @@ HRESULT WINAPI CreateDataCache( /* * Make sure it supports the interface required by the caller. */ - hr = IUnknown_QueryInterface((IUnknown*)&(newCache->lpvtbl2), riid, ppvObj); + hr = IUnknown_QueryInterface((IUnknown*)&(newCache->lpvtblNDIUnknown), riid, ppvObj); /* * Release the reference obtained in the constructor. If * the QueryInterface was unsuccessful, it will free the class. */ - IUnknown_Release((IUnknown*)&(newCache->lpvtbl2)); + IUnknown_Release((IUnknown*)&(newCache->lpvtblNDIUnknown)); return hr; } @@ -1766,12 +1791,12 @@ static DataCache* DataCache_Construct( /* * Initialize the virtual function table. */ - newObject->lpvtbl1 = &DataCache_IDataObject_VTable; - newObject->lpvtbl2 = &DataCache_NDIUnknown_VTable; - newObject->lpvtbl3 = &DataCache_IPersistStorage_VTable; - newObject->lpvtbl4 = &DataCache_IViewObject2_VTable; - newObject->lpvtbl5 = &DataCache_IOleCache2_VTable; - newObject->lpvtbl6 = &DataCache_IOleCacheControl_VTable; + newObject->lpVtbl = &DataCache_IDataObject_VTable; + newObject->lpvtblNDIUnknown = &DataCache_NDIUnknown_VTable; + newObject->lpvtblIPersistStorage = &DataCache_IPersistStorage_VTable; + newObject->lpvtblIViewObject = &DataCache_IViewObject2_VTable; + newObject->lpvtblIOleCache2 = &DataCache_IOleCache2_VTable; + newObject->lpvtblIOleCacheControl = &DataCache_IOleCacheControl_VTable; /* * Start with one reference count. The caller of this function @@ -1786,7 +1811,7 @@ static DataCache* DataCache_Construct( * lifetime. */ if (pUnkOuter==NULL) - pUnkOuter = (IUnknown*)&(newObject->lpvtbl2); + pUnkOuter = (IUnknown*)&(newObject->lpvtblNDIUnknown); newObject->outerUnknown = pUnkOuter; diff --git a/reactos/lib/ole32/defaulthandler.c b/reactos/lib/ole32/defaulthandler.c index d59c3b6ba3f..7486a524b11 100644 --- a/reactos/lib/ole32/defaulthandler.c +++ b/reactos/lib/ole32/defaulthandler.c @@ -70,10 +70,10 @@ struct DefaultHandler /* * List all interface VTables here */ - const IOleObjectVtbl* lpvtbl1; - const IUnknownVtbl* lpvtbl2; - const IDataObjectVtbl* lpvtbl3; - const IRunnableObjectVtbl* lpvtbl4; + const IOleObjectVtbl* lpVtbl; + const IUnknownVtbl* lpvtblIUnknown; + const IDataObjectVtbl* lpvtblIDataObject; + const IRunnableObjectVtbl* lpvtblIRunnableObject; /* * Reference count of this object @@ -82,7 +82,7 @@ struct DefaultHandler /* * IUnknown implementation of the outer object. - */ +p */ IUnknown* outerUnknown; /* @@ -123,15 +123,31 @@ struct DefaultHandler typedef struct DefaultHandler DefaultHandler; /* - * Here, I define utility macros to help with the casting of the + * Here, I define utility functions to help with the casting of the * "this" parameter. * There is a version to accommodate all of the VTables implemented * by this object. */ -#define _ICOM_THIS_From_IOleObject(class,name) class* this = (class*)name -#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*)) -#define _ICOM_THIS_From_IDataObject(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*)) -#define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*)) +static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface ) +{ + return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl)); +} + +static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface ) +{ + return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown)); +} + +static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface ) +{ + return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject)); +} + +static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface ) +{ + return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject)); +} + /* * Prototypes for the methods of the DefaultHandler class. @@ -432,13 +448,13 @@ HRESULT WINAPI OleCreateDefaultHandler( /* * Make sure it supports the interface required by the caller. */ - hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj); + hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtblIUnknown), riid, ppvObj); /* * Release the reference obtained in the constructor. If * the QueryInterface was unsuccessful, it will free the class. */ - IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2)); + IUnknown_Release((IUnknown*)&(newHandler->lpvtblIUnknown)); return hr; } @@ -463,10 +479,10 @@ static DefaultHandler* DefaultHandler_Construct( /* * Initialize the virtual function table. */ - newObject->lpvtbl1 = &DefaultHandler_IOleObject_VTable; - newObject->lpvtbl2 = &DefaultHandler_NDIUnknown_VTable; - newObject->lpvtbl3 = &DefaultHandler_IDataObject_VTable; - newObject->lpvtbl4 = &DefaultHandler_IRunnableObject_VTable; + newObject->lpVtbl = &DefaultHandler_IOleObject_VTable; + newObject->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable; + newObject->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable; + newObject->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable; /* * Start with one reference count. The caller of this function @@ -481,7 +497,7 @@ static DefaultHandler* DefaultHandler_Construct( * lifetime. */ if (pUnkOuter==NULL) - pUnkOuter = (IUnknown*)&(newObject->lpvtbl2); + pUnkOuter = (IUnknown*)&(newObject->lpvtblIUnknown); newObject->outerUnknown = pUnkOuter; @@ -580,7 +596,7 @@ static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); + DefaultHandler *this = impl_from_NDIUnknown(iface); /* * Perform a sanity check on the parameters. @@ -602,15 +618,15 @@ static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface( } else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0) { - *ppvObject = (IOleObject*)&(this->lpvtbl1); + *ppvObject = (IOleObject*)&(this->lpVtbl); } else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) { - *ppvObject = (IDataObject*)&(this->lpvtbl3); + *ppvObject = (IDataObject*)&(this->lpvtblIDataObject); } else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0) { - *ppvObject = (IRunnableObject*)&(this->lpvtbl4); + *ppvObject = (IRunnableObject*)&(this->lpvtblIRunnableObject); } else { @@ -650,7 +666,7 @@ static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface( static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( IUnknown* iface) { - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); + DefaultHandler *this = impl_from_NDIUnknown(iface); return InterlockedIncrement(&this->ref); } @@ -665,7 +681,7 @@ static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( static ULONG WINAPI DefaultHandler_NDIUnknown_Release( IUnknown* iface) { - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); + DefaultHandler *this = impl_from_NDIUnknown(iface); ULONG ref; /* @@ -696,7 +712,7 @@ static HRESULT WINAPI DefaultHandler_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -709,7 +725,7 @@ static HRESULT WINAPI DefaultHandler_QueryInterface( static ULONG WINAPI DefaultHandler_AddRef( IOleObject* iface) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -722,7 +738,7 @@ static ULONG WINAPI DefaultHandler_AddRef( static ULONG WINAPI DefaultHandler_Release( IOleObject* iface) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); return IUnknown_Release(this->outerUnknown); } @@ -739,7 +755,7 @@ static HRESULT WINAPI DefaultHandler_SetClientSite( IOleObject* iface, IOleClientSite* pClientSite) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %p)\n", iface, pClientSite); @@ -774,7 +790,7 @@ static HRESULT WINAPI DefaultHandler_GetClientSite( IOleObject* iface, IOleClientSite** ppClientSite) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); /* * Sanity check. @@ -805,7 +821,7 @@ static HRESULT WINAPI DefaultHandler_SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %s, %s)\n", iface, @@ -888,7 +904,7 @@ static HRESULT WINAPI DefaultHandler_GetMoniker( DWORD dwWhichMoniker, IMoniker** ppmk) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %ld, %ld, %p)\n", iface, dwAssign, dwWhichMoniker, ppmk); @@ -967,7 +983,7 @@ static HRESULT WINAPI DefaultHandler_EnumVerbs( IOleObject* iface, IEnumOLEVERB** ppEnumOleVerb) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %p)\n", iface, ppEnumOleVerb); @@ -1007,7 +1023,7 @@ static HRESULT WINAPI DefaultHandler_GetUserClassID( IOleObject* iface, CLSID* pClsid) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %p)\n", iface, pClsid); @@ -1035,7 +1051,7 @@ static HRESULT WINAPI DefaultHandler_GetUserType( DWORD dwFormOfType, LPOLESTR* pszUserType) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType); @@ -1076,7 +1092,7 @@ static HRESULT WINAPI DefaultHandler_GetExtent( IViewObject2* cacheView = NULL; HRESULT hres; - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel); @@ -1123,7 +1139,7 @@ static HRESULT WINAPI DefaultHandler_Advise( DWORD* pdwConnection) { HRESULT hres = S_OK; - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection); @@ -1157,7 +1173,7 @@ static HRESULT WINAPI DefaultHandler_Unadvise( IOleObject* iface, DWORD dwConnection) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %ld)\n", iface, dwConnection); @@ -1184,7 +1200,7 @@ static HRESULT WINAPI DefaultHandler_EnumAdvise( IOleObject* iface, IEnumSTATDATA** ppenumAdvise) { - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %p)\n", iface, ppenumAdvise); @@ -1220,7 +1236,7 @@ static HRESULT WINAPI DefaultHandler_GetMiscStatus( DWORD* pdwStatus) { HRESULT hres; - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IOleObject(iface); TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus); @@ -1262,7 +1278,7 @@ static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -1275,7 +1291,7 @@ static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface( static ULONG WINAPI DefaultHandler_IDataObject_AddRef( IDataObject* iface) { - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -1288,7 +1304,7 @@ static ULONG WINAPI DefaultHandler_IDataObject_AddRef( static ULONG WINAPI DefaultHandler_IDataObject_Release( IDataObject* iface) { - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); return IUnknown_Release(this->outerUnknown); } @@ -1308,7 +1324,7 @@ static HRESULT WINAPI DefaultHandler_GetData( IDataObject* cacheDataObject = NULL; HRESULT hres; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium); @@ -1352,7 +1368,7 @@ static HRESULT WINAPI DefaultHandler_QueryGetData( IDataObject* cacheDataObject = NULL; HRESULT hres; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %p)\n", iface, pformatetc); @@ -1405,7 +1421,7 @@ static HRESULT WINAPI DefaultHandler_SetData( IDataObject* cacheDataObject = NULL; HRESULT hres; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease); @@ -1440,7 +1456,7 @@ static HRESULT WINAPI DefaultHandler_EnumFormatEtc( IEnumFORMATETC** ppenumFormatEtc) { HRESULT hres; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc); @@ -1465,7 +1481,7 @@ static HRESULT WINAPI DefaultHandler_DAdvise( DWORD* pdwConnection) { HRESULT hres = S_OK; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %p, %ld, %p, %p)\n", iface, pformatetc, advf, pAdvSink, pdwConnection); @@ -1503,7 +1519,7 @@ static HRESULT WINAPI DefaultHandler_DUnadvise( IDataObject* iface, DWORD dwConnection) { - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %ld)\n", iface, dwConnection); @@ -1532,7 +1548,7 @@ static HRESULT WINAPI DefaultHandler_EnumDAdvise( IDataObject* iface, IEnumSTATDATA** ppenumAdvise) { - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IDataObject(iface); TRACE("(%p, %p)\n", iface, ppenumAdvise); @@ -1574,7 +1590,7 @@ static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IRunnableObject(iface); return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); } @@ -1587,7 +1603,7 @@ static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface( static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( IRunnableObject* iface) { - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IRunnableObject(iface); return IUnknown_AddRef(this->outerUnknown); } @@ -1600,7 +1616,7 @@ static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( static ULONG WINAPI DefaultHandler_IRunnableObject_Release( IRunnableObject* iface) { - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); + DefaultHandler *this = impl_from_IRunnableObject(iface); return IUnknown_Release(this->outerUnknown); } diff --git a/reactos/lib/ole32/errorinfo.c b/reactos/lib/ole32/errorinfo.c index dc3b41e721a..fbeed0404c8 100644 --- a/reactos/lib/ole32/errorinfo.c +++ b/reactos/lib/ole32/errorinfo.c @@ -147,14 +147,22 @@ static const ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable; /* converts an object pointer to This */ -#define _IErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtei))) -#define _ICOM_THIS_From_IErrorInfo(class, name) class* This = (class*)(((char*)name)-_IErrorInfo_Offset) -#define _ICreateErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtcei))) -#define _ICOM_THIS_From_ICreateErrorInfo(class, name) class* This = (class*)(((char*)name)-_ICreateErrorInfo_Offset) +static inline ErrorInfoImpl *impl_from_IErrorInfo( IErrorInfo *iface ) +{ + return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtei)); +} + +static inline ErrorInfoImpl *impl_from_ICreateErrorInfo( ICreateErrorInfo *iface ) +{ + return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtcei)); +} + +static inline ErrorInfoImpl *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface ) +{ + return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtsei)); +} -#define _ISupportErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtsei))) -#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset) /* converts This to an object pointer @@ -186,7 +194,7 @@ static HRESULT WINAPI IErrorInfoImpl_QueryInterface( REFIID riid, VOID** ppvoid) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvoid); *ppvoid = NULL; @@ -217,7 +225,7 @@ static HRESULT WINAPI IErrorInfoImpl_QueryInterface( static ULONG WINAPI IErrorInfoImpl_AddRef( IErrorInfo* iface) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(count=%lu)\n",This,This->ref); return InterlockedIncrement(&This->ref); } @@ -225,7 +233,7 @@ static ULONG WINAPI IErrorInfoImpl_AddRef( static ULONG WINAPI IErrorInfoImpl_Release( IErrorInfo* iface) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p)->(count=%lu)\n",This,ref+1); @@ -243,7 +251,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetGUID( IErrorInfo* iface, GUID * pGUID) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(count=%lu)\n",This,This->ref); if(!pGUID )return E_INVALIDARG; memcpy(pGUID, &This->m_Guid, sizeof(GUID)); @@ -254,7 +262,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetSource( IErrorInfo* iface, BSTR *pBstrSource) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(pBstrSource=%p)\n",This,pBstrSource); if (pBstrSource == NULL) return E_INVALIDARG; @@ -266,7 +274,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetDescription( IErrorInfo* iface, BSTR *pBstrDescription) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(pBstrDescription=%p)\n",This,pBstrDescription); if (pBstrDescription == NULL) @@ -280,7 +288,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetHelpFile( IErrorInfo* iface, BSTR *pBstrHelpFile) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(pBstrHelpFile=%p)\n",This, pBstrHelpFile); if (pBstrHelpFile == NULL) @@ -294,7 +302,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetHelpContext( IErrorInfo* iface, DWORD *pdwHelpContext) { - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_IErrorInfo(iface); TRACE("(%p)->(pdwHelpContext=%p)\n",This, pdwHelpContext); if (pdwHelpContext == NULL) return E_INVALIDARG; @@ -322,7 +330,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_QueryInterface( REFIID riid, VOID** ppvoid) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid); } @@ -330,7 +338,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_QueryInterface( static ULONG WINAPI ICreateErrorInfoImpl_AddRef( ICreateErrorInfo* iface) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_AddRef(_IErrorInfo_(This)); } @@ -338,7 +346,7 @@ static ULONG WINAPI ICreateErrorInfoImpl_AddRef( static ULONG WINAPI ICreateErrorInfoImpl_Release( ICreateErrorInfo* iface) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_Release(_IErrorInfo_(This)); } @@ -348,7 +356,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetGUID( ICreateErrorInfo* iface, REFGUID rguid) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p)->(%s)\n", This, debugstr_guid(rguid)); memcpy(&This->m_Guid, rguid, sizeof(GUID)); return S_OK; @@ -358,7 +366,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetSource( ICreateErrorInfo* iface, LPOLESTR szSource) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p): %s\n",This, debugstr_w(szSource)); if (This->bstrSource != NULL) ERRORINFO_SysFreeString(This->bstrSource); @@ -371,7 +379,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetDescription( ICreateErrorInfo* iface, LPOLESTR szDescription) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p): %s\n",This, debugstr_w(szDescription)); if (This->bstrDescription != NULL) ERRORINFO_SysFreeString(This->bstrDescription); @@ -384,7 +392,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpFile( ICreateErrorInfo* iface, LPOLESTR szHelpFile) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p,%s)\n",This,debugstr_w(szHelpFile)); if (This->bstrHelpFile != NULL) ERRORINFO_SysFreeString(This->bstrHelpFile); @@ -396,7 +404,7 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpContext( ICreateErrorInfo* iface, DWORD dwHelpContext) { - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface); TRACE("(%p,%ld)\n",This,dwHelpContext); This->m_dwHelpContext = dwHelpContext; return S_OK; @@ -420,7 +428,7 @@ static HRESULT WINAPI ISupportErrorInfoImpl_QueryInterface( REFIID riid, VOID** ppvoid) { - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid); @@ -429,7 +437,7 @@ static HRESULT WINAPI ISupportErrorInfoImpl_QueryInterface( static ULONG WINAPI ISupportErrorInfoImpl_AddRef( ISupportErrorInfo* iface) { - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_AddRef(_IErrorInfo_(This)); } @@ -437,7 +445,7 @@ static ULONG WINAPI ISupportErrorInfoImpl_AddRef( static ULONG WINAPI ISupportErrorInfoImpl_Release( ISupportErrorInfo* iface) { - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface); TRACE("(%p)\n", This); return IErrorInfo_Release(_IErrorInfo_(This)); } @@ -447,7 +455,7 @@ static HRESULT WINAPI ISupportErrorInfoImpl_InterfaceSupportsErrorInfo( ISupportErrorInfo* iface, REFIID riid) { - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); + ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface); TRACE("(%p)->(%s)\n", This, debugstr_guid(riid)); return (IsEqualIID(riid, &This->m_Guid)) ? S_OK : S_FALSE; } diff --git a/reactos/lib/ole32/filemoniker.c b/reactos/lib/ole32/filemoniker.c index a4e6a73a3bb..d4494361462 100644 --- a/reactos/lib/ole32/filemoniker.c +++ b/reactos/lib/ole32/filemoniker.c @@ -60,6 +60,11 @@ typedef struct FileMonikerImpl{ IUnknown *pMarshal; /* custom marshaler */ } FileMonikerImpl; +static inline IMoniker *impl_from_IROTData( IROTData *iface ) +{ + return (IMoniker *)((char*)iface - FIELD_OFFSET(FileMonikerImpl, lpvtbl2)); +} + /* Local function used by filemoniker implementation */ static HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* iface, LPCOLESTR lpszPathName); static HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* iface); @@ -1198,7 +1203,7 @@ static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppvObject); @@ -1211,7 +1216,7 @@ FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObje static ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",This); @@ -1224,7 +1229,7 @@ FileMonikerROTDataImpl_AddRef(IROTData *iface) static ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",This); @@ -1238,7 +1243,7 @@ static HRESULT WINAPI FileMonikerROTDataImpl_GetComparisonData(IROTData* iface, BYTE* pbData, ULONG cbMax, ULONG* pcbData) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); FileMonikerImpl *This1 = (FileMonikerImpl *)This; int len = (strlenW(This1->filePathName)+1); int i; diff --git a/reactos/lib/ole32/ftmarshal.c b/reactos/lib/ole32/ftmarshal.c index 6c0ad7346be..31e1262ce1f 100644 --- a/reactos/lib/ole32/ftmarshal.c +++ b/reactos/lib/ole32/ftmarshal.c @@ -47,8 +47,10 @@ typedef struct _FTMarshalImpl { #define _IFTMUnknown_(This)(IUnknown*)&(This->lpVtbl) #define _IFTMarshal_(This) (IMarshal*)&(This->lpvtblFTM) -#define _IFTMarshall_Offset ((int)(&(((FTMarshalImpl*)0)->lpvtblFTM))) -#define _ICOM_THIS_From_IFTMarshal(class, name) class* This = (class*)(((char*)name)-_IFTMarshall_Offset); +static inline FTMarshalImpl *impl_from_IMarshal( IMarshal *iface ) +{ + return (FTMarshalImpl *)((char*)iface - FIELD_OFFSET(FTMarshalImpl, lpvtblFTM)); +} /* inner IUnknown to handle aggregation */ static HRESULT WINAPI @@ -104,7 +106,7 @@ static HRESULT WINAPI FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv) { - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); + FTMarshalImpl *This = impl_from_IMarshal(iface); TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv); return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv); @@ -114,7 +116,7 @@ static ULONG WINAPI FTMarshalImpl_AddRef (LPMARSHAL iface) { - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); + FTMarshalImpl *This = impl_from_IMarshal(iface); TRACE ("\n"); return IUnknown_AddRef (This->pUnkOuter); @@ -124,7 +126,7 @@ static ULONG WINAPI FTMarshalImpl_Release (LPMARSHAL iface) { - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); + FTMarshalImpl *This = impl_from_IMarshal(iface); TRACE ("\n"); return IUnknown_Release (This->pUnkOuter); @@ -146,7 +148,7 @@ FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD d IMarshal *pMarshal = NULL; HRESULT hres; - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); + FTMarshalImpl *This = impl_from_IMarshal(iface); FIXME ("(), stub!\n"); @@ -172,7 +174,7 @@ FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, vo IMarshal *pMarshal = NULL; HRESULT hres; - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); + FTMarshalImpl *This = impl_from_IMarshal(iface); FIXME ("(), stub!\n"); diff --git a/reactos/lib/ole32/ifs.h b/reactos/lib/ole32/ifs.h index bd95d9016e0..c7d5ff445de 100644 --- a/reactos/lib/ole32/ifs.h +++ b/reactos/lib/ole32/ifs.h @@ -39,6 +39,8 @@ typedef LPCSTR LPCOLESTR16; */ #undef INTERFACE +typedef struct IMalloc16 *LPMALLOC16; + #define INTERFACE IMalloc16 DECLARE_INTERFACE_(IMalloc16,IUnknown) { @@ -64,6 +66,8 @@ extern LPMALLOC16 IMalloc16_Constructor(void); /**********************************************************************/ +typedef struct ILockBytes16 *LPLOCKBYTES16; + #define INTERFACE ILockBytes16 DECLARE_INTERFACE_(ILockBytes16,IUnknown) { @@ -99,6 +103,8 @@ typedef struct tagSTATSTG16 DWORD reserved; } STATSTG16; +typedef struct IStream16 *LPSTREAM16; + #define INTERFACE IStream16 DECLARE_INTERFACE_(IStream16,ISequentialStream) { @@ -126,6 +132,8 @@ DECLARE_INTERFACE_(IStream16,ISequentialStream) typedef OLECHAR16 **SNB16; +typedef struct IStorage16 *LPSTORAGE16; + #define INTERFACE IStorage16 DECLARE_INTERFACE_(IStorage16,IUnknown) { diff --git a/reactos/lib/ole32/itemmoniker.c b/reactos/lib/ole32/itemmoniker.c index 853c28a4426..d812df50416 100644 --- a/reactos/lib/ole32/itemmoniker.c +++ b/reactos/lib/ole32/itemmoniker.c @@ -61,6 +61,11 @@ typedef struct ItemMonikerImpl{ IUnknown *pMarshal; /* custom marshaler */ } ItemMonikerImpl; +static inline IMoniker *impl_from_IROTData( IROTData *iface ) +{ + return (IMoniker *)((char*)iface - FIELD_OFFSET(ItemMonikerImpl, lpvtbl2)); +} + /********************************************************************************/ /* ItemMoniker prototype functions : */ @@ -929,7 +934,7 @@ HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys) HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p,%p,%p)\n",iface,riid,ppvObject); @@ -941,7 +946,7 @@ HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid */ ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); @@ -953,7 +958,7 @@ ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface) */ ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); TRACE("(%p)\n",iface); @@ -968,7 +973,7 @@ HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData* iface, ULONG cbMax, ULONG* pcbData) { - ICOM_THIS_From_IROTData(IMoniker, iface); + IMoniker *This = impl_from_IROTData(iface); ItemMonikerImpl *This1 = (ItemMonikerImpl *)This; int len = (strlenW(This1->itemName)+1); int i; diff --git a/reactos/lib/ole32/marshal.c b/reactos/lib/ole32/marshal.c index d0b8f80df2f..72763276d52 100644 --- a/reactos/lib/ole32/marshal.c +++ b/reactos/lib/ole32/marshal.c @@ -269,7 +269,7 @@ static HRESULT WINAPI ClientIdentity_QueryMultipleInterfaces(IMultiQI *iface, UL /* get the ipid of the first entry */ /* FIXME: should we implement ClientIdentity on the ifproxies instead * of the proxy_manager so we use the correct ipid here? */ - ipid = &LIST_ENTRY(list_head(&This->interfaces), struct ifproxy, entry)->ipid; + ipid = &LIST_ENTRY(list_head(&This->interfaces), struct ifproxy, entry)->stdobjref.ipid; /* get IRemUnknown proxy so we can communicate with the remote object */ hr = proxy_manager_get_remunknown(This, &remunk); @@ -329,6 +329,72 @@ static const IMultiQIVtbl ClientIdentity_Vtbl = ClientIdentity_QueryMultipleInterfaces }; +static HRESULT WINAPI Proxy_QueryInterface(IMarshal *iface, REFIID riid, void **ppvObject) +{ + ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface); + return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject); +} + +static ULONG WINAPI Proxy_AddRef(IMarshal *iface) +{ + ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface); + return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl); +} + +/* FIXME: remove these */ +static HRESULT WINAPI StdMarshalImpl_GetUnmarshalClass(LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, CLSID* pCid); +static HRESULT WINAPI StdMarshalImpl_GetMarshalSizeMax(LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, DWORD* pSize); +static HRESULT WINAPI StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv); +static HRESULT WINAPI StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm); +static HRESULT WINAPI StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved); + +static ULONG WINAPI Proxy_Release(IMarshal *iface) +{ + ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface); + return IMultiQI_Release((IMultiQI *)&This->lpVtbl); +} + +static HRESULT WINAPI Proxy_MarshalInterface( + LPMARSHAL iface, IStream *pStm, REFIID riid, void* pv, DWORD dwDestContext, + void* pvDestContext, DWORD mshlflags) +{ + ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface); + ULONG res; + HRESULT hr; + STDOBJREF stdobjref; + struct ifproxy *ifproxy; + + TRACE("(...,%s,...)\n", debugstr_guid(riid)); + + hr = proxy_manager_find_ifproxy(This, riid, &ifproxy); + if (FAILED(hr)) + { + ERR("couldn't find proxy for interface %s, error 0x%08lx\n", debugstr_guid(riid), hr); + return hr; + } + + stdobjref = ifproxy->stdobjref; + /* FIXME: optimization - share out proxy's public references if possible + * instead of making new proxy do a roundtrip through the server */ + stdobjref.cPublicRefs = 0; /* InterlockedDecrement(&This->stdobjref.cPublicRefs) >= 0 ? 1 : 0 */ + hr = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res); + + return hr; +} + +static const IMarshalVtbl ProxyMarshal_Vtbl = +{ + Proxy_QueryInterface, + Proxy_AddRef, + Proxy_Release, + StdMarshalImpl_GetUnmarshalClass, + StdMarshalImpl_GetMarshalSizeMax, + Proxy_MarshalInterface, + StdMarshalImpl_UnmarshalInterface, + StdMarshalImpl_ReleaseMarshalData, + StdMarshalImpl_DisconnectObject +}; + static HRESULT ifproxy_get_public_ref(struct ifproxy * This) { HRESULT hr = S_OK; @@ -350,7 +416,7 @@ static HRESULT ifproxy_get_public_ref(struct ifproxy * This) { HRESULT hrref; REMINTERFACEREF rif; - rif.ipid = This->ipid; + rif.ipid = This->stdobjref.ipid; rif.cPublicRefs = NORMALEXTREFS; rif.cPrivateRefs = 0; hr = IRemUnknown_RemAddRef(remunk, 1, &rif, &hrref); @@ -385,7 +451,7 @@ static HRESULT ifproxy_release_public_refs(struct ifproxy * This) if (hr == S_OK) { REMINTERFACEREF rif; - rif.ipid = This->ipid; + rif.ipid = This->stdobjref.ipid; rif.cPublicRefs = This->refs; rif.cPrivateRefs = 0; hr = IRemUnknown_RemRelease(remunk, 1, &rif); @@ -454,6 +520,7 @@ static HRESULT proxy_manager_construct( } This->lpVtbl = &ClientIdentity_Vtbl; + This->lpVtblMarshal = &ProxyMarshal_Vtbl; list_init(&This->entry); list_init(&This->interfaces); @@ -505,9 +572,21 @@ static HRESULT proxy_manager_query_local_interface(struct proxy_manager * This, IsEqualIID(riid, &IID_IMultiQI)) { *ppv = (void *)&This->lpVtbl; - IMultiQI_AddRef((IMultiQI *)&This->lpVtbl); + IUnknown_AddRef((IUnknown *)*ppv); return S_OK; } + if (IsEqualIID(riid, &IID_IMarshal)) + { + *ppv = (void *)&This->lpVtblMarshal; + IUnknown_AddRef((IUnknown *)*ppv); + return S_OK; + } + if (IsEqualIID(riid, &IID_IClientSecurity)) + { + FIXME("requesting IClientSecurity, but it is unimplemented\n"); + *ppv = NULL; + return E_NOINTERFACE; + } hr = proxy_manager_find_ifproxy(This, riid, &ifproxy); if (hr == S_OK) @@ -522,7 +601,7 @@ static HRESULT proxy_manager_query_local_interface(struct proxy_manager * This, } static HRESULT proxy_manager_create_ifproxy( - struct proxy_manager * This, const IPID *ipid, REFIID riid, ULONG cPublicRefs, + struct proxy_manager * This, const STDOBJREF *stdobjref, REFIID riid, IRpcChannelBuffer * channel, struct ifproxy ** iif_out) { HRESULT hr; @@ -533,9 +612,9 @@ static HRESULT proxy_manager_create_ifproxy( list_init(&ifproxy->entry); ifproxy->parent = This; - ifproxy->ipid = *ipid; + ifproxy->stdobjref = *stdobjref; ifproxy->iid = *riid; - ifproxy->refs = cPublicRefs; + ifproxy->refs = stdobjref->cPublicRefs; ifproxy->proxy = NULL; assert(channel); @@ -584,7 +663,7 @@ static HRESULT proxy_manager_create_ifproxy( *iif_out = ifproxy; TRACE("ifproxy %p created for IPID %s, interface %s with %lu public refs\n", - ifproxy, debugstr_guid(ipid), debugstr_guid(riid), cPublicRefs); + ifproxy, debugstr_guid(&stdobjref->ipid), debugstr_guid(riid), stdobjref->cPublicRefs); } else ifproxy_destroy(ifproxy); @@ -901,14 +980,12 @@ static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt, REFI IRpcChannelBuffer *chanbuf; hr = RPC_CreateClientChannel(&stdobjref->oxid, &stdobjref->ipid, &chanbuf); if (hr == S_OK) - hr = proxy_manager_create_ifproxy(proxy_manager, &stdobjref->ipid, - riid, stdobjref->cPublicRefs, - chanbuf, &ifproxy); + hr = proxy_manager_create_ifproxy(proxy_manager, stdobjref, + riid, chanbuf, &ifproxy); } if (hr == S_OK) { - /* FIXME: push this AddRef inside proxy_manager_find_ifproxy/create_ifproxy? */ ClientIdentity_AddRef((IMultiQI*)&proxy_manager->lpVtbl); *object = ifproxy->iface; } @@ -958,7 +1035,7 @@ StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, v /* unref the ifstub. FIXME: only do this on success? */ if (!stub_manager_is_table_marshaled(stubmgr)) - stub_manager_ext_release(stubmgr, 1); + stub_manager_ext_release(stubmgr, stdobjref.cPublicRefs); stub_manager_int_release(stubmgr); return hres; diff --git a/reactos/lib/ole32/moniker.c b/reactos/lib/ole32/moniker.c index 1e7bf8840f3..216317fd079 100644 --- a/reactos/lib/ole32/moniker.c +++ b/reactos/lib/ole32/moniker.c @@ -981,8 +981,6 @@ static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(MInterfacePointer **m /* Shared implementation of moniker marshaler based on saving and loading of * monikers */ -#define ICOM_THIS_From_IMoniker(class, name) class* This = (class*)(((char*)name)-FIELD_OFFSET(class, lpVtblMarshal)) - typedef struct MonikerMarshal { const IUnknownVtbl *lpVtbl; @@ -992,6 +990,11 @@ typedef struct MonikerMarshal IMoniker *moniker; } MonikerMarshal; +static inline MonikerMarshal *impl_from_IMarshal( IMarshal *iface ) +{ + return (MonikerMarshal *)((char*)iface - FIELD_OFFSET(MonikerMarshal, lpVtblMarshal)); +} + static HRESULT WINAPI MonikerMarshalInner_QueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppv) { MonikerMarshal *This = (MonikerMarshal *)iface; @@ -1031,19 +1034,19 @@ static const IUnknownVtbl VT_MonikerMarshalInner = static HRESULT WINAPI MonikerMarshal_QueryInterface(IMarshal *iface, REFIID riid, LPVOID *ppv) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); return IMoniker_QueryInterface(This->moniker, riid, ppv); } static ULONG WINAPI MonikerMarshal_AddRef(IMarshal *iface) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); return IMoniker_AddRef(This->moniker); } static ULONG WINAPI MonikerMarshal_Release(IMarshal *iface) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); return IMoniker_Release(This->moniker); } @@ -1051,7 +1054,7 @@ static HRESULT WINAPI MonikerMarshal_GetUnmarshalClass( LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, CLSID* pCid) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); TRACE("(%s, %p, %lx, %p, %lx, %p)\n", debugstr_guid(riid), pv, dwDestContext, pvDestContext, mshlflags, pCid); @@ -1063,7 +1066,7 @@ static HRESULT WINAPI MonikerMarshal_GetMarshalSizeMax( LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, DWORD* pSize) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); HRESULT hr; ULARGE_INTEGER size; @@ -1080,7 +1083,7 @@ static HRESULT WINAPI MonikerMarshal_MarshalInterface(LPMARSHAL iface, IStream * REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); TRACE("(%p, %s, %p, %lx, %p, %lx)\n", pStm, debugstr_guid(riid), pv, dwDestContext, pvDestContext, mshlflags); @@ -1090,7 +1093,7 @@ static HRESULT WINAPI MonikerMarshal_MarshalInterface(LPMARSHAL iface, IStream * static HRESULT WINAPI MonikerMarshal_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv) { - ICOM_THIS_From_IMoniker(MonikerMarshal, iface); + MonikerMarshal *This = impl_from_IMarshal(iface); HRESULT hr; TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv); diff --git a/reactos/lib/ole32/moniker.h b/reactos/lib/ole32/moniker.h index 34ddfb00c02..4c64b9b13ce 100644 --- a/reactos/lib/ole32/moniker.h +++ b/reactos/lib/ole32/moniker.h @@ -1,8 +1,6 @@ #ifndef __WINE_MONIKER_H__ #define __WINE_MONIKER_H__ -#define ICOM_THIS_From_IROTData(class, name) class* This = (class*)(((char*)name)-sizeof(void*)) - extern const CLSID CLSID_FileMoniker; extern const CLSID CLSID_ItemMoniker; extern const CLSID CLSID_AntiMoniker; diff --git a/reactos/lib/ole32/ole16.c b/reactos/lib/ole32/ole16.c index 7536d3f5ed0..4beb8e6e74e 100644 --- a/reactos/lib/ole32/ole16.c +++ b/reactos/lib/ole32/ole16.c @@ -285,10 +285,6 @@ HRESULT WINAPI CLSIDFromString16( return __CLSIDFromStringA(idstr,id); } -extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags, - DWORD cbArgs, LPVOID pArgs, - LPDWORD pdwRetCode ); - /****************************************************************************** * _xmalloc16 [internal] * Allocates size bytes from the standard ole16 allocator. @@ -309,7 +305,7 @@ _xmalloc16(DWORD size, SEGPTR *ptr) { /* No need for a Callback entry, we have WOWCallback16Ex which does * everything we need. */ - if (!K32WOWCallback16Ex( + if (!WOWCallback16Ex( (DWORD)((const IMalloc16Vtbl*)MapSL( (SEGPTR)((LPMALLOC16)MapSL((SEGPTR)mllc))->lpVtbl ) )->Alloc, diff --git a/reactos/lib/ole32/ole2.c b/reactos/lib/ole32/ole2.c index d2304fd5e6a..6192ef2a2ed 100644 --- a/reactos/lib/ole32/ole2.c +++ b/reactos/lib/ole32/ole2.c @@ -2322,7 +2322,16 @@ done: /****************************************************************************** * OleDoAutoConvert [OLE32.@] */ -HRESULT WINAPI OleDoAutoConvert(IStorage *pStg, LPCLSID pClsidNew) +HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew) +{ + FIXME("(%p,%p) : stub\n",pStg,pClsidNew); + return E_NOTIMPL; +} + +/****************************************************************************** + * OleDoAutoConvert [OLE2.79] + */ +HRESULT WINAPI OleDoAutoConvert16(LPSTORAGE pStg, LPCLSID pClsidNew) { FIXME("(%p,%p) : stub\n",pStg,pClsidNew); return E_NOTIMPL; diff --git a/reactos/lib/ole32/ole2.spec b/reactos/lib/ole32/ole2.spec index 5d97ec295d4..0c8e732ed76 100644 --- a/reactos/lib/ole32/ole2.spec +++ b/reactos/lib/ole32/ole2.spec @@ -9,13 +9,13 @@ 9 stub OLECREATELINKFROMDATA 10 stub OLECREATE 11 stub OLECREATELINK -12 stub OLELOAD +12 pascal OleLoad(segptr ptr segptr ptr) OleLoad16 13 stub OLESAVE 14 stub OLERUN #15 ___EXPORTEDSTUB 16 stub OLEISRUNNING 17 stub OLELOCKRUNNING -18 stub READCLASSSTG +18 pascal ReadClassStg(segptr ptr) ReadClassStg16 19 stub WRITECLASSSTG 20 stub READCLASSSTM 21 stub WRITECLASSSTM @@ -74,10 +74,10 @@ 76 pascal -ret16 OleFlushClipboard() OleFlushClipboard16 77 stub OLEISCURRENTCLIPBOARD 78 stub OLETRANSLATEACCELERATOR -79 stub OLEDOAUTOCONVERT +79 pascal OleDoAutoConvert(ptr ptr) OleDoAutoConvert16 80 stub OLEGETAUTOCONVERT 81 stub OLESETAUTOCONVERT -82 stub GETCONVERTSTG +82 pascal GetConvertStg(ptr) GetConvertStg16 83 stub SETCONVERTSTG 84 stub CREATESTREAMONHGLOBAL 85 stub GETHGLOBALFROMSTREAM diff --git a/reactos/lib/ole32/ole2_16.c b/reactos/lib/ole32/ole2_16.c index 77c1d28b95b..79094122861 100644 --- a/reactos/lib/ole32/ole2_16.c +++ b/reactos/lib/ole32/ole2_16.c @@ -192,3 +192,20 @@ BOOL WINAPI IsValidInterface16(SEGPTR punk) return FALSE; return TRUE; } + +/****************************************************************************** + * OleLoad [OLE2.12] + * + * PARAMS + * pStg Segmented LPSTORAGE pointer. + * pClientSite Segmented LPOLECLIENTSITE pointer. + */ +HRESULT WINAPI OleLoad16( + SEGPTR pStg, + REFIID riid, + SEGPTR pClientSite, + LPVOID* ppvObj) +{ + FIXME("(%lx,%s,%lx,%p), stub!\n", pStg, debugstr_guid(riid), pClientSite, ppvObj); + return E_NOTIMPL; +} diff --git a/reactos/lib/ole32/ole32.spec b/reactos/lib/ole32/ole32.spec index 86477c116e6..44aca558eb3 100644 --- a/reactos/lib/ole32/ole32.spec +++ b/reactos/lib/ole32/ole32.spec @@ -6,6 +6,7 @@ @ stdcall CLSIDFromProgID(wstr ptr) @ stdcall CLSIDFromString(wstr ptr) @ stdcall CoAddRefServerProcess() +@ stdcall CoAllowSetForegroundWindow(ptr ptr) @ stdcall CoBuildVersion() @ stdcall CoCopyProxy(ptr ptr) @ stdcall CoCreateFreeThreadedMarshaler(ptr ptr) @@ -90,7 +91,7 @@ @ stub CreatePointerMoniker #@ stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED @ stdcall CreateStreamOnHGlobal(ptr long ptr) @ stdcall DllDebugObjectRPCHook(long ptr) -@ stdcall -private DllGetClassObject (ptr ptr ptr) OLE32_DllGetClassObject +@ stdcall -private DllGetClassObject (ptr ptr ptr) @ stub DllGetClassObjectWOW @ stdcall -private DllRegisterServer() @ stdcall -private DllUnregisterServer() diff --git a/reactos/lib/ole32/oleproxy.c b/reactos/lib/ole32/oleproxy.c index 48cd6a3631f..b7c23198b81 100644 --- a/reactos/lib/ole32/oleproxy.c +++ b/reactos/lib/ole32/oleproxy.c @@ -989,7 +989,7 @@ static const IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl; /*********************************************************************** * DllGetClassObject [OLE32.@] */ -HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) +HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) { *ppv = NULL; if (IsEqualIID(rclsid, &CLSID_PSFactoryBuffer)) diff --git a/reactos/lib/ole32/stg_prop.c b/reactos/lib/ole32/stg_prop.c index fe6d1fb453c..1d7b2dbd0b3 100644 --- a/reactos/lib/ole32/stg_prop.c +++ b/reactos/lib/ole32/stg_prop.c @@ -63,9 +63,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage); -#define _IPropertySetStorage_Offset ((int)(&(((StorageImpl*)0)->base.pssVtbl))) -#define _ICOM_THIS_From_IPropertySetStorage(class, name) \ - class* This = (class*)(((char*)name)-_IPropertySetStorage_Offset) +static inline StorageImpl *impl_from_IPropertySetStorage( IPropertySetStorage *iface ) +{ + return (StorageImpl *)((char*)iface - FIELD_OFFSET(StorageImpl, base.pssVtbl)); +} /* These are documented in MSDN, e.g. * http://msdn.microsoft.com/library/en-us/stg/stg/property_set_header.asp @@ -1021,7 +1022,7 @@ static HRESULT PropertyStorage_ReadDictionary(PropertyStorage_impl *This, ptr[cbEntry - 1] = '\0'; else *((LPWSTR)ptr + cbEntry / sizeof(WCHAR)) = '\0'; - hr = PropertyStorage_StoreNameWithId(This, ptr, This->codePage, propid); + hr = PropertyStorage_StoreNameWithId(This, (char*)ptr, This->codePage, propid); if (This->codePage == CP_UNICODE) { /* Unicode entries are padded to DWORD boundaries */ @@ -1059,7 +1060,7 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This, TRACE("Read byte 0x%x\n", prop->u.bVal); break; case VT_I2: - StorageUtl_ReadWord(data, 0, &prop->u.iVal); + StorageUtl_ReadWord(data, 0, (WORD*)&prop->u.iVal); TRACE("Read short %d\n", prop->u.iVal); break; case VT_UI2: @@ -1068,7 +1069,7 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This, break; case VT_INT: case VT_I4: - StorageUtl_ReadDWord(data, 0, &prop->u.lVal); + StorageUtl_ReadDWord(data, 0, (DWORD*)&prop->u.lVal); TRACE("Read long %ld\n", prop->u.lVal); break; case VT_UINT: @@ -2039,7 +2040,7 @@ static HRESULT WINAPI IPropertySetStorage_fnQueryInterface( REFIID riid, void** ppvObject) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); return IStorage_QueryInterface( (IStorage*)This, riid, ppvObject ); } @@ -2051,7 +2052,7 @@ static HRESULT WINAPI IPropertySetStorage_fnQueryInterface( static ULONG WINAPI IPropertySetStorage_fnAddRef( IPropertySetStorage *ppstg) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); return IStorage_AddRef( (IStorage*)This ); } @@ -2063,7 +2064,7 @@ static ULONG WINAPI IPropertySetStorage_fnAddRef( static ULONG WINAPI IPropertySetStorage_fnRelease( IPropertySetStorage *ppstg) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); return IStorage_Release( (IStorage*)This ); } @@ -2078,7 +2079,7 @@ static HRESULT WINAPI IPropertySetStorage_fnCreate( DWORD grfMode, IPropertyStorage** ppprstg) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); WCHAR name[CCH_MAX_PROPSTG_NAME]; IStream *stm = NULL; HRESULT r; @@ -2133,7 +2134,7 @@ static HRESULT WINAPI IPropertySetStorage_fnOpen( DWORD grfMode, IPropertyStorage** ppprstg) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); IStream *stm = NULL; WCHAR name[CCH_MAX_PROPSTG_NAME]; HRESULT r; @@ -2176,7 +2177,7 @@ static HRESULT WINAPI IPropertySetStorage_fnDelete( IPropertySetStorage *ppstg, REFFMTID rfmtid) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); IStorage *stg = NULL; WCHAR name[CCH_MAX_PROPSTG_NAME]; HRESULT r; @@ -2201,7 +2202,7 @@ static HRESULT WINAPI IPropertySetStorage_fnEnum( IPropertySetStorage *ppstg, IEnumSTATPROPSETSTG** ppenum) { - _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg); + StorageImpl *This = impl_from_IPropertySetStorage(ppstg); FIXME("%p\n", This); return E_NOTIMPL; } diff --git a/reactos/lib/ole32/storage.c b/reactos/lib/ole32/storage.c index 626d55fb25a..2129c770f30 100644 --- a/reactos/lib/ole32/storage.c +++ b/reactos/lib/ole32/storage.c @@ -89,7 +89,7 @@ static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1}; #define SMALLBLOCKS_PER_BIGBLOCK (BIGSIZE/SMALLSIZE) -#define READ_HEADER STORAGE_get_big_block(hf,-1,(LPBYTE)&sth);assert(!memcmp(STORAGE_magic,sth.magic,sizeof(STORAGE_magic))); +#define READ_HEADER(str) STORAGE_get_big_block(str,-1,(LPBYTE)&sth);assert(!memcmp(STORAGE_magic,sth.magic,sizeof(STORAGE_magic))); static IStorage16Vtbl stvt16; static const IStorage16Vtbl *segstvt16 = NULL; static IStream16Vtbl strvt16; @@ -319,6 +319,24 @@ static void _create_istream16(LPSTREAM16 *str); * deeper (but never shallower) tree. */ +typedef struct { + HANDLE hf; + SEGPTR lockbytes; +} stream_access16; +/* --- IStorage16 implementation struct */ + +typedef struct +{ + /* IUnknown fields */ + const IStorage16Vtbl *lpVtbl; + LONG ref; + /* IStorage16 fields */ + SEGPTR thisptr; /* pointer to this struct as segmented */ + struct storage_pps_entry stde; + int ppsent; + stream_access16 str; +} IStorage16Impl; + /****************************************************************************** * STORAGE_get_big_block [Internal] @@ -326,22 +344,80 @@ static void _create_istream16(LPSTREAM16 *str); * Reading OLE compound storage */ static BOOL -STORAGE_get_big_block(HANDLE hf,int n,BYTE *block) +STORAGE_get_big_block(stream_access16 *str,int n,BYTE *block) { DWORD result; assert(n>=-1); - if ((SetFilePointer( hf, (n+1)*BIGSIZE, NULL, - SEEK_SET ) == INVALID_SET_FILE_POINTER) && GetLastError()) - { - WARN(" seek failed (%ld)\n",GetLastError()); - return FALSE; + if (str->hf) { + if ((SetFilePointer( str->hf, (n+1)*BIGSIZE, NULL, + SEEK_SET ) == INVALID_SET_FILE_POINTER) && GetLastError()) + { + WARN("(%p,%d,%p), seek failed (%ld)\n",str->hf, n, block, GetLastError()); + return FALSE; + } + if (!ReadFile( str->hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) + { + WARN("(hf=%p, block size %d): read didn't read (%ld)\n",str->hf,n,GetLastError()); + return FALSE; + } + } else { + DWORD args[6]; + HRESULT hres; + HANDLE16 hsig; + + args[0] = (DWORD)str->lockbytes; /* iface */ + args[1] = (n+1)*BIGSIZE; + args[2] = 0; /* ULARGE_INTEGER offset */ + args[3] = WOWGlobalAllocLock16( 0, BIGSIZE, &hsig ); /* sig */ + args[4] = BIGSIZE; + args[5] = 0; + + if (!WOWCallback16Ex( + (DWORD)((const ILockBytes16Vtbl*)MapSL( + (SEGPTR)((LPLOCKBYTES16)MapSL(str->lockbytes))->lpVtbl) + )->ReadAt, + WCB16_PASCAL, + 6*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) { + ERR("CallTo16 ILockBytes16::ReadAt() failed, hres %lx\n",hres); + return FALSE; + } + memcpy(block, MapSL(args[3]), BIGSIZE); + WOWGlobalUnlockFree16(args[3]); } - if (!ReadFile( hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) - { - WARN("(block size %d): read didn't read (%ld)\n",n,GetLastError()); - return FALSE; + return TRUE; +} + +static BOOL +_ilockbytes16_writeat(SEGPTR lockbytes, DWORD offset, DWORD length, void *buffer) { + DWORD args[6]; + HRESULT hres; + + args[0] = (DWORD)lockbytes; /* iface */ + args[1] = offset; + args[2] = 0; /* ULARGE_INTEGER offset */ + args[3] = (DWORD)MapLS( buffer ); + args[4] = length; + args[5] = 0; + + /* THIS_ ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten); */ + + if (!WOWCallback16Ex( + (DWORD)((const ILockBytes16Vtbl*)MapSL( + (SEGPTR)((LPLOCKBYTES16)MapSL(lockbytes))->lpVtbl) + )->WriteAt, + WCB16_PASCAL, + 6*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) { + ERR("CallTo16 ILockBytes16::WriteAt() failed, hres %lx\n",hres); + return FALSE; } + UnMapLS(args[3]); return TRUE; } @@ -349,39 +425,44 @@ STORAGE_get_big_block(HANDLE hf,int n,BYTE *block) * STORAGE_put_big_block [INTERNAL] */ static BOOL -STORAGE_put_big_block(HANDLE hf,int n,BYTE *block) +STORAGE_put_big_block(stream_access16 *str,int n,BYTE *block) { DWORD result; assert(n>=-1); - if ((SetFilePointer( hf, (n+1)*BIGSIZE, NULL, - SEEK_SET ) == INVALID_SET_FILE_POINTER) && GetLastError()) - { - WARN("seek failed (%ld)\n",GetLastError()); - return FALSE; + if (str->hf) { + if ((SetFilePointer( str->hf, (n+1)*BIGSIZE, NULL, + SEEK_SET ) == INVALID_SET_FILE_POINTER) && GetLastError()) + { + WARN("seek failed (%ld)\n",GetLastError()); + return FALSE; + } + if (!WriteFile( str->hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) + { + WARN(" write failed (%ld)\n",GetLastError()); + return FALSE; + } + return TRUE; + } else { + _ilockbytes16_writeat(str->lockbytes, (n+1)*BIGSIZE, BIGSIZE, block); + return TRUE; } - if (!WriteFile( hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) - { - WARN(" write failed (%ld)\n",GetLastError()); - return FALSE; - } - return TRUE; } /****************************************************************************** * STORAGE_get_next_big_blocknr [INTERNAL] */ static int -STORAGE_get_next_big_blocknr(HANDLE hf,int blocknr) { +STORAGE_get_next_big_blocknr(stream_access16 *str,int blocknr) { INT bbs[BIGSIZE/sizeof(INT)]; struct storage_header sth; - READ_HEADER; + READ_HEADER(str); assert(blocknr>>7>7]==0xffffffff) return -5; - if (!STORAGE_get_big_block(hf,sth.bbd_list[blocknr>>7],(LPBYTE)bbs)) + if (!STORAGE_get_big_block(str,sth.bbd_list[blocknr>>7],(LPBYTE)bbs)) return -5; assert(bbs[blocknr&0x7f]!=STORAGE_CHAINENTRY_FREE); return bbs[blocknr&0x7f]; @@ -391,12 +472,13 @@ STORAGE_get_next_big_blocknr(HANDLE hf,int blocknr) { * STORAGE_get_nth_next_big_blocknr [INTERNAL] */ static int -STORAGE_get_nth_next_big_blocknr(HANDLE hf,int blocknr,int nr) { +STORAGE_get_nth_next_big_blocknr(stream_access16 *str,int blocknr,int nr) { INT bbs[BIGSIZE/sizeof(INT)]; int lastblock = -1; struct storage_header sth; - READ_HEADER; + TRACE("(blocknr=%d, nr=%d)\n", blocknr, nr); + READ_HEADER(str); assert(blocknr>=0); while (nr--) { @@ -405,7 +487,7 @@ STORAGE_get_nth_next_big_blocknr(HANDLE hf,int blocknr,int nr) { /* simple caching... */ if (lastblock!=sth.bbd_list[blocknr>>7]) { - BOOL ret = STORAGE_get_big_block(hf,sth.bbd_list[blocknr>>7],(LPBYTE)bbs); + BOOL ret = STORAGE_get_big_block(str,sth.bbd_list[blocknr>>7],(LPBYTE)bbs); assert(ret); lastblock = sth.bbd_list[blocknr>>7]; } @@ -418,16 +500,17 @@ STORAGE_get_nth_next_big_blocknr(HANDLE hf,int blocknr,int nr) { * STORAGE_get_root_pps_entry [Internal] */ static BOOL -STORAGE_get_root_pps_entry(HANDLE hf,struct storage_pps_entry *pstde) { +STORAGE_get_root_pps_entry(stream_access16* str,struct storage_pps_entry *pstde) { int blocknr,i; BYTE block[BIGSIZE]; struct storage_pps_entry *stde=(struct storage_pps_entry*)block; struct storage_header sth; - READ_HEADER; + READ_HEADER(str); blocknr = sth.root_startblock; + TRACE("startblock is %d\n", blocknr); while (blocknr>=0) { - BOOL ret = STORAGE_get_big_block(hf,blocknr,block); + BOOL ret = STORAGE_get_big_block(str,blocknr,block); assert(ret); for (i=0;i<4;i++) { if (!stde[i].pps_sizeofname) @@ -437,7 +520,8 @@ STORAGE_get_root_pps_entry(HANDLE hf,struct storage_pps_entry *pstde) { return TRUE; } } - blocknr=STORAGE_get_next_big_blocknr(hf,blocknr); + blocknr=STORAGE_get_next_big_blocknr(str,blocknr); + TRACE("next block is %d\n", blocknr); } return FALSE; } @@ -446,18 +530,19 @@ STORAGE_get_root_pps_entry(HANDLE hf,struct storage_pps_entry *pstde) { * STORAGE_get_small_block [INTERNAL] */ static BOOL -STORAGE_get_small_block(HANDLE hf,int blocknr,BYTE *sblock) { +STORAGE_get_small_block(stream_access16 *str,int blocknr,BYTE *sblock) { BYTE block[BIGSIZE]; int bigblocknr; struct storage_pps_entry root; BOOL ret; + TRACE("(blocknr=%d)\n", blocknr); assert(blocknr>=0); - ret = STORAGE_get_root_pps_entry(hf,&root); + ret = STORAGE_get_root_pps_entry(str,&root); assert(ret); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); + bigblocknr = STORAGE_get_nth_next_big_blocknr(str,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); memcpy(sblock,((LPBYTE)block)+SMALLSIZE*(blocknr&(SMALLBLOCKS_PER_BIGBLOCK-1)),SMALLSIZE); @@ -468,23 +553,24 @@ STORAGE_get_small_block(HANDLE hf,int blocknr,BYTE *sblock) { * STORAGE_put_small_block [INTERNAL] */ static BOOL -STORAGE_put_small_block(HANDLE hf,int blocknr,BYTE *sblock) { +STORAGE_put_small_block(stream_access16 *str,int blocknr,BYTE *sblock) { BYTE block[BIGSIZE]; int bigblocknr; struct storage_pps_entry root; BOOL ret; assert(blocknr>=0); + TRACE("(blocknr=%d)\n", blocknr); - ret = STORAGE_get_root_pps_entry(hf,&root); + ret = STORAGE_get_root_pps_entry(str,&root); assert(ret); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); + bigblocknr = STORAGE_get_nth_next_big_blocknr(str,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); memcpy(((LPBYTE)block)+SMALLSIZE*(blocknr&(SMALLBLOCKS_PER_BIGBLOCK-1)),sblock,SMALLSIZE); - ret = STORAGE_put_big_block(hf,bigblocknr,block); + ret = STORAGE_put_big_block(str,bigblocknr,block); assert(ret); return TRUE; } @@ -493,18 +579,19 @@ STORAGE_put_small_block(HANDLE hf,int blocknr,BYTE *sblock) { * STORAGE_get_next_small_blocknr [INTERNAL] */ static int -STORAGE_get_next_small_blocknr(HANDLE hf,int blocknr) { +STORAGE_get_next_small_blocknr(stream_access16 *str,int blocknr) { BYTE block[BIGSIZE]; LPINT sbd = (LPINT)block; int bigblocknr; struct storage_header sth; BOOL ret; - READ_HEADER; + TRACE("(blocknr=%d)\n", blocknr); + READ_HEADER(str); assert(blocknr>=0); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.sbd_startblock,blocknr/128); + bigblocknr = STORAGE_get_nth_next_big_blocknr(str,sth.sbd_startblock,blocknr/128); assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); assert(sbd[blocknr & 127]!=STORAGE_CHAINENTRY_FREE); return sbd[blocknr & (128-1)]; @@ -514,21 +601,22 @@ STORAGE_get_next_small_blocknr(HANDLE hf,int blocknr) { * STORAGE_get_nth_next_small_blocknr [INTERNAL] */ static int -STORAGE_get_nth_next_small_blocknr(HANDLE hf,int blocknr,int nr) { +STORAGE_get_nth_next_small_blocknr(stream_access16*str,int blocknr,int nr) { int lastblocknr=-1; BYTE block[BIGSIZE]; LPINT sbd = (LPINT)block; struct storage_header sth; BOOL ret; - READ_HEADER; + TRACE("(blocknr=%d, nr=%d)\n", blocknr, nr); + READ_HEADER(str); assert(blocknr>=0); while ((nr--) && (blocknr>=0)) { if (lastblocknr/128!=blocknr/128) { int bigblocknr; - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.sbd_startblock,blocknr/128); + bigblocknr = STORAGE_get_nth_next_big_blocknr(str,sth.sbd_startblock,blocknr/128); assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); lastblocknr = blocknr; } @@ -544,18 +632,19 @@ STORAGE_get_nth_next_small_blocknr(HANDLE hf,int blocknr,int nr) { * STORAGE_get_pps_entry [INTERNAL] */ static int -STORAGE_get_pps_entry(HANDLE hf,int n,struct storage_pps_entry *pstde) { +STORAGE_get_pps_entry(stream_access16*str,int n,struct storage_pps_entry *pstde) { int blocknr; BYTE block[BIGSIZE]; struct storage_pps_entry *stde = (struct storage_pps_entry*)(((LPBYTE)block)+128*(n&3)); struct storage_header sth; BOOL ret; - READ_HEADER; + TRACE("(n=%d)\n", n); + READ_HEADER(str); /* we have 4 pps entries per big block */ - blocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.root_startblock,n/4); + blocknr = STORAGE_get_nth_next_big_blocknr(str,sth.root_startblock,n/4); assert(blocknr>=0); - ret = STORAGE_get_big_block(hf,blocknr,block); + ret = STORAGE_get_big_block(str,blocknr,block); assert(ret); *pstde=*stde; @@ -566,22 +655,22 @@ STORAGE_get_pps_entry(HANDLE hf,int n,struct storage_pps_entry *pstde) { * STORAGE_put_pps_entry [Internal] */ static int -STORAGE_put_pps_entry(HANDLE hf,int n,struct storage_pps_entry *pstde) { +STORAGE_put_pps_entry(stream_access16*str,int n,struct storage_pps_entry *pstde) { int blocknr; BYTE block[BIGSIZE]; struct storage_pps_entry *stde = (struct storage_pps_entry*)(((LPBYTE)block)+128*(n&3)); struct storage_header sth; BOOL ret; - READ_HEADER; - + TRACE("(n=%d)\n", n); + READ_HEADER(str); /* we have 4 pps entries per big block */ - blocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.root_startblock,n/4); + blocknr = STORAGE_get_nth_next_big_blocknr(str,sth.root_startblock,n/4); assert(blocknr>=0); - ret = STORAGE_get_big_block(hf,blocknr,block); + ret = STORAGE_get_big_block(str,blocknr,block); assert(ret); *stde=*pstde; - ret = STORAGE_put_big_block(hf,blocknr,block); + ret = STORAGE_put_big_block(str,blocknr,block); assert(ret); return 1; } @@ -590,24 +679,25 @@ STORAGE_put_pps_entry(HANDLE hf,int n,struct storage_pps_entry *pstde) { * STORAGE_look_for_named_pps [Internal] */ static int -STORAGE_look_for_named_pps(HANDLE hf,int n,LPOLESTR name) { +STORAGE_look_for_named_pps(stream_access16*str,int n,LPOLESTR name) { struct storage_pps_entry stde; int ret; + TRACE("(n=%d,name=%s)\n", n, debugstr_w(name)); if (n==-1) return -1; - if (1!=STORAGE_get_pps_entry(hf,n,&stde)) + if (1!=STORAGE_get_pps_entry(str,n,&stde)) return -1; if (!lstrcmpW(name,stde.pps_rawname)) return n; if (stde.pps_prev != -1) { - ret=STORAGE_look_for_named_pps(hf,stde.pps_prev,name); + ret=STORAGE_look_for_named_pps(str,stde.pps_prev,name); if (ret!=-1) return ret; } if (stde.pps_next != -1) { - ret=STORAGE_look_for_named_pps(hf,stde.pps_next,name); + ret=STORAGE_look_for_named_pps(str,stde.pps_next,name); if (ret!=-1) return ret; } @@ -651,14 +741,15 @@ STORAGE_dump_pps_entry(struct storage_pps_entry *stde) { * STORAGE_init_storage [INTERNAL] */ static BOOL -STORAGE_init_storage(HANDLE hf) { +STORAGE_init_storage(stream_access16 *str) { BYTE block[BIGSIZE]; LPDWORD bbs; struct storage_header *sth; struct storage_pps_entry *stde; DWORD result; - SetFilePointer( hf, 0, NULL, SEEK_SET ); + if (str->hf) + SetFilePointer( str->hf, 0, NULL, SEEK_SET ); /* block -1 is the storage header */ sth = (struct storage_header*)block; memcpy(sth->magic,STORAGE_magic,8); @@ -670,13 +761,21 @@ STORAGE_init_storage(HANDLE hf) { sth->sbd_startblock = 0xffffffff; memset(sth->bbd_list,0xff,sizeof(sth->bbd_list)); sth->bbd_list[0] = 0; - if (!WriteFile( hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) return FALSE; + if (str->hf) { + if (!WriteFile( str->hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) return FALSE; + } else { + if (!_ilockbytes16_writeat(str->lockbytes, 0, BIGSIZE, block)) return FALSE; + } /* block 0 is the big block directory */ bbs=(LPDWORD)block; memset(block,0xff,sizeof(block)); /* mark all blocks as free */ bbs[0]=STORAGE_CHAINENTRY_ENDOFCHAIN; /* for this block */ bbs[1]=STORAGE_CHAINENTRY_ENDOFCHAIN; /* for directory entry */ - if (!WriteFile( hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) return FALSE; + if (str->hf) { + if (!WriteFile( str->hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) return FALSE; + } else { + if (!_ilockbytes16_writeat(str->lockbytes, BIGSIZE, BIGSIZE, block)) return FALSE; + } /* block 1 is the root directory entry */ memset(block,0x00,sizeof(block)); stde = (struct storage_pps_entry*)block; @@ -689,33 +788,37 @@ STORAGE_init_storage(HANDLE hf) { stde->pps_prev = -1; stde->pps_sb = 0xffffffff; stde->pps_size = 0; - return (WriteFile( hf, block, BIGSIZE, &result, NULL ) && result == BIGSIZE); + if (str->hf) { + return (WriteFile( str->hf, block, BIGSIZE, &result, NULL ) && result == BIGSIZE); + } else { + return _ilockbytes16_writeat(str->lockbytes, BIGSIZE, BIGSIZE, block); + } } /****************************************************************************** * STORAGE_set_big_chain [Internal] */ static BOOL -STORAGE_set_big_chain(HANDLE hf,int blocknr,INT type) { +STORAGE_set_big_chain(stream_access16*str,int blocknr,INT type) { BYTE block[BIGSIZE]; LPINT bbd = (LPINT)block; int nextblocknr,bigblocknr; struct storage_header sth; BOOL ret; - READ_HEADER; + READ_HEADER(str); assert(blocknr!=type); while (blocknr>=0) { bigblocknr = sth.bbd_list[blocknr/128]; assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); nextblocknr = bbd[blocknr&(128-1)]; bbd[blocknr&(128-1)] = type; if (type>=0) return TRUE; - ret = STORAGE_put_big_block(hf,bigblocknr,block); + ret = STORAGE_put_big_block(str,bigblocknr,block); assert(ret); type = STORAGE_CHAINENTRY_FREE; blocknr = nextblocknr; @@ -727,29 +830,29 @@ STORAGE_set_big_chain(HANDLE hf,int blocknr,INT type) { * STORAGE_set_small_chain [Internal] */ static BOOL -STORAGE_set_small_chain(HANDLE hf,int blocknr,INT type) { +STORAGE_set_small_chain(stream_access16*str,int blocknr,INT type) { BYTE block[BIGSIZE]; LPINT sbd = (LPINT)block; int lastblocknr,nextsmallblocknr,bigblocknr; struct storage_header sth; BOOL ret; - READ_HEADER; + READ_HEADER(str); assert(blocknr!=type); lastblocknr=-129;bigblocknr=-2; while (blocknr>=0) { /* cache block ... */ if (lastblocknr/128!=blocknr/128) { - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.sbd_startblock,blocknr/128); + bigblocknr = STORAGE_get_nth_next_big_blocknr(str,sth.sbd_startblock,blocknr/128); assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); } lastblocknr = blocknr; nextsmallblocknr = sbd[blocknr&(128-1)]; sbd[blocknr&(128-1)] = type; - ret = STORAGE_put_big_block(hf,bigblocknr,block); + ret = STORAGE_put_big_block(str,bigblocknr,block); assert(ret); if (type>=0) return TRUE; @@ -763,7 +866,7 @@ STORAGE_set_small_chain(HANDLE hf,int blocknr,INT type) { * STORAGE_get_free_big_blocknr [Internal] */ static int -STORAGE_get_free_big_blocknr(HANDLE hf) { +STORAGE_get_free_big_blocknr(stream_access16 *str) { BYTE block[BIGSIZE]; LPINT sbd = (LPINT)block; int lastbigblocknr,i,bigblocknr; @@ -771,21 +874,21 @@ STORAGE_get_free_big_blocknr(HANDLE hf) { struct storage_header sth; BOOL ret; - READ_HEADER; + READ_HEADER(str); curblock = 0; lastbigblocknr = -1; bigblocknr = sth.bbd_list[curblock]; while (curblock=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); + ret = STORAGE_get_big_block(str,bigblocknr,block); assert(ret); for (i=0;i<128;i++) if (sbd[i]==STORAGE_CHAINENTRY_FREE) { sbd[i] = STORAGE_CHAINENTRY_ENDOFCHAIN; - ret = STORAGE_put_big_block(hf,bigblocknr,block); + ret = STORAGE_put_big_block(str,bigblocknr,block); assert(ret); memset(block,0x42,sizeof(block)); - ret = STORAGE_put_big_block(hf,i+curblock*128,block); + ret = STORAGE_put_big_block(str,i+curblock*128,block); assert(ret); return i+curblock*128; } @@ -800,30 +903,30 @@ STORAGE_get_free_big_blocknr(HANDLE hf) { memset(block,0xff,sizeof(block)); /* mark the block allocated and returned by this function */ sbd[1] = STORAGE_CHAINENTRY_ENDOFCHAIN; - ret = STORAGE_put_big_block(hf,bigblocknr,block); + ret = STORAGE_put_big_block(str,bigblocknr,block); assert(ret); /* if we had a bbd block already (mostlikely) we need * to link the new one into the chain */ if (lastbigblocknr!=-1) { - ret = STORAGE_set_big_chain(hf,lastbigblocknr,bigblocknr); + ret = STORAGE_set_big_chain(str,lastbigblocknr,bigblocknr); assert(ret); } sth.bbd_list[curblock]=bigblocknr; sth.num_of_bbd_blocks++; assert(sth.num_of_bbd_blocks==curblock+1); - ret = STORAGE_put_big_block(hf,-1,(LPBYTE)&sth); + ret = STORAGE_put_big_block(str,-1,(LPBYTE)&sth); assert(ret); /* Set the end of the chain for the bigblockdepots */ - ret = STORAGE_set_big_chain(hf,bigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN); + ret = STORAGE_set_big_chain(str,bigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN); assert(ret); /* add 1, for the first entry is used for the additional big block * depot. (means we already used bigblocknr) */ memset(block,0x42,sizeof(block)); /* allocate this block (filled with 0x42) */ - ret = STORAGE_put_big_block(hf,bigblocknr+1,block); + ret = STORAGE_put_big_block(str,bigblocknr+1,block); assert(ret); return bigblocknr+1; } @@ -833,20 +936,20 @@ STORAGE_get_free_big_blocknr(HANDLE hf) { * STORAGE_get_free_small_blocknr [Internal] */ static int -STORAGE_get_free_small_blocknr(HANDLE hf) { +STORAGE_get_free_small_blocknr(stream_access16 *str) { BYTE block[BIGSIZE]; LPINT sbd = (LPINT)block; int lastbigblocknr,newblocknr,i,curblock,bigblocknr; struct storage_pps_entry root; struct storage_header sth; - READ_HEADER; + READ_HEADER(str); bigblocknr = sth.sbd_startblock; curblock = 0; lastbigblocknr = -1; newblocknr = -1; while (bigblocknr>=0) { - if (!STORAGE_get_big_block(hf,bigblocknr,block)) + if (!STORAGE_get_big_block(str,bigblocknr,block)) return -1; for (i=0;i<128;i++) if (sbd[i]==STORAGE_CHAINENTRY_FREE) { @@ -857,56 +960,56 @@ STORAGE_get_free_small_blocknr(HANDLE hf) { if (i!=128) break; lastbigblocknr = bigblocknr; - bigblocknr = STORAGE_get_next_big_blocknr(hf,bigblocknr); + bigblocknr = STORAGE_get_next_big_blocknr(str,bigblocknr); curblock++; } if (newblocknr==-1) { - bigblocknr = STORAGE_get_free_big_blocknr(hf); + bigblocknr = STORAGE_get_free_big_blocknr(str); if (bigblocknr<0) return -1; - READ_HEADER; + READ_HEADER(str); memset(block,0xff,sizeof(block)); sbd[0]=STORAGE_CHAINENTRY_ENDOFCHAIN; - if (!STORAGE_put_big_block(hf,bigblocknr,block)) + if (!STORAGE_put_big_block(str,bigblocknr,block)) return -1; if (lastbigblocknr==-1) { sth.sbd_startblock = bigblocknr; - if (!STORAGE_put_big_block(hf,-1,(LPBYTE)&sth)) /* need to write it */ + if (!STORAGE_put_big_block(str,-1,(LPBYTE)&sth)) /* need to write it */ return -1; } else { - if (!STORAGE_set_big_chain(hf,lastbigblocknr,bigblocknr)) + if (!STORAGE_set_big_chain(str,lastbigblocknr,bigblocknr)) return -1; } - if (!STORAGE_set_big_chain(hf,bigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(str,bigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return -1; newblocknr = curblock*128; } /* allocate enough big blocks for storing the allocated small block */ - if (!STORAGE_get_root_pps_entry(hf,&root)) + if (!STORAGE_get_root_pps_entry(str,&root)) return -1; if (root.pps_sb==-1) lastbigblocknr = -1; else - lastbigblocknr = STORAGE_get_nth_next_big_blocknr(hf,root.pps_sb,(root.pps_size-1)/BIGSIZE); + lastbigblocknr = STORAGE_get_nth_next_big_blocknr(str,root.pps_sb,(root.pps_size-1)/BIGSIZE); while (root.pps_size < (newblocknr*SMALLSIZE+SMALLSIZE-1)) { /* we need to allocate more stuff */ - bigblocknr = STORAGE_get_free_big_blocknr(hf); + bigblocknr = STORAGE_get_free_big_blocknr(str); if (bigblocknr<0) return -1; - READ_HEADER; + READ_HEADER(str); if (root.pps_sb==-1) { root.pps_sb = bigblocknr; root.pps_size += BIGSIZE; } else { - if (!STORAGE_set_big_chain(hf,lastbigblocknr,bigblocknr)) + if (!STORAGE_set_big_chain(str,lastbigblocknr,bigblocknr)) return -1; root.pps_size += BIGSIZE; } lastbigblocknr = bigblocknr; } - if (!STORAGE_set_big_chain(hf,lastbigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(str,lastbigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return -1; - if (!STORAGE_put_pps_entry(hf,0,&root)) + if (!STORAGE_put_pps_entry(str,0,&root)) return -1; return newblocknr; } @@ -915,38 +1018,38 @@ STORAGE_get_free_small_blocknr(HANDLE hf) { * STORAGE_get_free_pps_entry [Internal] */ static int -STORAGE_get_free_pps_entry(HANDLE hf) { +STORAGE_get_free_pps_entry(stream_access16*str) { int blocknr, i, curblock, lastblocknr=-1; BYTE block[BIGSIZE]; struct storage_pps_entry *stde = (struct storage_pps_entry*)block; struct storage_header sth; - READ_HEADER; + READ_HEADER(str); blocknr = sth.root_startblock; assert(blocknr>=0); curblock=0; while (blocknr>=0) { - if (!STORAGE_get_big_block(hf,blocknr,block)) + if (!STORAGE_get_big_block(str,blocknr,block)) return -1; for (i=0;i<4;i++) if (stde[i].pps_sizeofname==0) /* free */ return curblock*4+i; lastblocknr = blocknr; - blocknr = STORAGE_get_next_big_blocknr(hf,blocknr); + blocknr = STORAGE_get_next_big_blocknr(str,blocknr); curblock++; } assert(blocknr==STORAGE_CHAINENTRY_ENDOFCHAIN); - blocknr = STORAGE_get_free_big_blocknr(hf); + blocknr = STORAGE_get_free_big_blocknr(str); /* sth invalidated */ if (blocknr<0) return -1; - if (!STORAGE_set_big_chain(hf,lastblocknr,blocknr)) + if (!STORAGE_set_big_chain(str,lastblocknr,blocknr)) return -1; - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return -1; memset(block,0,sizeof(block)); - STORAGE_put_big_block(hf,blocknr,block); + STORAGE_put_big_block(str,blocknr,block); return curblock*4; } @@ -961,8 +1064,8 @@ typedef struct SEGPTR thisptr; /* pointer to this struct as segmented */ struct storage_pps_entry stde; int ppsent; - HANDLE hf; ULARGE_INTEGER offset; + stream_access16 str; } IStream16Impl; /****************************************************************************** @@ -989,20 +1092,82 @@ ULONG IStream16_fnAddRef(IStream16* iface) { return InterlockedIncrement(&This->ref); } +static void +_ilockbytes16_addref(SEGPTR lockbytes) { + DWORD args[1]; + HRESULT hres; + + args[0] = (DWORD)lockbytes; /* iface */ + if (!WOWCallback16Ex( + (DWORD)((const ILockBytes16Vtbl*)MapSL( + (SEGPTR)((LPLOCKBYTES16)MapSL(lockbytes))->lpVtbl) + )->AddRef, + WCB16_PASCAL, + 1*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) + ERR("CallTo16 ILockBytes16::AddRef() failed, hres %lx\n",hres); +} + +static void +_ilockbytes16_release(SEGPTR lockbytes) { + DWORD args[1]; + HRESULT hres; + + args[0] = (DWORD)lockbytes; /* iface */ + if (!WOWCallback16Ex( + (DWORD)((const ILockBytes16Vtbl*)MapSL( + (SEGPTR)((LPLOCKBYTES16)MapSL(lockbytes))->lpVtbl) + )->Release, + WCB16_PASCAL, + 1*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) + ERR("CallTo16 ILockBytes16::Release() failed, hres %lx\n",hres); +} + +static void +_ilockbytes16_flush(SEGPTR lockbytes) { + DWORD args[1]; + HRESULT hres; + + args[0] = (DWORD)lockbytes; /* iface */ + if (!WOWCallback16Ex( + (DWORD)((const ILockBytes16Vtbl*)MapSL( + (SEGPTR)((LPLOCKBYTES16)MapSL(lockbytes))->lpVtbl) + )->Flush, + WCB16_PASCAL, + 1*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) + ERR("CallTo16 ILockBytes16::Flush() failed, hres %lx\n",hres); +} + /****************************************************************************** * IStream16_Release [STORAGE.520] */ ULONG IStream16_fnRelease(IStream16* iface) { IStream16Impl *This = (IStream16Impl *)iface; ULONG ref; - FlushFileBuffers(This->hf); + + if (This->str.hf) + FlushFileBuffers(This->str.hf); + else + _ilockbytes16_flush(This->str.lockbytes); ref = InterlockedDecrement(&This->ref); - if (!ref) { - CloseHandle(This->hf); - UnMapLS( This->thisptr ); - HeapFree( GetProcessHeap(), 0, This ); - } - return ref; + if (ref) + return ref; + + if (This->str.hf) + CloseHandle(This->str.hf); + else + _ilockbytes16_release(This->str.lockbytes); + UnMapLS( This->thisptr ); + HeapFree( GetProcessHeap(), 0, This ); + return 0; } /****************************************************************************** @@ -1072,11 +1237,11 @@ HRESULT IStream16_fnRead( cb=This->stde.pps_size-This->offset.u.LowPart; if (This->stde.pps_size < 0x1000) { /* use small block reader */ - blocknr = STORAGE_get_nth_next_small_blocknr(This->hf,This->stde.pps_sb,This->offset.u.LowPart/SMALLSIZE); + blocknr = STORAGE_get_nth_next_small_blocknr(&This->str,This->stde.pps_sb,This->offset.u.LowPart/SMALLSIZE); while (cb) { unsigned int cc; - if (!STORAGE_get_small_block(This->hf,blocknr,block)) { + if (!STORAGE_get_small_block(&This->str,blocknr,block)) { WARN("small block read failed!!!\n"); return E_FAIL; } @@ -1088,15 +1253,15 @@ HRESULT IStream16_fnRead( pbv+=cc; *bytesread+=cc; cb-=cc; - blocknr = STORAGE_get_next_small_blocknr(This->hf,blocknr); + blocknr = STORAGE_get_next_small_blocknr(&This->str,blocknr); } } else { /* use big block reader */ - blocknr = STORAGE_get_nth_next_big_blocknr(This->hf,This->stde.pps_sb,This->offset.u.LowPart/BIGSIZE); + blocknr = STORAGE_get_nth_next_big_blocknr(&This->str,This->stde.pps_sb,This->offset.u.LowPart/BIGSIZE); while (cb) { unsigned int cc; - if (!STORAGE_get_big_block(This->hf,blocknr,block)) { + if (!STORAGE_get_big_block(&This->str,blocknr,block)) { WARN("big block read failed!!!\n"); return E_FAIL; } @@ -1108,7 +1273,7 @@ HRESULT IStream16_fnRead( pbv+=cc; *bytesread+=cc; cb-=cc; - blocknr=STORAGE_get_next_big_blocknr(This->hf,blocknr); + blocknr=STORAGE_get_next_big_blocknr(&This->str,blocknr); } } return S_OK; @@ -1124,7 +1289,6 @@ HRESULT IStream16_fnWrite( BYTE block[BIGSIZE]; ULONG *byteswritten=pcbWrite,xxwritten; int oldsize,newsize,i,curoffset=0,lastblocknr,blocknr,cc; - HANDLE hf = This->hf; const BYTE* pbv = (const BYTE*)pv; if (!pcbWrite) byteswritten=&xxwritten; @@ -1137,20 +1301,20 @@ HRESULT IStream16_fnWrite( if (newsize < oldsize) { if (oldsize < 0x1000) { /* only small blocks */ - blocknr=STORAGE_get_nth_next_small_blocknr(hf,This->stde.pps_sb,newsize/SMALLSIZE); + blocknr=STORAGE_get_nth_next_small_blocknr(&This->str,This->stde.pps_sb,newsize/SMALLSIZE); assert(blocknr>=0); /* will set the rest of the chain to 'free' */ - if (!STORAGE_set_small_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_small_chain(&This->str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return E_FAIL; } else { if (newsize >= 0x1000) { - blocknr=STORAGE_get_nth_next_big_blocknr(hf,This->stde.pps_sb,newsize/BIGSIZE); + blocknr=STORAGE_get_nth_next_big_blocknr(&This->str,This->stde.pps_sb,newsize/BIGSIZE); assert(blocknr>=0); /* will set the rest of the chain to 'free' */ - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(&This->str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return E_FAIL; } else { /* Migrate large blocks to small blocks @@ -1163,35 +1327,35 @@ HRESULT IStream16_fnWrite( blocknr = This->stde.pps_sb; curdata = data; while (cc>0) { - if (!STORAGE_get_big_block(hf,blocknr,curdata)) { + if (!STORAGE_get_big_block(&This->str,blocknr,curdata)) { HeapFree(GetProcessHeap(),0,data); return E_FAIL; } curdata += BIGSIZE; cc -= BIGSIZE; - blocknr = STORAGE_get_next_big_blocknr(hf,blocknr); + blocknr = STORAGE_get_next_big_blocknr(&This->str,blocknr); } /* frees complete chain for this stream */ - if (!STORAGE_set_big_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) + if (!STORAGE_set_big_chain(&This->str,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) goto err; curdata = data; - blocknr = This->stde.pps_sb = STORAGE_get_free_small_blocknr(hf); + blocknr = This->stde.pps_sb = STORAGE_get_free_small_blocknr(&This->str); if (blocknr<0) goto err; cc = newsize; while (cc>0) { - if (!STORAGE_put_small_block(hf,blocknr,curdata)) + if (!STORAGE_put_small_block(&This->str,blocknr,curdata)) goto err; cc -= SMALLSIZE; if (cc<=0) { - if (!STORAGE_set_small_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_small_chain(&This->str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) goto err; break; } else { - int newblocknr = STORAGE_get_free_small_blocknr(hf); + int newblocknr = STORAGE_get_free_small_blocknr(&This->str); if (newblocknr<0) goto err; - if (!STORAGE_set_small_chain(hf,blocknr,newblocknr)) + if (!STORAGE_set_small_chain(&This->str,blocknr,newblocknr)) goto err; blocknr = newblocknr; } @@ -1210,46 +1374,46 @@ HRESULT IStream16_fnWrite( if (newsize > oldsize) { if (oldsize >= 0x1000) { /* should return the block right before the 'endofchain' */ - blocknr = STORAGE_get_nth_next_big_blocknr(hf,This->stde.pps_sb,This->stde.pps_size/BIGSIZE); + blocknr = STORAGE_get_nth_next_big_blocknr(&This->str,This->stde.pps_sb,This->stde.pps_size/BIGSIZE); assert(blocknr>=0); lastblocknr = blocknr; for (i=oldsize/BIGSIZE;istr); if (blocknr<0) return E_FAIL; - if (!STORAGE_set_big_chain(hf,lastblocknr,blocknr)) + if (!STORAGE_set_big_chain(&This->str,lastblocknr,blocknr)) return E_FAIL; lastblocknr = blocknr; } - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(&This->str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return E_FAIL; } else { if (newsize < 0x1000) { /* find startblock */ if (!oldsize) - This->stde.pps_sb = blocknr = STORAGE_get_free_small_blocknr(hf); + This->stde.pps_sb = blocknr = STORAGE_get_free_small_blocknr(&This->str); else - blocknr = STORAGE_get_nth_next_small_blocknr(hf,This->stde.pps_sb,This->stde.pps_size/SMALLSIZE); + blocknr = STORAGE_get_nth_next_small_blocknr(&This->str,This->stde.pps_sb,This->stde.pps_size/SMALLSIZE); if (blocknr<0) return E_FAIL; /* allocate required new small blocks */ lastblocknr = blocknr; for (i=oldsize/SMALLSIZE;istr); if (blocknr<0) return E_FAIL; - if (!STORAGE_set_small_chain(hf,lastblocknr,blocknr)) + if (!STORAGE_set_small_chain(&This->str,lastblocknr,blocknr)) return E_FAIL; lastblocknr = blocknr; } /* and terminate the chain */ - if (!STORAGE_set_small_chain(hf,lastblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_small_chain(&This->str,lastblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return E_FAIL; } else { if (!oldsize) { /* no single block allocated yet */ - blocknr=STORAGE_get_free_big_blocknr(hf); + blocknr=STORAGE_get_free_big_blocknr(&This->str); if (blocknr<0) return E_FAIL; This->stde.pps_sb = blocknr; @@ -1263,34 +1427,34 @@ HRESULT IStream16_fnWrite( curdata = data; /* slurp in */ while (cc>0) { - if (!STORAGE_get_small_block(hf,blocknr,curdata)) + if (!STORAGE_get_small_block(&This->str,blocknr,curdata)) goto err2; curdata += SMALLSIZE; cc -= SMALLSIZE; - blocknr = STORAGE_get_next_small_blocknr(hf,blocknr); + blocknr = STORAGE_get_next_small_blocknr(&This->str,blocknr); } /* free small block chain */ - if (!STORAGE_set_small_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) + if (!STORAGE_set_small_chain(&This->str,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) goto err2; curdata = data; - blocknr = This->stde.pps_sb = STORAGE_get_free_big_blocknr(hf); + blocknr = This->stde.pps_sb = STORAGE_get_free_big_blocknr(&This->str); if (blocknr<0) goto err2; /* put the data into the big blocks */ cc = This->stde.pps_size; while (cc>0) { - if (!STORAGE_put_big_block(hf,blocknr,curdata)) + if (!STORAGE_put_big_block(&This->str,blocknr,curdata)) goto err2; cc -= BIGSIZE; if (cc<=0) { - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(&This->str,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) goto err2; break; } else { - int newblocknr = STORAGE_get_free_big_blocknr(hf); + int newblocknr = STORAGE_get_free_big_blocknr(&This->str); if (newblocknr<0) goto err2; - if (!STORAGE_set_big_chain(hf,blocknr,newblocknr)) + if (!STORAGE_set_big_chain(&This->str,blocknr,newblocknr)) goto err2; blocknr = newblocknr; } @@ -1305,15 +1469,15 @@ HRESULT IStream16_fnWrite( /* generate big blocks to fit the new data */ lastblocknr = blocknr; for (i=oldsize/BIGSIZE;istr); if (blocknr<0) return E_FAIL; - if (!STORAGE_set_big_chain(hf,lastblocknr,blocknr)) + if (!STORAGE_set_big_chain(&This->str,lastblocknr,blocknr)) return E_FAIL; lastblocknr = blocknr; } /* terminate chain */ - if (!STORAGE_set_big_chain(hf,lastblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) + if (!STORAGE_set_big_chain(&This->str,lastblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) return E_FAIL; } } @@ -1323,12 +1487,12 @@ HRESULT IStream16_fnWrite( /* There are just some cases where we didn't modify it, we write it out * everytime */ - if (!STORAGE_put_pps_entry(hf,This->ppsent,&(This->stde))) + if (!STORAGE_put_pps_entry(&This->str,This->ppsent,&(This->stde))) return E_FAIL; /* finally the write pass */ if (This->stde.pps_size < 0x1000) { - blocknr = STORAGE_get_nth_next_small_blocknr(hf,This->stde.pps_sb,This->offset.u.LowPart/SMALLSIZE); + blocknr = STORAGE_get_nth_next_small_blocknr(&This->str,This->stde.pps_sb,This->offset.u.LowPart/SMALLSIZE); assert(blocknr>=0); while (cb>0) { /* we ensured that it is allocated above */ @@ -1336,7 +1500,7 @@ HRESULT IStream16_fnWrite( /* Read old block everytime, since we can have * overlapping data at START and END of the write */ - if (!STORAGE_get_small_block(hf,blocknr,block)) + if (!STORAGE_get_small_block(&This->str,blocknr,block)) return E_FAIL; cc = SMALLSIZE-(This->offset.u.LowPart&(SMALLSIZE-1)); @@ -1346,17 +1510,17 @@ HRESULT IStream16_fnWrite( pbv+curoffset, cc ); - if (!STORAGE_put_small_block(hf,blocknr,block)) + if (!STORAGE_put_small_block(&This->str,blocknr,block)) return E_FAIL; cb -= cc; curoffset += cc; pbv += cc; This->offset.u.LowPart += cc; *byteswritten += cc; - blocknr = STORAGE_get_next_small_blocknr(hf,blocknr); + blocknr = STORAGE_get_next_small_blocknr(&This->str,blocknr); } } else { - blocknr = STORAGE_get_nth_next_big_blocknr(hf,This->stde.pps_sb,This->offset.u.LowPart/BIGSIZE); + blocknr = STORAGE_get_nth_next_big_blocknr(&This->str,This->stde.pps_sb,This->offset.u.LowPart/BIGSIZE); assert(blocknr>=0); while (cb>0) { /* we ensured that it is allocated above, so it better is */ @@ -1364,7 +1528,7 @@ HRESULT IStream16_fnWrite( /* read old block everytime, since we can have * overlapping data at START and END of the write */ - if (!STORAGE_get_big_block(hf,blocknr,block)) + if (!STORAGE_get_big_block(&This->str,blocknr,block)) return E_FAIL; cc = BIGSIZE-(This->offset.u.LowPart&(BIGSIZE-1)); @@ -1374,14 +1538,14 @@ HRESULT IStream16_fnWrite( pbv+curoffset, cc ); - if (!STORAGE_put_big_block(hf,blocknr,block)) + if (!STORAGE_put_big_block(&This->str,blocknr,block)) return E_FAIL; cb -= cc; curoffset += cc; pbv += cc; This->offset.u.LowPart += cc; *byteswritten += cc; - blocknr = STORAGE_get_next_big_blocknr(hf,blocknr); + blocknr = STORAGE_get_next_big_blocknr(&This->str,blocknr); } } return S_OK; @@ -1440,6 +1604,8 @@ static void _create_istream16(LPSTREAM16 *str) { lpst->lpVtbl = segstrvt16; lpst->ref = 1; lpst->thisptr = MapLS( lpst ); + lpst->str.hf = NULL; + lpst->str.lockbytes = 0; *str = (void*)lpst->thisptr; } @@ -1454,7 +1620,7 @@ typedef struct /* IStream32 fields */ struct storage_pps_entry stde; int ppsent; - HANDLE hf; + HANDLE hf; ULARGE_INTEGER offset; } IStream32Impl; @@ -1498,20 +1664,6 @@ ULONG WINAPI IStream_fnRelease(IStream* iface) { return ref; } -/* --- IStorage16 implementation */ - -typedef struct -{ - /* IUnknown fields */ - const IStorage16Vtbl *lpVtbl; - LONG ref; - /* IStorage16 fields */ - SEGPTR thisptr; /* pointer to this struct as segmented */ - struct storage_pps_entry stde; - int ppsent; - HANDLE hf; -} IStorage16Impl; - /****************************************************************************** * IStorage16_QueryInterface [STORAGE.500] */ @@ -1616,12 +1768,10 @@ HRESULT IStorage16_fnCreateStorage( int ppsent,x; struct storage_pps_entry stde; struct storage_header sth; - HANDLE hf=This->hf; BOOL ret; int nPPSEntries; - READ_HEADER; - + READ_HEADER(&This->str); TRACE("(%p)->(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n", This,pwcsName,grfMode,dwStgFormat,reserved2,ppstg ); @@ -1629,9 +1779,15 @@ HRESULT IStorage16_fnCreateStorage( FIXME("We do not support transacted Compound Storage. Using direct mode.\n"); _create_istorage16(ppstg); lpstg = MapSL((SEGPTR)*ppstg); - lpstg->hf = This->hf; + if (This->str.hf) { + DuplicateHandle( GetCurrentProcess(), This->str.hf, GetCurrentProcess(), + &lpstg->str.hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + } else { + lpstg->str.lockbytes = This->str.lockbytes; + _ilockbytes16_addref(This->str.lockbytes); + } - ppsent=STORAGE_get_free_pps_entry(lpstg->hf); + ppsent=STORAGE_get_free_pps_entry(&lpstg->str); if (ppsent<0) return E_FAIL; stde=This->stde; @@ -1641,18 +1797,18 @@ HRESULT IStorage16_fnCreateStorage( } else { FIXME(" use prev chain too ?\n"); x=stde.pps_dir; - if (1!=STORAGE_get_pps_entry(lpstg->hf,x,&stde)) + if (1!=STORAGE_get_pps_entry(&lpstg->str,x,&stde)) return E_FAIL; while (stde.pps_next!=-1) { x=stde.pps_next; - if (1!=STORAGE_get_pps_entry(lpstg->hf,x,&stde)) + if (1!=STORAGE_get_pps_entry(&lpstg->str,x,&stde)) return E_FAIL; } stde.pps_next = ppsent; } - ret = STORAGE_put_pps_entry(lpstg->hf,x,&stde); + ret = STORAGE_put_pps_entry(&lpstg->str,x,&stde); assert(ret); - nPPSEntries = STORAGE_get_pps_entry(lpstg->hf,ppsent,&(lpstg->stde)); + nPPSEntries = STORAGE_get_pps_entry(&lpstg->str,ppsent,&(lpstg->stde)); assert(nPPSEntries == 1); MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, lpstg->stde.pps_rawname, sizeof(lpstg->stde.pps_rawname)/sizeof(WCHAR)); @@ -1665,7 +1821,7 @@ HRESULT IStorage16_fnCreateStorage( lpstg->stde.pps_type = 1; lpstg->ppsent = ppsent; /* FIXME: timestamps? */ - if (!STORAGE_put_pps_entry(lpstg->hf,ppsent,&(lpstg->stde))) + if (!STORAGE_put_pps_entry(&lpstg->str,ppsent,&(lpstg->stde))) return E_FAIL; return S_OK; } @@ -1690,12 +1846,17 @@ HRESULT IStorage16_fnCreateStream( FIXME("We do not support transacted Compound Storage. Using direct mode.\n"); _create_istream16(ppstm); lpstr = MapSL((SEGPTR)*ppstm); - DuplicateHandle( GetCurrentProcess(), This->hf, GetCurrentProcess(), - &lpstr->hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + if (This->str.hf) { + DuplicateHandle( GetCurrentProcess(), This->str.hf, GetCurrentProcess(), + &lpstr->str.hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + } else { + lpstr->str.lockbytes = This->str.lockbytes; + _ilockbytes16_addref(This->str.lockbytes); + } lpstr->offset.u.LowPart = 0; - lpstr->offset.u.HighPart = 0; + lpstr->offset.u.HighPart= 0; - ppsent=STORAGE_get_free_pps_entry(lpstr->hf); + ppsent=STORAGE_get_free_pps_entry(&lpstr->str); if (ppsent<0) return E_FAIL; stde=This->stde; @@ -1704,13 +1865,13 @@ HRESULT IStorage16_fnCreateStream( else while (stde.pps_next!=-1) { x=stde.pps_next; - if (1!=STORAGE_get_pps_entry(lpstr->hf,x,&stde)) + if (1!=STORAGE_get_pps_entry(&lpstr->str,x,&stde)) return E_FAIL; } stde.pps_next = ppsent; - ret = STORAGE_put_pps_entry(lpstr->hf,x,&stde); + ret = STORAGE_put_pps_entry(&lpstr->str,x,&stde); assert(ret); - nPPSEntries = STORAGE_get_pps_entry(lpstr->hf,ppsent,&(lpstr->stde)); + nPPSEntries = STORAGE_get_pps_entry(&lpstr->str,ppsent,&(lpstr->stde)); assert(nPPSEntries == 1); MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, lpstr->stde.pps_rawname, sizeof(lpstr->stde.pps_rawname)/sizeof(WCHAR)); @@ -1722,8 +1883,9 @@ HRESULT IStorage16_fnCreateStream( lpstr->stde.pps_size = 0; lpstr->stde.pps_type = 2; lpstr->ppsent = ppsent; + /* FIXME: timestamps? */ - if (!STORAGE_put_pps_entry(lpstr->hf,ppsent,&(lpstr->stde))) + if (!STORAGE_put_pps_entry(&lpstr->str,ppsent,&(lpstr->stde))) return E_FAIL; return S_OK; } @@ -1739,23 +1901,28 @@ HRESULT IStorage16_fnOpenStorage( WCHAR name[33]; int newpps; - TRACE_(relay)("(%p)->(%s,%p,0x%08lx,%p,0x%08lx,%p)\n", + TRACE("(%p)->(%s,%p,0x%08lx,%p,0x%08lx,%p)\n", This,pwcsName,pstgPrio,grfMode,snbExclude,reserved,ppstg ); if (grfMode & STGM_TRANSACTED) FIXME("We do not support transacted Compound Storage. Using direct mode.\n"); _create_istorage16(ppstg); lpstg = MapSL((SEGPTR)*ppstg); - DuplicateHandle( GetCurrentProcess(), This->hf, GetCurrentProcess(), - &lpstg->hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + if (This->str.hf) { + DuplicateHandle( GetCurrentProcess(), This->str.hf, GetCurrentProcess(), + &lpstg->str.hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + } else { + lpstg->str.lockbytes = This->str.lockbytes; + _ilockbytes16_addref(This->str.lockbytes); + } MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, name, sizeof(name)/sizeof(WCHAR)); - newpps = STORAGE_look_for_named_pps(lpstg->hf,This->stde.pps_dir,name); + newpps = STORAGE_look_for_named_pps(&lpstg->str,This->stde.pps_dir,name); if (newpps==-1) { IStream16_fnRelease((IStream16*)lpstg); return E_FAIL; } - if (1!=STORAGE_get_pps_entry(lpstg->hf,newpps,&(lpstg->stde))) { + if (1!=STORAGE_get_pps_entry(&lpstg->str,newpps,&(lpstg->stde))) { IStream16_fnRelease((IStream16*)lpstg); return E_FAIL; } @@ -1774,29 +1941,34 @@ HRESULT IStorage16_fnOpenStream( WCHAR name[33]; int newpps; - TRACE_(relay)("(%p)->(%s,%p,0x%08lx,0x%08lx,%p)\n", + TRACE("(%p)->(%s,%p,0x%08lx,0x%08lx,%p)\n", This,pwcsName,reserved1,grfMode,reserved2,ppstm ); if (grfMode & STGM_TRANSACTED) FIXME("We do not support transacted Compound Storage. Using direct mode.\n"); _create_istream16(ppstm); lpstr = MapSL((SEGPTR)*ppstm); - DuplicateHandle( GetCurrentProcess(), This->hf, GetCurrentProcess(), - &lpstr->hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + if (This->str.hf) { + DuplicateHandle( GetCurrentProcess(), This->str.hf, GetCurrentProcess(), + &lpstr->str.hf, 0, TRUE, DUPLICATE_SAME_ACCESS ); + } else { + lpstr->str.lockbytes = This->str.lockbytes; + _ilockbytes16_addref(This->str.lockbytes); + } MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, name, sizeof(name)/sizeof(WCHAR)); - newpps = STORAGE_look_for_named_pps(lpstr->hf,This->stde.pps_dir,name); + newpps = STORAGE_look_for_named_pps(&lpstr->str,This->stde.pps_dir,name); if (newpps==-1) { IStream16_fnRelease((IStream16*)lpstr); return E_FAIL; } - if (1!=STORAGE_get_pps_entry(lpstr->hf,newpps,&(lpstr->stde))) { + if (1!=STORAGE_get_pps_entry(&lpstr->str,newpps,&(lpstr->stde))) { IStream16_fnRelease((IStream16*)lpstr); return E_FAIL; } - lpstr->offset.u.LowPart = 0; + lpstr->offset.u.LowPart = 0; lpstr->offset.u.HighPart = 0; - lpstr->ppsent = newpps; + lpstr->ppsent = newpps; return S_OK; } @@ -1858,6 +2030,8 @@ static void _create_istorage16(LPSTORAGE16 *stg) { } lpst = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpst) ); lpst->lpVtbl = segstvt16; + lpst->str.hf = NULL; + lpst->str.lockbytes = 0; lpst->ref = 1; lpst->thisptr = MapLS(lpst); *stg = (void*)lpst->thisptr; @@ -1888,15 +2062,16 @@ HRESULT WINAPI StgCreateDocFile16( return E_FAIL; } lpstg = MapSL((SEGPTR)*ppstgOpen); - lpstg->hf = hf; + lpstg->str.hf = hf; + lpstg->str.lockbytes = 0; /* FIXME: check for existence before overwriting? */ - if (!STORAGE_init_storage(hf)) { + if (!STORAGE_init_storage(&lpstg->str)) { CloseHandle(hf); return E_FAIL; } i=0;ret=0; while (!ret) { /* neither 1 nor <0 */ - ret=STORAGE_get_pps_entry(hf,i,&stde); + ret=STORAGE_get_pps_entry(&lpstg->str,i,&stde); if ((ret==1) && (stde.pps_type==5)) { lpstg->stde = stde; lpstg->ppsent = i; @@ -1948,11 +2123,11 @@ HRESULT WINAPI StgOpenStorage16( return E_FAIL; } lpstg = MapSL((SEGPTR)*ppstgOpen); - lpstg->hf = hf; + lpstg->str.hf = hf; i=0;ret=0; while (!ret) { /* neither 1 nor <0 */ - ret=STORAGE_get_pps_entry(hf,i,&stde); + ret=STORAGE_get_pps_entry(&lpstg->str,i,&stde); if ((ret==1) && (stde.pps_type==5)) { lpstg->stde=stde; break; @@ -1980,11 +2155,11 @@ HRESULT WINAPI StgIsStorageILockBytes16(SEGPTR plkbyt) args[0] = (DWORD)plkbyt; /* iface */ args[1] = args[2] = 0; /* ULARGE_INTEGER offset */ - args[3] = (DWORD)K32WOWGlobalAllocLock16( 0, 8, &hsig ); /* sig */ + args[3] = WOWGlobalAllocLock16( 0, 8, &hsig ); /* sig */ args[4] = 8; args[5] = 0; - if (!K32WOWCallback16Ex( + if (!WOWCallback16Ex( (DWORD)((const ILockBytes16Vtbl*)MapSL( (SEGPTR)((LPLOCKBYTES16)MapSL(plkbyt))->lpVtbl) )->ReadAt, @@ -1997,10 +2172,10 @@ HRESULT WINAPI StgIsStorageILockBytes16(SEGPTR plkbyt) return hres; } if (memcmp(MapSL(args[3]), STORAGE_magic, sizeof(STORAGE_magic)) == 0) { - K32WOWGlobalUnlockFree16(args[3]); + WOWGlobalUnlockFree16(args[3]); return S_OK; } - K32WOWGlobalUnlockFree16(args[3]); + WOWGlobalUnlockFree16(args[3]); return S_FALSE; } @@ -2008,24 +2183,97 @@ HRESULT WINAPI StgIsStorageILockBytes16(SEGPTR plkbyt) * StgOpenStorageOnILockBytes [STORAGE.4] */ HRESULT WINAPI StgOpenStorageOnILockBytes16( - ILockBytes16 *plkbyt, - IStorage16 *pstgPriority, - DWORD grfMode, - SNB16 snbExclude, - DWORD reserved, - IStorage16 **ppstgOpen) + SEGPTR /*ILockBytes16 **/plkbyt, + IStorage16 *pstgPriority, + DWORD grfMode, + SNB16 snbExclude, + DWORD reserved, + IStorage16 **ppstgOpen) { - IStorage16Impl* lpstg; + IStorage16Impl* lpstg; + int i,ret; + struct storage_pps_entry stde; - if ((plkbyt == 0) || (ppstgOpen == 0)) - return STG_E_INVALIDPOINTER; + FIXME("(%lx, %p, 0x%08lx, %d, %lx, %p)\n", plkbyt, pstgPriority, grfMode, (int)snbExclude, reserved, ppstgOpen); + if ((plkbyt == 0) || (ppstgOpen == 0)) + return STG_E_INVALIDPOINTER; - *ppstgOpen = 0; + *ppstgOpen = 0; - _create_istorage16(ppstgOpen); - lpstg = MapSL((SEGPTR)*ppstgOpen); - - /* just teach it to use HANDLE instead of ilockbytes :/ */ - - return S_OK; + _create_istorage16(ppstgOpen); + lpstg = MapSL((SEGPTR)*ppstgOpen); + lpstg->str.hf = NULL; + lpstg->str.lockbytes = plkbyt; + i=0;ret=0; + while (!ret) { /* neither 1 nor <0 */ + ret=STORAGE_get_pps_entry(&lpstg->str,i,&stde); + if ((ret==1) && (stde.pps_type==5)) { + lpstg->stde=stde; + break; + } + i++; + } + if (ret!=1) { + IStorage16_fnRelease((IStorage16*)lpstg); /* will remove it */ + return E_FAIL; + } + return S_OK; +} + +/*********************************************************************** + * ReadClassStg (OLE2.18) + * + * This method reads the CLSID previously written to a storage object with + * the WriteClassStg. + * + * PARAMS + * pstg Segmented LPSTORAGE pointer. + */ +HRESULT WINAPI ReadClassStg16(SEGPTR pstg, CLSID *pclsid) +{ + STATSTG16 statstg; + HANDLE16 hstatstg; + HRESULT hres; + DWORD args[3]; + + TRACE("(%lx, %p)\n", pstg, pclsid); + + if(pclsid==NULL) + return E_POINTER; + /* + * read a STATSTG structure (contains the clsid) from the storage + */ + args[0] = (DWORD)pstg; /* iface */ + args[1] = WOWGlobalAllocLock16( 0, sizeof(STATSTG16), &hstatstg ); + args[2] = STATFLAG_DEFAULT; + + if (!WOWCallback16Ex( + (DWORD)((const IStorage16Vtbl*)MapSL( + (SEGPTR)((LPSTORAGE16)MapSL(pstg))->lpVtbl) + )->Stat, + WCB16_PASCAL, + 3*sizeof(DWORD), + (LPVOID)args, + (LPDWORD)&hres + )) { + WOWGlobalUnlockFree16(args[1]); + ERR("CallTo16 IStorage16::Stat() failed, hres %lx\n",hres); + return hres; + } + memcpy(&statstg, MapSL(args[1]), sizeof(STATSTG16)); + WOWGlobalUnlockFree16(args[1]); + + if(SUCCEEDED(hres)) { + *pclsid=statstg.clsid; + TRACE("clsid is %s\n", debugstr_guid(&statstg.clsid)); + } + return hres; +} + +/*********************************************************************** + * GetConvertStg (OLE2.82) + */ +HRESULT WINAPI GetConvertStg16(LPSTORAGE stg) { + FIXME("unimplemented stub!\n"); + return E_FAIL; } diff --git a/reactos/lib/ole32/storage.spec b/reactos/lib/ole32/storage.spec index f9cf3cc5a31..fe6399d03c6 100644 --- a/reactos/lib/ole32/storage.spec +++ b/reactos/lib/ole32/storage.spec @@ -6,7 +6,7 @@ 2 stub StgCreateDocFileOnILockBytes # 2 pascal StgCreateDocFileOnILockBytes(ptr long long ptr) StgCreateDocFileOnILockBytes16 3 pascal StgOpenStorage(str ptr long ptr long ptr) StgOpenStorage16 -4 pascal StgOpenStorageOnILockBytes(ptr ptr long long long ptr) StgOpenStorageOnILockBytes16 +4 pascal StgOpenStorageOnILockBytes(segptr ptr long long long ptr) StgOpenStorageOnILockBytes16 5 pascal StgIsStorageFile(str) StgIsStorageFile16 6 pascal StgIsStorageILockBytes(segptr) StgIsStorageILockBytes16 7 stub StgSetTimes diff --git a/reactos/lib/ole32/storage32.c b/reactos/lib/ole32/storage32.c index fdd337fd418..6f7f22dbfb5 100644 --- a/reactos/lib/ole32/storage32.c +++ b/reactos/lib/ole32/storage32.c @@ -58,8 +58,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage); -#define FILE_BEGIN 0 - /* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ #define OLESTREAM_ID 0x501 #define OLESTREAM_MAX_STR_LEN 255 @@ -7093,7 +7091,7 @@ HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName { char strTemp[OLESTREAM_MAX_STR_LEN]; IStorageCompObj.dwCLSIDNameLength = OLESTREAM_MAX_STR_LEN; - hErr = RegQueryValueA(hKey, NULL, strTemp, &(IStorageCompObj.dwCLSIDNameLength)); + hErr = RegQueryValueA(hKey, NULL, strTemp, (LONG*) &(IStorageCompObj.dwCLSIDNameLength)); if(hErr == ERROR_SUCCESS) { strcpy(IStorageCompObj.strCLSIDName, strTemp);