From 53af5ece751a699416862a58d4735f516a8d9f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Fri, 31 Dec 2004 15:19:40 +0000 Subject: [PATCH] Need to remove existing files before doing vendor import svn path=/trunk/; revision=12574 --- reactos/lib/ole32/Makefile.in | 74 - reactos/lib/ole32/Makefile.ros-template | 21 - reactos/lib/ole32/antimoniker.c | 666 -- reactos/lib/ole32/bindctx.c | 590 -- reactos/lib/ole32/clipboard.c | 1786 ------ reactos/lib/ole32/compobj.c | 2269 ------- reactos/lib/ole32/compobj.spec | 218 - reactos/lib/ole32/compobj_private.h | 192 - reactos/lib/ole32/compositemoniker.c | 1727 ------ reactos/lib/ole32/datacache.c | 2023 ------ reactos/lib/ole32/dcom.h | 515 -- reactos/lib/ole32/dcom.idl | 292 - reactos/lib/ole32/defaulthandler.c | 1696 ----- reactos/lib/ole32/errorinfo.c | 523 -- reactos/lib/ole32/filemoniker.c | 1362 ----- reactos/lib/ole32/ftmarshal.c | 240 - reactos/lib/ole32/git.c | 366 -- reactos/lib/ole32/hglobalstream.c | 837 --- reactos/lib/ole32/ifs.c | 642 -- reactos/lib/ole32/ifs.h | 150 - reactos/lib/ole32/itemmoniker.c | 982 --- reactos/lib/ole32/makefile | 9 - reactos/lib/ole32/marshal.c | 809 --- reactos/lib/ole32/memlockbytes.c | 622 -- reactos/lib/ole32/memlockbytes16.c | 578 -- reactos/lib/ole32/moniker.c | 554 -- reactos/lib/ole32/moniker.h | 11 - reactos/lib/ole32/ole16.c | 527 -- reactos/lib/ole32/ole2.c | 2618 -------- reactos/lib/ole32/ole2.spec | 158 - reactos/lib/ole32/ole2_16.c | 144 - reactos/lib/ole32/ole2conv.spec | 9 - reactos/lib/ole32/ole2impl.c | 304 - reactos/lib/ole32/ole2nls.c | 136 - reactos/lib/ole32/ole2nls.spec | 12 - reactos/lib/ole32/ole2prox.spec | 3 - reactos/lib/ole32/ole2stubs.c | 175 - reactos/lib/ole32/ole2thk.spec | 7 - reactos/lib/ole32/ole32.spec | 266 - reactos/lib/ole32/ole32_main.c | 139 - reactos/lib/ole32/ole32_main.h | 33 - reactos/lib/ole32/ole32res.rc | 147 - reactos/lib/ole32/oleobj.c | 752 --- reactos/lib/ole32/oleproxy.c | 526 -- reactos/lib/ole32/olestd.h | 56 - reactos/lib/ole32/regsvr.c | 865 --- reactos/lib/ole32/rpc.c | 805 --- reactos/lib/ole32/stg_bigblockfile.c | 872 --- reactos/lib/ole32/stg_stream.c | 895 --- reactos/lib/ole32/storage.c | 2031 ------ reactos/lib/ole32/storage.spec | 59 - reactos/lib/ole32/storage32.c | 7491 ----------------------- reactos/lib/ole32/storage32.h | 892 --- reactos/lib/ole32/tests/Makefile | 28 - reactos/lib/ole32/tests/propvariant.c | 211 - reactos/lib/ole32/tests/storage32.c | 74 - reactos/lib/ole32/tests/testlist.c | 27 - reactos/lib/ole32/version.rc | 24 - reactos/lib/ole32/winehq2ros.patch | 67 - 59 files changed, 40107 deletions(-) delete mode 100644 reactos/lib/ole32/Makefile.in delete mode 100644 reactos/lib/ole32/Makefile.ros-template delete mode 100644 reactos/lib/ole32/antimoniker.c delete mode 100644 reactos/lib/ole32/bindctx.c delete mode 100644 reactos/lib/ole32/clipboard.c delete mode 100644 reactos/lib/ole32/compobj.c delete mode 100644 reactos/lib/ole32/compobj.spec delete mode 100644 reactos/lib/ole32/compobj_private.h delete mode 100644 reactos/lib/ole32/compositemoniker.c delete mode 100644 reactos/lib/ole32/datacache.c delete mode 100644 reactos/lib/ole32/dcom.h delete mode 100644 reactos/lib/ole32/dcom.idl delete mode 100644 reactos/lib/ole32/defaulthandler.c delete mode 100644 reactos/lib/ole32/errorinfo.c delete mode 100644 reactos/lib/ole32/filemoniker.c delete mode 100644 reactos/lib/ole32/ftmarshal.c delete mode 100644 reactos/lib/ole32/git.c delete mode 100644 reactos/lib/ole32/hglobalstream.c delete mode 100644 reactos/lib/ole32/ifs.c delete mode 100644 reactos/lib/ole32/ifs.h delete mode 100644 reactos/lib/ole32/itemmoniker.c delete mode 100644 reactos/lib/ole32/makefile delete mode 100644 reactos/lib/ole32/marshal.c delete mode 100644 reactos/lib/ole32/memlockbytes.c delete mode 100644 reactos/lib/ole32/memlockbytes16.c delete mode 100644 reactos/lib/ole32/moniker.c delete mode 100644 reactos/lib/ole32/moniker.h delete mode 100644 reactos/lib/ole32/ole16.c delete mode 100644 reactos/lib/ole32/ole2.c delete mode 100644 reactos/lib/ole32/ole2.spec delete mode 100644 reactos/lib/ole32/ole2_16.c delete mode 100644 reactos/lib/ole32/ole2conv.spec delete mode 100644 reactos/lib/ole32/ole2impl.c delete mode 100644 reactos/lib/ole32/ole2nls.c delete mode 100644 reactos/lib/ole32/ole2nls.spec delete mode 100644 reactos/lib/ole32/ole2prox.spec delete mode 100644 reactos/lib/ole32/ole2stubs.c delete mode 100644 reactos/lib/ole32/ole2thk.spec delete mode 100644 reactos/lib/ole32/ole32.spec delete mode 100644 reactos/lib/ole32/ole32_main.c delete mode 100644 reactos/lib/ole32/ole32_main.h delete mode 100644 reactos/lib/ole32/ole32res.rc delete mode 100644 reactos/lib/ole32/oleobj.c delete mode 100644 reactos/lib/ole32/oleproxy.c delete mode 100644 reactos/lib/ole32/olestd.h delete mode 100644 reactos/lib/ole32/regsvr.c delete mode 100644 reactos/lib/ole32/rpc.c delete mode 100644 reactos/lib/ole32/stg_bigblockfile.c delete mode 100644 reactos/lib/ole32/stg_stream.c delete mode 100644 reactos/lib/ole32/storage.c delete mode 100644 reactos/lib/ole32/storage.spec delete mode 100644 reactos/lib/ole32/storage32.c delete mode 100644 reactos/lib/ole32/storage32.h delete mode 100644 reactos/lib/ole32/tests/Makefile delete mode 100644 reactos/lib/ole32/tests/propvariant.c delete mode 100644 reactos/lib/ole32/tests/storage32.c delete mode 100644 reactos/lib/ole32/tests/testlist.c delete mode 100644 reactos/lib/ole32/version.rc delete mode 100644 reactos/lib/ole32/winehq2ros.patch diff --git a/reactos/lib/ole32/Makefile.in b/reactos/lib/ole32/Makefile.in deleted file mode 100644 index 9e1170351d3..00000000000 --- a/reactos/lib/ole32/Makefile.in +++ /dev/null @@ -1,74 +0,0 @@ -EXTRADEFS = -D_OLE32_ -DCOM_NO_WINDOWS_H -TOPSRCDIR = @top_srcdir@ -TOPOBJDIR = ../.. -SRCDIR = @srcdir@ -VPATH = @srcdir@ -MODULE = ole32.dll -IMPORTS = advapi32 user32 gdi32 rpcrt4 kernel32 ntdll -EXTRALIBS = -luuid - -C_SRCS = \ - antimoniker.c \ - bindctx.c \ - clipboard.c \ - compobj.c \ - compositemoniker.c \ - datacache.c \ - defaulthandler.c \ - errorinfo.c \ - filemoniker.c \ - ftmarshal.c \ - git.c \ - hglobalstream.c \ - ifs.c \ - itemmoniker.c \ - marshal.c \ - memlockbytes.c \ - moniker.c \ - ole2.c \ - ole2stubs.c \ - ole2impl.c \ - ole32_main.c \ - oleobj.c \ - oleproxy.c \ - regsvr.c \ - rpc.c \ - stg_bigblockfile.c \ - stg_stream.c \ - storage32.c - -C_SRCS16 = \ - memlockbytes16.c \ - ole16.c \ - ole2_16.c \ - ole2nls.c \ - storage.c - -SPEC_SRCS16 = \ - compobj.spec \ - ole2.spec \ - ole2conv.spec \ - ole2nls.spec \ - ole2prox.spec \ - ole2thk.spec \ - storage.spec - -RC_SRCS = ole32res.rc -RC_BINSRC = ole32res.rc -RC_BINARIES = \ - drag_copy.cur \ - drag_link.cur \ - drag_move.cur \ - nodrop.cur - -IDL_SRCS = \ - dcom.idl - -SUBDIRS = tests - -@MAKE_DLL_RULES@ - -### Dependencies: - -# note: this will get overwritten by make depend -$(ALL_OBJS): $(IDL_SRCS:.idl=.h) diff --git a/reactos/lib/ole32/Makefile.ros-template b/reactos/lib/ole32/Makefile.ros-template deleted file mode 100644 index 4880f0f797e..00000000000 --- a/reactos/lib/ole32/Makefile.ros-template +++ /dev/null @@ -1,21 +0,0 @@ -# $Id: Makefile.ros-template,v 1.3 2004/12/03 23:37:42 blight Exp $ - -TARGET_NAME = ole32 - -TARGET_OBJECTS = @C_SRCS@ - -TARGET_CFLAGS = @EXTRADEFS@ - -TARGET_SDKLIBS = @IMPORTS@ wine.a wine_uuid.a ntdll.a - -TARGET_BASE = $(TARGET_BASE_LIB_OLE32) - -TARGET_RC_SRCS = @RC_SRCS@ -TARGET_RC_BINSRC = @RC_BINSRC@ -TARGET_RC_BINARIES = @RC_BINARIES@ - -default: all - -DEP_OBJECTS = $(TARGET_OBJECTS) - -include $(TOOLS_PATH)/depend.mk diff --git a/reactos/lib/ole32/antimoniker.c b/reactos/lib/ole32/antimoniker.c deleted file mode 100644 index e919993e6f7..00000000000 --- a/reactos/lib/ole32/antimoniker.c +++ /dev/null @@ -1,666 +0,0 @@ -/*************************************************************************************** - * AntiMonikers implementation - * - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - ***************************************************************************************/ - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "wine/unicode.h" -#include "objbase.h" -#include "wine/debug.h" -#include "moniker.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -const CLSID CLSID_AntiMoniker = { - 0x305, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46} -}; - -/* AntiMoniker data structure */ -typedef struct AntiMonikerImpl{ - - IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/ - - /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether - * two monikers are equal. That's whay IROTData interface is implemented by monikers. - */ - IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/ - - ULONG ref; /* reference counter for this object */ - -} AntiMonikerImpl; - -/********************************************************************************/ -/* AntiMoniker prototype functions : */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface); -static ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface); - -/* IPersist prototype functions */ -static HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID); - -/* IPersistStream prototype functions */ -static HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface); -static HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface, IStream* pStm); -static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty); -static HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize); - -/* IMoniker prototype functions */ -static HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced); -static HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite); -static HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker); -static HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker); -static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash); -static HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning); -static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pAntiTime); -static HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk); -static HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix); -static HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath); -static HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName); -static HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut); -static HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys); - -/********************************************************************************/ -/* IROTData prototype functions */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject); -static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData* iface); -static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface); - -/* IROTData prototype function */ -static HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData); - -/* Local function used by AntiMoniker implementation */ -HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* iface); -HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* iface); - -/********************************************************************************/ -/* Virtual function table for the AntiMonikerImpl class which include IPersist,*/ -/* IPersistStream and IMoniker functions. */ -static IMonikerVtbl VT_AntiMonikerImpl = -{ - AntiMonikerImpl_QueryInterface, - AntiMonikerImpl_AddRef, - AntiMonikerImpl_Release, - AntiMonikerImpl_GetClassID, - AntiMonikerImpl_IsDirty, - AntiMonikerImpl_Load, - AntiMonikerImpl_Save, - AntiMonikerImpl_GetSizeMax, - AntiMonikerImpl_BindToObject, - AntiMonikerImpl_BindToStorage, - AntiMonikerImpl_Reduce, - AntiMonikerImpl_ComposeWith, - AntiMonikerImpl_Enum, - AntiMonikerImpl_IsEqual, - AntiMonikerImpl_Hash, - AntiMonikerImpl_IsRunning, - AntiMonikerImpl_GetTimeOfLastChange, - AntiMonikerImpl_Inverse, - AntiMonikerImpl_CommonPrefixWith, - AntiMonikerImpl_RelativePathTo, - AntiMonikerImpl_GetDisplayName, - AntiMonikerImpl_ParseDisplayName, - AntiMonikerImpl_IsSystemMoniker -}; - -/********************************************************************************/ -/* Virtual function table for the IROTData class. */ -static IROTDataVtbl VT_ROTDataImpl = -{ - AntiMonikerROTDataImpl_QueryInterface, - AntiMonikerROTDataImpl_AddRef, - AntiMonikerROTDataImpl_Release, - AntiMonikerROTDataImpl_GetComparaisonData -}; - -/******************************************************************************* - * AntiMoniker_QueryInterface - *******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject) -{ - AntiMonikerImpl *This = (AntiMonikerImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* Perform a sanity check on the parameters.*/ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* Initialize the return parameter */ - *ppvObject = 0; - - /* Compare the riid with the interface IDs implemented by this object.*/ - if (IsEqualIID(&IID_IUnknown, riid) || - IsEqualIID(&IID_IPersist, riid) || - IsEqualIID(&IID_IPersistStream, riid) || - IsEqualIID(&IID_IMoniker, riid) - ) - *ppvObject = iface; - else if (IsEqualIID(&IID_IROTData, riid)) - *ppvObject = (IROTData*)&(This->lpvtbl2); - - /* Check that we obtained an interface.*/ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* Query Interface always increases the reference count by one when it is successful */ - AntiMonikerImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_AddRef - ******************************************************************************/ -ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface) -{ - AntiMonikerImpl *This = (AntiMonikerImpl *)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * AntiMoniker_Release - ******************************************************************************/ -ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface) -{ - AntiMonikerImpl *This = (AntiMonikerImpl *)iface; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* destroy the object if there's no more reference on it */ - if (ref == 0) AntiMonikerImpl_Destroy(This); - - return ref; -} - -/****************************************************************************** - * AntiMoniker_GetClassID - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID) -{ - TRACE("(%p,%p),stub!\n",iface,pClassID); - - if (pClassID==NULL) - return E_POINTER; - - *pClassID = CLSID_AntiMoniker; - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_IsDirty - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_IsDirty(IMoniker* iface) -{ - /* Note that the OLE-provided implementations of the IPersistStream::IsDirty - method in the OLE-provided moniker interfaces always return S_FALSE because - their internal state never changes. */ - - TRACE("(%p)\n",iface); - - return S_FALSE; -} - -/****************************************************************************** - * AntiMoniker_Load - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm) -{ - DWORD constant=1,dwbuffer; - HRESULT res; - - /* data read by this function is only a DWORD constant (must be 1) ! */ - res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL); - - if (SUCCEEDED(res)&& dwbuffer!=constant) - return E_FAIL; - - return res; -} - -/****************************************************************************** - * AntiMoniker_Save - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty) -{ - DWORD constant=1; - HRESULT res; - - /* data written by this function is only a DWORD constant set to 1 ! */ - res=IStream_Write(pStm,&constant,sizeof(constant),NULL); - - return res; -} - -/****************************************************************************** - * AntiMoniker_GetSizeMax - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_GetSizeMax(IMoniker* iface, - ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */ -{ - TRACE("(%p,%p)\n",iface,pcbSize); - - if (pcbSize!=NULL) - return E_POINTER; - - /* for more details see AntiMonikerImpl_Save coments */ - - /* Normaly the sizemax must be the size of DWORD ! but I tested this function it ususlly return 16 bytes */ - /* more than the number of bytes used by AntiMoniker::Save function */ - pcbSize->u.LowPart = sizeof(DWORD)+16; - - pcbSize->u.HighPart=0; - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_Construct (local function) - *******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Construct(AntiMonikerImpl* This) -{ - - TRACE("(%p)\n",This); - - /* Initialize the virtual fgunction table. */ - This->lpvtbl1 = &VT_AntiMonikerImpl; - This->lpvtbl2 = &VT_ROTDataImpl; - This->ref = 0; - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_Destroy (local function) - *******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Destroy(AntiMonikerImpl* This) -{ - TRACE("(%p)\n",This); - - return HeapFree(GetProcessHeap(),0,This); -} - -/****************************************************************************** - * AntiMoniker_BindToObject - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_BindToObject(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - return E_NOTIMPL; -} - -/****************************************************************************** - * AntiMoniker_BindToStorage - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_BindToStorage(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - return E_NOTIMPL; -} - -/****************************************************************************** - * AntiMoniker_Reduce - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Reduce(IMoniker* iface, - IBindCtx* pbc, - DWORD dwReduceHowFar, - IMoniker** ppmkToLeft, - IMoniker** ppmkReduced) -{ - TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced); - - if (ppmkReduced==NULL) - return E_POINTER; - - AntiMonikerImpl_AddRef(iface); - - *ppmkReduced=iface; - - return MK_S_REDUCED_TO_SELF; -} -/****************************************************************************** - * AntiMoniker_ComposeWith - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_ComposeWith(IMoniker* iface, - IMoniker* pmkRight, - BOOL fOnlyIfNotGeneric, - IMoniker** ppmkComposite) -{ - - TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite); - - if ((ppmkComposite==NULL)||(pmkRight==NULL)) - return E_POINTER; - - *ppmkComposite=0; - - if (fOnlyIfNotGeneric) - return MK_E_NEEDGENERIC; - else - return CreateGenericComposite(iface,pmkRight,ppmkComposite); -} - -/****************************************************************************** - * AntiMoniker_Enum - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker) -{ - TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker); - - if (ppenumMoniker == NULL) - return E_POINTER; - - *ppenumMoniker = NULL; - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_IsEqual - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker) -{ - DWORD mkSys; - - TRACE("(%p,%p)\n",iface,pmkOtherMoniker); - - if (pmkOtherMoniker==NULL) - return S_FALSE; - - IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys); - - if (mkSys==MKSYS_ANTIMONIKER) - return S_OK; - else - return S_FALSE; -} - -/****************************************************************************** - * AntiMoniker_Hash - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash) -{ - if (pdwHash==NULL) - return E_POINTER; - - *pdwHash=0; - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_IsRunning - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_IsRunning(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - IMoniker* pmkNewlyRunning) -{ - IRunningObjectTable* rot; - HRESULT res; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); - - if (pbc==NULL) - return E_INVALIDARG; - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - res = IRunningObjectTable_IsRunning(rot,iface); - - IRunningObjectTable_Release(rot); - - return res; -} - -/****************************************************************************** - * AntiMoniker_GetTimeOfLastChange - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - FILETIME* pAntiTime) -{ - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime); - return E_NOTIMPL; -} - -/****************************************************************************** - * AntiMoniker_Inverse - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk) -{ - TRACE("(%p,%p)\n",iface,ppmk); - - if (ppmk==NULL) - return E_POINTER; - - *ppmk=0; - - return MK_E_NOINVERSE; -} - -/****************************************************************************** - * AntiMoniker_CommonPrefixWith - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix) -{ - DWORD mkSys; - - IMoniker_IsSystemMoniker(pmkOther,&mkSys); - - if(mkSys==MKSYS_ITEMMONIKER){ - - IMoniker_AddRef(iface); - - *ppmkPrefix=iface; - - IMoniker_AddRef(iface); - - return MK_S_US; - } - else - return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix); -} - -/****************************************************************************** - * AntiMoniker_RelativePathTo - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath) -{ - TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath); - - if (ppmkRelPath==NULL) - return E_POINTER; - - IMoniker_AddRef(pmOther); - - *ppmkRelPath=pmOther; - - return MK_S_HIM; -} - -/****************************************************************************** - * AntiMoniker_GetDisplayName - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_GetDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR *ppszDisplayName) -{ - static const WCHAR back[]={'\\','.','.',0}; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName); - - if (ppszDisplayName==NULL) - return E_POINTER; - - if (pmkToLeft!=NULL){ - FIXME("() pmkToLeft!=NULL not implemented \n"); - return E_NOTIMPL; - } - - *ppszDisplayName=CoTaskMemAlloc(sizeof(back)); - - if (*ppszDisplayName==NULL) - return E_OUTOFMEMORY; - - strcpyW(*ppszDisplayName,back); - - return S_OK; -} - -/****************************************************************************** - * AntiMoniker_ParseDisplayName - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_ParseDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR pszDisplayName, - ULONG* pchEaten, - IMoniker** ppmkOut) -{ - TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut); - return E_NOTIMPL; -} - -/****************************************************************************** - * AntiMoniker_IsSystemMoniker - ******************************************************************************/ -HRESULT WINAPI AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys) -{ - TRACE("(%p,%p)\n",iface,pwdMksys); - - if (!pwdMksys) - return E_POINTER; - - (*pwdMksys)=MKSYS_ANTIMONIKER; - - return S_OK; -} - -/******************************************************************************* - * AntiMonikerIROTData_QueryInterface - *******************************************************************************/ -HRESULT WINAPI AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) -{ - - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p,%p,%p)\n",iface,riid,ppvObject); - - return AntiMonikerImpl_QueryInterface(This, riid, ppvObject); -} - -/*********************************************************************** - * AntiMonikerIROTData_AddRef - */ -ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",iface); - - return AntiMonikerImpl_AddRef(This); -} - -/*********************************************************************** - * AntiMonikerIROTData_Release - */ -ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",iface); - - return AntiMonikerImpl_Release(This); -} - -/****************************************************************************** - * AntiMonikerIROTData_GetComparaisonData - ******************************************************************************/ -HRESULT WINAPI AntiMonikerROTDataImpl_GetComparaisonData(IROTData* iface, - BYTE* pbData, - ULONG cbMax, - ULONG* pcbData) -{ - FIXME("(),stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * CreateAntiMoniker [OLE32.@] - ******************************************************************************/ -HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk) -{ - AntiMonikerImpl* newAntiMoniker = 0; - HRESULT hr = S_OK; - IID riid=IID_IMoniker; - - TRACE("(%p)\n",ppmk); - - newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl)); - - if (newAntiMoniker == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = AntiMonikerImpl_Construct(newAntiMoniker); - - if (FAILED(hr)){ - - HeapFree(GetProcessHeap(),0,newAntiMoniker); - return hr; - } - - hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk); - - return hr; -} diff --git a/reactos/lib/ole32/bindctx.c b/reactos/lib/ole32/bindctx.c deleted file mode 100644 index d7cc892e72e..00000000000 --- a/reactos/lib/ole32/bindctx.c +++ /dev/null @@ -1,590 +0,0 @@ -/*************************************************************************************** - * BindCtx implementation - * - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - ***************************************************************************************/ - -#include -#include -#include - -#define COBJMACROS - -#include "winerror.h" -#include "windef.h" -#include "winbase.h" -#include "wine/unicode.h" -#include "objbase.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/* represent the first size table and it's increment block size */ -#define BLOCK_TAB_SIZE 10 -#define MAX_TAB_SIZE 0xFFFFFFFF - -/* data structure of the BindCtx table elements */ -typedef struct BindCtxObject{ - - IUnknown* pObj; /* point on a bound object */ - - LPOLESTR pkeyObj; /* key associated to this bound object */ - - BYTE regType; /* registration type: 1 if RegisterObjectParam and 0 if RegisterObjectBound */ - -} BindCtxObject; - -/* BindCtx data strucrture */ -typedef struct BindCtxImpl{ - - IBindCtxVtbl *lpVtbl; /* VTable relative to the IBindCtx interface.*/ - - ULONG ref; /* reference counter for this object */ - - BindCtxObject* bindCtxTable; /* this is a table in which all bounded objects are stored*/ - DWORD bindCtxTableLastIndex; /* first free index in the table */ - DWORD bindCtxTableSize; /* size table */ - - BIND_OPTS2 bindOption2; /* a structure which contains the bind options*/ - -} BindCtxImpl; - -/* IBindCtx prototype functions : */ - -/* IUnknown functions*/ -static HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface); -static ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface); -/* IBindCtx functions */ -static HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk); -static HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk); -static HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface); -static HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts); -static HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts); -static HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot); -static HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk); -static HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk); -static HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** ppenum); -static HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR pszkey); -/* Local functions*/ -HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This); -HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This); -HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This,IUnknown* punk,LPOLESTR pszkey,DWORD *index); - -/* Virtual function table for the BindCtx class. */ -static IBindCtxVtbl VT_BindCtxImpl = - { - BindCtxImpl_QueryInterface, - BindCtxImpl_AddRef, - BindCtxImpl_Release, - BindCtxImpl_RegisterObjectBound, - BindCtxImpl_RevokeObjectBound, - BindCtxImpl_ReleaseBoundObjects, - BindCtxImpl_SetBindOptions, - BindCtxImpl_GetBindOptions, - BindCtxImpl_GetRunningObjectTable, - BindCtxImpl_RegisterObjectParam, - BindCtxImpl_GetObjectParam, - BindCtxImpl_EnumObjectParam, - BindCtxImpl_RevokeObjectParam -}; - -/******************************************************************************* - * BindCtx_QueryInterface - *******************************************************************************/ -HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* Perform a sanity check on the parameters.*/ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* Initialize the return parameter.*/ - *ppvObject = 0; - - /* Compare the riid with the interface IDs implemented by this object.*/ - if (IsEqualIID(&IID_IUnknown, riid)) - *ppvObject = (IBindCtx*)This; - else - if (IsEqualIID(&IID_IBindCtx, riid)) - *ppvObject = (IBindCtx*)This; - - /* Check that we obtained an interface.*/ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* Query Interface always increases the reference count by one when it is successful */ - BindCtxImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * BindCtx_AddRef - ******************************************************************************/ -ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * BindCtx_Release - ******************************************************************************/ -ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - if (ref == 0){ - /* release all registered objects */ - BindCtxImpl_ReleaseBoundObjects((IBindCtx*)This); - - BindCtxImpl_Destroy(This); - } - return ref; -} - - -/****************************************************************************** - * BindCtx_Construct (local function) - *******************************************************************************/ -HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This) -{ - TRACE("(%p)\n",This); - - /* Initialize the virtual function table.*/ - This->lpVtbl = &VT_BindCtxImpl; - This->ref = 0; - - /* Initialize the BIND_OPTS2 structure */ - This->bindOption2.cbStruct = sizeof(BIND_OPTS2); - This->bindOption2.grfFlags = 0; - This->bindOption2.grfMode = STGM_READWRITE; - This->bindOption2.dwTickCountDeadline = 0; - - This->bindOption2.dwTrackFlags = 0; - This->bindOption2.dwClassContext = CLSCTX_SERVER; - This->bindOption2.locale = 1033; - This->bindOption2.pServerInfo = 0; - - /* Initialize the bindctx table */ - This->bindCtxTableSize=BLOCK_TAB_SIZE; - This->bindCtxTableLastIndex=0; - This->bindCtxTable= HeapAlloc(GetProcessHeap(), 0,This->bindCtxTableSize*sizeof(BindCtxObject)); - - if (This->bindCtxTable==NULL) - return E_OUTOFMEMORY; - - return S_OK; -} - -/****************************************************************************** - * BindCtx_Destroy (local function) - *******************************************************************************/ -HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This) -{ - TRACE("(%p)\n",This); - - /* free the table space memory */ - HeapFree(GetProcessHeap(),0,This->bindCtxTable); - - /* free the bindctx structure */ - HeapFree(GetProcessHeap(),0,This); - - return S_OK; -} - - -/****************************************************************************** - * BindCtx_RegisterObjectBound - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - DWORD lastIndex=This->bindCtxTableLastIndex; - - TRACE("(%p,%p)\n",This,punk); - - if (punk==NULL) - return E_POINTER; - - IUnknown_AddRef(punk); - - /* put the object in the first free element in the table */ - This->bindCtxTable[lastIndex].pObj = punk; - This->bindCtxTable[lastIndex].pkeyObj = NULL; - This->bindCtxTable[lastIndex].regType = 0; - lastIndex= ++This->bindCtxTableLastIndex; - - if (lastIndex == This->bindCtxTableSize){ /* the table is full so it must be resized */ - - if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){ - FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize); - return E_FAIL; - } - - This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */ - - This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable, - This->bindCtxTableSize * sizeof(BindCtxObject)); - if (!This->bindCtxTable) - return E_OUTOFMEMORY; - } - return S_OK; -} - -/****************************************************************************** - * BindCtx_RevokeObjectBound - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk) -{ - DWORD index,j; - - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%p)\n",This,punk); - - /* check if the object was registered or not */ - if (BindCtxImpl_GetObjectIndex(This,punk,NULL,&index)==S_FALSE) - return MK_E_NOTBOUND; - - if(This->bindCtxTable[index].pObj) - IUnknown_Release(This->bindCtxTable[index].pObj); - if(This->bindCtxTable[index].pkeyObj) - HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj); - - /* left-shift all elements in the right side of the current revoked object */ - for(j=index; jbindCtxTableLastIndex-1; j++) - This->bindCtxTable[j]= This->bindCtxTable[j+1]; - - This->bindCtxTableLastIndex--; - - return S_OK; -} - -/****************************************************************************** - * BindCtx_ReleaseBoundObjects - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface) -{ - DWORD i; - - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p)\n",This); - - for(i=0;ibindCtxTableLastIndex;i++) - { - if(This->bindCtxTable[i].pObj) - IUnknown_Release(This->bindCtxTable[i].pObj); - if(This->bindCtxTable[i].pkeyObj) - HeapFree(GetProcessHeap(),0,This->bindCtxTable[i].pkeyObj); - } - - This->bindCtxTableLastIndex = 0; - - return S_OK; -} - -/****************************************************************************** - * BindCtx_SetBindOptions - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%p)\n",This,pbindopts); - - if (pbindopts==NULL) - return E_POINTER; - - if (pbindopts->cbStruct > sizeof(BIND_OPTS2)) - { - WARN("invalid size\n"); - return E_INVALIDARG; /* FIXME : not verified */ - } - memcpy(&This->bindOption2, pbindopts, pbindopts->cbStruct); - return S_OK; -} - -/****************************************************************************** - * BindCtx_GetBindOptions - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts) -{ - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%p)\n",This,pbindopts); - - if (pbindopts==NULL) - return E_POINTER; - - if (pbindopts->cbStruct > sizeof(BIND_OPTS2)) - { - WARN("invalid size\n"); - return E_INVALIDARG; /* FIXME : not verified */ - } - memcpy(pbindopts, &This->bindOption2, pbindopts->cbStruct); - return S_OK; -} - -/****************************************************************************** - * BindCtx_GetRunningObjectTable - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot) -{ - HRESULT res; - - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%p)\n",This,pprot); - - if (pprot==NULL) - return E_POINTER; - - res=GetRunningObjectTable(0, pprot); - - return res; -} - -/****************************************************************************** - * BindCtx_RegisterObjectParam - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk) -{ - DWORD index=0; - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk); - - if (punk==NULL) - return E_INVALIDARG; - - if (pszkey!=NULL && BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_OK) - { - TRACE("Overwriting existing key\n"); - if(This->bindCtxTable[index].pObj!=NULL) - IUnknown_Release(This->bindCtxTable[index].pObj); - This->bindCtxTable[index].pObj=punk; - IUnknown_AddRef(punk); - return S_OK; - } - This->bindCtxTable[This->bindCtxTableLastIndex].pObj = punk; - This->bindCtxTable[This->bindCtxTableLastIndex].regType = 1; - - if (pszkey==NULL) - - This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=NULL; - - else{ - - This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj= - HeapAlloc(GetProcessHeap(),0,(sizeof(WCHAR)*(1+lstrlenW(pszkey)))); - - if (This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj==NULL) - return E_OUTOFMEMORY; - strcpyW(This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj,pszkey); - } - - This->bindCtxTableLastIndex++; - - if (This->bindCtxTableLastIndex == This->bindCtxTableSize){ /* table is full ! must be resized */ - - This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */ - - if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){ - FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize); - return E_FAIL; - } - This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable, - This->bindCtxTableSize * sizeof(BindCtxObject)); - if (!This->bindCtxTable) - return E_OUTOFMEMORY; - } - IUnknown_AddRef(punk); - return S_OK; -} - -/****************************************************************************** - * BindCtx_GetObjectParam - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk) -{ - DWORD index; - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk); - - if (punk==NULL) - return E_POINTER; - - *punk=0; - - if (BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_FALSE) - return E_FAIL; - - IUnknown_AddRef(This->bindCtxTable[index].pObj); - - *punk = This->bindCtxTable[index].pObj; - - return S_OK; -} - -/****************************************************************************** - * BindCtx_RevokeObjectParam - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR ppenum) -{ - DWORD index,j; - - BindCtxImpl *This = (BindCtxImpl *)iface; - - TRACE("(%p,%s)\n",This,debugstr_w(ppenum)); - - if (BindCtxImpl_GetObjectIndex(This,NULL,ppenum,&index)==S_FALSE) - return E_FAIL; - - /* release the object if it's found */ - if(This->bindCtxTable[index].pObj) - IUnknown_Release(This->bindCtxTable[index].pObj); - if(This->bindCtxTable[index].pkeyObj) - HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj); - - /* remove the object from the table with a left-shifting of all objects in the right side */ - for(j=index; jbindCtxTableLastIndex-1; j++) - This->bindCtxTable[j]= This->bindCtxTable[j+1]; - - This->bindCtxTableLastIndex--; - - return S_OK; -} - -/****************************************************************************** - * BindCtx_EnumObjectParam - ******************************************************************************/ -HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** pszkey) -{ - FIXME("(%p,%p),stub!\n",iface,pszkey); - return E_NOTIMPL; -} - -/******************************************************************************** - * GetObjectIndex (local function) - ********************************************************************************/ -HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This, - IUnknown* punk, - LPOLESTR pszkey, - DWORD *index) -{ - - DWORD i; - BYTE found=0; - - TRACE("(%p,%p,%p,%p)\n",This,punk,pszkey,index); - - if (punk==NULL) - /* search object identified by a register key */ - for(i=0; ( (ibindCtxTableLastIndex) && (!found));i++){ - - if(This->bindCtxTable[i].regType==1){ - - if ( ( (This->bindCtxTable[i].pkeyObj==NULL) && (pszkey==NULL) ) || - ( (This->bindCtxTable[i].pkeyObj!=NULL) && - (pszkey!=NULL) && - (lstrcmpW(This->bindCtxTable[i].pkeyObj,pszkey)==0) - ) - ) - - found=1; - } - } - else - /* search object identified by a moniker*/ - for(i=0; ( (ibindCtxTableLastIndex) && (!found));i++) - if(This->bindCtxTable[i].pObj==punk) - found=1; - - if (index != NULL) - *index=i-1; - - if (found) - return S_OK; - TRACE("key not found\n"); - return S_FALSE; -} - -/****************************************************************************** - * CreateBindCtx16 - ******************************************************************************/ -HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc) -{ - FIXME("(%ld,%p),stub!\n",reserved,ppbc); - return E_NOTIMPL; -} - -/****************************************************************************** - * CreateBindCtx (OLE32.@) - ******************************************************************************/ -HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC * ppbc) -{ - BindCtxImpl* newBindCtx = 0; - HRESULT hr; - IID riid=IID_IBindCtx; - - TRACE("(%ld,%p)\n",reserved,ppbc); - - newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl)); - - if (newBindCtx == 0) - return E_OUTOFMEMORY; - - hr = BindCtxImpl_Construct(newBindCtx); - - if (FAILED(hr)){ - - HeapFree(GetProcessHeap(),0,newBindCtx); - return hr; - } - - hr = BindCtxImpl_QueryInterface((IBindCtx*)newBindCtx,&riid,(void**)ppbc); - - return hr; -} - -HRESULT WINAPI BindMoniker(LPMONIKER pmk, DWORD grfOpt, REFIID riid, LPVOID * ppvResult) -{ - HRESULT res; - IBindCtx * pbc; - - TRACE("(%p, %lx, %s, %p)\n", pmk, grfOpt, debugstr_guid(riid), ppvResult); - - res = CreateBindCtx(grfOpt, &pbc); - if (SUCCEEDED(res)) - res = IMoniker_BindToObject(pmk, pbc, NULL, riid, ppvResult); - return res; -} diff --git a/reactos/lib/ole32/clipboard.c b/reactos/lib/ole32/clipboard.c deleted file mode 100644 index deef806b9a2..00000000000 --- a/reactos/lib/ole32/clipboard.c +++ /dev/null @@ -1,1786 +0,0 @@ -/* - * OLE 2 clipboard support - * - * Copyright 1999 Noel Borthwick - * Copyright 2000 Abey George - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * NOTES: - * This file contains the implementation for the OLE Clipboard and its - * internal interfaces. The OLE clipboard interacts with an IDataObject - * interface via the OleSetClipboard, OleGetClipboard and - * OleIsCurrentClipboard API's. An internal IDataObject delegates - * to a client supplied IDataObject or the WIN32 clipboard API depending - * on whether OleSetClipboard has been invoked. - * Here are some operating scenarios: - * - * 1. OleSetClipboard called: In this case the internal IDataObject - * delegates to the client supplied IDataObject. Additionally OLE takes - * ownership of the Windows clipboard and any HGLOCBAL IDataObject - * items are placed on the Windows clipboard. This allows non OLE aware - * applications to access these. A local WinProc fields WM_RENDERFORMAT - * and WM_RENDERALLFORMATS messages in this case. - * - * 2. OleGetClipboard called without previous OleSetClipboard. Here the internal - * IDataObject functionality wraps around the WIN32 clipboard API. - * - * 3. OleGetClipboard called after previous OleSetClipboard. Here the internal - * IDataObject delegates to the source IDataObjects functionality directly, - * thereby bypassing the Windows clipboard. - * - * Implementation references : Inside OLE 2'nd edition by Kraig Brockschmidt - * - * TODO: - * - Support for pasting between different processes. OLE clipboard support - * currently works only for in process copy and paste. Since we internally - * store a pointer to the source's IDataObject and delegate to that, this - * will fail if the IDataObject client belongs to a different process. - * - IDataObject::GetDataHere is not implemented - * - OleFlushClipboard needs to additionally handle TYMED_IStorage media - * by copying the storage into global memory. Subsequently the default - * data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL - * back to TYMED_IStorage. - * - OLE1 compatibility formats to be synthesized from OLE2 formats and put on - * clipboard in OleSetClipboard. - * - */ - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winerror.h" -#include "winnls.h" -#include "ole2.h" -#include "wine/debug.h" -#include "olestd.h" - -#include "storage32.h" - -#define HANDLE_ERROR(err) { hr = err; TRACE("(HRESULT=%lx)\n", (HRESULT)err); goto CLEANUP; } - -/* For CoGetMalloc (MEMCTX_TASK is currently ignored) */ -#ifndef MEMCTX_TASK - #define MEMCTX_TASK -1 -#endif - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/**************************************************************************** - * OLEClipbrd - * DO NOT add any members before the VTables declaration! - */ -struct OLEClipbrd -{ - /* - * List all interface VTables here - */ - IDataObjectVtbl* lpvtbl1; /* IDataObject VTable */ - - /* - * The hidden OLE clipboard window. This window is used as the bridge between the - * the OLE and windows clipboard API. (Windows creates one such window per process) - */ - HWND hWndClipboard; - - /* - * Pointer to the source data object (via OleSetClipboard) - */ - IDataObject* pIDataObjectSrc; - - /* - * The registered DataObject clipboard format - */ - UINT cfDataObj; - - /* - * The handle to ourself - */ - HGLOBAL hSelf; - - /* - * Reference count of this object - */ - ULONG ref; -}; - -typedef struct OLEClipbrd OLEClipbrd; - - -/**************************************************************************** -* IEnumFORMATETC implementation -* DO NOT add any members before the VTables declaration! -*/ -typedef struct -{ - /* IEnumFORMATETC VTable */ - IEnumFORMATETCVtbl *lpVtbl; - - /* IEnumFORMATETC fields */ - UINT posFmt; /* current enumerator position */ - UINT countFmt; /* number of EnumFORMATETC's in array */ - LPFORMATETC pFmt; /* array of EnumFORMATETC's */ - - /* - * Reference count of this object - */ - DWORD ref; - - /* - * IUnknown implementation of the parent data object. - */ - IUnknown* pUnkDataObj; - -} IEnumFORMATETCImpl; - -typedef struct PresentationDataHeader -{ - BYTE unknown1[28]; - DWORD dwObjectExtentX; - DWORD dwObjectExtentY; - DWORD dwSize; -} PresentationDataHeader; - -/* - * The one and only OLEClipbrd object which is created by OLEClipbrd_Initialize() - */ -static HGLOBAL hTheOleClipboard = 0; -static OLEClipbrd* theOleClipboard = NULL; - - -/* - * Prototypes for the methods of the OLEClipboard class. - */ -extern void OLEClipbrd_Initialize(); -extern void OLEClipbrd_UnInitialize(); -static OLEClipbrd* OLEClipbrd_Construct(); -static void OLEClipbrd_Destroy(OLEClipbrd* ptrToDestroy); -static HWND OLEClipbrd_CreateWindow(); -static void OLEClipbrd_DestroyWindow(HWND hwnd); -LRESULT CALLBACK OLEClipbrd_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); -static HRESULT OLEClipbrd_RenderFormat( IDataObject *pIDataObject, LPFORMATETC pFormatetc ); -static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc ); - -/* - * Prototypes for the methods of the OLEClipboard class - * that implement IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI OLEClipbrd_IDataObject_AddRef( - IDataObject* iface); -static ULONG WINAPI OLEClipbrd_IDataObject_Release( - IDataObject* iface); -static HRESULT WINAPI OLEClipbrd_IDataObject_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium); -static HRESULT WINAPI OLEClipbrd_IDataObject_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium); -static HRESULT WINAPI OLEClipbrd_IDataObject_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc); -static HRESULT WINAPI OLEClipbrd_IDataObject_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut); -static HRESULT WINAPI OLEClipbrd_IDataObject_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease); -static HRESULT WINAPI OLEClipbrd_IDataObject_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc); -static HRESULT WINAPI OLEClipbrd_IDataObject_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection); -static HRESULT WINAPI OLEClipbrd_IDataObject_DUnadvise( - IDataObject* iface, - DWORD dwConnection); -static HRESULT WINAPI OLEClipbrd_IDataObject_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise); - -/* - * Prototypes for the IEnumFORMATETC methods. - */ -static LPENUMFORMATETC OLEClipbrd_IEnumFORMATETC_Construct(UINT cfmt, const FORMATETC afmt[], - LPUNKNOWN pUnkDataObj); -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_QueryInterface(LPENUMFORMATETC iface, REFIID riid, - LPVOID* ppvObj); -static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface); -static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface); -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Next(LPENUMFORMATETC iface, ULONG celt, - FORMATETC* rgelt, ULONG* pceltFethed); -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface, ULONG celt); -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface); -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Clone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum); - - -/* - * Virtual function table for the OLEClipbrd's exposed IDataObject interface - */ -static IDataObjectVtbl OLEClipbrd_IDataObject_VTable = -{ - OLEClipbrd_IDataObject_QueryInterface, - OLEClipbrd_IDataObject_AddRef, - OLEClipbrd_IDataObject_Release, - OLEClipbrd_IDataObject_GetData, - OLEClipbrd_IDataObject_GetDataHere, - OLEClipbrd_IDataObject_QueryGetData, - OLEClipbrd_IDataObject_GetCanonicalFormatEtc, - OLEClipbrd_IDataObject_SetData, - OLEClipbrd_IDataObject_EnumFormatEtc, - OLEClipbrd_IDataObject_DAdvise, - OLEClipbrd_IDataObject_DUnadvise, - OLEClipbrd_IDataObject_EnumDAdvise -}; - -/* - * Virtual function table for IEnumFORMATETC interface - */ -static struct IEnumFORMATETCVtbl efvt = -{ - OLEClipbrd_IEnumFORMATETC_QueryInterface, - OLEClipbrd_IEnumFORMATETC_AddRef, - OLEClipbrd_IEnumFORMATETC_Release, - OLEClipbrd_IEnumFORMATETC_Next, - OLEClipbrd_IEnumFORMATETC_Skip, - OLEClipbrd_IEnumFORMATETC_Reset, - OLEClipbrd_IEnumFORMATETC_Clone -}; - -/* - * Name of our registered OLE clipboard window class - */ -CHAR OLEClipbrd_WNDCLASS[] = "CLIPBRDWNDCLASS"; - -/* - * If we need to store state info we can store it here. - * For now we don't need this functionality. - * -typedef struct tagClipboardWindowInfo -{ -} ClipboardWindowInfo; - */ - -/*---------------------------------------------------------------------* - * Win32 OLE clipboard API - *---------------------------------------------------------------------*/ - -/*********************************************************************** - * OleSetClipboard [OLE32.@] - * Places a pointer to the specified data object onto the clipboard, - * making the data object accessible to the OleGetClipboard function. - * - * RETURNS: - * - * S_OK IDataObject pointer placed on the clipboard - * CLIPBRD_E_CANT_OPEN OpenClipboard failed - * CLIPBRD_E_CANT_EMPTY EmptyClipboard failed - * CLIPBRD_E_CANT_CLOSE CloseClipboard failed - * CLIPBRD_E_CANT_SET SetClipboard failed - */ - -HRESULT WINAPI OleSetClipboard(IDataObject* pDataObj) -{ - HRESULT hr = S_OK; - IEnumFORMATETC* penumFormatetc = NULL; - FORMATETC rgelt; - BOOL bClipboardOpen = FALSE; -/* - HGLOBAL hDataObject = 0; - OLEClipbrd **ppDataObject; -*/ - - TRACE("(%p)\n", pDataObj); - - /* - * Make sure we have a clipboard object - */ - OLEClipbrd_Initialize(); - - /* - * If the Ole clipboard window hasn't been created yet, create it now. - */ - if ( !theOleClipboard->hWndClipboard ) - theOleClipboard->hWndClipboard = OLEClipbrd_CreateWindow(); - - if ( !theOleClipboard->hWndClipboard ) /* sanity check */ - HANDLE_ERROR( E_FAIL ); - - /* - * Open the Windows clipboard, associating it with our hidden window - */ - if ( !(bClipboardOpen = OpenClipboard(theOleClipboard->hWndClipboard)) ) - HANDLE_ERROR( CLIPBRD_E_CANT_OPEN ); - - /* - * Empty the current clipboard and make our window the clipboard owner - * NOTE: This will trigger a WM_DESTROYCLIPBOARD message - */ - if ( !EmptyClipboard() ) - HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY ); - - /* - * If we are already holding on to an IDataObject first release that. - */ - if ( theOleClipboard->pIDataObjectSrc ) - { - IDataObject_Release(theOleClipboard->pIDataObjectSrc); - theOleClipboard->pIDataObjectSrc = NULL; - } - - /* - * AddRef the data object passed in and save its pointer. - * A NULL value indicates that the clipboard should be emptied. - */ - theOleClipboard->pIDataObjectSrc = pDataObj; - if ( pDataObj ) - { - IDataObject_AddRef(theOleClipboard->pIDataObjectSrc); - } - - /* - * Enumerate all HGLOBAL formats supported by the source and make - * those formats available using delayed rendering using SetClipboardData. - * Only global memory based data items may be made available to non-OLE - * applications via the standard Windows clipboard API. Data based on other - * mediums(non TYMED_HGLOBAL) can only be accessed via the Ole Clipboard API. - * - * TODO: Do we need to additionally handle TYMED_IStorage media by copying - * the storage into global memory? - */ - if ( pDataObj ) - { - if ( FAILED(hr = IDataObject_EnumFormatEtc( pDataObj, - DATADIR_GET, - &penumFormatetc ))) - { - HANDLE_ERROR( hr ); - } - - while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) ) - { - if ( rgelt.tymed == TYMED_HGLOBAL ) - { - CHAR szFmtName[80]; - TRACE("(cfFormat=%d:%s)\n", rgelt.cfFormat, - GetClipboardFormatNameA(rgelt.cfFormat, szFmtName, sizeof(szFmtName)-1) - ? szFmtName : ""); - - SetClipboardData( rgelt.cfFormat, NULL); - } - } - IEnumFORMATETC_Release(penumFormatetc); - } - - /* - * Windows additionally creates a new "DataObject" clipboard format - * and stores in on the clipboard. We could possibly store a pointer - * to our internal IDataObject interface on the clipboard. I'm not - * sure what the use of this is though. - * Enable the code below for this functionality. - */ -/* - theOleClipboard->cfDataObj = RegisterClipboardFormatA("DataObject"); - hDataObject = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT, - sizeof(OLEClipbrd *)); - if (hDataObject==0) - HANDLE_ERROR( E_OUTOFMEMORY ); - - ppDataObject = (OLEClipbrd**)GlobalLock(hDataObject); - *ppDataObject = theOleClipboard; - GlobalUnlock(hDataObject); - - if ( !SetClipboardData( theOleClipboard->cfDataObj, hDataObject ) ) - HANDLE_ERROR( CLIPBRD_E_CANT_SET ); -*/ - - hr = S_OK; - -CLEANUP: - - /* - * Close Windows clipboard (It remains associated with our window) - */ - if ( bClipboardOpen && !CloseClipboard() ) - hr = CLIPBRD_E_CANT_CLOSE; - - /* - * Release the source IDataObject if something failed - */ - if ( FAILED(hr) ) - { - if (theOleClipboard->pIDataObjectSrc) - { - IDataObject_Release(theOleClipboard->pIDataObjectSrc); - theOleClipboard->pIDataObjectSrc = NULL; - } - } - - return hr; -} - - -/*********************************************************************** - * OleGetClipboard [OLE32.@] - * Returns a pointer to our internal IDataObject which represents the conceptual - * state of the Windows clipboard. If the current clipboard already contains - * an IDataObject, our internal IDataObject will delegate to this object. - */ -HRESULT WINAPI OleGetClipboard(IDataObject** ppDataObj) -{ - HRESULT hr = S_OK; - TRACE("()\n"); - - /* - * Make sure we have a clipboard object - */ - OLEClipbrd_Initialize(); - - if (!theOleClipboard) - return E_OUTOFMEMORY; - - /* Return a reference counted IDataObject */ - hr = IDataObject_QueryInterface( (IDataObject*)&(theOleClipboard->lpvtbl1), - &IID_IDataObject, (void**)ppDataObj); - return hr; -} - -/*********************************************************************** - * OleFlushClipboard [OLE2.76] - */ - -HRESULT WINAPI OleFlushClipboard16(void) -{ - return OleFlushClipboard(); -} - - -/****************************************************************************** - * OleFlushClipboard [OLE32.@] - * Renders the data from the source IDataObject into the windows clipboard - * - * TODO: OleFlushClipboard needs to additionally handle TYMED_IStorage media - * by copying the storage into global memory. Subsequently the default - * data object exposed through OleGetClipboard must convert this TYMED_HGLOBAL - * back to TYMED_IStorage. - */ -HRESULT WINAPI OleFlushClipboard() -{ - IEnumFORMATETC* penumFormatetc = NULL; - FORMATETC rgelt; - HRESULT hr = S_OK; - BOOL bClipboardOpen = FALSE; - IDataObject* pIDataObjectSrc = NULL; - - TRACE("()\n"); - - /* - * Make sure we have a clipboard object - */ - OLEClipbrd_Initialize(); - - /* - * Already flushed or no source DataObject? Nothing to do. - */ - if (!theOleClipboard->pIDataObjectSrc) - return S_OK; - - /* - * Addref and save the source data object we are holding on to temporarily, - * since it will be released when we empty the clipboard. - */ - pIDataObjectSrc = theOleClipboard->pIDataObjectSrc; - IDataObject_AddRef(pIDataObjectSrc); - - /* - * Open the Windows clipboard - */ - if ( !(bClipboardOpen = OpenClipboard(theOleClipboard->hWndClipboard)) ) - HANDLE_ERROR( CLIPBRD_E_CANT_OPEN ); - - /* - * Empty the current clipboard - */ - if ( !EmptyClipboard() ) - HANDLE_ERROR( CLIPBRD_E_CANT_EMPTY ); - - /* - * Render all HGLOBAL formats supported by the source into - * the windows clipboard. - */ - if ( FAILED( hr = IDataObject_EnumFormatEtc( pIDataObjectSrc, - DATADIR_GET, - &penumFormatetc) )) - { - HANDLE_ERROR( hr ); - } - - while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) ) - { - if ( rgelt.tymed == TYMED_HGLOBAL ) - { - CHAR szFmtName[80]; - TRACE("(cfFormat=%d:%s)\n", rgelt.cfFormat, - GetClipboardFormatNameA(rgelt.cfFormat, szFmtName, sizeof(szFmtName)-1) - ? szFmtName : ""); - - /* - * Render the clipboard data - */ - if ( FAILED(OLEClipbrd_RenderFormat( pIDataObjectSrc, &rgelt )) ) - continue; - } - } - - IEnumFORMATETC_Release(penumFormatetc); - - /* - * Release the source data object we are holding on to - */ - IDataObject_Release(pIDataObjectSrc); - -CLEANUP: - - /* - * Close Windows clipboard (It remains associated with our window) - */ - if ( bClipboardOpen && !CloseClipboard() ) - hr = CLIPBRD_E_CANT_CLOSE; - - return hr; -} - - -/*********************************************************************** - * OleIsCurrentClipboard [OLE32.@] - */ -HRESULT WINAPI OleIsCurrentClipboard ( IDataObject *pDataObject) -{ - TRACE("()\n"); - /* - * Make sure we have a clipboard object - */ - OLEClipbrd_Initialize(); - - if (!theOleClipboard) - return E_OUTOFMEMORY; - - return (pDataObject == theOleClipboard->pIDataObjectSrc) ? S_OK : S_FALSE; -} - - -/*---------------------------------------------------------------------* - * Internal implementation methods for the OLE clipboard - *---------------------------------------------------------------------*/ - -/*********************************************************************** - * OLEClipbrd_Initialize() - * Initializes the OLE clipboard. - */ -void OLEClipbrd_Initialize() -{ - /* - * Create the clipboard if necessary - */ - if ( !theOleClipboard ) - { - TRACE("()\n"); - theOleClipboard = OLEClipbrd_Construct(); - } -} - - -/*********************************************************************** - * OLEClipbrd_UnInitialize() - * Un-Initializes the OLE clipboard - */ -void OLEClipbrd_UnInitialize() -{ - TRACE("()\n"); - /* - * Destroy the clipboard if no one holds a reference to us. - * Note that the clipboard was created with a reference count of 1. - */ - if ( theOleClipboard && (theOleClipboard->ref <= 1) ) - { - OLEClipbrd_Destroy( theOleClipboard ); - } - else - { - WARN( "() : OLEClipbrd_UnInitialize called while client holds an IDataObject reference!\n"); - } -} - - -/********************************************************* - * Construct the OLEClipbrd class. - */ -static OLEClipbrd* OLEClipbrd_Construct() -{ - OLEClipbrd* newObject = NULL; - HGLOBAL hNewObject = 0; - - /* - * Allocate space for the object. We use GlobalAlloc since we need - * an HGLOBAL to expose our DataObject as a registered clipboard type. - */ - hNewObject = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT, - sizeof(OLEClipbrd)); - if (hNewObject==0) - return NULL; - - /* - * Lock the handle for the entire lifetime of the clipboard. - */ - newObject = GlobalLock(hNewObject); - - /* - * Initialize the virtual function table. - */ - newObject->lpvtbl1 = &OLEClipbrd_IDataObject_VTable; - - /* - * Start with one reference count. The caller of this function - * must release the interface pointer when it is done. - */ - newObject->ref = 1; - - newObject->hSelf = hNewObject; - - /* - * The Ole clipboard is a singleton - save the global handle and pointer - */ - theOleClipboard = newObject; - hTheOleClipboard = hNewObject; - - return theOleClipboard; -} - -static void OLEClipbrd_Destroy(OLEClipbrd* ptrToDestroy) -{ - TRACE("()\n"); - - if ( !ptrToDestroy ) - return; - - /* - * Destroy the Ole clipboard window - */ - if ( ptrToDestroy->hWndClipboard ) - OLEClipbrd_DestroyWindow(ptrToDestroy->hWndClipboard); - - /* - * Free the actual OLE Clipboard structure. - */ - TRACE("() - Destroying clipboard data object.\n"); - GlobalUnlock(ptrToDestroy->hSelf); - GlobalFree(ptrToDestroy->hSelf); - - /* - * The Ole clipboard is a singleton (ptrToDestroy == theOleClipboard) - */ - theOleClipboard = NULL; - hTheOleClipboard = 0; -} - - -/*********************************************************************** - * OLEClipbrd_CreateWindow() - * Create the clipboard window - */ -static HWND OLEClipbrd_CreateWindow() -{ - HWND hwnd = 0; - WNDCLASSEXA wcex; - - /* - * Register the clipboard window class if necessary - */ - ZeroMemory( &wcex, sizeof(WNDCLASSEXA)); - - wcex.cbSize = sizeof(WNDCLASSEXA); - /* Windows creates this class with a style mask of 0 - * We don't bother doing this since the FindClassByAtom code - * would have to be changed to deal with this idiosyncrasy. */ - wcex.style = CS_GLOBALCLASS; - wcex.lpfnWndProc = (WNDPROC)OLEClipbrd_WndProc; - wcex.hInstance = 0; - wcex.lpszClassName = OLEClipbrd_WNDCLASS; - - RegisterClassExA(&wcex); - - /* - * Create a hidden window to receive OLE clipboard messages - */ - -/* - * If we need to store state info we can store it here. - * For now we don't need this functionality. - * ClipboardWindowInfo clipboardInfo; - * ZeroMemory( &trackerInfo, sizeof(ClipboardWindowInfo)); - */ - - hwnd = CreateWindowA(OLEClipbrd_WNDCLASS, - "ClipboardWindow", - WS_POPUP | WS_CLIPSIBLINGS | WS_OVERLAPPED, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, - 0, - 0, - 0 /*(LPVOID)&clipboardInfo */); - - return hwnd; -} - -/*********************************************************************** - * OLEClipbrd_DestroyWindow(HWND) - * Destroy the clipboard window and unregister its class - */ -static void OLEClipbrd_DestroyWindow(HWND hwnd) -{ - /* - * Destroy clipboard window and unregister its WNDCLASS - */ - DestroyWindow(hwnd); - UnregisterClassA( OLEClipbrd_WNDCLASS, 0 ); -} - -/*********************************************************************** - * OLEClipbrd_WndProc(HWND, unsigned, WORD, LONG) - * Processes messages sent to the OLE clipboard window. - * Note that we will intercept messages in our WndProc only when data - * has been placed in the clipboard via OleSetClipboard(). - * i.e. Only when OLE owns the windows clipboard. - */ -LRESULT CALLBACK OLEClipbrd_WndProc - (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - /* - * WM_RENDERFORMAT - * We receive this message to allow us to handle delayed rendering of - * a specific clipboard format when an application requests data in - * that format by calling GetClipboardData. - * (Recall that in OleSetClipboard, we used SetClipboardData to - * make all HGLOBAL formats supported by the source IDataObject - * available using delayed rendering) - * On receiving this mesage we must actually render the data in the - * specified format and place it on the clipboard by calling the - * SetClipboardData function. - */ - case WM_RENDERFORMAT: - { - FORMATETC rgelt; - - ZeroMemory( &rgelt, sizeof(FORMATETC)); - - /* - * Initialize FORMATETC to a Windows clipboard friendly format - */ - rgelt.cfFormat = (UINT) wParam; - rgelt.dwAspect = DVASPECT_CONTENT; - rgelt.lindex = -1; - rgelt.tymed = TYMED_HGLOBAL; - - TRACE("(): WM_RENDERFORMAT(cfFormat=%d)\n", rgelt.cfFormat); - - /* - * Render the clipboard data. - * (We must have a source data object or we wouldn't be in this WndProc) - */ - OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt ); - - break; - } - - /* - * WM_RENDERALLFORMATS - * Sent before the clipboard owner window is destroyed. - * We should receive this message only when OleUninitialize is called - * while we have an IDataObject in the clipboard. - * For the content of the clipboard to remain available to other - * applications, we must render data in all the formats the source IDataObject - * is capable of generating, and place the data on the clipboard by calling - * SetClipboardData. - */ - case WM_RENDERALLFORMATS: - { - IEnumFORMATETC* penumFormatetc = NULL; - FORMATETC rgelt; - - TRACE("(): WM_RENDERALLFORMATS\n"); - - /* - * Render all HGLOBAL formats supported by the source into - * the windows clipboard. - */ - if ( FAILED( IDataObject_EnumFormatEtc( (IDataObject*)&(theOleClipboard->lpvtbl1), - DATADIR_GET, &penumFormatetc) ) ) - { - WARN("(): WM_RENDERALLFORMATS failed to retrieve EnumFormatEtc!\n"); - return 0; - } - - while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) ) - { - if ( rgelt.tymed == TYMED_HGLOBAL ) - { - /* - * Render the clipboard data. - */ - if ( FAILED(OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt )) ) - continue; - - TRACE("(): WM_RENDERALLFORMATS(cfFormat=%d)\n", rgelt.cfFormat); - } - } - - IEnumFORMATETC_Release(penumFormatetc); - - break; - } - - /* - * WM_DESTROYCLIPBOARD - * This is sent by EmptyClipboard before the clipboard is emptied. - * We should release any IDataObject we are holding onto when we receive - * this message, since it indicates that the OLE clipboard should be empty - * from this point on. - */ - case WM_DESTROYCLIPBOARD: - { - TRACE("(): WM_DESTROYCLIPBOARD\n"); - /* - * Release the data object we are holding on to - */ - if ( theOleClipboard->pIDataObjectSrc ) - { - IDataObject_Release(theOleClipboard->pIDataObjectSrc); - theOleClipboard->pIDataObjectSrc = NULL; - } - break; - } - -/* - case WM_ASKCBFORMATNAME: - case WM_CHANGECBCHAIN: - case WM_DRAWCLIPBOARD: - case WM_SIZECLIPBOARD: - case WM_HSCROLLCLIPBOARD: - case WM_VSCROLLCLIPBOARD: - case WM_PAINTCLIPBOARD: -*/ - default: - return DefWindowProcA(hWnd, message, wParam, lParam); - } - - return 0; -} - -#define MAX_CLIPFORMAT_NAME 80 - -/*********************************************************************** - * OLEClipbrd_RenderFormat(LPFORMATETC) - * Render the clipboard data. Note that this call will delegate to the - * source data object. - * Note: This function assumes it is passed an HGLOBAL format to render. - */ -static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pFormatetc) -{ - STGMEDIUM std; - HGLOBAL hDup; - HRESULT hr = S_OK; - char szFmtName[MAX_CLIPFORMAT_NAME]; - ILockBytes *ptrILockBytes = 0; - HGLOBAL hStorage = 0; - - GetClipboardFormatNameA(pFormatetc->cfFormat, szFmtName, MAX_CLIPFORMAT_NAME); - - /* If embed source */ - if (!strcmp(szFmtName, CF_EMBEDSOURCE)) - { - memset(&std, 0, sizeof(STGMEDIUM)); - std.tymed = pFormatetc->tymed = TYMED_ISTORAGE; - - hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0); - hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes); - hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg); - - if (FAILED(hr = IDataObject_GetDataHere(theOleClipboard->pIDataObjectSrc, pFormatetc, &std))) - { - WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%lx)\n", hr); - return hr; - } - - if (1) /* check whether the presentation data is already -not- present */ - { - FORMATETC fmt2; - STGMEDIUM std2; - METAFILEPICT *mfp = 0; - - fmt2.cfFormat = CF_METAFILEPICT; - fmt2.ptd = 0; - fmt2.dwAspect = DVASPECT_CONTENT; - fmt2.lindex = -1; - fmt2.tymed = TYMED_MFPICT; - - memset(&std2, 0, sizeof(STGMEDIUM)); - std2.tymed = TYMED_MFPICT; - - /* Get the metafile picture out of it */ - - if (!FAILED(hr = IDataObject_GetData(theOleClipboard->pIDataObjectSrc, &fmt2, &std2))) - { - mfp = (METAFILEPICT *)GlobalLock(std2.u.hGlobal); - } - - if (mfp) - { - OLECHAR name[]={ 2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0}; - IStream *pStream = 0; - void *mfBits; - PresentationDataHeader pdh; - INT nSize; - CLSID clsID; - LPOLESTR strProgID; - CHAR strOleTypeName[51]; - BYTE OlePresStreamHeader [] = - { - 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - }; - - nSize = GetMetaFileBitsEx(mfp->hMF, 0, NULL); - - memset(&pdh, 0, sizeof(PresentationDataHeader)); - memcpy(&pdh, OlePresStreamHeader, sizeof(OlePresStreamHeader)); - - pdh.dwObjectExtentX = mfp->xExt; - pdh.dwObjectExtentY = mfp->yExt; - pdh.dwSize = nSize; - - hr = IStorage_CreateStream(std.u.pstg, name, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &pStream); - - hr = IStream_Write(pStream, &pdh, sizeof(PresentationDataHeader), NULL); - - mfBits = HeapAlloc(GetProcessHeap(), 0, nSize); - nSize = GetMetaFileBitsEx(mfp->hMF, nSize, mfBits); - - hr = IStream_Write(pStream, mfBits, nSize, NULL); - - IStream_Release(pStream); - - HeapFree(GetProcessHeap(), 0, mfBits); - - GlobalUnlock(std2.u.hGlobal); - - ReadClassStg(std.u.pstg, &clsID); - ProgIDFromCLSID(&clsID, &strProgID); - - WideCharToMultiByte( CP_ACP, 0, strProgID, -1, strOleTypeName, sizeof(strOleTypeName), NULL, NULL ); - OLECONVERT_CreateOleStream(std.u.pstg); - OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName); - } - } - } - else - { - if (FAILED(hr = IDataObject_GetData(pIDataObject, pFormatetc, &std))) - { - WARN("() : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr); - return hr; - } - - /* To put a copy back on the clipboard */ - - hStorage = std.u.hGlobal; - } - - /* - * Put a copy of the rendered data back on the clipboard - */ - - if ( !(hDup = OLEClipbrd_GlobalDupMem(hStorage)) ) - HANDLE_ERROR( E_OUTOFMEMORY ); - - if ( !SetClipboardData( pFormatetc->cfFormat, hDup ) ) - { - GlobalFree(hDup); - WARN("() : Failed to set rendered clipboard data into clipboard!\n"); - } - -CLEANUP: - - ReleaseStgMedium(&std); - - return hr; -} - - -/*********************************************************************** - * OLEClipbrd_GlobalDupMem( HGLOBAL ) - * Helper method to duplicate an HGLOBAL chunk of memory - */ -static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc ) -{ - HGLOBAL hGlobalDest; - PVOID pGlobalSrc, pGlobalDest; - DWORD cBytes; - - if ( !hGlobalSrc ) - return 0; - - cBytes = GlobalSize(hGlobalSrc); - if ( 0 == cBytes ) - return 0; - - hGlobalDest = GlobalAlloc( GMEM_DDESHARE|GMEM_MOVEABLE, - cBytes ); - if ( !hGlobalDest ) - return 0; - - pGlobalSrc = GlobalLock(hGlobalSrc); - pGlobalDest = GlobalLock(hGlobalDest); - if ( !pGlobalSrc || !pGlobalDest ) - return 0; - - memcpy(pGlobalDest, pGlobalSrc, cBytes); - - GlobalUnlock(hGlobalSrc); - GlobalUnlock(hGlobalDest); - - return hGlobalDest; -} - - -/*---------------------------------------------------------------------* - * Implementation of the internal IDataObject interface exposed by - * the OLE clipboard. - *---------------------------------------------------------------------*/ - - -/************************************************************************ - * OLEClipbrd_IDataObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject) -{ - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObject); - - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = iface; - } - else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) - { - *ppvObject = (IDataObject*)&(This->lpvtbl1); - } - else /* We only support IUnknown and IDataObject */ - { - WARN( "() : asking for unsupported interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; - } - - /* - * Query Interface always increases the reference count by one when it is - * successful. - */ - IUnknown_AddRef((IUnknown*)*ppvObject); - - return S_OK; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI OLEClipbrd_IDataObject_AddRef( - IDataObject* iface) -{ - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - - TRACE("(%p)->(count=%lu)\n",This, This->ref); - - return InterlockedIncrement(&This->ref); - -} - -/************************************************************************ - * OLEClipbrd_IDataObject_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI OLEClipbrd_IDataObject_Release( - IDataObject* iface) -{ - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - ULONG ref; - - TRACE("(%p)->(count=%lu)\n",This, This->ref); - - /* - * Decrease the reference count on this object. - */ - ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref == 0) - { - OLEClipbrd_Destroy(This); - } - - return ref; -} - - -/************************************************************************ - * OLEClipbrd_IDataObject_GetData (IDataObject) - * - * The OLE Clipboard's implementation of this method delegates to - * a data source if there is one or wraps around the windows clipboard - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium) -{ - HANDLE hData = 0; - BOOL bClipboardOpen = FALSE; - HRESULT hr = S_OK; - LPVOID src; - - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - - TRACE("(%p,%p,%p)\n", iface, pformatetcIn, pmedium); - - if ( !pformatetcIn || !pmedium ) - return E_INVALIDARG; - - /* - * If we have a data source placed on the clipboard (via OleSetClipboard) - * simply delegate to the source object's QueryGetData - * NOTE: This code assumes that the IDataObject is in the same address space! - * We will need to add marshalling support when Wine handles multiple processes. - */ - if ( This->pIDataObjectSrc ) - { - return IDataObject_GetData(This->pIDataObjectSrc, pformatetcIn, pmedium); - } - - if ( pformatetcIn->lindex != -1 ) - return DV_E_LINDEX; - if ( (pformatetcIn->tymed & TYMED_HGLOBAL) != TYMED_HGLOBAL ) - return DV_E_TYMED; -/* - if ( pformatetcIn->dwAspect != DVASPECT_CONTENT ) - return DV_E_DVASPECT; -*/ - - /* - * Otherwise, get the data from the windows clipboard using GetClipboardData - */ - if ( !(bClipboardOpen = OpenClipboard(theOleClipboard->hWndClipboard)) ) - HANDLE_ERROR( CLIPBRD_E_CANT_OPEN ); - - hData = GetClipboardData(pformatetcIn->cfFormat); - - /* Must make a copy of global handle returned by GetClipboardData; it - * is not valid after we call CloseClipboard - * Application is responsible for freeing the memory (Forte Agent does this) - */ - src = GlobalLock(hData); - if(src) { - LPVOID dest; - ULONG size; - HANDLE hDest; - - size = GlobalSize(hData); - hDest = GlobalAlloc(GHND, size); - dest = GlobalLock(hDest); - memcpy(dest, src, size); - GlobalUnlock(hDest); - GlobalUnlock(hData); - hData = hDest; - } - - /* - * Return the clipboard data in the storage medium structure - */ - pmedium->tymed = (hData == 0) ? TYMED_NULL : TYMED_HGLOBAL; - pmedium->u.hGlobal = (HGLOBAL)hData; - pmedium->pUnkForRelease = NULL; - - hr = S_OK; - -CLEANUP: - /* - * Close Windows clipboard - */ - if ( bClipboardOpen && !CloseClipboard() ) - hr = CLIPBRD_E_CANT_CLOSE; - - if ( FAILED(hr) ) - return hr; - return (hData == 0) ? DV_E_FORMATETC : S_OK; -} - -static HRESULT WINAPI OLEClipbrd_IDataObject_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium) -{ - FIXME(": Stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_QueryGetData (IDataObject) - * - * The OLE Clipboard's implementation of this method delegates to - * a data source if there is one or wraps around the windows clipboard - * function IsClipboardFormatAvailable() otherwise. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc) -{ - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - - TRACE("(%p, %p)\n", iface, pformatetc); - - /* - * If we have a data source placed on the clipboard (via OleSetClipboard) - * simply delegate to the source object's QueryGetData - */ - if ( This->pIDataObjectSrc ) - { - return IDataObject_QueryGetData(This->pIDataObjectSrc, pformatetc); - } - - if (!pformatetc) - return E_INVALIDARG; -/* - if ( pformatetc->dwAspect != DVASPECT_CONTENT ) - return DV_E_DVASPECT; -*/ - if ( pformatetc->lindex != -1 ) - return DV_E_LINDEX; - - /* TODO: Handle TYMED_IStorage media which were put on the clipboard - * by copying the storage into global memory. We must convert this - * TYMED_HGLOBAL back to TYMED_IStorage. - */ - if ( pformatetc->tymed != TYMED_HGLOBAL ) - return DV_E_TYMED; - - /* - * Delegate to the Windows clipboard function IsClipboardFormatAvailable - */ - return (IsClipboardFormatAvailable(pformatetc->cfFormat)) ? S_OK : DV_E_FORMATETC; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_GetCanonicalFormatEtc (IDataObject) - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut) -{ - TRACE("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut); - - if ( !pformatectIn || !pformatetcOut ) - return E_INVALIDARG; - - memcpy(pformatetcOut, pformatectIn, sizeof(FORMATETC)); - return DATA_S_SAMEFORMATETC; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_SetData (IDataObject) - * - * The OLE Clipboard's does not implement this method - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease) -{ - TRACE("\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_EnumFormatEtc (IDataObject) - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc) -{ - HRESULT hr = S_OK; - FORMATETC *afmt = NULL; - int cfmt, i; - UINT format; - BOOL bClipboardOpen; - - /* - * Declare "This" pointer - */ - OLEClipbrd *This = (OLEClipbrd *)iface; - - TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc); - - /* - * If we have a data source placed on the clipboard (via OleSetClipboard) - * simply delegate to the source object's EnumFormatEtc - */ - if ( This->pIDataObjectSrc ) - { - return IDataObject_EnumFormatEtc(This->pIDataObjectSrc, - dwDirection, ppenumFormatEtc); - } - - /* - * Otherwise we must provide our own enumerator which wraps around the - * Windows clipboard function EnumClipboardFormats - */ - if ( !ppenumFormatEtc ) - return E_INVALIDARG; - - if ( dwDirection != DATADIR_GET ) /* IDataObject_SetData not implemented */ - return E_NOTIMPL; - - /* - * Store all current clipboard formats in an array of FORMATETC's, - * and create an IEnumFORMATETC enumerator from this list. - */ - cfmt = CountClipboardFormats(); - afmt = (FORMATETC *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof(FORMATETC) * cfmt); - /* - * Open the Windows clipboard, associating it with our hidden window - */ - if ( !(bClipboardOpen = OpenClipboard(This->hWndClipboard)) ) - HANDLE_ERROR( CLIPBRD_E_CANT_OPEN ); - - /* - * Store all current clipboard formats in an array of FORMATETC's - * TODO: Handle TYMED_IStorage media which were put on the clipboard - * by copying the storage into global memory. We must convert this - * TYMED_HGLOBAL back to TYMED_IStorage. - */ - for (i = 0, format = 0; i < cfmt; i++) - { - format = EnumClipboardFormats(format); - if (!format) /* Failed! */ - { - ERR("EnumClipboardFormats failed to return format!\n"); - HANDLE_ERROR( E_FAIL ); - } - - /* Init the FORMATETC struct */ - afmt[i].cfFormat = format; - afmt[i].ptd = NULL; - afmt[i].dwAspect = DVASPECT_CONTENT; - afmt[i].lindex = -1; - afmt[i].tymed = TYMED_HGLOBAL; - } - - /* - * Create an EnumFORMATETC enumerator and return an - * EnumFORMATETC after bumping up its ref count - */ - *ppenumFormatEtc = OLEClipbrd_IEnumFORMATETC_Construct( cfmt, afmt, (LPUNKNOWN)iface); - if (!(*ppenumFormatEtc)) - HANDLE_ERROR( E_OUTOFMEMORY ); - - if (FAILED( hr = IEnumFORMATETC_AddRef(*ppenumFormatEtc))) - HANDLE_ERROR( hr ); - - hr = S_OK; - -CLEANUP: - /* - * Free the array of FORMATETC's - */ - if (afmt) - HeapFree(GetProcessHeap(), 0, afmt); - - /* - * Close Windows clipboard - */ - if ( bClipboardOpen && !CloseClipboard() ) - hr = CLIPBRD_E_CANT_CLOSE; - - return hr; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_DAdvise (IDataObject) - * - * The OLE Clipboard's does not implement this method - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection) -{ - TRACE("\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_DUnadvise (IDataObject) - * - * The OLE Clipboard's does not implement this method - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_DUnadvise( - IDataObject* iface, - DWORD dwConnection) -{ - TRACE("\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * OLEClipbrd_IDataObject_EnumDAdvise (IDataObject) - * - * The OLE Clipboard does not implement this method - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI OLEClipbrd_IDataObject_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise) -{ - TRACE("\n"); - return E_NOTIMPL; -} - - -/*---------------------------------------------------------------------* - * Implementation of the internal IEnumFORMATETC interface returned by - * the OLE clipboard's IDataObject. - *---------------------------------------------------------------------*/ - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Construct (UINT, const FORMATETC, LPUNKNOWN) - * - * Creates an IEnumFORMATETC enumerator from an array of FORMATETC - * Structures. pUnkOuter is the outer unknown for reference counting only. - * NOTE: this does not AddRef the interface. - */ - -LPENUMFORMATETC OLEClipbrd_IEnumFORMATETC_Construct(UINT cfmt, const FORMATETC afmt[], - LPUNKNOWN pUnkDataObj) -{ - IEnumFORMATETCImpl* ef; - DWORD size=cfmt * sizeof(FORMATETC); - LPMALLOC pIMalloc; - - ef = (IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - sizeof(IEnumFORMATETCImpl)); - if (!ef) - return NULL; - - ef->ref = 0; - ef->lpVtbl = &efvt; - ef->pUnkDataObj = pUnkDataObj; - - ef->posFmt = 0; - ef->countFmt = cfmt; - if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) { - HeapFree(GetProcessHeap(), 0, ef); - return NULL; - } - ef->pFmt = (LPFORMATETC)IMalloc_Alloc(pIMalloc, size); - IMalloc_Release(pIMalloc); - - if (ef->pFmt) - memcpy(ef->pFmt, afmt, size); - - TRACE("(%p)->()\n",ef); - return (LPENUMFORMATETC)ef; -} - - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_QueryInterface - (LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - - TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj); - - /* - * Since enumerators are separate objects from the parent data object - * we only need to support the IUnknown and IEnumFORMATETC interfaces - */ - - *ppvObj = NULL; - - if(IsEqualIID(riid, &IID_IUnknown)) - { - *ppvObj = This; - } - else if(IsEqualIID(riid, &IID_IEnumFORMATETC)) - { - *ppvObj = (IDataObject*)This; - } - - if(*ppvObj) - { - IEnumFORMATETC_AddRef((IEnumFORMATETC*)*ppvObj); - TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj); - return S_OK; - } - - TRACE("-- Interface: E_NOINTERFACE\n"); - return E_NOINTERFACE; -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_AddRef (IUnknown) - * - * Since enumerating formats only makes sense when our data object is around, - * we insure that it stays as long as we stay by calling our parents IUnknown - * for AddRef and Release. But since we are not controlled by the lifetime of - * the outer object, we still keep our own reference count in order to - * free ourselves. - */ -static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - TRACE("(%p)->(count=%lu)\n",This, This->ref); - - if (This->pUnkDataObj) - IUnknown_AddRef(This->pUnkDataObj); - - return InterlockedIncrement(&This->ref); -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - LPMALLOC pIMalloc; - ULONG ref; - - TRACE("(%p)->(count=%lu)\n",This, This->ref); - - if (This->pUnkDataObj) - IUnknown_Release(This->pUnkDataObj); /* Release parent data object */ - - ref = InterlockedDecrement(&This->ref); - if (!ref) - { - TRACE("() - destroying IEnumFORMATETC(%p)\n",This); - if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) - { - IMalloc_Free(pIMalloc, This->pFmt); - IMalloc_Release(pIMalloc); - } - - HeapFree(GetProcessHeap(),0,This); - } - return ref; -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Next (IEnumFORMATETC) - * - * Standard enumerator members for IEnumFORMATETC - */ -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Next - (LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - UINT cfetch; - HRESULT hres = S_FALSE; - - TRACE("(%p)->(pos=%u)\n", This, This->posFmt); - - if (This->posFmt < This->countFmt) - { - cfetch = This->countFmt - This->posFmt; - if (cfetch >= celt) - { - cfetch = celt; - hres = S_OK; - } - - memcpy(rgelt, &This->pFmt[This->posFmt], cfetch * sizeof(FORMATETC)); - This->posFmt += cfetch; - } - else - { - cfetch = 0; - } - - if (pceltFethed) - { - *pceltFethed = cfetch; - } - - return hres; -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Skip (IEnumFORMATETC) - * - * Standard enumerator members for IEnumFORMATETC - */ -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Skip(LPENUMFORMATETC iface, ULONG celt) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - TRACE("(%p)->(num=%lu)\n", This, celt); - - This->posFmt += celt; - if (This->posFmt > This->countFmt) - { - This->posFmt = This->countFmt; - return S_FALSE; - } - return S_OK; -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Reset (IEnumFORMATETC) - * - * Standard enumerator members for IEnumFORMATETC - */ -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Reset(LPENUMFORMATETC iface) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - TRACE("(%p)->()\n", This); - - This->posFmt = 0; - return S_OK; -} - -/************************************************************************ - * OLEClipbrd_IEnumFORMATETC_Clone (IEnumFORMATETC) - * - * Standard enumerator members for IEnumFORMATETC - */ -static HRESULT WINAPI OLEClipbrd_IEnumFORMATETC_Clone - (LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum) -{ - IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface; - HRESULT hr = S_OK; - - TRACE("(%p)->(ppenum=%p)\n", This, ppenum); - - if ( !ppenum ) - return E_INVALIDARG; - - *ppenum = OLEClipbrd_IEnumFORMATETC_Construct(This->countFmt, - This->pFmt, - This->pUnkDataObj); - - if (FAILED( hr = IEnumFORMATETC_AddRef(*ppenum))) - return ( hr ); - - return (*ppenum) ? S_OK : E_OUTOFMEMORY; -} diff --git a/reactos/lib/ole32/compobj.c b/reactos/lib/ole32/compobj.c deleted file mode 100644 index c2f4fe4d56c..00000000000 --- a/reactos/lib/ole32/compobj.c +++ /dev/null @@ -1,2269 +0,0 @@ -/* - * COMPOBJ library - * - * Copyright 1995 Martin von Loewis - * Copyright 1998 Justin Bradford - * Copyright 1999 Francis Beaudet - * Copyright 1999 Sylvain St-Germain - * Copyright 2002 Marcus Meissner - * Copyright 2004 Mike Hearn - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "ole2ver.h" -#include "rpc.h" -#include "winerror.h" -#include "winreg.h" -#include "wownt32.h" -#include "wine/unicode.h" -#include "objbase.h" -#include "ole32_main.h" -#include "compobj_private.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -typedef LPCSTR LPCOLESTR16; - -/**************************************************************************** - * This section defines variables internal to the COM module. - * - * TODO: Most of these things will have to be made thread-safe. - */ -HINSTANCE COMPOBJ_hInstance32 = 0; - -static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid, DWORD dwClsContext, LPUNKNOWN* ppUnk); -static void COM_RevokeAllClasses(); -static void COM_ExternalLockFreeList(); - -const CLSID CLSID_StdGlobalInterfaceTable = { 0x00000323, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} }; - -APARTMENT MTA, *apts; - -static CRITICAL_SECTION csApartment; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &csApartment, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { 0, (DWORD)(__FILE__ ": csApartment") } -}; -static CRITICAL_SECTION csApartment = { &critsect_debug, -1, 0, 0, 0, 0 }; - -/* - * This lock count counts the number of times CoInitialize is called. It is - * decreased every time CoUninitialize is called. When it hits 0, the COM - * libraries are freed - */ -static LONG s_COMLockCount = 0; - -/* - * This linked list contains the list of registered class objects. These - * are mostly used to register the factories for out-of-proc servers of OLE - * objects. - * - * TODO: Make this data structure aware of inter-process communication. This - * means that parts of this will be exported to the Wine Server. - */ -typedef struct tagRegisteredClass -{ - CLSID classIdentifier; - LPUNKNOWN classObject; - DWORD runContext; - DWORD connectFlags; - DWORD dwCookie; - HANDLE hThread; /* only for localserver */ - struct tagRegisteredClass* nextClass; -} RegisteredClass; - -static RegisteredClass* firstRegisteredClass = NULL; - -static CRITICAL_SECTION csRegisteredClassList; -static CRITICAL_SECTION_DEBUG class_cs_debug = -{ - 0, 0, &csRegisteredClassList, - { &class_cs_debug.ProcessLocksList, &class_cs_debug.ProcessLocksList }, - 0, 0, { 0, (DWORD)(__FILE__ ": csRegisteredClassList") } -}; -static CRITICAL_SECTION csRegisteredClassList = { &class_cs_debug, -1, 0, 0, 0, 0 }; - -/***************************************************************************** - * This section contains OpenDllList definitions - * - * The OpenDllList contains only handles of dll loaded by CoGetClassObject or - * other functions that do LoadLibrary _without_ giving back a HMODULE. - * Without this list these handles would never be freed. - * - * FIXME: a DLL that says OK when asked for unloading is unloaded in the - * next unload-call but not before 600 sec. - */ - -typedef struct tagOpenDll { - HINSTANCE hLibrary; - struct tagOpenDll *next; -} OpenDll; - -static OpenDll *openDllList = NULL; /* linked list of open dlls */ - -static CRITICAL_SECTION csOpenDllList; -static CRITICAL_SECTION_DEBUG dll_cs_debug = -{ - 0, 0, &csOpenDllList, - { &dll_cs_debug.ProcessLocksList, &dll_cs_debug.ProcessLocksList }, - 0, 0, { 0, (DWORD)(__FILE__ ": csOpenDllList") } -}; -static CRITICAL_SECTION csOpenDllList = { &dll_cs_debug, -1, 0, 0, 0, 0 }; - -static const char aptWinClass[] = "WINE_OLE32_APT_CLASS"; -static LRESULT CALLBACK COM_AptWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - -static void COMPOBJ_DLLList_Add(HANDLE hLibrary); -static void COMPOBJ_DllList_FreeUnused(int Timeout); - -void COMPOBJ_InitProcess( void ) -{ - WNDCLASSA wclass; - - /* Dispatching to the correct thread in an apartment is done through - * window messages rather than RPC transports. When an interface is - * marshalled into another apartment in the same process, a window of the - * following class is created. The *caller* of CoMarshalInterface (ie the - * application) is responsible for pumping the message loop in that thread. - * The WM_USER messages which point to the RPCs are then dispatched to - * COM_AptWndProc by the user's code from the apartment in which the interface - * was unmarshalled. - */ - memset(&wclass, 0, sizeof(wclass)); - wclass.lpfnWndProc = &COM_AptWndProc; - wclass.hInstance = OLE32_hInstance; - wclass.lpszClassName = aptWinClass; - RegisterClassA(&wclass); -} - -void COMPOBJ_UninitProcess( void ) -{ - UnregisterClassA(aptWinClass, OLE32_hInstance); -} - -/****************************************************************************** - * Manage apartments. - */ - - -/* The multi-threaded apartment (MTA) contains zero or more threads interacting - with free threaded (ie thread safe) COM objects. There is only ever one MTA - in a process - you can enter it by calling CoInitializeEx(COINIT_MULTITHREADED) - */ -static void COM_InitMTA(void) -{ - /* OXIDs are object exporter IDs. Each apartment has an OXID, which is unique - within a network. That is, two different MTAs on different machines will have - different OXIDs. - - This method of generating an OXID is therefore wrong as it doesn't work across - a network, but for local RPC only it's OK. We can distinguish between MTAs and - STAs because STAs use the thread ID as well, and no thread can have an ID of zero. - - The algorithm Microsoft use is currently unknown. - */ - MTA.oxid = ((OXID)GetCurrentProcessId() << 32); - InitializeCriticalSection(&MTA.cs); -} - -static void COM_UninitMTA(void) -{ - DeleteCriticalSection(&MTA.cs); - MTA.oxid = 0; -} - -/* creates an apartment structure which stores OLE thread-local - * information. Call with COINIT_UNINITIALIZED to create an apartment - * that will be initialized with a model later. Note: do not call - * with COINIT_UNINITIALIZED if the apartment has already been initialized - * with a different COINIT value */ -APARTMENT* COM_CreateApartment(DWORD model) -{ - APARTMENT *apt; - BOOL create = (NtCurrentTeb()->ReservedForOle == NULL); - - if (create) - { - apt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APARTMENT)); - apt->tid = GetCurrentThreadId(); - DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), &apt->thread, - THREAD_ALL_ACCESS, FALSE, 0); - } - else - apt = NtCurrentTeb()->ReservedForOle; - - apt->model = model; - if (model & COINIT_APARTMENTTHREADED) { - /* FIXME: how does windoze create OXIDs? */ - apt->oxid = MTA.oxid | GetCurrentThreadId(); - apt->win = CreateWindowA(aptWinClass, NULL, 0, - 0, 0, 0, 0, - 0, 0, OLE32_hInstance, NULL); - InitializeCriticalSection(&apt->cs); - } - else if (!(model & COINIT_UNINITIALIZED)) { - apt->parent = &MTA; - apt->oxid = MTA.oxid; - } - EnterCriticalSection(&csApartment); - if (create) - { - if (apts) apts->prev = apt; - apt->next = apts; - apts = apt; - } - LeaveCriticalSection(&csApartment); - NtCurrentTeb()->ReservedForOle = apt; - return apt; -} - -static void COM_DestroyApartment(APARTMENT *apt) -{ - EnterCriticalSection(&csApartment); - if (apt->prev) apt->prev->next = apt->next; - if (apt->next) apt->next->prev = apt->prev; - if (apts == apt) apts = apt->next; - apt->prev = NULL; apt->next = NULL; - LeaveCriticalSection(&csApartment); - if (apt->model & COINIT_APARTMENTTHREADED) { - if (apt->win) DestroyWindow(apt->win); - DeleteCriticalSection(&apt->cs); - } - CloseHandle(apt->thread); - HeapFree(GetProcessHeap(), 0, apt); -} - -/* The given OXID must be local to this process: you cannot use apartment - windows to send RPCs to other processes. This all needs to move to rpcrt4 */ -HWND COM_GetApartmentWin(OXID oxid) -{ - APARTMENT *apt; - HWND win = 0; - - EnterCriticalSection(&csApartment); - apt = apts; - while (apt && apt->oxid != oxid) apt = apt->next; - if (apt) win = apt->win; - LeaveCriticalSection(&csApartment); - return win; -} - -/* Currently inter-thread marshalling is not fully implemented, so this does nothing */ -static LRESULT CALLBACK COM_AptWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - return DefWindowProcA(hWnd, msg, wParam, lParam); -} - -/***************************************************************************** - * This section contains OpenDllList implemantation - */ - -static void COMPOBJ_DLLList_Add(HANDLE hLibrary) -{ - OpenDll *ptr; - OpenDll *tmp; - - TRACE("\n"); - - EnterCriticalSection( &csOpenDllList ); - - if (openDllList == NULL) { - /* empty list -- add first node */ - openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll)); - openDllList->hLibrary=hLibrary; - openDllList->next = NULL; - } else { - /* search for this dll */ - int found = FALSE; - for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) { - if (ptr->hLibrary == hLibrary) { - found = TRUE; - break; - } - } - if (!found) { - /* dll not found, add it */ - tmp = openDllList; - openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll)); - openDllList->hLibrary = hLibrary; - openDllList->next = tmp; - } - } - - LeaveCriticalSection( &csOpenDllList ); -} - -static void COMPOBJ_DllList_FreeUnused(int Timeout) -{ - OpenDll *curr, *next, *prev = NULL; - typedef HRESULT(*DllCanUnloadNowFunc)(void); - DllCanUnloadNowFunc DllCanUnloadNow; - - TRACE("\n"); - - EnterCriticalSection( &csOpenDllList ); - - for (curr = openDllList; curr != NULL; ) { - DllCanUnloadNow = (DllCanUnloadNowFunc) GetProcAddress(curr->hLibrary, "DllCanUnloadNow"); - - if ( (DllCanUnloadNow != NULL) && (DllCanUnloadNow() == S_OK) ) { - next = curr->next; - - TRACE("freeing %p\n", curr->hLibrary); - FreeLibrary(curr->hLibrary); - - HeapFree(GetProcessHeap(), 0, curr); - if (curr == openDllList) { - openDllList = next; - } else { - prev->next = next; - } - - curr = next; - } else { - prev = curr; - curr = curr->next; - } - } - - LeaveCriticalSection( &csOpenDllList ); -} - -/****************************************************************************** - * CoBuildVersion [COMPOBJ.1] - * CoBuildVersion [OLE32.@] - * - * RETURNS - * Current build version, hiword is majornumber, loword is minornumber - */ -DWORD WINAPI CoBuildVersion(void) -{ - TRACE("Returning version %d, build %d.\n", rmm, rup); - return (rmm<<16)+rup; -} - -/****************************************************************************** - * CoInitialize [OLE32.@] - * - * Initializes the COM libraries by calling CoInitializeEx with - * COINIT_APARTMENTTHREADED, ie it enters a STA thread. - * - * SEE ALSO - * CoInitializeEx - */ -HRESULT WINAPI CoInitialize( - LPVOID lpReserved /* [in] pointer to win32 malloc interface - (obsolete, should be NULL) */ -) -{ - /* - * Just delegate to the newer method. - */ - return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED); -} - -/****************************************************************************** - * CoInitializeEx [OLE32.@] - * - * Initializes the COM libraries. The behavior used to set the win32 - * IMalloc used for memory management is obsolete. If - * COINIT_APARTMENTTHREADED is specified this thread enters a new STA - * (single threaded apartment), otherwise COINIT_MULTITHREADED should - * be specified which indicates that the thread will enter the MTA. - * - * Currently STA threading is only partly implemented. - * - * RETURNS - * S_OK if successful, - * S_FALSE if this function was called already. - * RPC_E_CHANGED_MODE if a previous call to CoInitializeEx specified another - * threading model. - * - * SEE ALSO - * CoUninitialize - */ -HRESULT WINAPI CoInitializeEx( - LPVOID lpReserved, /* [in] pointer to win32 malloc interface - (obsolete, should be NULL) */ - DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */ -) -{ - HRESULT hr = S_OK; - APARTMENT *apt; - - TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit); - - if (lpReserved!=NULL) - { - ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved); - } - - apt = NtCurrentTeb()->ReservedForOle; - if (apt && !(apt->model == COINIT_UNINITIALIZED)) - { - if (dwCoInit != apt->model) - { - /* Changing the threading model after it's been set is illegal. If this warning is triggered by Wine - code then we are probably using the wrong threading model to implement that API. */ - ERR("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit); - return RPC_E_CHANGED_MODE; - } - hr = S_FALSE; - } - else - hr = S_OK; - - /* - * Check the lock count. If this is the first time going through the initialize - * process, we have to initialize the libraries. - * - * And crank-up that lock count. - */ - if (InterlockedExchangeAdd(&s_COMLockCount,1)==0) - { - /* - * Initialize the various COM libraries and data structures. - */ - TRACE("() - Initializing the COM libraries\n"); - - COM_InitMTA(); - - RunningObjectTableImpl_Initialize(); - } - - if (!apt || apt->model == COINIT_UNINITIALIZED) apt = COM_CreateApartment(dwCoInit); - - InterlockedIncrement(&apt->inits); - if (hr == S_OK) NtCurrentTeb()->ReservedForOle = apt; - - return hr; -} - -/* On COM finalization for a STA thread, the message queue is flushed to ensure no - pending RPCs are ignored. Non-COM messages are discarded at this point. - */ -void COM_FlushMessageQueue(void) -{ - MSG message; - APARTMENT *apt = NtCurrentTeb()->ReservedForOle; - - if (!apt || !apt->win) return; - - TRACE("Flushing STA message queue\n"); - - while (PeekMessageA(&message, NULL, 0, 0, PM_REMOVE)) { - if (message.hwnd != apt->win) continue; - TranslateMessage(&message); - DispatchMessageA(&message); - } -} - -/*********************************************************************** - * CoUninitialize [OLE32.@] - * - * This method will decrement the refcount on the COM libraries, - * potentially unloading them. The current thread leaves the apartment - * it's currently in. If not in an apartment, the routine does - * nothing. - * - * If COM is to be shut down, any outstanding proxies are - * disconnected, all registered class objects are unregistered and the - * message queue for the thread is flushed (if native does - * this or not is unknown). - * - * SEE ALSO - * CoInitializeEx - */ -void WINAPI CoUninitialize(void) -{ - LONG lCOMRefCnt; - APARTMENT *apt; - - TRACE("()\n"); - - apt = NtCurrentTeb()->ReservedForOle; - if (!apt) return; - if (InterlockedDecrement(&apt->inits)==0) { - NtCurrentTeb()->ReservedForOle = NULL; - COM_DestroyApartment(apt); - apt = NULL; - } - - /* - * Decrease the reference count. - * If we are back to 0 locks on the COM library, make sure we free - * all the associated data structures. - */ - lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1); - if (lCOMRefCnt==1) - { - TRACE("() - Releasing the COM libraries\n"); - - RunningObjectTableImpl_UnInitialize(); - - /* disconnect proxies to release the corresponding stubs. - * It is confirmed in "Essential COM" in the sub-chapter on - * "Lifecycle Management and Marshalling" that the native version also - * does some kind of proxy cleanup in this function. - * FIXME: does it just disconnect or completely destroy the proxies? - * FIXME: should this be in the apartment destructor? */ - MARSHAL_Disconnect_Proxies(); - - /* Release the references to the registered class objects */ - COM_RevokeAllClasses(); - - /* This will free the loaded COM Dlls */ - CoFreeAllLibraries(); - - /* This will free list of external references to COM objects */ - COM_ExternalLockFreeList(); - - /* This ensures we deal with any pending RPCs */ - COM_FlushMessageQueue(); - - COM_UninitMTA(); - } - else if (lCOMRefCnt<1) { - ERR( "CoUninitialize() - not CoInitialized.\n" ); - InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */ - } -} - -/****************************************************************************** - * CoDisconnectObject [COMPOBJ.15] - * CoDisconnectObject [OLE32.@] - * - * Disconnects all connections to this object from remote processes. Dispatches - * pending RPCs while blocking new RPCs from occurring, and then calls - * IMarshal::DisconnectObject on the given object. - * - * Typically called when the object server is forced to shut down, for instance by - * the user. - */ -HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved ) -{ - FIXME("(%p, %lx): stub - probably harmless\n",lpUnk,reserved); - return S_OK; -} - -/****************************************************************************** - * CoCreateGuid[OLE32.@] - * - * Simply forwards to UuidCreate in RPCRT4. - * - * SEE ALSO - * UuidCreate - * - */ -HRESULT WINAPI CoCreateGuid( - GUID *pguid /* [out] points to the GUID to initialize */ -) { - return UuidCreate(pguid); -} - -/****************************************************************************** - * CLSIDFromString [OLE32.@] - * IIDFromString [OLE32.@] - * - * Converts a unique identifier from its string representation into - * the GUID struct. - * - * In Windows, if idstr is not a valid CLSID string then it gets - * treated as a ProgID. Wine currently doesn't do this. If idstr is - * NULL it's treated as an all-zero GUID. - * - * RETURNS - * S_OK on success - * CO_E_CLASSSTRING if idstr is not a valid CLSID - */ -HRESULT WINAPI __CLSIDFromStringA( - LPCSTR idstr, /* [in] string representation of guid */ - CLSID *id) /* [out] GUID converted from string */ -{ - const BYTE *s = (const BYTE *) idstr; - int i; - BYTE table[256]; - - if (!s) - s = "{00000000-0000-0000-0000-000000000000}"; - else { /* validate the CLSID string */ - - if (strlen(s) != 38) - return CO_E_CLASSSTRING; - - 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; - } - } - - TRACE("%s -> %p\n", s, id); - - /* quick lookup table */ - memset(table, 0, 256); - - for (i = 0; i < 10; i++) { - table['0' + i] = i; - } - for (i = 0; i < 6; i++) { - table['A' + i] = i+10; - table['a' + i] = i+10; - } - - /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */ - - id->Data1 = (table[s[1]] << 28 | table[s[2]] << 24 | table[s[3]] << 20 | table[s[4]] << 16 | - table[s[5]] << 12 | table[s[6]] << 8 | table[s[7]] << 4 | table[s[8]]); - id->Data2 = table[s[10]] << 12 | table[s[11]] << 8 | table[s[12]] << 4 | table[s[13]]; - id->Data3 = table[s[15]] << 12 | table[s[16]] << 8 | table[s[17]] << 4 | table[s[18]]; - - /* these are just sequential bytes */ - id->Data4[0] = table[s[20]] << 4 | table[s[21]]; - id->Data4[1] = table[s[22]] << 4 | table[s[23]]; - id->Data4[2] = table[s[25]] << 4 | table[s[26]]; - id->Data4[3] = table[s[27]] << 4 | table[s[28]]; - id->Data4[4] = table[s[29]] << 4 | table[s[30]]; - id->Data4[5] = table[s[31]] << 4 | table[s[32]]; - id->Data4[6] = table[s[33]] << 4 | table[s[34]]; - id->Data4[7] = table[s[35]] << 4 | table[s[36]]; - - return S_OK; -} - -/*****************************************************************************/ - -HRESULT WINAPI CLSIDFromString( - LPOLESTR idstr, /* [in] string representation of GUID */ - CLSID *id ) /* [out] GUID represented by above string */ -{ - char xid[40]; - HRESULT ret; - - if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL )) - return CO_E_CLASSSTRING; - - - ret = __CLSIDFromStringA(xid,id); - if(ret != S_OK) { /* It appears a ProgID is also valid */ - ret = CLSIDFromProgID(idstr, id); - } - return ret; -} - -/* Converts a GUID into the respective string representation. */ -HRESULT WINE_StringFromCLSID( - const CLSID *id, /* [in] GUID to be converted */ - LPSTR idstr /* [out] pointer to buffer to contain converted guid */ -) { - static const char *hex = "0123456789ABCDEF"; - char *s; - int i; - - if (!id) - { ERR("called with id=Null\n"); - *idstr = 0x00; - return E_FAIL; - } - - sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-", - id->Data1, id->Data2, id->Data3, - id->Data4[0], id->Data4[1]); - s = &idstr[25]; - - /* 6 hex bytes */ - for (i = 2; i < 8; i++) { - *s++ = hex[id->Data4[i]>>4]; - *s++ = hex[id->Data4[i] & 0xf]; - } - - *s++ = '}'; - *s++ = '\0'; - - TRACE("%p->%s\n", id, idstr); - - return S_OK; -} - - -/****************************************************************************** - * StringFromCLSID [OLE32.@] - * StringFromIID [OLE32.@] - * - * Converts a GUID into the respective string representation. - * The target string is allocated using the OLE IMalloc. - * - * RETURNS - * S_OK - * E_FAIL - */ -HRESULT WINAPI StringFromCLSID( - REFCLSID id, /* [in] the GUID to be converted */ - LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */ -) { - char buf[80]; - HRESULT ret; - LPMALLOC mllc; - - if ((ret = CoGetMalloc(0,&mllc))) - return ret; - - ret=WINE_StringFromCLSID(id,buf); - if (!ret) { - DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 ); - *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) ); - MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len ); - } - return ret; -} - -/****************************************************************************** - * StringFromGUID2 [COMPOBJ.76] - * StringFromGUID2 [OLE32.@] - * - * Modified version of StringFromCLSID that allows you to specify max - * buffer size. - * - * RETURNS - * The length of the resulting string, 0 if there was any problem. - */ -INT WINAPI StringFromGUID2( - REFGUID id, /* [in] GUID to convert to string */ - LPOLESTR str, /* [out] Unicode buffer to hold result */ - INT cmax) -{ - char xguid[80]; - - if (WINE_StringFromCLSID(id,xguid)) - return 0; - return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax ); -} - -/****************************************************************************** - * ProgIDFromCLSID [OLE32.@] - * - * Converts a class id into the respective Program ID. (By using a - * registry lookup) - * - * RETURNS - * S_OK - * E_OUTOFMEMORY - * REGDB_E_CLASSNOTREG if the given clsid has no associated ProgID - */ -HRESULT WINAPI ProgIDFromCLSID( - REFCLSID clsid, /* [in] class id as found in registry */ - LPOLESTR *lplpszProgID/* [out] associated Prog ID */ -) -{ - char strCLSID[50], *buf, *buf2; - DWORD buf2len; - HKEY xhkey; - LPMALLOC mllc; - HRESULT ret = S_OK; - - WINE_StringFromCLSID(clsid, strCLSID); - - buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14); - sprintf(buf,"CLSID\\%s\\ProgID", strCLSID); - if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey)) - ret = REGDB_E_CLASSNOTREG; - - HeapFree(GetProcessHeap(), 0, buf); - - if (ret == S_OK) - { - buf2 = HeapAlloc(GetProcessHeap(), 0, 255); - buf2len = 255; - if (RegQueryValueA(xhkey, NULL, buf2, &buf2len)) - ret = REGDB_E_CLASSNOTREG; - - if (ret == S_OK) - { - if (CoGetMalloc(0,&mllc)) - ret = E_OUTOFMEMORY; - else - { - DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 ); - *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) ); - MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len ); - } - } - HeapFree(GetProcessHeap(), 0, buf2); - } - - RegCloseKey(xhkey); - return ret; -} - -HRESULT WINAPI CLSIDFromProgID16( - LPCOLESTR16 progid, /* [in] program id as found in registry */ - LPCLSID riid /* [out] associated CLSID */ -) { - char *buf,buf2[80]; - DWORD buf2len; - HRESULT err; - HKEY xhkey; - - buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8); - sprintf(buf,"%s\\CLSID",progid); - if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) { - HeapFree(GetProcessHeap(),0,buf); - return CO_E_CLASSSTRING; - } - HeapFree(GetProcessHeap(),0,buf); - buf2len = sizeof(buf2); - if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) { - RegCloseKey(xhkey); - return CO_E_CLASSSTRING; - } - RegCloseKey(xhkey); - return __CLSIDFromStringA(buf2,riid); -} - -/****************************************************************************** - * CLSIDFromProgID [COMPOBJ.61] - * - * Converts a program id into the respective GUID. (By using a - * registry lookup) - * - * RETURNS - * S_OK - * CO_E_CLASSSTRING if the given ProgID cannot be found - */ -HRESULT WINAPI CLSIDFromProgID( - LPCOLESTR progid, /* [in] Unicode program id as found in registry */ - LPCLSID riid ) /* [out] associated CLSID */ -{ - static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 }; - char buf2[80]; - DWORD buf2len = sizeof(buf2); - HKEY xhkey; - - WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) ); - strcpyW( buf, progid ); - strcatW( buf, clsidW ); - if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey)) - { - HeapFree(GetProcessHeap(),0,buf); - return CO_E_CLASSSTRING; - } - HeapFree(GetProcessHeap(),0,buf); - - if (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) - { - RegCloseKey(xhkey); - return CO_E_CLASSSTRING; - } - RegCloseKey(xhkey); - return __CLSIDFromStringA(buf2,riid); -} - - - -/***************************************************************************** - * CoGetPSClsid [OLE32.@] - * - * This function returns the CLSID of the proxy/stub factory that - * implements IPSFactoryBuffer for the specified interface. - * - * The standard marshaller activates the object with the CLSID - * returned and uses the CreateProxy and CreateStub methods on its - * IPSFactoryBuffer interface to construct the proxies and stubs for a - * given object. - * - * CoGetPSClsid determines this CLSID by searching the - * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 - * in the registry and any interface id registered by - * CoRegisterPSClsid within the current process. - * - * FIXME: We only search the registry, not ids registered with - * CoRegisterPSClsid. - * - * RETURNS - * S_OK - * E_OUTOFMEMORY - * E_INVALIDARG if no PSFactoryBuffer is associated with the IID, or it could not be parsed - */ -HRESULT WINAPI CoGetPSClsid( - REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */ - CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */ -{ - char *buf, buf2[40]; - DWORD buf2len; - HKEY xhkey; - - TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid); - - /* Get the input iid as a string */ - WINE_StringFromCLSID(riid, buf2); - /* Allocate memory for the registry key we will construct. - (length of iid string plus constant length of static text */ - buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27); - if (buf == NULL) - { - return (E_OUTOFMEMORY); - } - - /* Construct the registry key we want */ - sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2); - - /* Open the key.. */ - if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey)) - { - WARN("No PSFactoryBuffer object is registered for this IID\n"); - HeapFree(GetProcessHeap(),0,buf); - return (E_INVALIDARG); - } - HeapFree(GetProcessHeap(),0,buf); - - /* ... Once we have the key, query the registry to get the - value of CLSID as a string, and convert it into a - proper CLSID structure to be passed back to the app */ - buf2len = sizeof(buf2); - if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) ) - { - RegCloseKey(xhkey); - return E_INVALIDARG; - } - RegCloseKey(xhkey); - - /* We have the CLSid we want back from the registry as a string, so - lets convert it into a CLSID structure */ - if ( (__CLSIDFromStringA(buf2,pclsid)) != NOERROR) { - return E_INVALIDARG; - } - - TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid)); - return (S_OK); -} - - - -/*********************************************************************** - * WriteClassStm (OLE32.@) - * - * This function write a CLSID on stream - */ -HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid) -{ - TRACE("(%p,%p)\n",pStm,rclsid); - - if (rclsid==NULL) - return E_INVALIDARG; - - return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL); -} - -/*********************************************************************** - * ReadClassStm (OLE32.@) - * - * This function read a CLSID from a stream - */ -HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid) -{ - ULONG nbByte; - HRESULT res; - - TRACE("(%p,%p)\n",pStm,pclsid); - - if (pclsid==NULL) - return E_INVALIDARG; - - res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte); - - if (FAILED(res)) - return res; - - if (nbByte != sizeof(CLSID)) - return S_FALSE; - else - return S_OK; -} - - -/*** - * COM_GetRegisteredClassObject - * - * This internal method is used to scan the registered class list to - * find a class object. - * - * Params: - * rclsid Class ID of the class to find. - * dwClsContext Class context to match. - * ppv [out] returns a pointer to the class object. Complying - * to normal COM usage, this method will increase the - * reference count on this object. - */ -static HRESULT COM_GetRegisteredClassObject( - REFCLSID rclsid, - DWORD dwClsContext, - LPUNKNOWN* ppUnk) -{ - HRESULT hr = S_FALSE; - RegisteredClass* curClass; - - EnterCriticalSection( &csRegisteredClassList ); - - /* - * Sanity check - */ - assert(ppUnk!=0); - - /* - * Iterate through the whole list and try to match the class ID. - */ - curClass = firstRegisteredClass; - - while (curClass != 0) - { - /* - * Check if we have a match on the class ID. - */ - if (IsEqualGUID(&(curClass->classIdentifier), rclsid)) - { - /* - * Since we don't do out-of process or DCOM just right away, let's ignore the - * class context. - */ - - /* - * We have a match, return the pointer to the class object. - */ - *ppUnk = curClass->classObject; - - IUnknown_AddRef(curClass->classObject); - - hr = S_OK; - goto end; - } - - /* - * Step to the next class in the list. - */ - curClass = curClass->nextClass; - } - -end: - LeaveCriticalSection( &csRegisteredClassList ); - /* - * If we get to here, we haven't found our class. - */ - return hr; -} - -static DWORD WINAPI -_LocalServerThread(LPVOID param) { - HANDLE hPipe; - char pipefn[200]; - RegisteredClass *newClass = (RegisteredClass*)param; - HRESULT hres; - IStream *pStm; - STATSTG ststg; - unsigned char *buffer; - int buflen; - IClassFactory *classfac; - LARGE_INTEGER seekto; - ULARGE_INTEGER newpos; - ULONG res; - - TRACE("Starting threader for %s.\n",debugstr_guid(&newClass->classIdentifier)); - - strcpy(pipefn,PIPEPREF); - WINE_StringFromCLSID(&newClass->classIdentifier,pipefn+strlen(PIPEPREF)); - - hPipe = CreateNamedPipeA( pipefn, PIPE_ACCESS_DUPLEX, - PIPE_TYPE_BYTE|PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, - 4096, 4096, NMPWAIT_USE_DEFAULT_WAIT, NULL ); - if (hPipe == INVALID_HANDLE_VALUE) { - FIXME("pipe creation failed for %s, le is %lx\n",pipefn,GetLastError()); - return 1; - } - while (1) { - if (!ConnectNamedPipe(hPipe,NULL)) { - ERR("Failure during ConnectNamedPipe %lx, ABORT!\n",GetLastError()); - break; - } - - TRACE("marshalling IClassFactory to client\n"); - - hres = IUnknown_QueryInterface(newClass->classObject,&IID_IClassFactory,(LPVOID*)&classfac); - if (hres) return hres; - - hres = CreateStreamOnHGlobal(0,TRUE,&pStm); - if (hres) { - FIXME("Failed to create stream on hglobal.\n"); - return hres; - } - hres = CoMarshalInterface(pStm,&IID_IClassFactory,(LPVOID)classfac,0,NULL,0); - if (hres) { - FIXME("CoMarshalInterface failed, %lx!\n",hres); - return hres; - } - - IUnknown_Release(classfac); /* is this right? */ - - hres = IStream_Stat(pStm,&ststg,0); - if (hres) return hres; - - buflen = ststg.cbSize.u.LowPart; - buffer = HeapAlloc(GetProcessHeap(),0,buflen); - seekto.u.LowPart = 0; - seekto.u.HighPart = 0; - hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos); - if (hres) { - FIXME("IStream_Seek failed, %lx\n",hres); - return hres; - } - - hres = IStream_Read(pStm,buffer,buflen,&res); - if (hres) { - FIXME("Stream Read failed, %lx\n",hres); - return hres; - } - - IStream_Release(pStm); - - WriteFile(hPipe,buffer,buflen,&res,NULL); - FlushFileBuffers(hPipe); - DisconnectNamedPipe(hPipe); - - TRACE("done marshalling IClassFactory\n"); - } - CloseHandle(hPipe); - return 0; -} - -/****************************************************************************** - * CoRegisterClassObject [OLE32.@] - * - * This method will register the class object for a given class - * ID. Servers housed in EXE files use this method instead of - * exporting DllGetClassObject to allow other code to connect to their - * objects. - * - * When a class object (an object which implements IClassFactory) is - * registered in this way, a new thread is started which listens for - * connections on a named pipe specific to the registered CLSID. When - * something else connects to it, it writes out the marshalled - * IClassFactory interface to the pipe. The code on the other end uses - * this buffer to unmarshal the class factory, and can then call - * methods on it. - * - * In Windows, such objects are registered with the RPC endpoint - * mapper, not with a unique named pipe. - * - * MSDN claims that multiple interface registrations are legal, but we - * can't do that with our current implementation. - * - * RETURNS - * S_OK on success, - * E_INVALIDARG if lpdwRegister or pUnk are NULL, - * CO_E_OBJISREG if the object is already registered. We should not return this. - * - * SEE ALSO - * CoRevokeClassObject, CoGetClassObject - */ -HRESULT WINAPI CoRegisterClassObject( - REFCLSID rclsid, /* [in] CLSID of the object to register */ - LPUNKNOWN pUnk, /* [in] IUnknown of the object */ - DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */ - DWORD flags, /* [in] REGCLS flags indicating how connections are made */ - LPDWORD lpdwRegister) /* [out] A unique cookie that can be passed to CoRevokeClassObject */ -{ - RegisteredClass* newClass; - LPUNKNOWN foundObject; - HRESULT hr; - - TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n", - debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister); - - if ( (lpdwRegister==0) || (pUnk==0) ) - return E_INVALIDARG; - - *lpdwRegister = 0; - - /* - * First, check if the class is already registered. - * If it is, this should cause an error. - */ - hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject); - if (hr == S_OK) { - IUnknown_Release(foundObject); - return CO_E_OBJISREG; - } - - newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass)); - if ( newClass == NULL ) - return E_OUTOFMEMORY; - - EnterCriticalSection( &csRegisteredClassList ); - - newClass->classIdentifier = *rclsid; - newClass->runContext = dwClsContext; - newClass->connectFlags = flags; - /* - * Use the address of the chain node as the cookie since we are sure it's - * unique. - */ - newClass->dwCookie = (DWORD)newClass; - newClass->nextClass = firstRegisteredClass; - - /* - * Since we're making a copy of the object pointer, we have to increase its - * reference count. - */ - newClass->classObject = pUnk; - IUnknown_AddRef(newClass->classObject); - - firstRegisteredClass = newClass; - LeaveCriticalSection( &csRegisteredClassList ); - - *lpdwRegister = newClass->dwCookie; - - if (dwClsContext & CLSCTX_LOCAL_SERVER) { - DWORD tid; - - STUBMGR_Start(); - newClass->hThread=CreateThread(NULL,0,_LocalServerThread,newClass,0,&tid); - } - return S_OK; -} - -/*********************************************************************** - * CoRevokeClassObject [OLE32.@] - * - * This method will remove a class object from the class registry - * - * See the Windows documentation for more details. - */ -HRESULT WINAPI CoRevokeClassObject( - DWORD dwRegister) -{ - HRESULT hr = E_INVALIDARG; - RegisteredClass** prevClassLink; - RegisteredClass* curClass; - - TRACE("(%08lx)\n",dwRegister); - - EnterCriticalSection( &csRegisteredClassList ); - - /* - * Iterate through the whole list and try to match the cookie. - */ - curClass = firstRegisteredClass; - prevClassLink = &firstRegisteredClass; - - while (curClass != 0) - { - /* - * Check if we have a match on the cookie. - */ - if (curClass->dwCookie == dwRegister) - { - /* - * Remove the class from the chain. - */ - *prevClassLink = curClass->nextClass; - - /* - * Release the reference to the class object. - */ - IUnknown_Release(curClass->classObject); - - /* - * Free the memory used by the chain node. - */ - HeapFree(GetProcessHeap(), 0, curClass); - - hr = S_OK; - goto end; - } - - /* - * Step to the next class in the list. - */ - prevClassLink = &(curClass->nextClass); - curClass = curClass->nextClass; - } - -end: - LeaveCriticalSection( &csRegisteredClassList ); - /* - * If we get to here, we haven't found our class. - */ - return hr; -} - -/*********************************************************************** - * compobj_RegReadPath [internal] - * - * Reads a registry value and expands it when necessary - */ -HRESULT compobj_RegReadPath(char * keyname, char * valuename, char * dst, DWORD dstlen) -{ - HRESULT hres; - HKEY key; - DWORD keytype; - char src[MAX_PATH]; - DWORD dwLength = dstlen; - - if((hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key)) == ERROR_SUCCESS) { - if( (hres = RegQueryValueExA(key, NULL, NULL, &keytype, (LPBYTE)src, &dwLength)) == ERROR_SUCCESS ) { - if (keytype == REG_EXPAND_SZ) { - if (dstlen <= ExpandEnvironmentStringsA(src, dst, dstlen)) hres = ERROR_MORE_DATA; - } else { - lstrcpynA(dst, src, dstlen); - } - } - RegCloseKey (key); - } - return hres; -} - -/*********************************************************************** - * CoGetClassObject [COMPOBJ.7] - * CoGetClassObject [OLE32.@] - * - * FIXME. If request allows of several options and there is a failure - * with one (other than not being registered) do we try the - * others or return failure? (E.g. inprocess is registered but - * the DLL is not found but the server version works) - */ -HRESULT WINAPI CoGetClassObject( - REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo, - REFIID iid, LPVOID *ppv -) { - LPUNKNOWN regClassObject; - HRESULT hres = E_UNEXPECTED; - char xclsid[80]; - HINSTANCE hLibrary; - typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv); - DllGetClassObjectFunc DllGetClassObject; - - WINE_StringFromCLSID((LPCLSID)rclsid,xclsid); - - TRACE("\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); - } - - /* - * First, try and see if we can't match the class ID with one of the - * registered classes. - */ - if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject)) - { - /* - * Get the required interface from the retrieved pointer. - */ - hres = IUnknown_QueryInterface(regClassObject, iid, ppv); - - /* - * Since QI got another reference on the pointer, we want to release the - * one we already have. If QI was unsuccessful, this will release the object. This - * is good since we are not returning it in the "out" parameter. - */ - IUnknown_Release(regClassObject); - - return hres; - } - - /* first try: in-process */ - if ((CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER) & dwClsContext) { - char keyname[MAX_PATH]; - char dllpath[MAX_PATH+1]; - - sprintf(keyname,"CLSID\\%s\\InprocServer32",xclsid); - - if ( compobj_RegReadPath(keyname, NULL, dllpath, sizeof(dllpath)) != ERROR_SUCCESS) { - /* failure: CLSID is not found in registry */ - WARN("class %s not registered inproc\n", xclsid); - hres = REGDB_E_CLASSNOTREG; - } else { - if ((hLibrary = LoadLibraryExA(dllpath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) { - /* failure: DLL could not be loaded */ - ERR("couldn't load InprocServer32 dll %s\n", dllpath); - hres = E_ACCESSDENIED; /* FIXME: or should this be CO_E_DLLNOTFOUND? */ - } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) { - /* failure: the dll did not export DllGetClassObject */ - ERR("couldn't find function DllGetClassObject in %s\n", dllpath); - FreeLibrary( hLibrary ); - hres = CO_E_DLLNOTFOUND; - } else { - /* OK: get the ClassObject */ - COMPOBJ_DLLList_Add( hLibrary ); - return DllGetClassObject(rclsid, iid, ppv); - } - } - } - - /* Next try out of process */ - if (CLSCTX_LOCAL_SERVER & dwClsContext) - { - return create_marshalled_proxy(rclsid,iid,ppv); - } - - /* Finally try remote: this requires networked DCOM (a lot of work) */ - if (CLSCTX_REMOTE_SERVER & dwClsContext) - { - FIXME ("CLSCTX_REMOTE_SERVER not supported\n"); - hres = E_NOINTERFACE; - } - - return hres; -} -/*********************************************************************** - * CoResumeClassObjects (OLE32.@) - * - * Resumes classobjects registered with REGCLS suspended - */ -HRESULT WINAPI CoResumeClassObjects(void) -{ - FIXME("stub\n"); - return S_OK; -} - -/*********************************************************************** - * GetClassFile (OLE32.@) - * - * This function supplies the CLSID associated with the given filename. - */ -HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid) -{ - IStorage *pstg=0; - HRESULT res; - int nbElm, length, i; - LONG sizeProgId; - LPOLESTR *pathDec=0,absFile=0,progId=0; - LPWSTR extension; - static const WCHAR bkslashW[] = {'\\',0}; - static const WCHAR dotW[] = {'.',0}; - - TRACE("%s, %p\n", debugstr_w(filePathName), pclsid); - - /* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/ - if((StgIsStorageFile(filePathName))==S_OK){ - - res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg); - - if (SUCCEEDED(res)) - res=ReadClassStg(pstg,pclsid); - - IStorage_Release(pstg); - - return res; - } - /* if the file is not a storage object then attemps to match various bits in the file against a - pattern in the registry. this case is not frequently used ! so I present only the psodocode for - this case - - for(i=0;i= 0) && *(extension = &absFile[i]) != '.'; i--) - /* nothing */; - - if (!extension || !lstrcmpW(extension, dotW)) - return MK_E_INVALIDEXTENSION; - - res=RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId); - - /* get the progId associated to the extension */ - progId = CoTaskMemAlloc(sizeProgId); - res = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId); - - if (res==ERROR_SUCCESS) - /* return the clsid associated to the progId */ - res= CLSIDFromProgID(progId,pclsid); - - for(i=0; pathDec[i]!=NULL;i++) - CoTaskMemFree(pathDec[i]); - CoTaskMemFree(pathDec); - - CoTaskMemFree(progId); - - if (res==ERROR_SUCCESS) - return res; - - return MK_E_INVALIDEXTENSION; -} -/*********************************************************************** - * CoCreateInstance [COMPOBJ.13] - * CoCreateInstance [OLE32.@] - */ -HRESULT WINAPI CoCreateInstance( - REFCLSID rclsid, - LPUNKNOWN pUnkOuter, - DWORD dwClsContext, - REFIID iid, - LPVOID *ppv) -{ - HRESULT hres; - LPCLASSFACTORY lpclf = 0; - - if (!COM_CurrentApt()) return CO_E_NOTINITIALIZED; - - /* - * Sanity check - */ - if (ppv==0) - return E_POINTER; - - /* - * Initialize the "out" parameter - */ - *ppv = 0; - - /* - * The Standard Global Interface Table (GIT) object is a process-wide singleton. - * Rather than create a class factory, we can just check for it here - */ - if (IsEqualIID(rclsid, &CLSID_StdGlobalInterfaceTable)) { - if (StdGlobalInterfaceTableInstance == NULL) - StdGlobalInterfaceTableInstance = StdGlobalInterfaceTable_Construct(); - hres = IGlobalInterfaceTable_QueryInterface( (IGlobalInterfaceTable*) StdGlobalInterfaceTableInstance, iid, ppv); - if (hres) return hres; - - TRACE("Retrieved GIT (%p)\n", *ppv); - return S_OK; - } - - /* - * Get a class factory to construct the object we want. - */ - hres = CoGetClassObject(rclsid, - dwClsContext, - NULL, - &IID_IClassFactory, - (LPVOID)&lpclf); - - if (FAILED(hres)) { - FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n", - debugstr_guid(rclsid),hres); - return hres; - } - - /* - * Create the object and don't forget to release the factory - */ - hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv); - IClassFactory_Release(lpclf); - if(FAILED(hres)) - FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n", - debugstr_guid(iid), debugstr_guid(rclsid),hres); - - return hres; -} - -/*********************************************************************** - * CoCreateInstanceEx [OLE32.@] - */ -HRESULT WINAPI CoCreateInstanceEx( - REFCLSID rclsid, - LPUNKNOWN pUnkOuter, - DWORD dwClsContext, - COSERVERINFO* pServerInfo, - ULONG cmq, - MULTI_QI* pResults) -{ - IUnknown* pUnk = NULL; - HRESULT hr; - ULONG index; - ULONG successCount = 0; - - /* - * Sanity check - */ - if ( (cmq==0) || (pResults==NULL)) - return E_INVALIDARG; - - if (pServerInfo!=NULL) - FIXME("() non-NULL pServerInfo not supported!\n"); - - /* - * Initialize all the "out" parameters. - */ - for (index = 0; index < cmq; index++) - { - pResults[index].pItf = NULL; - pResults[index].hr = E_NOINTERFACE; - } - - /* - * Get the object and get its IUnknown pointer. - */ - hr = CoCreateInstance(rclsid, - pUnkOuter, - dwClsContext, - &IID_IUnknown, - (VOID**)&pUnk); - - if (hr) - return hr; - - /* - * Then, query for all the interfaces requested. - */ - for (index = 0; index < cmq; index++) - { - pResults[index].hr = IUnknown_QueryInterface(pUnk, - pResults[index].pIID, - (VOID**)&(pResults[index].pItf)); - - if (pResults[index].hr == S_OK) - successCount++; - } - - /* - * Release our temporary unknown pointer. - */ - IUnknown_Release(pUnk); - - if (successCount == 0) - return E_NOINTERFACE; - - if (successCount!=cmq) - return CO_S_NOTALLINTERFACES; - - return S_OK; -} - -/*********************************************************************** - * CoLoadLibrary (OLE32.@) - */ -HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree) -{ - TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree); - - return LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH); -} - -/*********************************************************************** - * CoFreeLibrary [OLE32.@] - * - * NOTES: don't believe the documentation - */ -void WINAPI CoFreeLibrary(HINSTANCE hLibrary) -{ - FreeLibrary(hLibrary); -} - - -/*********************************************************************** - * CoFreeAllLibraries [OLE32.@] - * - * NOTES: don't believe the documentation - */ -void WINAPI CoFreeAllLibraries(void) -{ - /* NOP */ -} - - -/*********************************************************************** - * CoFreeUnusedLibraries [COMPOBJ.17] - * CoFreeUnusedLibraries [OLE32.@] - * - * FIXME: Calls to CoFreeUnusedLibraries from any thread always route - * through the main apartment's thread to call DllCanUnloadNow - */ -void WINAPI CoFreeUnusedLibraries(void) -{ - COMPOBJ_DllList_FreeUnused(0); -} - -/*********************************************************************** - * CoFileTimeNow [COMPOBJ.82] - * CoFileTimeNow [OLE32.@] - * - * RETURNS - * the current system time in lpFileTime - */ -HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */ -{ - GetSystemTimeAsFileTime( lpFileTime ); - return S_OK; -} - -/*********************************************************************** - * CoLoadLibrary (OLE32.@) - */ -static void COM_RevokeAllClasses() -{ - EnterCriticalSection( &csRegisteredClassList ); - - while (firstRegisteredClass!=0) - { - CoRevokeClassObject(firstRegisteredClass->dwCookie); - } - - LeaveCriticalSection( &csRegisteredClassList ); -} - -/**************************************************************************** - * COM External Lock methods implementation - * - * This api provides a linked list to managed external references to - * COM objects. - * - * The public interface consists of three calls: - * COM_ExternalLockAddRef - * COM_ExternalLockRelease - * COM_ExternalLockFreeList - */ - -#define EL_END_OF_LIST 0 -#define EL_NOT_FOUND 0 - -/* - * Declaration of the static structure that manage the - * external lock to COM objects. - */ -typedef struct COM_ExternalLock COM_ExternalLock; -typedef struct COM_ExternalLockList COM_ExternalLockList; - -struct COM_ExternalLock -{ - IUnknown *pUnk; /* IUnknown referenced */ - ULONG uRefCount; /* external lock counter to IUnknown object*/ - COM_ExternalLock *next; /* Pointer to next element in list */ -}; - -struct COM_ExternalLockList -{ - COM_ExternalLock *head; /* head of list */ -}; - -/* - * Declaration and initialization of the static structure that manages - * the external lock to COM objects. - */ -static COM_ExternalLockList elList = { EL_END_OF_LIST }; - -/* - * Private methods used to managed the linked list - */ - - -static COM_ExternalLock* COM_ExternalLockLocate( - COM_ExternalLock *element, - IUnknown *pUnk); - -/**************************************************************************** - * Internal - Insert a new IUnknown* to the linked list - */ -static BOOL COM_ExternalLockInsert( - IUnknown *pUnk) -{ - COM_ExternalLock *newLock = NULL; - COM_ExternalLock *previousHead = NULL; - - /* - * Allocate space for the new storage object - */ - newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock)); - - if (newLock!=NULL) { - if ( elList.head == EL_END_OF_LIST ) { - elList.head = newLock; /* The list is empty */ - } else { - /* insert does it at the head */ - previousHead = elList.head; - elList.head = newLock; - } - - /* Set new list item data member */ - newLock->pUnk = pUnk; - newLock->uRefCount = 1; - newLock->next = previousHead; - - return TRUE; - } - return FALSE; -} - -/**************************************************************************** - * Internal - Method that removes an item from the linked list. - */ -static void COM_ExternalLockDelete( - COM_ExternalLock *itemList) -{ - COM_ExternalLock *current = elList.head; - - if ( current == itemList ) { - /* this section handles the deletion of the first node */ - elList.head = itemList->next; - HeapFree( GetProcessHeap(), 0, itemList); - } else { - do { - if ( current->next == itemList ){ /* We found the item to free */ - current->next = itemList->next; /* readjust the list pointers */ - HeapFree( GetProcessHeap(), 0, itemList); - break; - } - - /* Skip to the next item */ - current = current->next; - - } while ( current != EL_END_OF_LIST ); - } -} - -/**************************************************************************** - * Internal - Recursivity agent for IUnknownExternalLockList_Find - * - * NOTES: how long can the list be ?? (recursive!!!) - */ -static COM_ExternalLock* COM_ExternalLockLocate( COM_ExternalLock *element, IUnknown *pUnk) -{ - if ( element == EL_END_OF_LIST ) - return EL_NOT_FOUND; - else if ( element->pUnk == pUnk ) /* We found it */ - return element; - else /* Not the right guy, keep on looking */ - return COM_ExternalLockLocate( element->next, pUnk); -} - -/**************************************************************************** - * Public - Method that increments the count for a IUnknown* in the linked - * list. The item is inserted if not already in the list. - */ -static void COM_ExternalLockAddRef(IUnknown *pUnk) -{ - COM_ExternalLock *externalLock = COM_ExternalLockLocate(elList.head, pUnk); - - /* - * Add an external lock to the object. If it was already externally - * locked, just increase the reference count. If it was not. - * add the item to the list. - */ - if ( externalLock == EL_NOT_FOUND ) - COM_ExternalLockInsert(pUnk); - else - externalLock->uRefCount++; - - /* - * Add an internal lock to the object - */ - IUnknown_AddRef(pUnk); -} - -/**************************************************************************** - * Public - Method that decrements the count for a IUnknown* in the linked - * list. The item is removed from the list if its count end up at zero or if - * bRelAll is TRUE. - */ -static void COM_ExternalLockRelease( - IUnknown *pUnk, - BOOL bRelAll) -{ - COM_ExternalLock *externalLock = COM_ExternalLockLocate(elList.head, pUnk); - - if ( externalLock != EL_NOT_FOUND ) { - do { - externalLock->uRefCount--; /* release external locks */ - IUnknown_Release(pUnk); /* release local locks as well */ - - if ( bRelAll == FALSE ) break; /* perform single release */ - - } while ( externalLock->uRefCount > 0 ); - - if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */ - COM_ExternalLockDelete(externalLock); - } -} -/**************************************************************************** - * Public - Method that frees the content of the list. - */ -static void COM_ExternalLockFreeList() -{ - COM_ExternalLock *head; - - head = elList.head; /* grab it by the head */ - while ( head != EL_END_OF_LIST ) { - COM_ExternalLockDelete(head); /* get rid of the head stuff */ - head = elList.head; /* get the new head... */ - } -} - -/**************************************************************************** - * Public - Method that dump the content of the list. - */ -void COM_ExternalLockDump() -{ - COM_ExternalLock *current = elList.head; - - DPRINTF("\nExternal lock list contains:\n"); - - while ( current != EL_END_OF_LIST ) { - DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount); - - /* Skip to the next item */ - current = current->next; - } -} - -/****************************************************************************** - * CoLockObjectExternal [OLE32.@] - */ -HRESULT WINAPI CoLockObjectExternal( - LPUNKNOWN pUnk, /* [in] object to be locked */ - BOOL fLock, /* [in] do lock */ - BOOL fLastUnlockReleases) /* [in] unlock all */ -{ - - if (fLock) { - /* - * Increment the external lock coutner, COM_ExternalLockAddRef also - * increment the object's internal lock counter. - */ - COM_ExternalLockAddRef( pUnk); - } else { - /* - * Decrement the external lock coutner, COM_ExternalLockRelease also - * decrement the object's internal lock counter. - */ - COM_ExternalLockRelease( pUnk, fLastUnlockReleases); - } - - return S_OK; -} - -/*********************************************************************** - * CoInitializeWOW (OLE32.@) - */ -HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) { - FIXME("(0x%08lx,0x%08lx),stub!\n",x,y); - return 0; -} - -/*********************************************************************** - * CoGetState [OLE32.@] - * - * NOTES: might be incomplete - */ -HRESULT WINAPI CoGetState(IUnknown ** ppv) -{ - APARTMENT * apt = COM_CurrentInfo(); - - FIXME("\n"); - - if(apt && apt->state) { - IUnknown_AddRef(apt->state); - *ppv = apt->state; - FIXME("-- %p\n", *ppv); - return S_OK; - } - *ppv = NULL; - return E_FAIL; - -} - -/*********************************************************************** - * CoSetState [OLE32.@] - * - */ -HRESULT WINAPI CoSetState(IUnknown * pv) -{ - APARTMENT * apt = COM_CurrentInfo(); - - if (!apt) apt = COM_CreateApartment(COINIT_UNINITIALIZED); - - FIXME("(%p),stub!\n", pv); - - if (pv) { - IUnknown_AddRef(pv); - } - - if (apt->state) { - TRACE("-- release %p now\n", apt->state); - IUnknown_Release(apt->state); - } - apt->state = pv; - return S_OK; -} - - -/****************************************************************************** - * OleGetAutoConvert [OLE32.@] - */ -HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew) -{ - HKEY hkey = 0; - char buf[200]; - WCHAR wbuf[200]; - DWORD len; - HRESULT res = S_OK; - - sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]); - if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey)) - { - res = REGDB_E_CLASSNOTREG; - goto done; - } - len = 200; - /* we can just query for the default value of AutoConvertTo key like that, - without opening the AutoConvertTo key and querying for NULL (default) */ - if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len)) - { - res = REGDB_E_KEYMISSING; - goto done; - } - MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) ); - CLSIDFromString(wbuf,pClsidNew); -done: - if (hkey) RegCloseKey(hkey); - return res; -} - -/****************************************************************************** - * OleSetAutoConvert [OLE32.@] - */ -HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew) -{ - HKEY hkey = 0; - char buf[200], szClsidNew[200]; - HRESULT res = S_OK; - - TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew)); - sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]); - WINE_StringFromCLSID(clsidNew, szClsidNew); - if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey)) - { - res = REGDB_E_CLASSNOTREG; - goto done; - } - if (RegSetValueA(hkey, "AutoConvertTo", REG_SZ, szClsidNew, strlen(szClsidNew)+1)) - { - res = REGDB_E_WRITEREGDB; - goto done; - } - -done: - if (hkey) RegCloseKey(hkey); - return res; -} - -/****************************************************************************** - * OleDoAutoConvert [OLE32.@] - */ -HRESULT WINAPI OleDoAutoConvert(IStorage *pStg, LPCLSID pClsidNew) -{ - FIXME("(%p,%p) : stub\n",pStg,pClsidNew); - return E_NOTIMPL; -} - -/****************************************************************************** - * CoTreatAsClass [OLE32.@] - * - * Sets TreatAs value of a class - */ -HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew) -{ - HKEY hkey = 0; - char buf[47]; - char szClsidNew[39]; - HRESULT res = S_OK; - char auto_treat_as[39]; - LONG auto_treat_as_size = sizeof(auto_treat_as); - CLSID id; - - sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]); - WINE_StringFromCLSID(clsidNew, szClsidNew); - if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey)) - { - res = REGDB_E_CLASSNOTREG; - goto done; - } - if (!memcmp( clsidOld, clsidNew, sizeof(*clsidOld) )) - { - if (!RegQueryValueA(hkey, "AutoTreatAs", auto_treat_as, &auto_treat_as_size) && - !__CLSIDFromStringA(auto_treat_as, &id)) - { - if (RegSetValueA(hkey, "TreatAs", REG_SZ, auto_treat_as, strlen(auto_treat_as)+1)) - { - res = REGDB_E_WRITEREGDB; - goto done; - } - } - else - { - RegDeleteKeyA(hkey, "TreatAs"); - goto done; - } - } - else if (RegSetValueA(hkey, "TreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1)) - { - res = REGDB_E_WRITEREGDB; - goto done; - } - -done: - if (hkey) RegCloseKey(hkey); - return res; -} - -/****************************************************************************** - * CoGetTreatAsClass [OLE32.@] - * - * Reads the TreatAs value from a class. - */ -HRESULT WINAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID clsidNew) -{ - HKEY hkey = 0; - char buf[200], szClsidNew[200]; - HRESULT res = S_OK; - LONG len = sizeof(szClsidNew); - - FIXME("(%s,%p)\n", debugstr_guid(clsidOld), clsidNew); - sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]); - memcpy(clsidNew,clsidOld,sizeof(CLSID)); /* copy over old value */ - - if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey)) - { - res = REGDB_E_CLASSNOTREG; - goto done; - } - if (RegQueryValueA(hkey, "TreatAs", szClsidNew, &len)) - { - res = S_FALSE; - goto done; - } - res = __CLSIDFromStringA(szClsidNew,clsidNew); - if (FAILED(res)) - FIXME("Failed CLSIDFromStringA(%s), hres %lx?\n",szClsidNew,res); -done: - if (hkey) RegCloseKey(hkey); - return res; - -} - -/*********************************************************************** - * IsEqualGUID [OLE32.@] - * - * Compares two Unique Identifiers. - * - * RETURNS - * TRUE if equal - */ -#undef IsEqualGUID -BOOL WINAPI IsEqualGUID( - REFGUID rguid1, /* [in] unique id 1 */ - REFGUID rguid2 /* [in] unique id 2 */ - ) -{ - return !memcmp(rguid1,rguid2,sizeof(GUID)); -} - -/*********************************************************************** - * CoInitializeSecurity [OLE32.@] - */ -HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc, - SOLE_AUTHENTICATION_SERVICE* asAuthSvc, - void* pReserved1, DWORD dwAuthnLevel, - DWORD dwImpLevel, void* pReserved2, - DWORD dwCapabilities, void* pReserved3) -{ - FIXME("(%p,%ld,%p,%p,%ld,%ld,%p,%ld,%p) - stub!\n", pSecDesc, cAuthSvc, - asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pReserved2, - dwCapabilities, pReserved3); - return S_OK; -} - -/*********************************************************************** - * CoSuspendClassObjects [OLE32.@] - */ -HRESULT WINAPI CoSuspendClassObjects(void) -{ - FIXME("\n"); - return S_OK; -} - -/*********************************************************************** - * CoAddRefServerProcess [OLE32.@] - */ -ULONG WINAPI CoAddRefServerProcess(void) -{ - FIXME("\n"); - return 2; -} - -/*********************************************************************** - * CoReleaseServerProcess [OLE32.@] - */ -ULONG WINAPI CoReleaseServerProcess(void) -{ - FIXME("\n"); - return 1; -} diff --git a/reactos/lib/ole32/compobj.spec b/reactos/lib/ole32/compobj.spec deleted file mode 100644 index 90425a0a6e7..00000000000 --- a/reactos/lib/ole32/compobj.spec +++ /dev/null @@ -1,218 +0,0 @@ -1 pascal CoBuildVersion() CoBuildVersion -2 pascal CoInitialize(long) CoInitialize16 -3 pascal CoUninitialize() CoUninitialize16 -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 -8 stub COMARSHALINTERFACE -9 stub COUNMARSHALINTERFACE -10 stub COLOADLIBRARY -11 stub COFREELIBRARY -12 stub COFREEALLLIBRARIES -13 pascal CoCreateInstance(ptr ptr long ptr ptr) CoCreateInstance -14 stub STRINGFROMIID -15 pascal CoDisconnectObject(ptr long) CoDisconnectObject -16 stub CORELEASEMARSHALDATA -17 pascal -ret16 CoFreeUnusedLibraries() CoFreeUnusedLibraries -18 pascal -ret16 IsEqualGUID(ptr ptr) IsEqualGUID16 -19 pascal StringFromCLSID(ptr ptr) StringFromCLSID16 -20 pascal CLSIDFromString(str ptr) CLSIDFromString16 -21 stub ISVALIDPTRIN -22 stub ISVALIDPTROUT -23 stub ISVALIDINTERFACE -24 stub ISVALIDIID -25 stub RESULTFROMSCODE -26 stub GETSCODE -27 pascal CoRegisterMessageFilter(ptr ptr) CoRegisterMessageFilter16 -28 stub COISHANDLERCONNECTED -29 stub SHRADDREF -30 pascal -ret16 CoFileTimeToDosDateTime(ptr ptr ptr) CoFileTimeToDosDateTime16 -31 pascal -ret16 CoDosDateTimeToFileTime(word word ptr) CoDosDateTimeToFileTime16 -32 stub COMARSHALHRESULT -33 stub COUNMARSHALHRESULT -34 pascal CoGetCurrentProcess() CoGetCurrentProcess -35 stub SHRCREATE -36 stub COISOLE1CLASS -37 stub _GUID_NULL -38 stub _IID_IUNKNOWN -39 stub _IID_ICLASSFACTORY -40 stub _IID_IMALLOC -41 stub _IID_IMARSHAL -42 stub _IID_IRPCCHANNEL -43 stub _IID_IRPCSTUB -44 stub _IID_ISTUBMANAGER -45 stub _IID_IRPCPROXY -46 stub _IID_IPROXYMANAGER -47 stub _IID_IPSFACTORY -48 stub _IID_ILOCKBYTES -49 stub _IID_ISTORAGE -50 stub _IID_ISTREAM -51 stub _IID_IENUMSTATSTG -52 stub _IID_IBINDCTX -53 stub _IID_IMONIKER -54 stub _IID_IRUNNINGOBJECTTABLE -55 stub _IID_IINTERNALMONIKER -56 stub _IID_IROOTSTORAGE -57 stub _IID_IDFRESERVED1 -58 stub _IID_IDFRESERVED2 -59 stub _IID_IDFRESERVED3 -60 stub _IID_IMESSAGEFILTER -61 pascal CLSIDFromProgID(str ptr) CLSIDFromProgID16 -62 pascal ProgIDFromCLSID(ptr ptr) ProgIDFromCLSID16 -63 pascal CoLockObjectExternal(segptr word word) CoLockObjectExternal16 -64 stub _CLSID_STDMARSHAL -65 stub COGETTREATASCLASS -66 stub COTREATASCLASS -67 stub COGETSTANDARDMARSHAL -68 stub PROPAGATERESULT -69 stub IIDFROMSTRING -70 stub _IID_ISTDMARSHALINFO -71 pascal CoCreateStandardMalloc(long ptr) CoCreateStandardMalloc16 -72 stub _IID_IEXTERNALCONNECTION -73 stub COCREATEGUID -75 stub FNASSERT -76 pascal StringFromGUID2(ptr ptr word) StringFromGUID2 -77 stub COGETCLASSEXT -78 stub OLE1CLASSFROMCLSID2 -79 stub CLSIDFROMOLE1CLASS -80 stub COOPENCLASSKEY -81 stub GUIDFROMSTRING -82 pascal CoFileTimeNow(ptr) CoFileTimeNow -83 stub REMALLOCOID -84 stub REMFREEOID -85 stub REMCREATEREMOTEHANDLER -86 stub REMCONNECTTOOBJECT -87 stub REMGETINFOFORCID -88 stub LRPCCALL -89 stub LRPCDISPATCH -90 stub LRPCREGISTERMONITOR -91 stub LRPCREVOKEMONITOR -92 stub LRPCGETTHREADWINDOW -93 stub TIMERCALLBACKPROC -94 pascal LookupETask(ptr ptr) LookupETask16 -95 pascal -ret16 SetETask(word ptr) SetETask16 -96 stub LRPCFREEMONITORDATA -97 stub REMLOOKUPSHUNK -98 stub SHRGETSIZE -99 stub CALLTHKMGRUNINITIALIZE -100 stub ??0CARRAYFVALUE@@REC@KI@Z -101 stub ??1CARRAYFVALUE@@REC@XZ -102 stub ?ASSERTVALID@CARRAYFVALUE@@RFCXXZ -103 stub ?FREEEXTRA@CARRAYFVALUE@@RECXXZ -104 stub ?_GETAT@CARRAYFVALUE@@RFCPEXH@Z -105 stub ?GETSIZE@CARRAYFVALUE@@RFCHXZ -106 stub ?REMOVEALL@CARRAYFVALUE@@RECXXZ -107 stub SHRDESTROY -108 stub ?INDEXOF@CARRAYFVALUE@@RECHPEXII@Z -109 stub ?INSERTAT@CARRAYFVALUE@@RECHHPEXH@Z -110 stub COSETSTATE -111 stub ?REMOVEAT@CARRAYFVALUE@@RECXHH@Z -112 stub ?SETAT@CARRAYFVALUE@@RECXHPEX@Z -113 stub ?SETATGROW@CARRAYFVALUE@@RECHHPEX@Z -114 stub ?SETSIZE@CARRAYFVALUE@@RECHHH@Z -115 pascal CoGetState(ptr) CoGetState16 -116 pascal DllEntryPoint(long word word word long word) COMPOBJ_DllEntryPoint -117 stub ?RELEASE@CSTDMALLOC@@VEAKXZ -118 stub ?ALLOC@CSTDMALLOC@@VEAPEXK@Z -119 stub SHRRELEASE -120 stub ?GETASSOCAT@CMAPKEYTOVALUE@@BFCPEUCASSOC@1@PEXIAEI@Z -121 stub ?SETASSOCKEY@CMAPKEYTOVALUE@@BFCHPEUCASSOC@1@PEXI@Z -122 stub ??1CMAPKEYTOVALUE@@REC@XZ -123 stub ?GETASSOCKEYPTR@CMAPKEYTOVALUE@@BFCXPEUCASSOC@1@PEPEXPEI@Z -124 stub ?NEWASSOC@CMAPKEYTOVALUE@@BECPEUCASSOC@1@IPEXI0@Z -125 stub ?SIZEASSOC@CMAPKEYTOVALUE@@BFCIXZ -126 stub ?FREEASSOC@CMAPKEYTOVALUE@@BECXPEUCASSOC@1@@Z -127 stub ?GETSTARTPOSITION@CMAPKEYTOVALUE@@RFCPEXXZ -128 stub ?GETNEXTASSOC@CMAPKEYTOVALUE@@RFCXPEPEXPEXPEI1@Z -129 stub ?COMPAREASSOCKEY@CMAPKEYTOVALUE@@BFCHPEUCASSOC@1@PEXI@Z -130 stub ?REMOVEHKEY@CMAPKEYTOVALUE@@RECHK@Z -131 stub ?GETHKEY@CMAPKEYTOVALUE@@RFCKPEXI@Z -132 stub ?GETCOUNT@CMAPKEYTOVALUE@@RFCHXZ -133 stub ?LOOKUP@CMAPKEYTOVALUE@@RFCHPEXI0@Z -134 stub ?GETASSOCVALUE@CMAPKEYTOVALUE@@BFCXPEUCASSOC@1@PEX@Z -135 stub ?REMOVEKEY@CMAPKEYTOVALUE@@RECHPEXI@Z -136 stub ?REMOVEALL@CMAPKEYTOVALUE@@RECXXZ -137 stub SHRALLOC -138 stub ?FREEASSOCKEY@CMAPKEYTOVALUE@@BFCXPEUCASSOC@1@@Z -139 stub ?SETAT@CMAPKEYTOVALUE@@RECHPEXI0@Z -140 stub ?LOOKUPHKEY@CMAPKEYTOVALUE@@RFCHKPEX@Z -141 stub ?ASSERTVALID@CMAPKEYTOVALUE@@RFCXXZ -142 stub ?SETASSOCVALUE@CMAPKEYTOVALUE@@BFCXPEUCASSOC@1@PEX@Z -143 stub ?SETATHKEY@CMAPKEYTOVALUE@@RECHKPEX@Z -144 stub ??0CMAPKEYTOVALUE@@REC@KIIHP7CIPEXI@ZI@Z -145 stub ?INITHASHTABLE@CMAPKEYTOVALUE@@BECHXZ -146 stub ?GETASSOCVALUEPTR@CMAPKEYTOVALUE@@BFCXPEUCASSOC@1@PEPEX@Z -147 stub ?LOOKUPADD@CMAPKEYTOVALUE@@RFCHPEXI0@Z -148 stub MKVDEFAULTHASHKEY -149 stub DELETE16 -150 stub COMEMCTXOF -151 stub COMEMALLOC -152 stub COMEMFREE -153 stub SHRREALLOC -154 stub ___EXPORTEDSTUB -155 stub LRPCREGISTERWIN32SMONITOR -156 stub MYREMGETINFOFORCID -157 stub SHRFREE -158 stub OPNEW16 -159 stub ADDCOINFO -160 stub CORUNMODALLOOP -161 stub COHANDLEINCOMINGCALL -162 stub COSETACKSTATE -163 stub SHRDIDALLOC -164 stub ?GETAT@CARRAYFVALUE@@RFCPEXH@Z -165 stub ?GETUPPERBOUND@CARRAYFVALUE@@RFCHXZ -166 stub OPDELETE16 -167 stub ?GETSIZEVALUE@CARRAYFVALUE@@RFCHXZ -168 stub ?PROXY1632ADDREF@@ZAKPEVCPROXY1632@@@Z -# FIXME: 169 is a duplicate of 97 -169 stub REMLOOKUPSHUNK_dup -170 stub ?ISEMPTY@CMAPKEYTOVALUE@@RFCHXZ -171 stub ?FREE@CSTDMALLOC@@VEAXPEX@Z -172 stub CALLTHKMGRINITIALIZE -173 stub ?REALLOC@CSTDMALLOC@@VEAPEXPEXK@Z -174 stub ?SM16RHQI@@ZAPEXPEVCSM16RELEASEHANDLER@@AFUGUID@@PEPEX@Z -175 stub ?PROXY1632METHOD10@@ZAKPEVCPROXY1632@@@Z -# FIXME: 176 is a duplicate of 154 -176 stub ___EXPORTEDSTUB_dup -177 stub ?PROXY1632METHOD20@@ZAKPEVCPROXY1632@@@Z -178 stub ?PROXY1632METHOD11@@ZAKPEVCPROXY1632@@@Z -179 stub ?PROXY1632METHOD30@@ZAKPEVCPROXY1632@@@Z -180 stub ?PROXY1632METHOD21@@ZAKPEVCPROXY1632@@@Z -181 stub ?PROXY1632METHOD12@@ZAKPEVCPROXY1632@@@Z -182 stub ?PROXY1632METHOD31@@ZAKPEVCPROXY1632@@@Z -183 stub ?PROXY1632METHOD22@@ZAKPEVCPROXY1632@@@Z -184 stub ?PROXY1632METHOD13@@ZAKPEVCPROXY1632@@@Z -185 stub ?GETSIZE@CSTDMALLOC@@VEAKPEX@Z -186 stub ?PROXY1632METHOD23@@ZAKPEVCPROXY1632@@@Z -187 stub ?PROXY1632METHOD14@@ZAKPEVCPROXY1632@@@Z -188 stub ?PROXY1632METHOD24@@ZAKPEVCPROXY1632@@@Z -189 stub ?PROXY1632METHOD15@@ZAKPEVCPROXY1632@@@Z -190 stub ?PROXY1632METHOD25@@ZAKPEVCPROXY1632@@@Z -191 stub ?PROXY1632METHOD16@@ZAKPEVCPROXY1632@@@Z -192 stub ?PROXY1632METHOD26@@ZAKPEVCPROXY1632@@@Z -193 stub ?PROXY1632METHOD17@@ZAKPEVCPROXY1632@@@Z -194 stub ?PROXY1632METHOD27@@ZAKPEVCPROXY1632@@@Z -195 stub ?PROXY1632METHOD18@@ZAKPEVCPROXY1632@@@Z -196 stub ?PROXY1632METHOD28@@ZAKPEVCPROXY1632@@@Z -197 stub ?ADDREF@CSTDMALLOC@@VEAKXZ -198 stub ?PROXY1632METHOD19@@ZAKPEVCPROXY1632@@@Z -199 stub ?PROXY1632METHOD29@@ZAKPEVCPROXY1632@@@Z -200 stub CALL32INITIALIZE -201 pascal CALLOBJECTINWOW(ptr ptr) CallObjectInWOW -203 stub CALLOBJECTINWOWCHECKINIT -204 stub CALLOBJECTINWOWCHECKTHKMGR -205 stub CONVERTHR1632 -206 stub CONVERTHR3216 -207 stub ADDAPPCOMPATFLAG - -# WINE internal relays (for Win16 interfaces) -500 cdecl IMalloc16_QueryInterface(ptr ptr ptr) IMalloc16_fnQueryInterface -501 cdecl IMalloc16_AddRef(ptr) IMalloc16_fnAddRef -502 cdecl IMalloc16_Release(ptr) IMalloc16_fnRelease -503 cdecl IMalloc16_Alloc(ptr long) IMalloc16_fnAlloc -504 cdecl IMalloc16_Realloc(ptr segptr long) IMalloc16_fnRealloc -505 cdecl IMalloc16_Free(ptr segptr) IMalloc16_fnFree -506 cdecl IMalloc16_GetSize(ptr segptr) IMalloc16_fnGetSize -507 cdecl IMalloc16_DidAlloc(ptr segptr) IMalloc16_fnDidAlloc -508 cdecl IMalloc16_HeapMinimize(ptr) IMalloc16_fnHeapMinimize diff --git a/reactos/lib/ole32/compobj_private.h b/reactos/lib/ole32/compobj_private.h deleted file mode 100644 index 32d17727435..00000000000 --- a/reactos/lib/ole32/compobj_private.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 1995 Martin von Loewis - * Copyright 1998 Justin Bradford - * Copyright 1999 Francis Beaudet - * Copyright 1999 Sylvain St-Germain - * Copyright 2002 Marcus Meissner - * Copyright 2003 Ove Kåven, TransGaming Technologies - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __WINE_OLE_COMPOBJ_H -#define __WINE_OLE_COMPOBJ_H - -/* All private prototype functions used by OLE will be added to this header file */ - -#include - -#include "windef.h" -#include "winbase.h" -#include "wtypes.h" -#include "dcom.h" -#include "winreg.h" -#include "winternl.h" - -/* Windows maps COINIT values to 0x80 for apartment threaded, 0x140 - * for free threaded, and 0 for uninitialized apartments. There is - * no real advantage in us doing this and certainly no release version - * of an app should be poking around with these flags. So we need a - * special value for uninitialized */ -#define COINIT_UNINITIALIZED 0x100 - -/* exported interface */ -typedef struct tagXIF { - struct tagXIF *next; - LPVOID iface; /* interface pointer */ - IID iid; /* interface ID */ - IPID ipid; /* exported interface ID */ - LPRPCSTUBBUFFER stub; /* interface stub */ - DWORD refs; /* external reference count */ - HRESULT hres; /* result of stub creation attempt */ -} XIF; - -/* exported object */ -typedef struct tagXOBJECT { - IRpcStubBufferVtbl *lpVtbl; - struct tagAPARTMENT *parent; - struct tagXOBJECT *next; - LPUNKNOWN obj; /* object identity (IUnknown) */ - OID oid; /* object ID */ - DWORD ifc; /* interface ID counter */ - XIF *ifaces; /* exported interfaces */ - DWORD refs; /* external reference count */ -} XOBJECT; - -/* imported interface */ -typedef struct tagIIF { - struct tagIIF *next; - LPVOID iface; /* interface pointer */ - IID iid; /* interface ID */ - IPID ipid; /* imported interface ID */ - LPRPCPROXYBUFFER proxy; /* interface proxy */ - DWORD refs; /* imported (public) references */ - HRESULT hres; /* result of proxy creation attempt */ -} IIF; - -/* imported object */ -typedef struct tagIOBJECT { - IRemUnknownVtbl *lpVtbl; - struct tagAPARTMENT *parent; - struct tagIOBJECT *next; - LPRPCCHANNELBUFFER chan; /* channel to object */ - OXID oxid; /* object exported ID */ - OID oid; /* object ID */ - IPID ipid; /* first imported interface ID */ - IIF *ifaces; /* imported interfaces */ - DWORD refs; /* proxy reference count */ -} IOBJECT; - -/* apartment */ -typedef struct tagAPARTMENT { - struct tagAPARTMENT *next, *prev, *parent; - DWORD model; /* threading model */ - DWORD inits; /* CoInitialize count */ - DWORD tid; /* thread id */ - HANDLE thread; /* thread handle */ - OXID oxid; /* object exporter ID */ - OID oidc; /* object ID counter */ - HWND win; /* message window */ - CRITICAL_SECTION cs; /* thread safety */ - LPMESSAGEFILTER filter; /* message filter */ - XOBJECT *objs; /* exported objects */ - IOBJECT *proxies; /* imported objects */ - LPUNKNOWN state; /* state object (see Co[Get,Set]State) */ - LPVOID ErrorInfo; /* thread error info */ -} APARTMENT; - -extern APARTMENT MTA, *apts; - -extern void* StdGlobalInterfaceTable_Construct(); -extern void StdGlobalInterfaceTable_Destroy(void* self); -extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv); - -extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr); -extern HRESULT create_marshalled_proxy(REFCLSID rclsid, REFIID iid, LPVOID *ppv); - -extern void* StdGlobalInterfaceTableInstance; - -#define PIPEPREF "\\\\.\\pipe\\" -#define OLESTUBMGR PIPEPREF"WINE_OLE_StubMgr" - -/* Standard Marshalling definitions */ -typedef struct _wine_marshal_id { - DWORD processid; - DWORD objectid; /* unique value corresp. IUnknown of object */ - IID iid; -} wine_marshal_id; - -inline static BOOL -MARSHAL_Compare_Mids(wine_marshal_id *mid1,wine_marshal_id *mid2) { - return - (mid1->processid == mid2->processid) && - (mid1->objectid == mid2->objectid) && - IsEqualIID(&(mid1->iid),&(mid2->iid)) - ; -} - -/* compare without interface compare */ -inline static BOOL -MARSHAL_Compare_Mids_NoInterface(wine_marshal_id *mid1, wine_marshal_id *mid2) { - return - (mid1->processid == mid2->processid) && - (mid1->objectid == mid2->objectid) - ; -} - -HRESULT MARSHAL_Find_Stub_Buffer(wine_marshal_id *mid,IRpcStubBuffer **stub); -void MARSHAL_Invalidate_Stub_From_MID(wine_marshal_id *mid); -HRESULT MARSHAL_Disconnect_Proxies(); - -HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv); - -void STUBMGR_Start(); - -extern HRESULT PIPE_GetNewPipeBuf(wine_marshal_id *mid, IRpcChannelBuffer **pipebuf); - -/* This function initialize the Running Object Table */ -HRESULT WINAPI RunningObjectTableImpl_Initialize(); - -/* This function uninitialize the Running Object Table */ -HRESULT WINAPI RunningObjectTableImpl_UnInitialize(); - -/* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */ -int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable); - -HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id); - -/* - * Per-thread values are stored in the TEB on offset 0xF80, - * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm - */ -static inline APARTMENT* COM_CurrentInfo(void) -{ - APARTMENT* apt = NtCurrentTeb()->ReservedForOle; - return apt; -} -static inline APARTMENT* COM_CurrentApt(void) -{ - APARTMENT* apt = COM_CurrentInfo(); - if (apt && apt->parent) apt = apt->parent; - return apt; -} - -/* compobj.c */ -APARTMENT* COM_CreateApartment(DWORD model); -HWND COM_GetApartmentWin(OXID oxid); - -#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field)) - -#endif /* __WINE_OLE_COMPOBJ_H */ diff --git a/reactos/lib/ole32/compositemoniker.c b/reactos/lib/ole32/compositemoniker.c deleted file mode 100644 index 9d7fa0c08b0..00000000000 --- a/reactos/lib/ole32/compositemoniker.c +++ /dev/null @@ -1,1727 +0,0 @@ -/* - * CompositeMonikers implementation - * - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winerror.h" -#include "wine/debug.h" -#include "wine/unicode.h" -#include "ole2.h" -#include "moniker.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -const CLSID CLSID_CompositeMoniker = { - 0x309, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46} -}; - -#define BLOCK_TAB_SIZE 5 /* represent the first size table and it's increment block size */ - -/* CompositeMoniker data structure */ -typedef struct CompositeMonikerImpl{ - - IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/ - - /* The ROT (RunningObjectTable implementation) uses the IROTData - * interface to test whether two monikers are equal. That's why IROTData - * interface is implemented by monikers. - */ - IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/ - - ULONG ref; /* reference counter for this object */ - - IMoniker** tabMoniker; /* dynamaic table containing all components (monikers) of this composite moniker */ - - ULONG tabSize; /* size of tabMoniker */ - - ULONG tabLastIndex; /* first free index in tabMoniker */ - -} CompositeMonikerImpl; - - -/* EnumMoniker data structure */ -typedef struct EnumMonikerImpl{ - - IEnumMonikerVtbl *lpVtbl; /* VTable relative to the IEnumMoniker interface.*/ - - ULONG ref; /* reference counter for this object */ - - IMoniker** tabMoniker; /* dynamic table containing the enumerated monikers */ - - ULONG tabSize; /* size of tabMoniker */ - - ULONG currentPos; /* index pointer on the current moniker */ - -} EnumMonikerImpl; - - -/********************************************************************************/ -/* CompositeMoniker prototype functions : */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI CompositeMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI CompositeMonikerImpl_AddRef(IMoniker* iface); -static ULONG WINAPI CompositeMonikerImpl_Release(IMoniker* iface); - -/* IPersist prototype functions */ -static HRESULT WINAPI CompositeMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID); - -/* IPersistStream prototype functions */ -static HRESULT WINAPI CompositeMonikerImpl_IsDirty(IMoniker* iface); -static HRESULT WINAPI CompositeMonikerImpl_Load(IMoniker* iface, IStream* pStm); -static HRESULT WINAPI CompositeMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty); -static HRESULT WINAPI CompositeMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize); - -/* IMoniker prototype functions */ -static HRESULT WINAPI CompositeMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI CompositeMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI CompositeMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced); -static HRESULT WINAPI CompositeMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite); -static HRESULT WINAPI CompositeMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker); -static HRESULT WINAPI CompositeMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker); -static HRESULT WINAPI CompositeMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash); -static HRESULT WINAPI CompositeMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning); -static HRESULT WINAPI CompositeMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pCompositeTime); -static HRESULT WINAPI CompositeMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk); -static HRESULT WINAPI CompositeMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix); -static HRESULT WINAPI CompositeMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath); -static HRESULT WINAPI CompositeMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName); -static HRESULT WINAPI CompositeMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut); -static HRESULT WINAPI CompositeMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys); - -/********************************************************************************/ -/* IROTData prototype functions */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI CompositeMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject); -static ULONG WINAPI CompositeMonikerROTDataImpl_AddRef(IROTData* iface); -static ULONG WINAPI CompositeMonikerROTDataImpl_Release(IROTData* iface); - -/* IROTData prototype function */ -static HRESULT WINAPI CompositeMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData); - -/* Local function used by CompositeMoniker implementation */ -HRESULT WINAPI CompositeMonikerImpl_Construct(CompositeMonikerImpl* This,LPMONIKER pmkFirst, LPMONIKER pmkRest); -HRESULT WINAPI CompositeMonikerImpl_Destroy(CompositeMonikerImpl* iface); - -/********************************************************************************/ -/* IEnumMoniker prototype functions */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI EnumMonikerImpl_QueryInterface(IEnumMoniker* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI EnumMonikerImpl_AddRef(IEnumMoniker* iface); -static ULONG WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface); - -/* IEnumMoniker prototype functions */ -static HRESULT WINAPI EnumMonikerImpl_Next(IEnumMoniker* iface,ULONG celt,IMoniker** rgelt,ULONG* pceltFetched); -static HRESULT WINAPI EnumMonikerImpl_Skip(IEnumMoniker* iface,ULONG celt); -static HRESULT WINAPI EnumMonikerImpl_Reset(IEnumMoniker* iface); -static HRESULT WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface,IEnumMoniker** ppenum); - -HRESULT WINAPI EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker,ULONG tabSize,ULONG currentPos,BOOL leftToRigth,IEnumMoniker ** ppmk); - -/********************************************************************************/ -/* Virtual function table for the CompositeMonikerImpl class which includes */ -/* IPersist, IPersistStream and IMoniker functions. */ - -static IMonikerVtbl VT_CompositeMonikerImpl = -{ - CompositeMonikerImpl_QueryInterface, - CompositeMonikerImpl_AddRef, - CompositeMonikerImpl_Release, - CompositeMonikerImpl_GetClassID, - CompositeMonikerImpl_IsDirty, - CompositeMonikerImpl_Load, - CompositeMonikerImpl_Save, - CompositeMonikerImpl_GetSizeMax, - CompositeMonikerImpl_BindToObject, - CompositeMonikerImpl_BindToStorage, - CompositeMonikerImpl_Reduce, - CompositeMonikerImpl_ComposeWith, - CompositeMonikerImpl_Enum, - CompositeMonikerImpl_IsEqual, - CompositeMonikerImpl_Hash, - CompositeMonikerImpl_IsRunning, - CompositeMonikerImpl_GetTimeOfLastChange, - CompositeMonikerImpl_Inverse, - CompositeMonikerImpl_CommonPrefixWith, - CompositeMonikerImpl_RelativePathTo, - CompositeMonikerImpl_GetDisplayName, - CompositeMonikerImpl_ParseDisplayName, - CompositeMonikerImpl_IsSystemMoniker -}; - -/********************************************************************************/ -/* Virtual function table for the IROTData class. */ -static IROTDataVtbl VT_ROTDataImpl = -{ - CompositeMonikerROTDataImpl_QueryInterface, - CompositeMonikerROTDataImpl_AddRef, - CompositeMonikerROTDataImpl_Release, - CompositeMonikerROTDataImpl_GetComparaisonData -}; - -/********************************************************************************/ -/* Virtual function table for the IROTData class */ -static IEnumMonikerVtbl VT_EnumMonikerImpl = -{ - EnumMonikerImpl_QueryInterface, - EnumMonikerImpl_AddRef, - EnumMonikerImpl_Release, - EnumMonikerImpl_Next, - EnumMonikerImpl_Skip, - EnumMonikerImpl_Reset, - EnumMonikerImpl_Clone -}; - -/******************************************************************************* - * CompositeMoniker_QueryInterface - *******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject) -{ - CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* Perform a sanity check on the parameters.*/ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* Initialize the return parameter */ - *ppvObject = 0; - - /* Compare the riid with the interface IDs implemented by this object.*/ - if (IsEqualIID(&IID_IUnknown, riid) || - IsEqualIID(&IID_IPersist, riid) || - IsEqualIID(&IID_IPersistStream, riid) || - IsEqualIID(&IID_IMoniker, riid) - ) - *ppvObject = iface; - else if (IsEqualIID(&IID_IROTData, riid)) - *ppvObject = (IROTData*)&(This->lpvtbl2); - - /* Check that we obtained an interface.*/ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* Query Interface always increases the reference count by one when it is successful */ - CompositeMonikerImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * CompositeMoniker_AddRef - ******************************************************************************/ -ULONG WINAPI CompositeMonikerImpl_AddRef(IMoniker* iface) -{ - CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * CompositeMoniker_Release - ******************************************************************************/ -ULONG WINAPI CompositeMonikerImpl_Release(IMoniker* iface) -{ - CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface; - ULONG i; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* destroy the object if there's no more reference on it */ - if (ref == 0){ - - /* release all the components before destroying this object */ - for (i=0;itabLastIndex;i++) - IMoniker_Release(This->tabMoniker[i]); - - CompositeMonikerImpl_Destroy(This); - } - return ref; -} - -/****************************************************************************** - * CompositeMoniker_GetClassID - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID) -{ - TRACE("(%p,%p),stub!\n",iface,pClassID); - - if (pClassID==NULL) - return E_POINTER; - - *pClassID = CLSID_CompositeMoniker; - - return S_OK; -} - -/****************************************************************************** - * CompositeMoniker_IsDirty - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_IsDirty(IMoniker* iface) -{ - /* Note that the OLE-provided implementations of the IPersistStream::IsDirty - method in the OLE-provided moniker interfaces always return S_FALSE because - their internal state never changes. */ - - TRACE("(%p)\n",iface); - - return S_FALSE; -} - -/****************************************************************************** - * CompositeMoniker_Load - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Load(IMoniker* iface,IStream* pStm) -{ - HRESULT res; - DWORD constant; - CLSID clsid; - WCHAR string[1]={0}; - - CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface; - - TRACE("(%p,%p)\n",iface,pStm); - - /* this function call OleLoadFromStream function for each moniker within this object */ - - /* read the a constant written by CompositeMonikerImpl_Save (see CompositeMonikerImpl_Save for more details)*/ - res=IStream_Read(pStm,&constant,sizeof(DWORD),NULL); - - if (SUCCEEDED(res)&& constant!=3) - return E_FAIL; - - while(1){ -#if 0 - res=OleLoadFromStream(pStm,&IID_IMoniker,(void**)&This->tabMoniker[This->tabLastIndex]); -#endif - res=ReadClassStm(pStm,&clsid); - DPRINTF("res=%ld",res); - if (FAILED(res)) - break; - - if (IsEqualIID(&clsid,&CLSID_FileMoniker)){ - res=CreateFileMoniker(string,&This->tabMoniker[This->tabLastIndex]); - if (FAILED(res)) - break; - res=IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm); - if (FAILED(res)) - break; - } - else if (IsEqualIID(&clsid,&CLSID_ItemMoniker)){ - CreateItemMoniker(string,string,&This->tabMoniker[This->tabLastIndex]); - if (res!=S_OK) - break; - IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm); - if (FAILED(res)) - break; - } - else if (IsEqualIID(&clsid,&CLSID_AntiMoniker)){ - CreateAntiMoniker(&This->tabMoniker[This->tabLastIndex]); - if (FAILED(res)) - break; - IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm); - if (FAILED(res)) - break; - } - else if (IsEqualIID(&clsid,&CLSID_CompositeMoniker)) - return E_FAIL; - - else - { - FIXME("()\n"); - /* FIXME: To whoever wrote this code: It's either return or break. it cannot be both! */ - break; - return E_NOTIMPL; - } - - /* resize the table if needed */ - if (++This->tabLastIndex==This->tabSize){ - - This->tabSize+=BLOCK_TAB_SIZE; - This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker)); - - if (This->tabMoniker==NULL) - return E_OUTOFMEMORY; - } - } - - return res; -} - -/****************************************************************************** - * CompositeMoniker_Save - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty) -{ - HRESULT res; - IEnumMoniker *enumMk; - IMoniker *pmk; - DWORD constant=3; - - TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty); - - /* This function calls OleSaveToStream function for each moniker within - * this object. - * When I tested this function in windows, I usually found this constant - * at the beginning of the stream. I don't known why (there's no - * indication in the specification) ! - */ - res=IStream_Write(pStm,&constant,sizeof(constant),NULL); - - IMoniker_Enum(iface,TRUE,&enumMk); - - while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)==S_OK){ - - res=OleSaveToStream((IPersistStream*)pmk,pStm); - - IMoniker_Release(pmk); - - if (FAILED(res)){ - - IEnumMoniker_Release(pmk); - return res; - } - } - - IEnumMoniker_Release(enumMk); - - return S_OK; -} - -/****************************************************************************** - * CompositeMoniker_GetSizeMax - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_GetSizeMax(IMoniker* iface,ULARGE_INTEGER* pcbSize) -{ - IEnumMoniker *enumMk; - IMoniker *pmk; - ULARGE_INTEGER ptmpSize; - - /* The sizeMax of this object is calculated by calling GetSizeMax on - * each moniker within this object then summing all returned values - */ - - TRACE("(%p,%p)\n",iface,pcbSize); - - if (pcbSize!=NULL) - return E_POINTER; - - pcbSize->u.LowPart =0; - pcbSize->u.HighPart=0; - - IMoniker_Enum(iface,TRUE,&enumMk); - - while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)==TRUE){ - - IMoniker_GetSizeMax(pmk,&ptmpSize); - - IMoniker_Release(pmk); - - pcbSize->u.LowPart +=ptmpSize.u.LowPart; - pcbSize->u.HighPart+=ptmpSize.u.HighPart; - } - - IEnumMoniker_Release(enumMk); - - return S_OK; -} - -/****************************************************************************** - * Composite-Moniker_Construct (local function) - *******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Construct(CompositeMonikerImpl* This,LPMONIKER pmkFirst, LPMONIKER pmkRest) -{ - DWORD mkSys; - IEnumMoniker *enumMoniker; - IMoniker *tempMk; - HRESULT res; - - TRACE("(%p,%p,%p)\n",This,pmkFirst,pmkRest); - - /* Initialize the virtual function table. */ - This->lpvtbl1 = &VT_CompositeMonikerImpl; - This->lpvtbl2 = &VT_ROTDataImpl; - This->ref = 0; - - This->tabSize=BLOCK_TAB_SIZE; - This->tabLastIndex=0; - - This->tabMoniker=HeapAlloc(GetProcessHeap(),0,This->tabSize*sizeof(IMoniker)); - if (This->tabMoniker==NULL) - return E_OUTOFMEMORY; - - IMoniker_IsSystemMoniker(pmkFirst,&mkSys); - - /* put the first moniker contents in the beginning of the table */ - if (mkSys!=MKSYS_GENERICCOMPOSITE){ - - This->tabMoniker[(This->tabLastIndex)++]=pmkFirst; - IMoniker_AddRef(pmkFirst); - } - else{ - - IMoniker_Enum(pmkFirst,TRUE,&enumMoniker); - - while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){ - - - if (++This->tabLastIndex==This->tabSize){ - - This->tabSize+=BLOCK_TAB_SIZE; - This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker)); - - if (This->tabMoniker==NULL) - return E_OUTOFMEMORY; - } - } - - IEnumMoniker_Release(enumMoniker); - } - - /* put the rest moniker contents after the first one and make simplification if needed */ - - IMoniker_IsSystemMoniker(pmkRest,&mkSys); - - if (mkSys!=MKSYS_GENERICCOMPOSITE){ - - /* add a simple moniker to the moniker table */ - - res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],pmkRest,TRUE,&tempMk); - - if (res==MK_E_NEEDGENERIC){ - - /* there's no simplification in this case */ - This->tabMoniker[This->tabLastIndex]=pmkRest; - - This->tabLastIndex++; - - IMoniker_AddRef(pmkRest); - } - else if (tempMk==NULL){ - - /* we have an antimoniker after a simple moniker so we can make a simplification in this case */ - IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]); - - This->tabLastIndex--; - } - else if (SUCCEEDED(res)){ - - /* the non-generic composition was successful so we can make a simplification in this case */ - IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]); - - This->tabMoniker[This->tabLastIndex-1]=tempMk; - } else - return res; - - /* resize tabMoniker if needed */ - if (This->tabLastIndex==This->tabSize){ - - This->tabSize+=BLOCK_TAB_SIZE; - - This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker)); - - if (This->tabMoniker==NULL) - return E_OUTOFMEMORY; - } - } - else{ - - /* add a composite moniker to the moniker table (do the same thing - * for each moniker within the composite moniker as a simple moniker - * (see above for how to add a simple moniker case) ) - */ - IMoniker_Enum(pmkRest,TRUE,&enumMoniker); - - while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){ - - res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],This->tabMoniker[This->tabLastIndex],TRUE,&tempMk); - - if (res==MK_E_NEEDGENERIC){ - - This->tabLastIndex++; - } - else if (tempMk==NULL){ - - IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]); - IMoniker_Release(This->tabMoniker[This->tabLastIndex]); - This->tabLastIndex--; - } - else{ - - IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]); - - This->tabMoniker[This->tabLastIndex-1]=tempMk; - } - - if (This->tabLastIndex==This->tabSize){ - - This->tabSize+=BLOCK_TAB_SIZE; - - This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker)); - - if (This->tabMoniker==NULL) - return E_OUTOFMEMORY; - } - } - - IEnumMoniker_Release(enumMoniker); - } - - return S_OK; -} - -/****************************************************************************** - * CompositeMoniker_Destroy (local function) - *******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Destroy(CompositeMonikerImpl* This) -{ - TRACE("(%p)\n",This); - - HeapFree(GetProcessHeap(),0,This->tabMoniker); - - HeapFree(GetProcessHeap(),0,This); - - return S_OK; -} - -/****************************************************************************** - * CompositeMoniker_BindToObject - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_BindToObject(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - HRESULT res; - IRunningObjectTable *prot; - IMoniker *tempMk,*antiMk,*mostRigthMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - - if (ppvResult==NULL) - return E_POINTER; - - *ppvResult=0; - /* If pmkToLeft is NULL, this method looks for the moniker in the ROT, and if found, queries the retrieved */ - /* object for the requested interface pointer. */ - if(pmkToLeft==NULL){ - - res=IBindCtx_GetRunningObjectTable(pbc,&prot); - - if (SUCCEEDED(res)){ - - /* if the requested class was loaded before ! we don't need to reload it */ - res = IRunningObjectTable_GetObject(prot,iface,(IUnknown**)ppvResult); - - if (res==S_OK) - return res; - } - } - else{ - /* If pmkToLeft is not NULL, the method recursively calls IMoniker::BindToObject on the rightmost */ - /* component of the composite, passing the rest of the composite as the pmkToLeft parameter for that call */ - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - res=CompositeMonikerImpl_BindToObject(mostRigthMk,pbc,tempMk,riid,ppvResult); - - IMoniker_Release(tempMk); - IMoniker_Release(mostRigthMk); - } - - return res; -} - -/****************************************************************************** - * CompositeMoniker_BindToStorage - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_BindToStorage(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - HRESULT res; - IMoniker *tempMk,*antiMk,*mostRigthMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - - *ppvResult=0; - - /* This method recursively calls BindToStorage on the rightmost component of the composite, */ - /* passing the rest of the composite as the pmkToLeft parameter for that call. */ - - if (pmkToLeft!=NULL){ - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - res=CompositeMonikerImpl_BindToStorage(mostRigthMk,pbc,tempMk,riid,ppvResult); - - IMoniker_Release(tempMk); - - IMoniker_Release(mostRigthMk); - - return res; - } - else - return IMoniker_BindToStorage(iface,pbc,NULL,riid,ppvResult); -} - -/****************************************************************************** - * CompositeMoniker_Reduce - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Reduce(IMoniker* iface, - IBindCtx* pbc, - DWORD dwReduceHowFar, - IMoniker** ppmkToLeft, - IMoniker** ppmkReduced) -{ - HRESULT res; - IMoniker *tempMk,*antiMk,*mostRigthMk,*leftReducedComposedMk,*mostRigthReducedMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced); - - if (ppmkReduced==NULL) - return E_POINTER; - - /* This method recursively calls Reduce for each of its component monikers. */ - - if (ppmkToLeft==NULL){ - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - return CompositeMonikerImpl_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk, ppmkReduced); - } - else if (*ppmkToLeft==NULL) - - return IMoniker_Reduce(iface,pbc,dwReduceHowFar,NULL,ppmkReduced); - - else{ - - /* separate the composite moniker in to left and right moniker */ - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - /* If any of the components reduces itself, the method returns S_OK and passes back a composite */ - /* of the reduced components */ - if (IMoniker_Reduce(mostRigthMk,pbc,dwReduceHowFar,NULL,&mostRigthReducedMk) && - CompositeMonikerImpl_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk,&leftReducedComposedMk) - ) - - return CreateGenericComposite(leftReducedComposedMk,mostRigthReducedMk,ppmkReduced); - - else{ - /* If no reduction occurred, the method passes back the same moniker and returns MK_S_REDUCED_TO_SELF.*/ - - IMoniker_AddRef(iface); - - *ppmkReduced=iface; - - return MK_S_REDUCED_TO_SELF; - } - } -} - -/****************************************************************************** - * CompositeMoniker_ComposeWith - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_ComposeWith(IMoniker* iface, - IMoniker* pmkRight, - BOOL fOnlyIfNotGeneric, - IMoniker** ppmkComposite) -{ - TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite); - - if ((ppmkComposite==NULL)||(pmkRight==NULL)) - return E_POINTER; - - *ppmkComposite=0; - - /* If fOnlyIfNotGeneric is TRUE, this method sets *pmkComposite to NULL and returns MK_E_NEEDGENERIC; */ - /* otherwise, the method returns the result of combining the two monikers by calling the */ - /* CreateGenericComposite function */ - - if (fOnlyIfNotGeneric) - return MK_E_NEEDGENERIC; - - return CreateGenericComposite(iface,pmkRight,ppmkComposite); -} - -/****************************************************************************** - * CompositeMoniker_Enum - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker) -{ - CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface; - - TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker); - - if (ppenumMoniker == NULL) - return E_POINTER; - - return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabLastIndex,0,fForward,ppenumMoniker); -} - -/****************************************************************************** - * CompositeMoniker_IsEqual - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker) -{ - IEnumMoniker *enumMoniker1,*enumMoniker2; - IMoniker *tempMk1,*tempMk2; - HRESULT res1,res2,res; - - TRACE("(%p,%p)\n",iface,pmkOtherMoniker); - - if (pmkOtherMoniker==NULL) - return S_FALSE; - - /* This method returns S_OK if the components of both monikers are equal when compared in the */ - /* left-to-right order.*/ - IMoniker_Enum(pmkOtherMoniker,TRUE,&enumMoniker1); - - if (enumMoniker1==NULL) - return S_FALSE; - - IMoniker_Enum(iface,TRUE,&enumMoniker2); - - while(1){ - - res1=IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL); - res2=IEnumMoniker_Next(enumMoniker2,1,&tempMk2,NULL); - - if((res1==S_OK)&&(res2==S_OK)){ - - if(IMoniker_IsEqual(tempMk1,tempMk2)==S_FALSE){ - res= S_FALSE; - break; - } - else - continue; - } - else if ( (res1==S_FALSE) && (res2==S_FALSE) ){ - res = S_OK; - break; - } - else{ - res = S_FALSE; - break; - } - - if (res1==S_OK) - IMoniker_Release(tempMk1); - - if (res2==S_OK) - IMoniker_Release(tempMk2); - } - - IEnumMoniker_Release(enumMoniker1); - IEnumMoniker_Release(enumMoniker2); - - return res; -} -/****************************************************************************** - * CompositeMoniker_Hash - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash) -{ - FIXME("(),stub!\n"); - - return E_NOTIMPL; -} - -/****************************************************************************** - * CompositeMoniker_IsRunning - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_IsRunning(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - IMoniker* pmkNewlyRunning) -{ - IRunningObjectTable* rot; - HRESULT res; - IMoniker *tempMk,*antiMk,*mostRigthMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); - - /* If pmkToLeft is non-NULL, this method composes pmkToLeft with this moniker and calls IsRunning on the result.*/ - if (pmkToLeft!=NULL){ - - CreateGenericComposite(pmkToLeft,iface,&tempMk); - - res = IMoniker_IsRunning(tempMk,pbc,NULL,pmkNewlyRunning); - - IMoniker_Release(tempMk); - - return res; - } - else - /* If pmkToLeft is NULL, this method returns S_OK if pmkNewlyRunning is non-NULL and is equal */ - /* to this moniker */ - - if (pmkNewlyRunning!=NULL) - - if (IMoniker_IsEqual(iface,pmkNewlyRunning)==S_OK) - return S_OK; - - else - return S_FALSE; - - else{ - - if (pbc==NULL) - return E_POINTER; - - /* If pmkToLeft and pmkNewlyRunning are both NULL, this method checks the ROT to see whether */ - /* the moniker is running. If so, the method returns S_OK; otherwise, it recursively calls */ - /* IMoniker::IsRunning on the rightmost component of the composite, passing the remainder of */ - /* the composite as the pmkToLeft parameter for that call. */ - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - res = IRunningObjectTable_IsRunning(rot,iface); - IRunningObjectTable_Release(rot); - - if(res==S_OK) - return S_OK; - - else{ - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - res=IMoniker_IsRunning(mostRigthMk,pbc,tempMk,pmkNewlyRunning); - - IMoniker_Release(tempMk); - IMoniker_Release(mostRigthMk); - - return res; - } - } -} - -/****************************************************************************** - * CompositeMoniker_GetTimeOfLastChange - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_GetTimeOfLastChange(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - FILETIME* pCompositeTime) -{ - IRunningObjectTable* rot; - HRESULT res; - IMoniker *tempMk,*antiMk,*mostRigthMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pCompositeTime); - - if (pCompositeTime==NULL) - return E_INVALIDARG; - - /* This method creates a composite of pmkToLeft (if non-NULL) and this moniker and uses the ROT to */ - /* retrieve the time of last change. If the object is not in the ROT, the method recursively calls */ - /* IMoniker::GetTimeOfLastChange on the rightmost component of the composite, passing the remainder */ - /* of the composite as the pmkToLeft parameter for that call. */ - if (pmkToLeft!=NULL){ - - res=CreateGenericComposite(pmkToLeft,iface,&tempMk); - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - if (IRunningObjectTable_GetTimeOfLastChange(rot,tempMk,pCompositeTime)==S_OK) - return res; - else - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - res=CompositeMonikerImpl_GetTimeOfLastChange(mostRigthMk,pbc,tempMk,pCompositeTime); - - IMoniker_Release(tempMk); - IMoniker_Release(mostRigthMk); - - return res; - } - else - return IMoniker_GetTimeOfLastChange(iface,pbc,NULL,pCompositeTime); -} - -/****************************************************************************** - * CompositeMoniker_Inverse - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk) -{ - HRESULT res; - IMoniker *tempMk,*antiMk,*mostRigthMk,*tempInvMk,*mostRigthInvMk; - IEnumMoniker *enumMoniker; - - TRACE("(%p,%p)\n",iface,ppmk); - - if (ppmk==NULL) - return E_POINTER; - - /* This method returns a composite moniker that consists of the inverses of each of the components */ - /* of the original composite, stored in reverse order */ - - res=CreateAntiMoniker(&antiMk); - res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk); - IMoniker_Release(antiMk); - - if (tempMk==NULL) - - return IMoniker_Inverse(iface,ppmk); - - else{ - - IMoniker_Enum(iface,FALSE,&enumMoniker); - IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL); - IEnumMoniker_Release(enumMoniker); - - IMoniker_Inverse(mostRigthMk,&mostRigthInvMk); - CompositeMonikerImpl_Inverse(tempMk,&tempInvMk); - - res=CreateGenericComposite(mostRigthInvMk,tempInvMk,ppmk); - - IMoniker_Release(tempMk); - IMoniker_Release(mostRigthMk); - IMoniker_Release(tempInvMk); - IMoniker_Release(mostRigthInvMk); - - return res; - } -} - -/****************************************************************************** - * CompositeMoniker_CommonPrefixWith - ******************************************************************************/ -HRESULT WINAPI CompositeMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix) -{ - DWORD mkSys; - HRESULT res1,res2; - IMoniker *tempMk1,*tempMk2,*mostLeftMk1,*mostLeftMk2; - IEnumMoniker *enumMoniker1,*enumMoniker2; - ULONG i,nbCommonMk=0; - - /* If the other moniker is a composite, this method compares the components of each composite from left */ - /* to right. The returned common prefix moniker might also be a composite moniker, depending on how many */ - /* of the leftmost components were common to both monikers. */ - - if (ppmkPrefix==NULL) - return E_POINTER; - - *ppmkPrefix=0; - - if (pmkOther==NULL) - return MK_E_NOPREFIX; - - IMoniker_IsSystemMoniker(pmkOther,&mkSys); - - if((mkSys==MKSYS_GENERICCOMPOSITE)){ - - IMoniker_Enum(iface,TRUE,&enumMoniker1); - IMoniker_Enum(pmkOther,TRUE,&enumMoniker2); - - while(1){ - - res1=IEnumMoniker_Next(enumMoniker1,1,&mostLeftMk1,NULL); - res2=IEnumMoniker_Next(enumMoniker2,1,&mostLeftMk2,NULL); - - if ((res1==S_FALSE) && (res2==S_FALSE)){ - - /* If the monikers are equal, the method returns MK_S_US and sets ppmkPrefix to this moniker.*/ - *ppmkPrefix=iface; - IMoniker_AddRef(iface); - return MK_S_US; - } - else if ((res1==S_OK) && (res2==S_OK)){ - - if (IMoniker_IsEqual(mostLeftMk1,mostLeftMk2)==S_OK) - - nbCommonMk++; - - else - break; - - } - else if (res1==S_OK){ - - /* If the other moniker is a prefix of this moniker, the method returns MK_S_HIM and sets */ - /* ppmkPrefix to the other moniker. */ - *ppmkPrefix=pmkOther; - return MK_S_HIM; - } - else{ - /* If this moniker is a prefix of the other, this method returns MK_S_ME and sets ppmkPrefix */ - /* to this moniker. */ - *ppmkPrefix=iface; - return MK_S_ME; - } - } - - IEnumMoniker_Release(enumMoniker1); - IEnumMoniker_Release(enumMoniker2); - - /* If there is no common prefix, this method returns MK_E_NOPREFIX and sets ppmkPrefix to NULL. */ - if (nbCommonMk==0) - return MK_E_NOPREFIX; - - IEnumMoniker_Reset(enumMoniker1); - - IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL); - - /* if we have more than one commun moniker the result will be a composite moniker */ - if (nbCommonMk>1){ - - /* initialize the common prefix moniker with the composite of two first moniker (from the left)*/ - IEnumMoniker_Next(enumMoniker1,1,&tempMk2,NULL); - CreateGenericComposite(tempMk1,tempMk2,ppmkPrefix); - IMoniker_Release(tempMk1); - IMoniker_Release(tempMk2); - - /* compose all common monikers in a composite moniker */ - for(i=0;iref); - -} - -/****************************************************************************** - * EnumMonikerImpl_Release - ******************************************************************************/ -ULONG WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface) -{ - EnumMonikerImpl *This = (EnumMonikerImpl *)iface; - ULONG i; - ULONG ref; - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* destroy the object if there's no more reference on it */ - if (ref == 0) { - - for(i=0;itabSize;i++) - IMoniker_Release(This->tabMoniker[i]); - - HeapFree(GetProcessHeap(),0,This->tabMoniker); - HeapFree(GetProcessHeap(),0,This); - } - return ref; -} - -/****************************************************************************** - * EnumMonikerImpl_Next - ******************************************************************************/ -HRESULT WINAPI EnumMonikerImpl_Next(IEnumMoniker* iface,ULONG celt, IMoniker** rgelt, ULONG* pceltFethed){ - - EnumMonikerImpl *This = (EnumMonikerImpl *)iface; - ULONG i; - - /* retrieve the requested number of moniker from the current position */ - for(i=0;((This->currentPos < This->tabSize) && (i < celt));i++) - - rgelt[i]=This->tabMoniker[This->currentPos++]; - - if (pceltFethed!=NULL) - *pceltFethed= i; - - if (i==celt) - return S_OK; - else - return S_FALSE; -} - -/****************************************************************************** - * EnumMonikerImpl_Skip - ******************************************************************************/ -HRESULT WINAPI EnumMonikerImpl_Skip(IEnumMoniker* iface,ULONG celt){ - - EnumMonikerImpl *This = (EnumMonikerImpl *)iface; - - if ((This->currentPos+celt) >= This->tabSize) - return S_FALSE; - - This->currentPos+=celt; - - return S_OK; -} - -/****************************************************************************** - * EnumMonikerImpl_Reset - ******************************************************************************/ -HRESULT WINAPI EnumMonikerImpl_Reset(IEnumMoniker* iface){ - - EnumMonikerImpl *This = (EnumMonikerImpl *)iface; - - This->currentPos=0; - - return S_OK; -} - -/****************************************************************************** - * EnumMonikerImpl_Clone - ******************************************************************************/ -HRESULT WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface,IEnumMoniker** ppenum){ - - EnumMonikerImpl *This = (EnumMonikerImpl *)iface; - - return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabSize,This->currentPos,TRUE,ppenum); -} - -/****************************************************************************** - * EnumMonikerImpl_CreateEnumMoniker - ******************************************************************************/ -HRESULT WINAPI EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker, - ULONG tabSize, - ULONG currentPos, - BOOL leftToRigth, - IEnumMoniker ** ppmk) -{ - EnumMonikerImpl* newEnumMoniker; - int i; - - - if (currentPos > tabSize) - return E_INVALIDARG; - - newEnumMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl)); - - if (newEnumMoniker == 0) - return STG_E_INSUFFICIENTMEMORY; - - /* Initialize the virtual function table. */ - newEnumMoniker->lpVtbl = &VT_EnumMonikerImpl; - newEnumMoniker->ref = 0; - - newEnumMoniker->tabSize=tabSize; - newEnumMoniker->currentPos=currentPos; - - newEnumMoniker->tabMoniker=HeapAlloc(GetProcessHeap(),0,tabSize*sizeof(IMoniker)); - - if (newEnumMoniker->tabMoniker==NULL) { - HeapFree(GetProcessHeap(), 0, newEnumMoniker); - return E_OUTOFMEMORY; - } - - if (leftToRigth) - for (i=0;itabMoniker[i]=tabMoniker[i]; - IMoniker_AddRef(tabMoniker[i]); - } - else - for (i=tabSize-1;i>=0;i--){ - - newEnumMoniker->tabMoniker[tabSize-i-1]=tabMoniker[i]; - IMoniker_AddRef(tabMoniker[i]); - } - - *ppmk=(IEnumMoniker*)newEnumMoniker; - - return S_OK; -} - -/****************************************************************************** - * CreateGenericComposite [OLE32.@] - ******************************************************************************/ -HRESULT WINAPI CreateGenericComposite(LPMONIKER pmkFirst, LPMONIKER pmkRest, LPMONIKER* ppmkComposite) -{ - CompositeMonikerImpl* newCompositeMoniker = 0; - HRESULT hr = S_OK; - - TRACE("(%p,%p,%p)\n",pmkFirst,pmkRest,ppmkComposite); - - if (ppmkComposite==NULL) - return E_POINTER; - - *ppmkComposite=0; - - if (pmkFirst==NULL && pmkRest!=NULL){ - - *ppmkComposite=pmkRest; - return S_OK; - } - else if (pmkFirst!=NULL && pmkRest==NULL){ - *ppmkComposite=pmkFirst; - return S_OK; - } - else if (pmkFirst==NULL && pmkRest==NULL) - return S_OK; - - newCompositeMoniker = HeapAlloc(GetProcessHeap(), 0,sizeof(CompositeMonikerImpl)); - - if (newCompositeMoniker == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = CompositeMonikerImpl_Construct(newCompositeMoniker,pmkFirst,pmkRest); - - if (FAILED(hr)){ - - HeapFree(GetProcessHeap(),0,newCompositeMoniker); - return hr; - } - if (newCompositeMoniker->tabLastIndex==1) - - hr = IMoniker_QueryInterface(newCompositeMoniker->tabMoniker[0],&IID_IMoniker,(void**)ppmkComposite); - else - - hr = CompositeMonikerImpl_QueryInterface((IMoniker*)newCompositeMoniker,&IID_IMoniker,(void**)ppmkComposite); - - return hr; -} - -/****************************************************************************** - * MonikerCommonPrefixWith [OLE32.@] - ******************************************************************************/ -HRESULT WINAPI MonikerCommonPrefixWith(IMoniker* pmkThis,IMoniker* pmkOther,IMoniker** ppmkCommon) -{ - FIXME("(),stub!\n"); - return E_NOTIMPL; -} diff --git a/reactos/lib/ole32/datacache.c b/reactos/lib/ole32/datacache.c deleted file mode 100644 index d5e6ed6eb2e..00000000000 --- a/reactos/lib/ole32/datacache.c +++ /dev/null @@ -1,2023 +0,0 @@ -/* - * OLE 2 Data cache - * - * Copyright 1999 Francis Beaudet - * Copyright 2000 Abey George - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * NOTES: - * The OLE2 data cache supports a whole whack of - * interfaces including: - * IDataObject, IPersistStorage, IViewObject2, - * IOleCache2 and IOleCacheControl. - * - * Most of the implementation details are taken from: Inside OLE - * second edition by Kraig Brockschmidt, - * - * NOTES - * - This implementation of the datacache will let your application - * load documents that have embedded OLE objects in them and it will - * also retrieve the metafile representation of those objects. - * - This implementation of the datacache will also allow your - * application to save new documents with OLE objects in them. - * - The main thing that it doesn't do is allow you to activate - * or modify the OLE objects in any way. - * - I haven't found any good documentation on the real usage of - * the streams created by the data cache. In particular, How to - * determine what the XXX stands for in the stream name - * "\002OlePresXXX". It appears to just be a counter. - * - Also, I don't know the real content of the presentation stream - * header. I was able to figure-out where the extent of the object - * was stored and the aspect, but that's about it. - */ -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winerror.h" -#include "wine/unicode.h" -#include "ole2.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/**************************************************************************** - * PresentationDataHeader - * - * This structure represents the header of the \002OlePresXXX stream in - * the OLE object strorage. - * - * Most fields are still unknown. - */ -typedef struct PresentationDataHeader -{ - DWORD unknown1; /* -1 */ - DWORD unknown2; /* 3, possibly CF_METAFILEPICT */ - DWORD unknown3; /* 4, possibly TYMED_ISTREAM */ - DVASPECT dvAspect; - DWORD unknown5; /* -1 */ - - DWORD unknown6; - DWORD unknown7; /* 0 */ - DWORD dwObjectExtentX; - DWORD dwObjectExtentY; - DWORD dwSize; -} PresentationDataHeader; - -/**************************************************************************** - * DataCache - */ -struct DataCache -{ - /* - * List all interface VTables here - */ - IDataObjectVtbl* lpvtbl1; - IUnknownVtbl* lpvtbl2; - IPersistStorageVtbl* lpvtbl3; - IViewObject2Vtbl* lpvtbl4; - IOleCache2Vtbl* lpvtbl5; - IOleCacheControlVtbl* lpvtbl6; - - /* - * Reference count of this object - */ - ULONG ref; - - /* - * IUnknown implementation of the outer object. - */ - IUnknown* outerUnknown; - - /* - * This storage pointer is set through a call to - * IPersistStorage_Load. This is where the visual - * representation of the object is stored. - */ - IStorage* presentationStorage; - - /* - * The user of this object can setup ONE advise sink - * connection with the object. These parameters describe - * that connection. - */ - DWORD sinkAspects; - DWORD sinkAdviseFlag; - IAdviseSink* sinkInterface; - -}; - -typedef struct DataCache DataCache; - -/* - * Here, I define utility macros 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_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*)) - -/* - * Prototypes for the methods of the DataCache class. - */ -static DataCache* DataCache_Construct(REFCLSID clsid, - LPUNKNOWN pUnkOuter); -static void DataCache_Destroy(DataCache* ptrToDestroy); -static HRESULT DataCache_ReadPresentationData(DataCache* this, - DWORD drawAspect, - PresentationDataHeader* header); -static HRESULT DataCache_OpenPresStream(DataCache *this, - DWORD drawAspect, - IStream **pStm); -static HMETAFILE DataCache_ReadPresMetafile(DataCache* this, - DWORD drawAspect); -static void DataCache_FireOnViewChange(DataCache* this, - DWORD aspect, - LONG lindex); - -/* - * Prototypes for the methods of the DataCache class - * that implement non delegating IUnknown methods. - */ -static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface( - IUnknown* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_NDIUnknown_AddRef( - IUnknown* iface); -static ULONG WINAPI DataCache_NDIUnknown_Release( - IUnknown* iface); - -/* - * Prototypes for the methods of the DataCache class - * that implement IDataObject methods. - */ -static HRESULT WINAPI DataCache_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_IDataObject_AddRef( - IDataObject* iface); -static ULONG WINAPI DataCache_IDataObject_Release( - IDataObject* iface); -static HRESULT WINAPI DataCache_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium); -static HRESULT WINAPI DataCache_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium); -static HRESULT WINAPI DataCache_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc); -static HRESULT WINAPI DataCache_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut); -static HRESULT WINAPI DataCache_IDataObject_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease); -static HRESULT WINAPI DataCache_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc); -static HRESULT WINAPI DataCache_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection); -static HRESULT WINAPI DataCache_DUnadvise( - IDataObject* iface, - DWORD dwConnection); -static HRESULT WINAPI DataCache_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise); - -/* - * Prototypes for the methods of the DataCache class - * that implement IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface( - IPersistStorage* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_IPersistStorage_AddRef( - IPersistStorage* iface); -static ULONG WINAPI DataCache_IPersistStorage_Release( - IPersistStorage* iface); -static HRESULT WINAPI DataCache_GetClassID( - IPersistStorage* iface, - CLSID* pClassID); -static HRESULT WINAPI DataCache_IsDirty( - IPersistStorage* iface); -static HRESULT WINAPI DataCache_InitNew( - IPersistStorage* iface, - IStorage* pStg); -static HRESULT WINAPI DataCache_Load( - IPersistStorage* iface, - IStorage* pStg); -static HRESULT WINAPI DataCache_Save( - IPersistStorage* iface, - IStorage* pStg, - BOOL fSameAsLoad); -static HRESULT WINAPI DataCache_SaveCompleted( - IPersistStorage* iface, - IStorage* pStgNew); -static HRESULT WINAPI DataCache_HandsOffStorage( - IPersistStorage* iface); - -/* - * Prototypes for the methods of the DataCache class - * that implement IViewObject2 methods. - */ -static HRESULT WINAPI DataCache_IViewObject2_QueryInterface( - IViewObject2* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_IViewObject2_AddRef( - IViewObject2* iface); -static ULONG WINAPI DataCache_IViewObject2_Release( - IViewObject2* iface); -static HRESULT WINAPI DataCache_Draw( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DVTARGETDEVICE* ptd, - HDC hdcTargetDev, - HDC hdcDraw, - LPCRECTL lprcBounds, - LPCRECTL lprcWBounds, - BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), - ULONG_PTR dwContinue); -static HRESULT WINAPI DataCache_GetColorSet( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DVTARGETDEVICE* ptd, - HDC hicTargetDevice, - LOGPALETTE** ppColorSet); -static HRESULT WINAPI DataCache_Freeze( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DWORD* pdwFreeze); -static HRESULT WINAPI DataCache_Unfreeze( - IViewObject2* iface, - DWORD dwFreeze); -static HRESULT WINAPI DataCache_SetAdvise( - IViewObject2* iface, - DWORD aspects, - DWORD advf, - IAdviseSink* pAdvSink); -static HRESULT WINAPI DataCache_GetAdvise( - IViewObject2* iface, - DWORD* pAspects, - DWORD* pAdvf, - IAdviseSink** ppAdvSink); -static HRESULT WINAPI DataCache_GetExtent( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - DVTARGETDEVICE* ptd, - LPSIZEL lpsizel); - -/* - * Prototypes for the methods of the DataCache class - * that implement IOleCache2 methods. - */ -static HRESULT WINAPI DataCache_IOleCache2_QueryInterface( - IOleCache2* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_IOleCache2_AddRef( - IOleCache2* iface); -static ULONG WINAPI DataCache_IOleCache2_Release( - IOleCache2* iface); -static HRESULT WINAPI DataCache_Cache( - IOleCache2* iface, - FORMATETC* pformatetc, - DWORD advf, - DWORD* pdwConnection); -static HRESULT WINAPI DataCache_Uncache( - IOleCache2* iface, - DWORD dwConnection); -static HRESULT WINAPI DataCache_EnumCache( - IOleCache2* iface, - IEnumSTATDATA** ppenumSTATDATA); -static HRESULT WINAPI DataCache_InitCache( - IOleCache2* iface, - IDataObject* pDataObject); -static HRESULT WINAPI DataCache_IOleCache2_SetData( - IOleCache2* iface, - FORMATETC* pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease); -static HRESULT WINAPI DataCache_UpdateCache( - IOleCache2* iface, - LPDATAOBJECT pDataObject, - DWORD grfUpdf, - LPVOID pReserved); -static HRESULT WINAPI DataCache_DiscardCache( - IOleCache2* iface, - DWORD dwDiscardOptions); - -/* - * Prototypes for the methods of the DataCache class - * that implement IOleCacheControl methods. - */ -static HRESULT WINAPI DataCache_IOleCacheControl_QueryInterface( - IOleCacheControl* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataCache_IOleCacheControl_AddRef( - IOleCacheControl* iface); -static ULONG WINAPI DataCache_IOleCacheControl_Release( - IOleCacheControl* iface); -static HRESULT WINAPI DataCache_OnRun( - IOleCacheControl* iface, - LPDATAOBJECT pDataObject); -static HRESULT WINAPI DataCache_OnStop( - IOleCacheControl* iface); - -/* - * Virtual function tables for the DataCache class. - */ -static IUnknownVtbl DataCache_NDIUnknown_VTable = -{ - DataCache_NDIUnknown_QueryInterface, - DataCache_NDIUnknown_AddRef, - DataCache_NDIUnknown_Release -}; - -static IDataObjectVtbl DataCache_IDataObject_VTable = -{ - DataCache_IDataObject_QueryInterface, - DataCache_IDataObject_AddRef, - DataCache_IDataObject_Release, - DataCache_GetData, - DataCache_GetDataHere, - DataCache_QueryGetData, - DataCache_GetCanonicalFormatEtc, - DataCache_IDataObject_SetData, - DataCache_EnumFormatEtc, - DataCache_DAdvise, - DataCache_DUnadvise, - DataCache_EnumDAdvise -}; - -static IPersistStorageVtbl DataCache_IPersistStorage_VTable = -{ - DataCache_IPersistStorage_QueryInterface, - DataCache_IPersistStorage_AddRef, - DataCache_IPersistStorage_Release, - DataCache_GetClassID, - DataCache_IsDirty, - DataCache_InitNew, - DataCache_Load, - DataCache_Save, - DataCache_SaveCompleted, - DataCache_HandsOffStorage -}; - -static IViewObject2Vtbl DataCache_IViewObject2_VTable = -{ - DataCache_IViewObject2_QueryInterface, - DataCache_IViewObject2_AddRef, - DataCache_IViewObject2_Release, - DataCache_Draw, - DataCache_GetColorSet, - DataCache_Freeze, - DataCache_Unfreeze, - DataCache_SetAdvise, - DataCache_GetAdvise, - DataCache_GetExtent -}; - -static IOleCache2Vtbl DataCache_IOleCache2_VTable = -{ - DataCache_IOleCache2_QueryInterface, - DataCache_IOleCache2_AddRef, - DataCache_IOleCache2_Release, - DataCache_Cache, - DataCache_Uncache, - DataCache_EnumCache, - DataCache_InitCache, - DataCache_IOleCache2_SetData, - DataCache_UpdateCache, - DataCache_DiscardCache -}; - -static IOleCacheControlVtbl DataCache_IOleCacheControl_VTable = -{ - DataCache_IOleCacheControl_QueryInterface, - DataCache_IOleCacheControl_AddRef, - DataCache_IOleCacheControl_Release, - DataCache_OnRun, - DataCache_OnStop -}; - -/****************************************************************************** - * CreateDataCache [OLE32.@] - */ -HRESULT WINAPI CreateDataCache( - LPUNKNOWN pUnkOuter, - REFCLSID rclsid, - REFIID riid, - LPVOID* ppvObj) -{ - DataCache* newCache = NULL; - HRESULT hr = S_OK; - - TRACE("(%s, %p, %s, %p)\n", debugstr_guid(rclsid), pUnkOuter, debugstr_guid(riid), ppvObj); - - /* - * Sanity check - */ - if (ppvObj==0) - return E_POINTER; - - *ppvObj = 0; - - /* - * If this cache is constructed for aggregation, make sure - * the caller is requesting the IUnknown interface. - * This is necessary because it's the only time the non-delegating - * IUnknown pointer can be returned to the outside. - */ - if ( (pUnkOuter!=NULL) && - (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) != 0) ) - return CLASS_E_NOAGGREGATION; - - /* - * Try to construct a new instance of the class. - */ - newCache = DataCache_Construct(rclsid, - pUnkOuter); - - if (newCache == 0) - return E_OUTOFMEMORY; - - /* - * Make sure it supports the interface required by the caller. - */ - hr = IUnknown_QueryInterface((IUnknown*)&(newCache->lpvtbl2), riid, ppvObj); - - /* - * Release the reference obtained in the constructor. If - * the QueryInterface was unsuccessful, it will free the class. - */ - IUnknown_Release((IUnknown*)&(newCache->lpvtbl2)); - - return hr; -} - -/********************************************************* - * Method implementation for DataCache class. - */ -static DataCache* DataCache_Construct( - REFCLSID clsid, - LPUNKNOWN pUnkOuter) -{ - DataCache* newObject = 0; - - /* - * Allocate space for the object. - */ - newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DataCache)); - - if (newObject==0) - return newObject; - - /* - * 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; - - /* - * Start with one reference count. The caller of this function - * must release the interface pointer when it is done. - */ - newObject->ref = 1; - - /* - * Initialize the outer unknown - * We don't keep a reference on the outer unknown since, the way - * aggregation works, our lifetime is at least as large as it's - * lifetime. - */ - if (pUnkOuter==NULL) - pUnkOuter = (IUnknown*)&(newObject->lpvtbl2); - - newObject->outerUnknown = pUnkOuter; - - /* - * Initialize the other members of the structure. - */ - newObject->presentationStorage = NULL; - newObject->sinkAspects = 0; - newObject->sinkAdviseFlag = 0; - newObject->sinkInterface = 0; - - return newObject; -} - -static void DataCache_Destroy( - DataCache* ptrToDestroy) -{ - TRACE("()\n"); - - if (ptrToDestroy->sinkInterface != NULL) - { - IAdviseSink_Release(ptrToDestroy->sinkInterface); - ptrToDestroy->sinkInterface = NULL; - } - - if (ptrToDestroy->presentationStorage != NULL) - { - IStorage_Release(ptrToDestroy->presentationStorage); - ptrToDestroy->presentationStorage = NULL; - } - - /* - * Free the datacache pointer. - */ - HeapFree(GetProcessHeap(), 0, ptrToDestroy); -} - -/************************************************************************ - * DataCache_ReadPresentationData - * - * This method will read information for the requested presentation - * into the given structure. - * - * Param: - * this - Pointer to the DataCache object - * drawAspect - The aspect of the object that we wish to draw. - * header - The structure containing information about this - * aspect of the object. - */ -static HRESULT DataCache_ReadPresentationData( - DataCache* this, - DWORD drawAspect, - PresentationDataHeader* header) -{ - IStream* presStream = NULL; - HRESULT hres; - - /* - * Open the presentation stream. - */ - hres = DataCache_OpenPresStream( - this, - drawAspect, - &presStream); - - if (FAILED(hres)) - return hres; - - /* - * Read the header. - */ - - hres = IStream_Read( - presStream, - header, - sizeof(PresentationDataHeader), - NULL); - - /* - * Cleanup. - */ - IStream_Release(presStream); - - /* - * We don't want to propagate any other error - * code than a failure. - */ - if (hres!=S_OK) - hres = E_FAIL; - - return hres; -} - -/************************************************************************ - * DataCache_FireOnViewChange - * - * This method will fire an OnViewChange notification to the advise - * sink registered with the datacache. - * - * See IAdviseSink::OnViewChange for more details. - */ -static void DataCache_FireOnViewChange( - DataCache* this, - DWORD aspect, - LONG lindex) -{ - TRACE("(%p, %lx, %ld)\n", this, aspect, lindex); - - /* - * The sink supplies a filter when it registers - * we make sure we only send the notifications when that - * filter matches. - */ - if ((this->sinkAspects & aspect) != 0) - { - if (this->sinkInterface != NULL) - { - IAdviseSink_OnViewChange(this->sinkInterface, - aspect, - lindex); - - /* - * Some sinks want to be unregistered automatically when - * the first notification goes out. - */ - if ( (this->sinkAdviseFlag & ADVF_ONLYONCE) != 0) - { - IAdviseSink_Release(this->sinkInterface); - - this->sinkInterface = NULL; - this->sinkAspects = 0; - this->sinkAdviseFlag = 0; - } - } - } -} - -/* Helper for DataCache_OpenPresStream */ -static BOOL DataCache_IsPresentationStream(const STATSTG *elem) -{ - /* The presentation streams have names of the form "\002OlePresXXX", - * where XXX goes from 000 to 999. */ - static const WCHAR OlePres[] = { 2,'O','l','e','P','r','e','s' }; - - LPCWSTR name = elem->pwcsName; - - return (elem->type == STGTY_STREAM) - && (elem->cbSize.u.LowPart >= sizeof(PresentationDataHeader)) - && (strlenW(name) == 11) - && (strncmpW(name, OlePres, 8) == 0) - && (name[8] >= '0') && (name[8] <= '9') - && (name[9] >= '0') && (name[9] <= '9') - && (name[10] >= '0') && (name[10] <= '9'); -} - -/************************************************************************ - * DataCache_OpenPresStream - * - * This method will find the stream for the given presentation. It makes - * no attempt at fallback. - * - * Param: - * this - Pointer to the DataCache object - * drawAspect - The aspect of the object that we wish to draw. - * pStm - A returned stream. It points to the beginning of the - * - presentation data, including the header. - * - * Errors: - * S_OK The requested stream has been opened. - * OLE_E_BLANK The requested stream could not be found. - * Quite a few others I'm too lazy to map correctly. - * - * Notes: - * Algorithm: Scan the elements of the presentation storage, looking - * for presentation streams. For each presentation stream, - * load the header and check to see if the aspect maches. - * - * If a fallback is desired, just opening the first presentation stream - * is a possibility. - */ -static HRESULT DataCache_OpenPresStream( - DataCache *this, - DWORD drawAspect, - IStream **ppStm) -{ - STATSTG elem; - IEnumSTATSTG *pEnum; - HRESULT hr; - - if (!ppStm) return E_POINTER; - - hr = IStorage_EnumElements(this->presentationStorage, 0, NULL, 0, &pEnum); - if (FAILED(hr)) return hr; - - while ((hr = IEnumSTATSTG_Next(pEnum, 1, &elem, NULL)) == S_OK) - { - if (DataCache_IsPresentationStream(&elem)) - { - IStream *pStm; - - hr = IStorage_OpenStream(this->presentationStorage, elem.pwcsName, - NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, - &pStm); - if (SUCCEEDED(hr)) - { - PresentationDataHeader header; - ULONG actual_read; - - hr = IStream_Read(pStm, &header, sizeof(header), &actual_read); - - /* can't use SUCCEEDED(hr): S_FALSE counts as an error */ - if (hr == S_OK && actual_read == sizeof(header) - && header.dvAspect == drawAspect) - { - /* Rewind the stream before returning it. */ - LARGE_INTEGER offset; - offset.u.LowPart = 0; - offset.u.HighPart = 0; - IStream_Seek(pStm, offset, STREAM_SEEK_SET, NULL); - - *ppStm = pStm; - - CoTaskMemFree(elem.pwcsName); - IEnumSTATSTG_Release(pEnum); - - return S_OK; - } - - IStream_Release(pStm); - } - } - - CoTaskMemFree(elem.pwcsName); - } - - IEnumSTATSTG_Release(pEnum); - - return (hr == S_FALSE ? OLE_E_BLANK : hr); -} - -/************************************************************************ - * DataCache_ReadPresentationData - * - * This method will read information for the requested presentation - * into the given structure. - * - * Param: - * this - Pointer to the DataCache object - * drawAspect - The aspect of the object that we wish to draw. - * - * Returns: - * This method returns a metafile handle if it is successful. - * it will return 0 if not. - */ -static HMETAFILE DataCache_ReadPresMetafile( - DataCache* this, - DWORD drawAspect) -{ - LARGE_INTEGER offset; - IStream* presStream = NULL; - HRESULT hres; - void* metafileBits; - STATSTG streamInfo; - HMETAFILE newMetafile = 0; - - /* - * Open the presentation stream. - */ - hres = DataCache_OpenPresStream( - this, - drawAspect, - &presStream); - - if (FAILED(hres)) - return (HMETAFILE)hres; - - /* - * Get the size of the stream. - */ - hres = IStream_Stat(presStream, - &streamInfo, - STATFLAG_NONAME); - - /* - * Skip the header - */ - offset.u.HighPart = 0; - offset.u.LowPart = sizeof(PresentationDataHeader); - - hres = IStream_Seek( - presStream, - offset, - STREAM_SEEK_SET, - NULL); - - streamInfo.cbSize.u.LowPart -= offset.u.LowPart; - - /* - * Allocate a buffer for the metafile bits. - */ - metafileBits = HeapAlloc(GetProcessHeap(), - 0, - streamInfo.cbSize.u.LowPart); - - /* - * Read the metafile bits. - */ - hres = IStream_Read( - presStream, - metafileBits, - streamInfo.cbSize.u.LowPart, - NULL); - - /* - * Create a metafile with those bits. - */ - if (SUCCEEDED(hres)) - { - newMetafile = SetMetaFileBitsEx(streamInfo.cbSize.u.LowPart, metafileBits); - } - - /* - * Cleanup. - */ - HeapFree(GetProcessHeap(), 0, metafileBits); - IStream_Release(presStream); - - if (newMetafile==0) - hres = E_FAIL; - - return newMetafile; -} - -/********************************************************* - * Method implementation for the non delegating IUnknown - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_NDIUnknown_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface( - IUnknown* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_NDIUnknown(DataCache, iface); - - /* - * Perform a sanity check on the parameters. - */ - if ( (this==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = iface; - } - else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) - { - *ppvObject = (IDataObject*)&(this->lpvtbl1); - } - else if ( (memcmp(&IID_IPersistStorage, riid, sizeof(IID_IPersistStorage)) == 0) || - (memcmp(&IID_IPersist, riid, sizeof(IID_IPersist)) == 0) ) - { - *ppvObject = (IPersistStorage*)&(this->lpvtbl3); - } - else if ( (memcmp(&IID_IViewObject, riid, sizeof(IID_IViewObject)) == 0) || - (memcmp(&IID_IViewObject2, riid, sizeof(IID_IViewObject2)) == 0) ) - { - *ppvObject = (IViewObject2*)&(this->lpvtbl4); - } - else if ( (memcmp(&IID_IOleCache, riid, sizeof(IID_IOleCache)) == 0) || - (memcmp(&IID_IOleCache2, riid, sizeof(IID_IOleCache2)) == 0) ) - { - *ppvObject = (IOleCache2*)&(this->lpvtbl5); - } - else if (memcmp(&IID_IOleCacheControl, riid, sizeof(IID_IOleCacheControl)) == 0) - { - *ppvObject = (IOleCacheControl*)&(this->lpvtbl6); - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - { - WARN( "() : asking for unsupported interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; - } - - /* - * Query Interface always increases the reference count by one when it is - * successful. - */ - IUnknown_AddRef((IUnknown*)*ppvObject); - - return S_OK; -} - -/************************************************************************ - * DataCache_NDIUnknown_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static ULONG WINAPI DataCache_NDIUnknown_AddRef( - IUnknown* iface) -{ - _ICOM_THIS_From_NDIUnknown(DataCache, iface); - return InterlockedIncrement(&this->ref); -} - -/************************************************************************ - * DataCache_NDIUnknown_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static ULONG WINAPI DataCache_NDIUnknown_Release( - IUnknown* iface) -{ - _ICOM_THIS_From_NDIUnknown(DataCache, iface); - ULONG ref; - - /* - * Decrease the reference count on this object. - */ - ref = InterlockedDecrement(&this->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref == 0) DataCache_Destroy(this); - - return ref; -} - -/********************************************************* - * Method implementation for the IDataObject - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_IDataObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataCache_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IDataObject(DataCache, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DataCache_IDataObject_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IDataObject_AddRef( - IDataObject* iface) -{ - _ICOM_THIS_From_IDataObject(DataCache, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DataCache_IDataObject_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IDataObject_Release( - IDataObject* iface) -{ - _ICOM_THIS_From_IDataObject(DataCache, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DataCache_GetData - * - * Get Data from a source dataobject using format pformatetcIn->cfFormat - * See Windows documentation for more details on GetData. - * TODO: Currently only CF_METAFILEPICT is implemented - */ -static HRESULT WINAPI DataCache_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium) -{ - HRESULT hr = 0; - HRESULT hrRet = E_UNEXPECTED; - IPersistStorage *pPersistStorage = 0; - IStorage *pStorage = 0; - IStream *pStream = 0; - OLECHAR name[]={ 2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0}; - HGLOBAL hGlobalMF = 0; - void *mfBits = 0; - PresentationDataHeader pdh; - METAFILEPICT *mfPict; - HMETAFILE hMetaFile = 0; - - if (pformatetcIn->cfFormat == CF_METAFILEPICT) - { - /* Get the Persist Storage */ - - hr = IDataObject_QueryInterface(iface, &IID_IPersistStorage, (void**)&pPersistStorage); - - if (hr != S_OK) - goto cleanup; - - /* Create a doc file to copy the doc to a storage */ - - hr = StgCreateDocfile(NULL, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage); - - if (hr != S_OK) - goto cleanup; - - /* Save it to storage */ - - hr = OleSave(pPersistStorage, pStorage, FALSE); - - if (hr != S_OK) - goto cleanup; - - /* Open the Presentation data srteam */ - - hr = IStorage_OpenStream(pStorage, name, 0, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &pStream); - - if (hr != S_OK) - goto cleanup; - - /* Read the presentation header */ - - hr = IStream_Read(pStream, &pdh, sizeof(PresentationDataHeader), NULL); - - if (hr != S_OK) - goto cleanup; - - mfBits = HeapAlloc(GetProcessHeap(), 0, pdh.dwSize); - - /* Read the Metafile bits */ - - hr = IStream_Read(pStream, mfBits, pdh.dwSize, NULL); - - if (hr != S_OK) - goto cleanup; - - /* Create the metafile and place it in the STGMEDIUM structure */ - - hMetaFile = SetMetaFileBitsEx(pdh.dwSize, mfBits); - - hGlobalMF = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, sizeof(METAFILEPICT)); - mfPict = (METAFILEPICT *)GlobalLock(hGlobalMF); - mfPict->hMF = hMetaFile; - - GlobalUnlock(hGlobalMF); - - pmedium->u.hGlobal = hGlobalMF; - pmedium->tymed = TYMED_MFPICT; - hrRet = S_OK; - -cleanup: - - if (mfBits) - HeapFree(GetProcessHeap(), 0, mfBits); - - if (pStream) - IStream_Release(pStream); - - if (pStorage) - IStorage_Release(pStorage); - - if (pPersistStorage) - IPersistStorage_Release(pPersistStorage); - - return hrRet; - } - - /* TODO: Other formats are not implemented */ - - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DataCache_EnumFormatEtc (IDataObject) - * - * The data cache doesn't implement this method. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut) -{ - TRACE("()\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DataCache_IDataObject_SetData (IDataObject) - * - * This method is delegated to the IOleCache2 implementation. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_IDataObject_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease) -{ - IOleCache2* oleCache = NULL; - HRESULT hres; - - TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease); - - hres = IDataObject_QueryInterface(iface, &IID_IOleCache2, (void**)&oleCache); - - if (FAILED(hres)) - return E_UNEXPECTED; - - hres = IOleCache2_SetData(oleCache, pformatetc, pmedium, fRelease); - - IOleCache2_Release(oleCache); - - return hres; -} - -/************************************************************************ - * DataCache_EnumFormatEtc (IDataObject) - * - * The data cache doesn't implement this method. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc) -{ - TRACE("()\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DataCache_DAdvise (IDataObject) - * - * The data cache doesn't support connections. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection) -{ - TRACE("()\n"); - return OLE_E_ADVISENOTSUPPORTED; -} - -/************************************************************************ - * DataCache_DUnadvise (IDataObject) - * - * The data cache doesn't support connections. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_DUnadvise( - IDataObject* iface, - DWORD dwConnection) -{ - TRACE("()\n"); - return OLE_E_NOCONNECTION; -} - -/************************************************************************ - * DataCache_EnumDAdvise (IDataObject) - * - * The data cache doesn't support connections. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DataCache_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise) -{ - TRACE("()\n"); - return OLE_E_ADVISENOTSUPPORTED; -} - -/********************************************************* - * Method implementation for the IDataObject - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_IPersistStorage_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface( - IPersistStorage* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DataCache_IPersistStorage_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IPersistStorage_AddRef( - IPersistStorage* iface) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DataCache_IPersistStorage_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IPersistStorage_Release( - IPersistStorage* iface) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DataCache_GetClassID (IPersistStorage) - * - * The data cache doesn't implement this method. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_GetClassID( - IPersistStorage* iface, - CLSID* pClassID) -{ - TRACE("(%p, %p)\n", iface, pClassID); - return E_NOTIMPL; -} - -/************************************************************************ - * DataCache_IsDirty (IPersistStorage) - * - * Until we actully connect to a running object and retrieve new - * information to it, we never get dirty. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_IsDirty( - IPersistStorage* iface) -{ - TRACE("(%p)\n", iface); - - return S_FALSE; -} - -/************************************************************************ - * DataCache_InitNew (IPersistStorage) - * - * The data cache implementation of IPersistStorage_InitNew simply stores - * the storage pointer. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_InitNew( - IPersistStorage* iface, - IStorage* pStg) -{ - TRACE("(%p, %p)\n", iface, pStg); - - return DataCache_Load(iface, pStg); -} - -/************************************************************************ - * DataCache_Load (IPersistStorage) - * - * The data cache implementation of IPersistStorage_Load doesn't - * actually load anything. Instead, it holds on to the storage pointer - * and it will load the presentation information when the - * IDataObject_GetData or IViewObject2_Draw methods are called. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_Load( - IPersistStorage* iface, - IStorage* pStg) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - TRACE("(%p, %p)\n", iface, pStg); - - if (this->presentationStorage != NULL) - { - IStorage_Release(this->presentationStorage); - } - - this->presentationStorage = pStg; - - if (this->presentationStorage != NULL) - { - IStorage_AddRef(this->presentationStorage); - } - return S_OK; -} - -/************************************************************************ - * DataCache_Save (IPersistStorage) - * - * Until we actully connect to a running object and retrieve new - * information to it, we never have to save anything. However, it is - * our responsability to copy the information when saving to a new - * storage. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_Save( - IPersistStorage* iface, - IStorage* pStg, - BOOL fSameAsLoad) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - TRACE("(%p, %p, %d)\n", iface, pStg, fSameAsLoad); - - if ( (!fSameAsLoad) && - (this->presentationStorage!=NULL) ) - { - return IStorage_CopyTo(this->presentationStorage, - 0, - NULL, - NULL, - pStg); - } - - return S_OK; -} - -/************************************************************************ - * DataCache_SaveCompleted (IPersistStorage) - * - * This method is called to tell the cache to release the storage - * pointer it's currentlu holding. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_SaveCompleted( - IPersistStorage* iface, - IStorage* pStgNew) -{ - TRACE("(%p, %p)\n", iface, pStgNew); - - if (pStgNew) - { - /* - * First, make sure we get our hands off any storage we have. - */ - - DataCache_HandsOffStorage(iface); - - /* - * Then, attach to the new storage. - */ - - DataCache_Load(iface, pStgNew); - } - - return S_OK; -} - -/************************************************************************ - * DataCache_HandsOffStorage (IPersistStorage) - * - * This method is called to tell the cache to release the storage - * pointer it's currentlu holding. - * - * See Windows documentation for more details on IPersistStorage methods. - */ -static HRESULT WINAPI DataCache_HandsOffStorage( - IPersistStorage* iface) -{ - _ICOM_THIS_From_IPersistStorage(DataCache, iface); - - TRACE("(%p)\n", iface); - - if (this->presentationStorage != NULL) - { - IStorage_Release(this->presentationStorage); - this->presentationStorage = NULL; - } - - return S_OK; -} - -/********************************************************* - * Method implementation for the IViewObject2 - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_IViewObject2_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataCache_IViewObject2_QueryInterface( - IViewObject2* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DataCache_IViewObject2_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IViewObject2_AddRef( - IViewObject2* iface) -{ - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DataCache_IViewObject2_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IViewObject2_Release( - IViewObject2* iface) -{ - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DataCache_Draw (IViewObject2) - * - * This method will draw the cached representation of the object - * to the given device context. - * - * See Windows documentation for more details on IViewObject2 methods. - */ -static HRESULT WINAPI DataCache_Draw( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DVTARGETDEVICE* ptd, - HDC hdcTargetDev, - HDC hdcDraw, - LPCRECTL lprcBounds, - LPCRECTL lprcWBounds, - BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), - ULONG_PTR dwContinue) -{ - PresentationDataHeader presData; - HMETAFILE presMetafile = 0; - HRESULT hres; - - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - TRACE("(%p, %lx, %ld, %p, %p, %p, %p, %p, %p, %lx)\n", - iface, - dwDrawAspect, - lindex, - pvAspect, - hdcTargetDev, - hdcDraw, - lprcBounds, - lprcWBounds, - pfnContinue, - dwContinue); - - /* - * Sanity check - */ - if (lprcBounds==NULL) - return E_INVALIDARG; - - /* - * First, we need to retrieve the dimensions of the - * image in the metafile. - */ - hres = DataCache_ReadPresentationData(this, - dwDrawAspect, - &presData); - - if (FAILED(hres)) - return hres; - - /* - * Then, we can extract the metafile itself from the cached - * data. - * - * FIXME Unless it isn't a metafile. I think it could be any CF_XXX type, - * particularly CF_DIB. - */ - presMetafile = DataCache_ReadPresMetafile(this, - dwDrawAspect); - - /* - * If we have a metafile, just draw baby... - * We have to be careful not to modify the state of the - * DC. - */ - if (presMetafile!=0) - { - INT prevMapMode = SetMapMode(hdcDraw, MM_ANISOTROPIC); - SIZE oldWindowExt; - SIZE oldViewportExt; - POINT oldViewportOrg; - - SetWindowExtEx(hdcDraw, - presData.dwObjectExtentX, - presData.dwObjectExtentY, - &oldWindowExt); - - SetViewportExtEx(hdcDraw, - lprcBounds->right - lprcBounds->left, - lprcBounds->bottom - lprcBounds->top, - &oldViewportExt); - - SetViewportOrgEx(hdcDraw, - lprcBounds->left, - lprcBounds->top, - &oldViewportOrg); - - PlayMetaFile(hdcDraw, presMetafile); - - SetWindowExtEx(hdcDraw, - oldWindowExt.cx, - oldWindowExt.cy, - NULL); - - SetViewportExtEx(hdcDraw, - oldViewportExt.cx, - oldViewportExt.cy, - NULL); - - SetViewportOrgEx(hdcDraw, - oldViewportOrg.x, - oldViewportOrg.y, - NULL); - - SetMapMode(hdcDraw, prevMapMode); - - DeleteMetaFile(presMetafile); - } - - return S_OK; -} - -static HRESULT WINAPI DataCache_GetColorSet( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DVTARGETDEVICE* ptd, - HDC hicTargetDevice, - LOGPALETTE** ppColorSet) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_Freeze( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - void* pvAspect, - DWORD* pdwFreeze) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_Unfreeze( - IViewObject2* iface, - DWORD dwFreeze) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DataCache_SetAdvise (IViewObject2) - * - * This sets-up an advisory sink with the data cache. When the object's - * view changes, this sink is called. - * - * See Windows documentation for more details on IViewObject2 methods. - */ -static HRESULT WINAPI DataCache_SetAdvise( - IViewObject2* iface, - DWORD aspects, - DWORD advf, - IAdviseSink* pAdvSink) -{ - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - TRACE("(%p, %lx, %lx, %p)\n", iface, aspects, advf, pAdvSink); - - /* - * A call to this function removes the previous sink - */ - if (this->sinkInterface != NULL) - { - IAdviseSink_Release(this->sinkInterface); - this->sinkInterface = NULL; - this->sinkAspects = 0; - this->sinkAdviseFlag = 0; - } - - /* - * Now, setup the new one. - */ - if (pAdvSink!=NULL) - { - this->sinkInterface = pAdvSink; - this->sinkAspects = aspects; - this->sinkAdviseFlag = advf; - - IAdviseSink_AddRef(this->sinkInterface); - } - - /* - * When the ADVF_PRIMEFIRST flag is set, we have to advise the - * sink immediately. - */ - if (advf & ADVF_PRIMEFIRST) - { - DataCache_FireOnViewChange(this, - DVASPECT_CONTENT, - -1); - } - - return S_OK; -} - -/************************************************************************ - * DataCache_GetAdvise (IViewObject2) - * - * This method queries the current state of the advise sink - * installed on the data cache. - * - * See Windows documentation for more details on IViewObject2 methods. - */ -static HRESULT WINAPI DataCache_GetAdvise( - IViewObject2* iface, - DWORD* pAspects, - DWORD* pAdvf, - IAdviseSink** ppAdvSink) -{ - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - TRACE("(%p, %p, %p, %p)\n", iface, pAspects, pAdvf, ppAdvSink); - - /* - * Just copy all the requested values. - */ - if (pAspects!=NULL) - *pAspects = this->sinkAspects; - - if (pAdvf!=NULL) - *pAdvf = this->sinkAdviseFlag; - - if (ppAdvSink!=NULL) - { - IAdviseSink_QueryInterface(this->sinkInterface, - &IID_IAdviseSink, - (void**)ppAdvSink); - } - - return S_OK; -} - -/************************************************************************ - * DataCache_GetExtent (IViewObject2) - * - * This method retrieves the "natural" size of this cached object. - * - * See Windows documentation for more details on IViewObject2 methods. - */ -static HRESULT WINAPI DataCache_GetExtent( - IViewObject2* iface, - DWORD dwDrawAspect, - LONG lindex, - DVTARGETDEVICE* ptd, - LPSIZEL lpsizel) -{ - PresentationDataHeader presData; - HRESULT hres = E_FAIL; - - _ICOM_THIS_From_IViewObject2(DataCache, iface); - - TRACE("(%p, %lx, %ld, %p, %p)\n", - iface, dwDrawAspect, lindex, ptd, lpsizel); - - /* - * Sanity check - */ - if (lpsizel==NULL) - return E_POINTER; - - /* - * Initialize the out parameter. - */ - lpsizel->cx = 0; - lpsizel->cy = 0; - - /* - * This flag should be set to -1. - */ - if (lindex!=-1) - FIXME("Unimplemented flag lindex = %ld\n", lindex); - - /* - * Right now, we support only the callback from - * the default handler. - */ - if (ptd!=NULL) - FIXME("Unimplemented ptd = %p\n", ptd); - - /* - * Get the presentation information from the - * cache. - */ - hres = DataCache_ReadPresentationData(this, - dwDrawAspect, - &presData); - - if (SUCCEEDED(hres)) - { - lpsizel->cx = presData.dwObjectExtentX; - lpsizel->cy = presData.dwObjectExtentY; - } - - /* - * This method returns OLE_E_BLANK when it fails. - */ - if (FAILED(hres)) - hres = OLE_E_BLANK; - - return hres; -} - - -/********************************************************* - * Method implementation for the IOleCache2 - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_IOleCache2_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataCache_IOleCache2_QueryInterface( - IOleCache2* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IOleCache2(DataCache, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DataCache_IOleCache2_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IOleCache2_AddRef( - IOleCache2* iface) -{ - _ICOM_THIS_From_IOleCache2(DataCache, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DataCache_IOleCache2_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IOleCache2_Release( - IOleCache2* iface) -{ - _ICOM_THIS_From_IOleCache2(DataCache, iface); - - return IUnknown_Release(this->outerUnknown); -} - -static HRESULT WINAPI DataCache_Cache( - IOleCache2* iface, - FORMATETC* pformatetc, - DWORD advf, - DWORD* pdwConnection) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_Uncache( - IOleCache2* iface, - DWORD dwConnection) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_EnumCache( - IOleCache2* iface, - IEnumSTATDATA** ppenumSTATDATA) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_InitCache( - IOleCache2* iface, - IDataObject* pDataObject) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_IOleCache2_SetData( - IOleCache2* iface, - FORMATETC* pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_UpdateCache( - IOleCache2* iface, - LPDATAOBJECT pDataObject, - DWORD grfUpdf, - LPVOID pReserved) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_DiscardCache( - IOleCache2* iface, - DWORD dwDiscardOptions) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - - -/********************************************************* - * Method implementation for the IOleCacheControl - * part of the DataCache class. - */ - -/************************************************************************ - * DataCache_IOleCacheControl_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataCache_IOleCacheControl_QueryInterface( - IOleCacheControl* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DataCache_IOleCacheControl_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IOleCacheControl_AddRef( - IOleCacheControl* iface) -{ - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DataCache_IOleCacheControl_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataCache_IOleCacheControl_Release( - IOleCacheControl* iface) -{ - _ICOM_THIS_From_IOleCacheControl(DataCache, iface); - - return IUnknown_Release(this->outerUnknown); -} - -static HRESULT WINAPI DataCache_OnRun( - IOleCacheControl* iface, - LPDATAOBJECT pDataObject) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI DataCache_OnStop( - IOleCacheControl* iface) -{ - FIXME("stub\n"); - return E_NOTIMPL; -} diff --git a/reactos/lib/ole32/dcom.h b/reactos/lib/ole32/dcom.h deleted file mode 100644 index 3ea35faaf13..00000000000 --- a/reactos/lib/ole32/dcom.h +++ /dev/null @@ -1,515 +0,0 @@ -/*** Autogenerated by WIDL 0.1 from dcom.idl - Do not edit ***/ -#include -#include - -#ifndef __WIDL_DCOM_H -#define __WIDL_DCOM_H -#ifdef __cplusplus -extern "C" { -#endif -#include -typedef MIDL_uhyper ID; - -typedef ID MID; - -typedef ID OXID; - -typedef ID OID; - -typedef ID SETID; - -typedef GUID IPID; - -typedef GUID CID; - -typedef REFGUID REFIPID; - -#define COM_MINOR_VERSION_1 (1) - -#define COM_MINOR_VERSION_2 (2) - -#define COM_MAJOR_VERSION (5) - -#define COM_MINOR_VERSION (3) - -typedef struct tagCOMVERSION { - unsigned short MajorVersion; - unsigned short MinorVersion; -} COMVERSION; - -#define ORPCF_NULL (0) - -#define ORPCF_LOCAL (1) - -#define ORPCF_RESERVED1 (2) - -#define ORPCF_RESERVED2 (4) - -#define ORPCF_RESERVED3 (8) - -#define ORPCF_RESERVED4 (16) - -typedef struct tagORPC_EXTENT { - GUID id; - unsigned long size; - byte data[1]; -} ORPC_EXTENT; - -typedef struct tagORPC_EXTENT_ARRAY { - unsigned long size; - unsigned long reserved; - ORPC_EXTENT **extent; -} ORPC_EXTENT_ARRAY; - -typedef struct tagORPCTHIS { - COMVERSION version; - unsigned long flags; - unsigned long reserved1; - CID cid; - ORPC_EXTENT_ARRAY *extensions; -} ORPCTHIS; - -typedef struct tagORPCTHAT { - unsigned long flags; - ORPC_EXTENT_ARRAY *extensions; -} ORPCTHAT; - -#define NCADG_IP_UDP (0x8) - -#define NCACN_IP_TCP (0x7) - -#define NCADG_IPX (0xe) - -#define NCACN_SPX (0xc) - -#define NCACN_NB_NB (0x12) - -#define NCACN_NB_IPX (0xd) - -#define NCACN_DNET_NSP (0x4) - -#define NCACN_HTTP (0x1f) - -typedef struct tagSTRINGBINDING { - unsigned short wTowerId; - unsigned short aNetworkAddr[1]; -} STRINGBINDING; - -#define COM_C_AUTHZ_NONE (0xffff) - -typedef struct tagSECURITYBINDING { - unsigned short wAuthnSvc; - unsigned short wAuthzSvc; - unsigned short aPrincName[1]; -} SECURITYBINDING; - -typedef struct tagDUALSTRINGARRAY { - unsigned short wNumEntries; - unsigned short wSecurityOffset; - unsigned short aStringArray[1]; -} DUALSTRINGARRAY; - -#define OBJREF_SIGNATURE (0x574f454d) - -#define OBJREF_STANDARD (0x1) - -#define OBJREF_HANDLER (0x2) - -#define OBJREF_CUSTOM (0x4) - -#define SORF_OXRES1 (0x1) - -#define SORF_OXRES2 (0x20) - -#define SORF_OXRES3 (0x40) - -#define SORF_OXRES4 (0x80) - -#define SORF_OXRES5 (0x100) - -#define SORF_OXRES6 (0x200) - -#define SORF_OXRES7 (0x400) - -#define SORF_OXRES8 (0x800) - -#define SORF_NULL (0x0) - -#define SORF_NOPING (0x1000) - -typedef struct tagSTDOBJREF { - unsigned long flags; - unsigned long cPublicRefs; - OXID oxid; - OID oid; - IPID ipid; -} STDOBJREF; - -typedef struct tagOBJREF { - unsigned long signature; - unsigned long flags; - GUID iid; - union { - struct OR_STANDARD { - STDOBJREF std; - DUALSTRINGARRAY saResAddr; - } u_standard; - struct OR_HANDLER { - STDOBJREF std; - CLSID clsid; - DUALSTRINGARRAY saResAddr; - } u_handler; - struct OR_CUSTOM { - CLSID clsid; - unsigned long cbExtension; - unsigned long size; - byte *pData; - } u_custom; - } u_objref; -} OBJREF; - -typedef struct tagMInterfacePointer { - ULONG ulCntData; - BYTE abData[1]; -} MInterfacePointer; - -typedef MInterfacePointer *PMInterfacePointer; - -#ifndef __IRemUnknown_FWD_DEFINED__ -#define __IRemUnknown_FWD_DEFINED__ -typedef struct IRemUnknown IRemUnknown; -#endif - -typedef IRemUnknown *LPREMUNKNOWN; - -typedef struct tagREMQIRESULT { - HRESULT hResult; - STDOBJREF std; -} REMQIRESULT; - -typedef struct tagREMINTERFACEREF { - IPID ipid; - unsigned long cPublicRefs; - unsigned long cPrivateRefs; -} REMINTERFACEREF; - -/***************************************************************************** - * IRemUnknown interface - */ -#ifndef __IRemUnknown_INTERFACE_DEFINED__ -#define __IRemUnknown_INTERFACE_DEFINED__ - -DEFINE_GUID(IID_IRemUnknown, 0x00000131, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46); -#if defined(__cplusplus) && !defined(CINTERFACE) -struct IRemUnknown : public IUnknown -{ - virtual HRESULT STDMETHODCALLTYPE RemQueryInterface( - REFIPID ripid, - unsigned long cRefs, - unsigned short cIids, - IID* iids, - REMQIRESULT** ppQIResults) = 0; - - virtual HRESULT STDMETHODCALLTYPE RemAddRef( - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs, - HRESULT* pResults) = 0; - - virtual HRESULT STDMETHODCALLTYPE RemRelease( - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs) = 0; - -}; -#else -typedef struct IRemUnknownVtbl IRemUnknownVtbl; -struct IRemUnknown { - const IRemUnknownVtbl* lpVtbl; -}; -struct IRemUnknownVtbl { - BEGIN_INTERFACE - - /*** IUnknown methods ***/ - HRESULT (STDMETHODCALLTYPE *QueryInterface)( - IRemUnknown* This, - REFIID riid, - void** ppvObject); - - ULONG (STDMETHODCALLTYPE *AddRef)( - IRemUnknown* This); - - ULONG (STDMETHODCALLTYPE *Release)( - IRemUnknown* This); - - /*** IRemUnknown methods ***/ - HRESULT (STDMETHODCALLTYPE *RemQueryInterface)( - IRemUnknown* This, - REFIPID ripid, - unsigned long cRefs, - unsigned short cIids, - IID* iids, - REMQIRESULT** ppQIResults); - - HRESULT (STDMETHODCALLTYPE *RemAddRef)( - IRemUnknown* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs, - HRESULT* pResults); - - HRESULT (STDMETHODCALLTYPE *RemRelease)( - IRemUnknown* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs); - - END_INTERFACE -}; - -#ifdef COBJMACROS -/*** IUnknown methods ***/ -#define IRemUnknown_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) -#define IRemUnknown_AddRef(p) (p)->lpVtbl->AddRef(p) -#define IRemUnknown_Release(p) (p)->lpVtbl->Release(p) -/*** IRemUnknown methods ***/ -#define IRemUnknown_RemQueryInterface(p,a,b,c,d,e) (p)->lpVtbl->RemQueryInterface(p,a,b,c,d,e) -#define IRemUnknown_RemAddRef(p,a,b,c) (p)->lpVtbl->RemAddRef(p,a,b,c) -#define IRemUnknown_RemRelease(p,a,b) (p)->lpVtbl->RemRelease(p,a,b) -#endif - -#endif - -#define IRemUnknown_METHODS \ - /*** IUnknown methods ***/ \ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; \ - STDMETHOD_(ULONG,AddRef)(THIS) PURE; \ - STDMETHOD_(ULONG,Release)(THIS) PURE; \ - /*** IRemUnknown methods ***/ \ - STDMETHOD_(HRESULT,RemQueryInterface)(THIS_ REFIPID ripid, unsigned long cRefs, unsigned short cIids, IID* iids, REMQIRESULT** ppQIResults) PURE; \ - STDMETHOD_(HRESULT,RemAddRef)(THIS_ unsigned short cInterfaceRefs, REMINTERFACEREF* InterfaceRefs, HRESULT* pResults) PURE; \ - STDMETHOD_(HRESULT,RemRelease)(THIS_ unsigned short cInterfaceRefs, REMINTERFACEREF* InterfaceRefs) PURE; - -HRESULT CALLBACK IRemUnknown_RemQueryInterface_Proxy( - IRemUnknown* This, - REFIPID ripid, - unsigned long cRefs, - unsigned short cIids, - IID* iids, - REMQIRESULT** ppQIResults); -void __RPC_STUB IRemUnknown_RemQueryInterface_Stub( - struct IRpcStubBuffer* This, - struct IRpcChannelBuffer* pRpcChannelBuffer, - PRPC_MESSAGE pRpcMessage, - DWORD* pdwStubPhase); -HRESULT CALLBACK IRemUnknown_RemAddRef_Proxy( - IRemUnknown* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs, - HRESULT* pResults); -void __RPC_STUB IRemUnknown_RemAddRef_Stub( - struct IRpcStubBuffer* This, - struct IRpcChannelBuffer* pRpcChannelBuffer, - PRPC_MESSAGE pRpcMessage, - DWORD* pdwStubPhase); -HRESULT CALLBACK IRemUnknown_RemRelease_Proxy( - IRemUnknown* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs); -void __RPC_STUB IRemUnknown_RemRelease_Stub( - struct IRpcStubBuffer* This, - struct IRpcChannelBuffer* pRpcChannelBuffer, - PRPC_MESSAGE pRpcMessage, - DWORD* pdwStubPhase); - -#endif /* __IRemUnknown_INTERFACE_DEFINED__ */ - -#ifndef __IRemUnknown2_FWD_DEFINED__ -#define __IRemUnknown2_FWD_DEFINED__ -typedef struct IRemUnknown2 IRemUnknown2; -#endif - -typedef IRemUnknown2 *LPREMUNKNOWN2; - -/***************************************************************************** - * IRemUnknown2 interface - */ -#ifndef __IRemUnknown2_INTERFACE_DEFINED__ -#define __IRemUnknown2_INTERFACE_DEFINED__ - -DEFINE_GUID(IID_IRemUnknown2, 0x00000142, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46); -#if defined(__cplusplus) && !defined(CINTERFACE) -struct IRemUnknown2 : public IRemUnknown -{ - virtual HRESULT STDMETHODCALLTYPE RemQueryInterface2( - REFIPID ripid, - unsigned short cIids, - IID* iids, - HRESULT* phr, - MInterfacePointer** ppMIF) = 0; - -}; -#else -typedef struct IRemUnknown2Vtbl IRemUnknown2Vtbl; -struct IRemUnknown2 { - const IRemUnknown2Vtbl* lpVtbl; -}; -struct IRemUnknown2Vtbl { - BEGIN_INTERFACE - - /*** IUnknown methods ***/ - HRESULT (STDMETHODCALLTYPE *QueryInterface)( - IRemUnknown2* This, - REFIID riid, - void** ppvObject); - - ULONG (STDMETHODCALLTYPE *AddRef)( - IRemUnknown2* This); - - ULONG (STDMETHODCALLTYPE *Release)( - IRemUnknown2* This); - - /*** IRemUnknown methods ***/ - HRESULT (STDMETHODCALLTYPE *RemQueryInterface)( - IRemUnknown2* This, - REFIPID ripid, - unsigned long cRefs, - unsigned short cIids, - IID* iids, - REMQIRESULT** ppQIResults); - - HRESULT (STDMETHODCALLTYPE *RemAddRef)( - IRemUnknown2* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs, - HRESULT* pResults); - - HRESULT (STDMETHODCALLTYPE *RemRelease)( - IRemUnknown2* This, - unsigned short cInterfaceRefs, - REMINTERFACEREF* InterfaceRefs); - - /*** IRemUnknown2 methods ***/ - HRESULT (STDMETHODCALLTYPE *RemQueryInterface2)( - IRemUnknown2* This, - REFIPID ripid, - unsigned short cIids, - IID* iids, - HRESULT* phr, - MInterfacePointer** ppMIF); - - END_INTERFACE -}; - -#ifdef COBJMACROS -/*** IUnknown methods ***/ -#define IRemUnknown2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) -#define IRemUnknown2_AddRef(p) (p)->lpVtbl->AddRef(p) -#define IRemUnknown2_Release(p) (p)->lpVtbl->Release(p) -/*** IRemUnknown methods ***/ -#define IRemUnknown2_RemQueryInterface(p,a,b,c,d,e) (p)->lpVtbl->RemQueryInterface(p,a,b,c,d,e) -#define IRemUnknown2_RemAddRef(p,a,b,c) (p)->lpVtbl->RemAddRef(p,a,b,c) -#define IRemUnknown2_RemRelease(p,a,b) (p)->lpVtbl->RemRelease(p,a,b) -/*** IRemUnknown2 methods ***/ -#define IRemUnknown2_RemQueryInterface2(p,a,b,c,d,e) (p)->lpVtbl->RemQueryInterface2(p,a,b,c,d,e) -#endif - -#endif - -#define IRemUnknown2_METHODS \ - /*** IUnknown methods ***/ \ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; \ - STDMETHOD_(ULONG,AddRef)(THIS) PURE; \ - STDMETHOD_(ULONG,Release)(THIS) PURE; \ - /*** IRemUnknown methods ***/ \ - STDMETHOD_(HRESULT,RemQueryInterface)(THIS_ REFIPID ripid, unsigned long cRefs, unsigned short cIids, IID* iids, REMQIRESULT** ppQIResults) PURE; \ - STDMETHOD_(HRESULT,RemAddRef)(THIS_ unsigned short cInterfaceRefs, REMINTERFACEREF* InterfaceRefs, HRESULT* pResults) PURE; \ - STDMETHOD_(HRESULT,RemRelease)(THIS_ unsigned short cInterfaceRefs, REMINTERFACEREF* InterfaceRefs) PURE; \ - /*** IRemUnknown2 methods ***/ \ - STDMETHOD_(HRESULT,RemQueryInterface2)(THIS_ REFIPID ripid, unsigned short cIids, IID* iids, HRESULT* phr, MInterfacePointer** ppMIF) PURE; - -HRESULT CALLBACK IRemUnknown2_RemQueryInterface2_Proxy( - IRemUnknown2* This, - REFIPID ripid, - unsigned short cIids, - IID* iids, - HRESULT* phr, - MInterfacePointer** ppMIF); -void __RPC_STUB IRemUnknown2_RemQueryInterface2_Stub( - struct IRpcStubBuffer* This, - struct IRpcChannelBuffer* pRpcChannelBuffer, - PRPC_MESSAGE pRpcMessage, - DWORD* pdwStubPhase); - -#endif /* __IRemUnknown2_INTERFACE_DEFINED__ */ - -#if 0 -/***************************************************************************** - * IOXIDResolver interface (v0.0) - */ -DEFINE_GUID(IID_IOXIDResolver, 0x99fcfec4, 0x5260, 0x101b, 0xbb,0xcb, 0x00,0xaa,0x00,0x21,0x34,0x7a); -extern RPC_IF_HANDLE IOXIDResolver_v0_0_c_ifspec; -extern RPC_IF_HANDLE IOXIDResolver_v0_0_s_ifspec; -error_status_t ResolveOxid( - handle_t hRpc, - OXID* pOxid, - unsigned short cRequestedProtseqs, - unsigned short arRequestedProtseqs[], - DUALSTRINGARRAY** ppdsaOxidBindings, - IPID* pipidRemUnknown, - DWORD* pAuthnHint); -error_status_t SimplePing( - handle_t hRpc, - SETID* pSetId); -error_status_t ComplexPing( - handle_t hRpc, - SETID* pSetId, - unsigned short SequenceNum, - unsigned short cAddToSet, - unsigned short cDelFromSet, - OID AddToSet[], - OID DelFromSet[], - unsigned short* pPingBackoffFactor); -error_status_t ServerAlive( - handle_t hRpc); -error_status_t ResolveOxid2( - handle_t hRpc, - OXID* pOxid, - unsigned short cRequestedProtseqs, - unsigned short arRequestedProtseqs[], - DUALSTRINGARRAY** ppdsaOxidBindings, - IPID* pipidRemUnknown, - DWORD* pAuthnHint, - COMVERSION* pComVersion); - -#define MODE_GET_CLASS_OBJECT (0xffffffff) - -/***************************************************************************** - * IRemoteActivation interface (v0.0) - */ -DEFINE_GUID(IID_IRemoteActivation, 0x4d9f4ab8, 0x7d1c, 0x11cf, 0x86,0x1e, 0x00,0x20,0xaf,0x6e,0x7c,0x57); -extern RPC_IF_HANDLE IRemoteActivation_v0_0_c_ifspec; -extern RPC_IF_HANDLE IRemoteActivation_v0_0_s_ifspec; -HRESULT RemoteActivation( - handle_t hRpc, - ORPCTHIS* ORPCthis, - ORPCTHAT* ORPCthat, - GUID* Clsid, - WCHAR* pwszObjectName, - MInterfacePointer* pObjectStorage, - DWORD ClientImpLevel, - DWORD Mode, - DWORD Interfaces, - IID* pIIDs, - unsigned short cRequestedProtseqs, - unsigned short RequestedProtseqs[], - OXID* pOxid, - DUALSTRINGARRAY** ppdsaOxidBindings, - IPID* pipidRemUnknown, - DWORD* pAuthnHint, - COMVERSION* pServerVersion, - HRESULT* phr, - MInterfacePointer** ppInterfaceData, - HRESULT* pResults); - -#endif -#ifdef __cplusplus -} -#endif -#endif /* __WIDL_DCOM_H */ diff --git a/reactos/lib/ole32/dcom.idl b/reactos/lib/ole32/dcom.idl deleted file mode 100644 index a5bebc5eb50..00000000000 --- a/reactos/lib/ole32/dcom.idl +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright 2003 Ove Kåven, TransGaming Technologies - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* see http://www.microsoft.com/msj/0398/dcom.htm */ -/* and the official DCOM specification - * (there's a copy at http://www.grimes.demon.co.uk/DCOM/DCOMSpec.htm) */ - -import "unknwn.idl"; - -[ - uuid(99fcfe60-5260-101b-bbcb-00aa0021347a), - pointer_default(unique) -] -interface ObjectRpcBaseTypes -{ - typedef unsigned hyper ID; - typedef ID MID; - typedef ID OXID; - typedef ID OID; - typedef ID SETID; - typedef GUID IPID; - typedef GUID CID; - typedef REFGUID REFIPID; - - const unsigned short COM_MINOR_VERSION_1 = 1; - const unsigned short COM_MINOR_VERSION_2 = 2; - - const unsigned short COM_MAJOR_VERSION = 5; - const unsigned short COM_MINOR_VERSION = 3; - - typedef struct tagCOMVERSION { - unsigned short MajorVersion; - unsigned short MinorVersion; - } COMVERSION; - - const unsigned long ORPCF_NULL = 0; - const unsigned long ORPCF_LOCAL = 1; - const unsigned long ORPCF_RESERVED1 = 2; - const unsigned long ORPCF_RESERVED2 = 4; - const unsigned long ORPCF_RESERVED3 = 8; - const unsigned long ORPCF_RESERVED4 = 16; - - typedef struct tagORPC_EXTENT { - GUID id; - unsigned long size; - [size_is((size+7)&~7)] byte data[]; - } ORPC_EXTENT; - - typedef struct tagORPC_EXTENT_ARRAY { - unsigned long size; - unsigned long reserved; - [size_is((size+1)&~1,), unique] ORPC_EXTENT **extent; - } ORPC_EXTENT_ARRAY; - - typedef struct tagORPCTHIS { - COMVERSION version; - unsigned long flags; - unsigned long reserved1; - CID cid; - [unique] ORPC_EXTENT_ARRAY *extensions; - } ORPCTHIS; - - typedef struct tagORPCTHAT { - unsigned long flags; - [unique] ORPC_EXTENT_ARRAY *extensions; - } ORPCTHAT; - - const unsigned short NCADG_IP_UDP = 0x08; - const unsigned short NCACN_IP_TCP = 0x07; - const unsigned short NCADG_IPX = 0x0E; - const unsigned short NCACN_SPX = 0x0C; - const unsigned short NCACN_NB_NB = 0x12; - const unsigned short NCACN_NB_IPX = 0x0D; - const unsigned short NCACN_DNET_NSP = 0x04; - const unsigned short NCACN_HTTP = 0x1F; - - typedef struct tagSTRINGBINDING { - unsigned short wTowerId; - [string] unsigned short aNetworkAddr[]; - } STRINGBINDING; - - const unsigned short COM_C_AUTHZ_NONE = 0xffff; - - typedef struct tagSECURITYBINDING { - unsigned short wAuthnSvc; - unsigned short wAuthzSvc; - [string] unsigned short aPrincName[]; - } SECURITYBINDING; - - typedef struct tagDUALSTRINGARRAY { - unsigned short wNumEntries; - unsigned short wSecurityOffset; - [size_is(wNumEntries)] unsigned short aStringArray[]; - } DUALSTRINGARRAY; - - const unsigned long OBJREF_SIGNATURE = 0x574f454d; /* "MEOW" */ - const unsigned long OBJREF_STANDARD = 0x1; - const unsigned long OBJREF_HANDLER = 0x2; - const unsigned long OBJREF_CUSTOM = 0x4; - const unsigned long SORF_OXRES1 = 0x1; - const unsigned long SORF_OXRES2 = 0x20; - const unsigned long SORF_OXRES3 = 0x40; - const unsigned long SORF_OXRES4 = 0x80; - const unsigned long SORF_OXRES5 = 0x100; - const unsigned long SORF_OXRES6 = 0x200; - const unsigned long SORF_OXRES7 = 0x400; - const unsigned long SORF_OXRES8 = 0x800; - const unsigned long SORF_NULL = 0x0; - const unsigned long SORF_NOPING = 0x1000; - - typedef struct tagSTDOBJREF { - unsigned long flags; - unsigned long cPublicRefs; - OXID oxid; - OID oid; - IPID ipid; - } STDOBJREF; - - typedef struct tagOBJREF { - unsigned long signature; - unsigned long flags; - GUID iid; - [switch_is(flags)] union { - [case(OBJREF_STANDARD)] struct OR_STANDARD { - STDOBJREF std; - DUALSTRINGARRAY saResAddr; - } u_standard; - [case(OBJREF_HANDLER)] struct OR_HANDLER { - STDOBJREF std; - CLSID clsid; - DUALSTRINGARRAY saResAddr; - } u_handler; - [case(OBJREF_CUSTOM)] struct OR_CUSTOM { - CLSID clsid; - unsigned long cbExtension; - unsigned long size; - [size_is(size), ref] byte *pData; - } u_custom; - } u_objref; - } OBJREF; - - typedef struct tagMInterfacePointer { - ULONG ulCntData; - [size_is(ulCntData)] BYTE abData[]; - } MInterfacePointer; - - typedef [unique] MInterfacePointer *PMInterfacePointer; - -} /* interface ObjectRpcBaseTypes */ - -[ - object, - uuid(00000131-0000-0000-C000-000000000046) -] -interface IRemUnknown : IUnknown -{ - typedef [unique] IRemUnknown *LPREMUNKNOWN; - - typedef struct tagREMQIRESULT { - HRESULT hResult; - STDOBJREF std; - } REMQIRESULT; - - typedef struct tagREMINTERFACEREF { - IPID ipid; - unsigned long cPublicRefs; - unsigned long cPrivateRefs; - } REMINTERFACEREF; - - HRESULT RemQueryInterface( - [in] REFIPID ripid, - [in] unsigned long cRefs, - [in] unsigned short cIids, - [in, size_is(cIids)] IID *iids, - [out, size_is(,cIids)] REMQIRESULT **ppQIResults); - - HRESULT RemAddRef( - [in] unsigned short cInterfaceRefs, - [in, size_is(cInterfaceRefs)] REMINTERFACEREF* InterfaceRefs, - [out, size_is(cInterfaceRefs)] HRESULT *pResults); - - HRESULT RemRelease( - [in] unsigned short cInterfaceRefs, - [in, size_is(cInterfaceRefs)] REMINTERFACEREF* InterfaceRefs); -} - -[ - object, - uuid(00000142-0000-0000-C000-000000000046) -] -interface IRemUnknown2 : IRemUnknown -{ - typedef [unique] IRemUnknown2 *LPREMUNKNOWN2; - - HRESULT RemQueryInterface2( - [in] REFIPID ripid, - [in] unsigned short cIids, - [in, size_is(cIids)] IID *iids, - [out, size_is(cIids)] HRESULT *phr, - [out, size_is(cIids)] MInterfacePointer **ppMIF); -} - -cpp_quote("#if 0") -[ - uuid(99fcfec4-5260-101b-bbcb-00aa0021347a), - pointer_default(unique) -] -interface IOXIDResolver -{ - [idempotent] error_status_t ResolveOxid( - [in] handle_t hRpc, - [in] OXID *pOxid, - [in] unsigned short cRequestedProtseqs, - [in, ref, size_is(cRequestedProtseqs)] unsigned short arRequestedProtseqs[], - [out, ref] DUALSTRINGARRAY **ppdsaOxidBindings, - [out, ref] IPID *pipidRemUnknown, - [out, ref] DWORD *pAuthnHint); - - [idempotent] error_status_t SimplePing( - [in] handle_t hRpc, - [in] SETID *pSetId); - - [idempotent] error_status_t ComplexPing( - [in] handle_t hRpc, - [in, out] SETID *pSetId, - [in] unsigned short SequenceNum, - [in] unsigned short cAddToSet, - [in] unsigned short cDelFromSet, - [in, unique, size_is(cAddToSet)] OID AddToSet[], - [in, unique, size_is(cDelFromSet)] OID DelFromSet[], - [out] unsigned short *pPingBackoffFactor); - - [idempotent] error_status_t ServerAlive( - [in] handle_t hRpc); - - [idempotent] error_status_t ResolveOxid2( - [in] handle_t hRpc, - [in] OXID *pOxid, - [in] unsigned short cRequestedProtseqs, - [in, ref, size_is(cRequestedProtseqs)] unsigned short arRequestedProtseqs[], - [out, ref] DUALSTRINGARRAY **ppdsaOxidBindings, - [out, ref] IPID *pipidRemUnknown, - [out, ref] DWORD *pAuthnHint, - [out, ref] COMVERSION *pComVersion); -} - -[ - uuid(4d9f4ab8-7d1c-11cf-861e-0020af6e7c57), - pointer_default(unique) -] -interface IRemoteActivation -{ - const unsigned long MODE_GET_CLASS_OBJECT = 0xffffffff; - - HRESULT RemoteActivation( - [in] handle_t hRpc, - [in] ORPCTHIS *ORPCthis, - [out] ORPCTHAT *ORPCthat, - [in] GUID *Clsid, - [in, string, unique] WCHAR *pwszObjectName, - [in, unique] MInterfacePointer *pObjectStorage, - [in] DWORD ClientImpLevel, - [in] DWORD Mode, - [in] DWORD Interfaces, - [in, unique, size_is(Interfaces)] IID *pIIDs, - [in] unsigned short cRequestedProtseqs, - [in, size_is(cRequestedProtseqs)] unsigned short RequestedProtseqs[], - [out] OXID *pOxid, - [out] DUALSTRINGARRAY **ppdsaOxidBindings, - [out] IPID *pipidRemUnknown, - [out] DWORD *pAuthnHint, - [out] COMVERSION *pServerVersion, - [out] HRESULT *phr, - [out,size_is(Interfaces)] MInterfacePointer **ppInterfaceData, - [out,size_is(Interfaces)] HRESULT *pResults); -} -cpp_quote("#endif") diff --git a/reactos/lib/ole32/defaulthandler.c b/reactos/lib/ole32/defaulthandler.c deleted file mode 100644 index 956709cda1b..00000000000 --- a/reactos/lib/ole32/defaulthandler.c +++ /dev/null @@ -1,1696 +0,0 @@ -/* - * OLE 2 default object handler - * - * Copyright 1999 Francis Beaudet - * Copyright 2000 Abey George - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * NOTES: - * The OLE2 default object handler supports a whole whack of - * interfaces including: - * IOleObject, IDataObject, IPersistStorage, IViewObject2, - * IRunnableObject, IOleCache2, IOleCacheControl and much more. - * - * All the implementation details are taken from: Inside OLE - * second edition by Kraig Brockschmidt, - * - * TODO - * - This implementation of the default handler does not launch the - * server in the DoVerb, Update, GetData, GetDataHere and Run - * methods. When it is fixed to do so, all the methods will have - * to be revisited to allow delegating to the running object - * - * - All methods in the class that use the class ID should be - * aware that it is possible for a class to be treated as - * another one and go into emulation mode. Nothing has been - * done in this area. - * - * - Some functions still return E_NOTIMPL they have to be - * implemented. Most of those are related to the running of the - * actual server. - * - * - All the methods related to notification and advise sinks are - * in place but no notifications are sent to the sinks yet. - */ -#include -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winerror.h" -#include "wine/unicode.h" -#include "ole2.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/**************************************************************************** - * DefaultHandler - * - */ -struct DefaultHandler -{ - /* - * List all interface VTables here - */ - IOleObjectVtbl* lpvtbl1; - IUnknownVtbl* lpvtbl2; - IDataObjectVtbl* lpvtbl3; - IRunnableObjectVtbl* lpvtbl4; - - /* - * Reference count of this object - */ - ULONG ref; - - /* - * IUnknown implementation of the outer object. - */ - IUnknown* outerUnknown; - - /* - * Class Id that this handler object represents. - */ - CLSID clsid; - - /* - * IUnknown implementation of the datacache. - */ - IUnknown* dataCache; - - /* - * Client site for the embedded object. - */ - IOleClientSite* clientSite; - - /* - * The IOleAdviseHolder maintains the connections - * on behalf of the default handler. - */ - IOleAdviseHolder* oleAdviseHolder; - - /* - * The IDataAdviseHolder maintains the data - * connections on behalf of the default handler. - */ - IDataAdviseHolder* dataAdviseHolder; - - /* - * Name of the container and object contained - */ - LPWSTR containerApp; - LPWSTR containerObj; - -}; - -typedef struct DefaultHandler DefaultHandler; - -/* - * Here, I define utility macros 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*)) - -/* - * Prototypes for the methods of the DefaultHandler class. - */ -static DefaultHandler* DefaultHandler_Construct(REFCLSID clsid, - LPUNKNOWN pUnkOuter); -static void DefaultHandler_Destroy(DefaultHandler* ptrToDestroy); - -/* - * Prototypes for the methods of the DefaultHandler class - * that implement non delegating IUnknown methods. - */ -static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface( - IUnknown* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( - IUnknown* iface); -static ULONG WINAPI DefaultHandler_NDIUnknown_Release( - IUnknown* iface); - -/* - * Prototypes for the methods of the DefaultHandler class - * that implement IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_QueryInterface( - IOleObject* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DefaultHandler_AddRef( - IOleObject* iface); -static ULONG WINAPI DefaultHandler_Release( - IOleObject* iface); -static HRESULT WINAPI DefaultHandler_SetClientSite( - IOleObject* iface, - IOleClientSite* pClientSite); -static HRESULT WINAPI DefaultHandler_GetClientSite( - IOleObject* iface, - IOleClientSite** ppClientSite); -static HRESULT WINAPI DefaultHandler_SetHostNames( - IOleObject* iface, - LPCOLESTR szContainerApp, - LPCOLESTR szContainerObj); -static HRESULT WINAPI DefaultHandler_Close( - IOleObject* iface, - DWORD dwSaveOption); -static HRESULT WINAPI DefaultHandler_SetMoniker( - IOleObject* iface, - DWORD dwWhichMoniker, - IMoniker* pmk); -static HRESULT WINAPI DefaultHandler_GetMoniker( - IOleObject* iface, - DWORD dwAssign, - DWORD dwWhichMoniker, - IMoniker** ppmk); -static HRESULT WINAPI DefaultHandler_InitFromData( - IOleObject* iface, - IDataObject* pDataObject, - BOOL fCreation, - DWORD dwReserved); -static HRESULT WINAPI DefaultHandler_GetClipboardData( - IOleObject* iface, - DWORD dwReserved, - IDataObject** ppDataObject); -static HRESULT WINAPI DefaultHandler_DoVerb( - IOleObject* iface, - LONG iVerb, - struct tagMSG* lpmsg, - IOleClientSite* pActiveSite, - LONG lindex, - HWND hwndParent, - LPCRECT lprcPosRect); -static HRESULT WINAPI DefaultHandler_EnumVerbs( - IOleObject* iface, - IEnumOLEVERB** ppEnumOleVerb); -static HRESULT WINAPI DefaultHandler_Update( - IOleObject* iface); -static HRESULT WINAPI DefaultHandler_IsUpToDate( - IOleObject* iface); -static HRESULT WINAPI DefaultHandler_GetUserClassID( - IOleObject* iface, - CLSID* pClsid); -static HRESULT WINAPI DefaultHandler_GetUserType( - IOleObject* iface, - DWORD dwFormOfType, - LPOLESTR* pszUserType); -static HRESULT WINAPI DefaultHandler_SetExtent( - IOleObject* iface, - DWORD dwDrawAspect, - SIZEL* psizel); -static HRESULT WINAPI DefaultHandler_GetExtent( - IOleObject* iface, - DWORD dwDrawAspect, - SIZEL* psizel); -static HRESULT WINAPI DefaultHandler_Advise( - IOleObject* iface, - IAdviseSink* pAdvSink, - DWORD* pdwConnection); -static HRESULT WINAPI DefaultHandler_Unadvise( - IOleObject* iface, - DWORD dwConnection); -static HRESULT WINAPI DefaultHandler_EnumAdvise( - IOleObject* iface, - IEnumSTATDATA** ppenumAdvise); -static HRESULT WINAPI DefaultHandler_GetMiscStatus( - IOleObject* iface, - DWORD dwAspect, - DWORD* pdwStatus); -static HRESULT WINAPI DefaultHandler_SetColorScheme( - IOleObject* iface, - struct tagLOGPALETTE* pLogpal); - -/* - * Prototypes for the methods of the DefaultHandler class - * that implement IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DefaultHandler_IDataObject_AddRef( - IDataObject* iface); -static ULONG WINAPI DefaultHandler_IDataObject_Release( - IDataObject* iface); -static HRESULT WINAPI DefaultHandler_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium); -static HRESULT WINAPI DefaultHandler_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium); -static HRESULT WINAPI DefaultHandler_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc); -static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut); -static HRESULT WINAPI DefaultHandler_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease); -static HRESULT WINAPI DefaultHandler_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc); -static HRESULT WINAPI DefaultHandler_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection); -static HRESULT WINAPI DefaultHandler_DUnadvise( - IDataObject* iface, - DWORD dwConnection); -static HRESULT WINAPI DefaultHandler_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise); - -/* - * Prototypes for the methods of the DefaultHandler class - * that implement IRunnableObject methods. - */ -static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface( - IRunnableObject* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( - IRunnableObject* iface); -static ULONG WINAPI DefaultHandler_IRunnableObject_Release( - IRunnableObject* iface); -static HRESULT WINAPI DefaultHandler_GetRunningClass( - IRunnableObject* iface, - LPCLSID lpClsid); -static HRESULT WINAPI DefaultHandler_Run( - IRunnableObject* iface, - IBindCtx* pbc); -static BOOL WINAPI DefaultHandler_IsRunning( - IRunnableObject* iface); -static HRESULT WINAPI DefaultHandler_LockRunning( - IRunnableObject* iface, - BOOL fLock, - BOOL fLastUnlockCloses); -static HRESULT WINAPI DefaultHandler_SetContainedObject( - IRunnableObject* iface, - BOOL fContained); - - -/* - * Virtual function tables for the DefaultHandler class. - */ -static IOleObjectVtbl DefaultHandler_IOleObject_VTable = -{ - DefaultHandler_QueryInterface, - DefaultHandler_AddRef, - DefaultHandler_Release, - DefaultHandler_SetClientSite, - DefaultHandler_GetClientSite, - DefaultHandler_SetHostNames, - DefaultHandler_Close, - DefaultHandler_SetMoniker, - DefaultHandler_GetMoniker, - DefaultHandler_InitFromData, - DefaultHandler_GetClipboardData, - DefaultHandler_DoVerb, - DefaultHandler_EnumVerbs, - DefaultHandler_Update, - DefaultHandler_IsUpToDate, - DefaultHandler_GetUserClassID, - DefaultHandler_GetUserType, - DefaultHandler_SetExtent, - DefaultHandler_GetExtent, - DefaultHandler_Advise, - DefaultHandler_Unadvise, - DefaultHandler_EnumAdvise, - DefaultHandler_GetMiscStatus, - DefaultHandler_SetColorScheme -}; - -static IUnknownVtbl DefaultHandler_NDIUnknown_VTable = -{ - DefaultHandler_NDIUnknown_QueryInterface, - DefaultHandler_NDIUnknown_AddRef, - DefaultHandler_NDIUnknown_Release, -}; - -static IDataObjectVtbl DefaultHandler_IDataObject_VTable = -{ - DefaultHandler_IDataObject_QueryInterface, - DefaultHandler_IDataObject_AddRef, - DefaultHandler_IDataObject_Release, - DefaultHandler_GetData, - DefaultHandler_GetDataHere, - DefaultHandler_QueryGetData, - DefaultHandler_GetCanonicalFormatEtc, - DefaultHandler_SetData, - DefaultHandler_EnumFormatEtc, - DefaultHandler_DAdvise, - DefaultHandler_DUnadvise, - DefaultHandler_EnumDAdvise -}; - -static IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable = -{ - DefaultHandler_IRunnableObject_QueryInterface, - DefaultHandler_IRunnableObject_AddRef, - DefaultHandler_IRunnableObject_Release, - DefaultHandler_GetRunningClass, - DefaultHandler_Run, - DefaultHandler_IsRunning, - DefaultHandler_LockRunning, - DefaultHandler_SetContainedObject -}; - -/****************************************************************************** - * OleCreateDefaultHandler [OLE32.@] - */ -HRESULT WINAPI OleCreateDefaultHandler( - REFCLSID clsid, - LPUNKNOWN pUnkOuter, - REFIID riid, - LPVOID* ppvObj) -{ - DefaultHandler* newHandler = NULL; - HRESULT hr = S_OK; - - TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj); - - /* - * Sanity check - */ - if (ppvObj==0) - return E_POINTER; - - *ppvObj = 0; - - /* - * If this handler is constructed for aggregation, make sure - * the caller is requesting the IUnknown interface. - * This is necessary because it's the only time the non-delegating - * IUnknown pointer can be returned to the outside. - */ - if ( (pUnkOuter!=NULL) && - (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) != 0) ) - return CLASS_E_NOAGGREGATION; - - /* - * Try to construct a new instance of the class. - */ - newHandler = DefaultHandler_Construct(clsid, - pUnkOuter); - - if (newHandler == 0) - return E_OUTOFMEMORY; - - /* - * Make sure it supports the interface required by the caller. - */ - hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj); - - /* - * Release the reference obtained in the constructor. If - * the QueryInterface was unsuccessful, it will free the class. - */ - IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2)); - - return hr; -} - -/********************************************************* - * Methods implementation for the DefaultHandler class. - */ -static DefaultHandler* DefaultHandler_Construct( - REFCLSID clsid, - LPUNKNOWN pUnkOuter) -{ - DefaultHandler* newObject = 0; - - /* - * Allocate space for the object. - */ - newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler)); - - if (newObject==0) - return newObject; - - /* - * 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; - - /* - * Start with one reference count. The caller of this function - * must release the interface pointer when it is done. - */ - newObject->ref = 1; - - /* - * Initialize the outer unknown - * We don't keep a reference on the outer unknown since, the way - * aggregation works, our lifetime is at least as large as it's - * lifetime. - */ - if (pUnkOuter==NULL) - pUnkOuter = (IUnknown*)&(newObject->lpvtbl2); - - newObject->outerUnknown = pUnkOuter; - - /* - * Create a datacache object. - * We aggregate with the datacache. Make sure we pass our outer - * unknown as the datacache's outer unknown. - */ - CreateDataCache(newObject->outerUnknown, - clsid, - &IID_IUnknown, - (void**)&newObject->dataCache); - - /* - * Initialize the other data members of the class. - */ - memcpy(&(newObject->clsid), clsid, sizeof(CLSID)); - newObject->clientSite = NULL; - newObject->oleAdviseHolder = NULL; - newObject->dataAdviseHolder = NULL; - newObject->containerApp = NULL; - newObject->containerObj = NULL; - - return newObject; -} - -static void DefaultHandler_Destroy( - DefaultHandler* ptrToDestroy) -{ - /* - * Free the strings idenfitying the object - */ - if (ptrToDestroy->containerApp!=NULL) - { - HeapFree( GetProcessHeap(), 0, ptrToDestroy->containerApp ); - ptrToDestroy->containerApp = NULL; - } - - if (ptrToDestroy->containerObj!=NULL) - { - HeapFree( GetProcessHeap(), 0, ptrToDestroy->containerObj ); - ptrToDestroy->containerObj = NULL; - } - - /* - * Release our reference to the data cache. - */ - if (ptrToDestroy->dataCache!=NULL) - { - IUnknown_Release(ptrToDestroy->dataCache); - ptrToDestroy->dataCache = NULL; - } - - /* - * Same thing for the client site. - */ - if (ptrToDestroy->clientSite!=NULL) - { - IOleClientSite_Release(ptrToDestroy->clientSite); - ptrToDestroy->clientSite = NULL; - } - - /* - * And the advise holder. - */ - if (ptrToDestroy->oleAdviseHolder!=NULL) - { - IOleAdviseHolder_Release(ptrToDestroy->oleAdviseHolder); - ptrToDestroy->oleAdviseHolder = NULL; - } - - /* - * And the data advise holder. - */ - if (ptrToDestroy->dataAdviseHolder!=NULL) - { - IDataAdviseHolder_Release(ptrToDestroy->dataAdviseHolder); - ptrToDestroy->dataAdviseHolder = NULL; - } - - - /* - * Free the actual default handler structure. - */ - HeapFree(GetProcessHeap(), 0, ptrToDestroy); -} - -/********************************************************* - * Method implementation for the non delegating IUnknown - * part of the DefaultHandler class. - */ - -/************************************************************************ - * DefaultHandler_NDIUnknown_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface( - IUnknown* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); - - /* - * Perform a sanity check on the parameters. - */ - if ( (this==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = iface; - } - else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0) - { - *ppvObject = (IOleObject*)&(this->lpvtbl1); - } - else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) - { - *ppvObject = (IDataObject*)&(this->lpvtbl3); - } - else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0) - { - *ppvObject = (IRunnableObject*)&(this->lpvtbl4); - } - else - { - /* - * Blind aggregate the data cache to "inherit" it's interfaces. - */ - if (IUnknown_QueryInterface(this->dataCache, riid, ppvObject) == S_OK) - return S_OK; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - { - WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; - } - - /* - * Query Interface always increases the reference count by one when it is - * successful. - */ - IUnknown_AddRef((IUnknown*)*ppvObject); - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_NDIUnknown_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( - IUnknown* iface) -{ - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); - return InterlockedIncrement(&this->ref); -} - -/************************************************************************ - * DefaultHandler_NDIUnknown_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - * - * This version of QueryInterface will not delegate it's implementation - * to the outer unknown. - */ -static ULONG WINAPI DefaultHandler_NDIUnknown_Release( - IUnknown* iface) -{ - _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface); - ULONG ref; - - /* - * Decrease the reference count on this object. - */ - ref = InterlockedDecrement(&this->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref == 0) DefaultHandler_Destroy(this); - - return ref; -} - -/********************************************************* - * Methods implementation for the IOleObject part of - * the DefaultHandler class. - */ - -/************************************************************************ - * DefaultHandler_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DefaultHandler_QueryInterface( - IOleObject* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DefaultHandler_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_AddRef( - IOleObject* iface) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_Release( - IOleObject* iface) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_SetClientSite (IOleObject) - * - * The default handler's implementation of this method only keeps the - * client site pointer for future reference. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetClientSite( - IOleObject* iface, - IOleClientSite* pClientSite) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, pClientSite); - - /* - * Make sure we release the previous client site if there - * was one. - */ - if (this->clientSite!=NULL) - { - IOleClientSite_Release(this->clientSite); - } - - this->clientSite = pClientSite; - - if (this->clientSite!=NULL) - { - IOleClientSite_AddRef(this->clientSite); - } - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_GetClientSite (IOleObject) - * - * The default handler's implementation of this method returns the - * last pointer set in IOleObject_SetClientSite. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetClientSite( - IOleObject* iface, - IOleClientSite** ppClientSite) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - /* - * Sanity check. - */ - if (ppClientSite == NULL) - return E_POINTER; - - *ppClientSite = this->clientSite; - - if (this->clientSite != NULL) - { - IOleClientSite_AddRef(this->clientSite); - } - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_SetHostNames (IOleObject) - * - * The default handler's implementation of this method just stores - * the strings and returns S_OK. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetHostNames( - IOleObject* iface, - LPCOLESTR szContainerApp, - LPCOLESTR szContainerObj) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %s, %s)\n", - iface, - debugstr_w(szContainerApp), - debugstr_w(szContainerObj)); - - /* - * Be sure to cleanup before re-assinging the strings. - */ - if (this->containerApp!=NULL) - { - HeapFree( GetProcessHeap(), 0, this->containerApp ); - this->containerApp = NULL; - } - - if (this->containerObj!=NULL) - { - HeapFree( GetProcessHeap(), 0, this->containerObj ); - this->containerObj = NULL; - } - - /* - * Copy the string supplied. - */ - if (szContainerApp != NULL) - { - if ((this->containerApp = HeapAlloc( GetProcessHeap(), 0, - (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) ))) - strcpyW( this->containerApp, szContainerApp ); - } - - if (szContainerObj != NULL) - { - if ((this->containerObj = HeapAlloc( GetProcessHeap(), 0, - (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) ))) - strcpyW( this->containerObj, szContainerObj ); - } - return S_OK; -} - -/************************************************************************ - * DefaultHandler_Close (IOleObject) - * - * The default handler's implementation of this method is meaningless - * without a running server so it does nothing. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_Close( - IOleObject* iface, - DWORD dwSaveOption) -{ - TRACE("()\n"); - return S_OK; -} - -/************************************************************************ - * DefaultHandler_SetMoniker (IOleObject) - * - * The default handler's implementation of this method does nothing. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetMoniker( - IOleObject* iface, - DWORD dwWhichMoniker, - IMoniker* pmk) -{ - TRACE("(%p, %ld, %p)\n", - iface, - dwWhichMoniker, - pmk); - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_GetMoniker (IOleObject) - * - * Delegate this request to the client site if we have one. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetMoniker( - IOleObject* iface, - DWORD dwAssign, - DWORD dwWhichMoniker, - IMoniker** ppmk) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %ld, %ld, %p)\n", - iface, dwAssign, dwWhichMoniker, ppmk); - - if (this->clientSite) - { - return IOleClientSite_GetMoniker(this->clientSite, - dwAssign, - dwWhichMoniker, - ppmk); - - } - - return E_FAIL; -} - -/************************************************************************ - * DefaultHandler_InitFromData (IOleObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_InitFromData( - IOleObject* iface, - IDataObject* pDataObject, - BOOL fCreation, - DWORD dwReserved) -{ - TRACE("(%p, %p, %d, %ld)\n", - iface, pDataObject, fCreation, dwReserved); - - return OLE_E_NOTRUNNING; -} - -/************************************************************************ - * DefaultHandler_GetClipboardData (IOleObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetClipboardData( - IOleObject* iface, - DWORD dwReserved, - IDataObject** ppDataObject) -{ - TRACE("(%p, %ld, %p)\n", - iface, dwReserved, ppDataObject); - - return OLE_E_NOTRUNNING; -} - -static HRESULT WINAPI DefaultHandler_DoVerb( - IOleObject* iface, - LONG iVerb, - struct tagMSG* lpmsg, - IOleClientSite* pActiveSite, - LONG lindex, - HWND hwndParent, - LPCRECT lprcPosRect) -{ - FIXME(": Stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DefaultHandler_EnumVerbs (IOleObject) - * - * The default handler implementation of this method simply delegates - * to OleRegEnumVerbs - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_EnumVerbs( - IOleObject* iface, - IEnumOLEVERB** ppEnumOleVerb) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, ppEnumOleVerb); - - return OleRegEnumVerbs(&this->clsid, ppEnumOleVerb); -} - -static HRESULT WINAPI DefaultHandler_Update( - IOleObject* iface) -{ - FIXME(": Stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DefaultHandler_IsUpToDate (IOleObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_IsUpToDate( - IOleObject* iface) -{ - TRACE("(%p)\n", iface); - - return OLE_E_NOTRUNNING; -} - -/************************************************************************ - * DefaultHandler_GetUserClassID (IOleObject) - * - * TODO: Map to a new class ID if emulation is active. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetUserClassID( - IOleObject* iface, - CLSID* pClsid) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, pClsid); - - /* - * Sanity check. - */ - if (pClsid==NULL) - return E_POINTER; - - memcpy(pClsid, &this->clsid, sizeof(CLSID)); - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_GetUserType (IOleObject) - * - * The default handler implementation of this method simply delegates - * to OleRegGetUserType - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetUserType( - IOleObject* iface, - DWORD dwFormOfType, - LPOLESTR* pszUserType) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType); - - return OleRegGetUserType(&this->clsid, dwFormOfType, pszUserType); -} - -/************************************************************************ - * DefaultHandler_SetExtent (IOleObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetExtent( - IOleObject* iface, - DWORD dwDrawAspect, - SIZEL* psizel) -{ - TRACE("(%p, %lx, (%ld x %ld))\n", iface, - dwDrawAspect, psizel->cx, psizel->cy); - return OLE_E_NOTRUNNING; -} - -/************************************************************************ - * DefaultHandler_GetExtent (IOleObject) - * - * The default handler's implementation of this method returns uses - * the cache to locate the aspect and extract the extent from it. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetExtent( - IOleObject* iface, - DWORD dwDrawAspect, - SIZEL* psizel) -{ - DVTARGETDEVICE* targetDevice; - IViewObject2* cacheView = NULL; - HRESULT hres; - - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel); - - hres = IUnknown_QueryInterface(this->dataCache, &IID_IViewObject2, (void**)&cacheView); - - if (FAILED(hres)) - return E_UNEXPECTED; - - /* - * Prepare the call to the cache's GetExtent method. - * - * Here we would build a valid DVTARGETDEVICE structure - * but, since we are calling into the data cache, we - * know it's implementation and we'll skip this - * extra work until later. - */ - targetDevice = NULL; - - hres = IViewObject2_GetExtent(cacheView, - dwDrawAspect, - -1, - targetDevice, - psizel); - - /* - * Cleanup - */ - IViewObject2_Release(cacheView); - - return hres; -} - -/************************************************************************ - * DefaultHandler_Advise (IOleObject) - * - * The default handler's implementation of this method simply - * delegates to the OleAdviseHolder. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_Advise( - IOleObject* iface, - IAdviseSink* pAdvSink, - DWORD* pdwConnection) -{ - HRESULT hres = S_OK; - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection); - - /* - * Make sure we have an advise holder before we start. - */ - if (this->oleAdviseHolder==NULL) - { - hres = CreateOleAdviseHolder(&this->oleAdviseHolder); - } - - if (SUCCEEDED(hres)) - { - hres = IOleAdviseHolder_Advise(this->oleAdviseHolder, - pAdvSink, - pdwConnection); - } - - return hres; -} - -/************************************************************************ - * DefaultHandler_Unadvise (IOleObject) - * - * The default handler's implementation of this method simply - * delegates to the OleAdviseHolder. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_Unadvise( - IOleObject* iface, - DWORD dwConnection) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %ld)\n", iface, dwConnection); - - /* - * If we don't have an advise holder yet, it means we don't have - * a connection. - */ - if (this->oleAdviseHolder==NULL) - return OLE_E_NOCONNECTION; - - return IOleAdviseHolder_Unadvise(this->oleAdviseHolder, - dwConnection); -} - -/************************************************************************ - * DefaultHandler_EnumAdvise (IOleObject) - * - * The default handler's implementation of this method simply - * delegates to the OleAdviseHolder. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_EnumAdvise( - IOleObject* iface, - IEnumSTATDATA** ppenumAdvise) -{ - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, ppenumAdvise); - - /* - * Sanity check - */ - if (ppenumAdvise==NULL) - return E_POINTER; - - /* - * Initialize the out parameter. - */ - *ppenumAdvise = NULL; - - if (this->oleAdviseHolder==NULL) - return IOleAdviseHolder_EnumAdvise(this->oleAdviseHolder, - ppenumAdvise); - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_GetMiscStatus (IOleObject) - * - * The default handler's implementation of this method simply delegates - * to OleRegGetMiscStatus. - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetMiscStatus( - IOleObject* iface, - DWORD dwAspect, - DWORD* pdwStatus) -{ - HRESULT hres; - _ICOM_THIS_From_IOleObject(DefaultHandler, iface); - - TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus); - - hres = OleRegGetMiscStatus(&(this->clsid), dwAspect, pdwStatus); - - if (FAILED(hres)) - *pdwStatus = 0; - - return S_OK; -} - -/************************************************************************ - * DefaultHandler_SetExtent (IOleObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IOleObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetColorScheme( - IOleObject* iface, - struct tagLOGPALETTE* pLogpal) -{ - TRACE("(%p, %p))\n", iface, pLogpal); - return OLE_E_NOTRUNNING; -} - -/********************************************************* - * Methods implementation for the IDataObject part of - * the DefaultHandler class. - */ - -/************************************************************************ - * DefaultHandler_IDataObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface( - IDataObject* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DefaultHandler_IDataObject_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_IDataObject_AddRef( - IDataObject* iface) -{ - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_IDataObject_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_IDataObject_Release( - IDataObject* iface) -{ - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_GetData - * - * Get Data from a source dataobject using format pformatetcIn->cfFormat - * See Windows documentation for more details on GetData. - * Default handler's implementation of this method delegates to the cache. - */ -static HRESULT WINAPI DefaultHandler_GetData( - IDataObject* iface, - LPFORMATETC pformatetcIn, - STGMEDIUM* pmedium) -{ - IDataObject* cacheDataObject = NULL; - HRESULT hres; - - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium); - - hres = IUnknown_QueryInterface(this->dataCache, - &IID_IDataObject, - (void**)&cacheDataObject); - - if (FAILED(hres)) - return E_UNEXPECTED; - - hres = IDataObject_GetData(cacheDataObject, - pformatetcIn, - pmedium); - - IDataObject_Release(cacheDataObject); - - return hres; -} - -static HRESULT WINAPI DefaultHandler_GetDataHere( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium) -{ - FIXME(": Stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DefaultHandler_QueryGetData (IDataObject) - * - * The default handler's implementation of this method delegates to - * the cache. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_QueryGetData( - IDataObject* iface, - LPFORMATETC pformatetc) -{ - IDataObject* cacheDataObject = NULL; - HRESULT hres; - - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, pformatetc); - - hres = IUnknown_QueryInterface(this->dataCache, - &IID_IDataObject, - (void**)&cacheDataObject); - - if (FAILED(hres)) - return E_UNEXPECTED; - - hres = IDataObject_QueryGetData(cacheDataObject, - pformatetc); - - IDataObject_Release(cacheDataObject); - - return hres; -} - -/************************************************************************ - * DefaultHandler_GetCanonicalFormatEtc (IDataObject) - * - * This method is meaningless if the server is not running - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc( - IDataObject* iface, - LPFORMATETC pformatectIn, - LPFORMATETC pformatetcOut) -{ - FIXME("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut); - - return OLE_E_NOTRUNNING; -} - -/************************************************************************ - * DefaultHandler_SetData (IDataObject) - * - * The default handler's implementation of this method delegates to - * the cache. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetData( - IDataObject* iface, - LPFORMATETC pformatetc, - STGMEDIUM* pmedium, - BOOL fRelease) -{ - IDataObject* cacheDataObject = NULL; - HRESULT hres; - - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease); - - hres = IUnknown_QueryInterface(this->dataCache, - &IID_IDataObject, - (void**)&cacheDataObject); - - if (FAILED(hres)) - return E_UNEXPECTED; - - hres = IDataObject_SetData(cacheDataObject, - pformatetc, - pmedium, - fRelease); - - IDataObject_Release(cacheDataObject); - - return hres; -} - -/************************************************************************ - * DefaultHandler_EnumFormatEtc (IDataObject) - * - * The default handler's implementation of this method simply delegates - * to OleRegEnumFormatEtc. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_EnumFormatEtc( - IDataObject* iface, - DWORD dwDirection, - IEnumFORMATETC** ppenumFormatEtc) -{ - HRESULT hres; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc); - - hres = OleRegEnumFormatEtc(&(this->clsid), dwDirection, ppenumFormatEtc); - - return hres; -} - -/************************************************************************ - * DefaultHandler_DAdvise (IDataObject) - * - * The default handler's implementation of this method simply - * delegates to the DataAdviseHolder. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_DAdvise( - IDataObject* iface, - FORMATETC* pformatetc, - DWORD advf, - IAdviseSink* pAdvSink, - DWORD* pdwConnection) -{ - HRESULT hres = S_OK; - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %p, %ld, %p, %p)\n", - iface, pformatetc, advf, pAdvSink, pdwConnection); - - /* - * Make sure we have a data advise holder before we start. - */ - if (this->dataAdviseHolder==NULL) - { - hres = CreateDataAdviseHolder(&this->dataAdviseHolder); - } - - if (SUCCEEDED(hres)) - { - hres = IDataAdviseHolder_Advise(this->dataAdviseHolder, - iface, - pformatetc, - advf, - pAdvSink, - pdwConnection); - } - - return hres; -} - -/************************************************************************ - * DefaultHandler_DUnadvise (IDataObject) - * - * The default handler's implementation of this method simply - * delegates to the DataAdviseHolder. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_DUnadvise( - IDataObject* iface, - DWORD dwConnection) -{ - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %ld)\n", iface, dwConnection); - - /* - * If we don't have a data advise holder yet, it means that - * we don't have any connections.. - */ - if (this->dataAdviseHolder==NULL) - { - return OLE_E_NOCONNECTION; - } - - return IDataAdviseHolder_Unadvise(this->dataAdviseHolder, - dwConnection); -} - -/************************************************************************ - * DefaultHandler_EnumDAdvise (IDataObject) - * - * The default handler's implementation of this method simply - * delegates to the DataAdviseHolder. - * - * See Windows documentation for more details on IDataObject methods. - */ -static HRESULT WINAPI DefaultHandler_EnumDAdvise( - IDataObject* iface, - IEnumSTATDATA** ppenumAdvise) -{ - _ICOM_THIS_From_IDataObject(DefaultHandler, iface); - - TRACE("(%p, %p)\n", iface, ppenumAdvise); - - /* - * Sanity check - */ - if (ppenumAdvise == NULL) - return E_POINTER; - - /* - * Initialize the out parameter. - */ - *ppenumAdvise = NULL; - - /* - * If we have a data advise holder object, delegate. - */ - if (this->dataAdviseHolder!=NULL) - { - return IDataAdviseHolder_EnumAdvise(this->dataAdviseHolder, - ppenumAdvise); - } - - return S_OK; -} - -/********************************************************* - * Methods implementation for the IRunnableObject part - * of the DefaultHandler class. - */ - -/************************************************************************ - * DefaultHandler_IRunnableObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface( - IRunnableObject* iface, - REFIID riid, - void** ppvObject) -{ - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); - - return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject); -} - -/************************************************************************ - * DefaultHandler_IRunnableObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( - IRunnableObject* iface) -{ - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); - - return IUnknown_AddRef(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_IRunnableObject_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DefaultHandler_IRunnableObject_Release( - IRunnableObject* iface) -{ - _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface); - - return IUnknown_Release(this->outerUnknown); -} - -/************************************************************************ - * DefaultHandler_GetRunningClass (IRunnableObject) - * - * According to Brockscmidt, Chapter 19, the default handler's - * implementation of IRunnableobject does nothing until the object - * is actually running. - * - * See Windows documentation for more details on IRunnableObject methods. - */ -static HRESULT WINAPI DefaultHandler_GetRunningClass( - IRunnableObject* iface, - LPCLSID lpClsid) -{ - TRACE("()\n"); - return S_OK; -} - -static HRESULT WINAPI DefaultHandler_Run( - IRunnableObject* iface, - IBindCtx* pbc) -{ - FIXME(": Stub\n"); - return E_NOTIMPL; -} - -/************************************************************************ - * DefaultHandler_IsRunning (IRunnableObject) - * - * According to Brockscmidt, Chapter 19, the default handler's - * implementation of IRunnableobject does nothing until the object - * is actually running. - * - * See Windows documentation for more details on IRunnableObject methods. - */ -static BOOL WINAPI DefaultHandler_IsRunning( - IRunnableObject* iface) -{ - TRACE("()\n"); - return S_FALSE; -} - -/************************************************************************ - * DefaultHandler_LockRunning (IRunnableObject) - * - * According to Brockscmidt, Chapter 19, the default handler's - * implementation of IRunnableobject does nothing until the object - * is actually running. - * - * See Windows documentation for more details on IRunnableObject methods. - */ -static HRESULT WINAPI DefaultHandler_LockRunning( - IRunnableObject* iface, - BOOL fLock, - BOOL fLastUnlockCloses) -{ - TRACE("()\n"); - return S_OK; -} - -/************************************************************************ - * DefaultHandler_SetContainedObject (IRunnableObject) - * - * According to Brockscmidt, Chapter 19, the default handler's - * implementation of IRunnableobject does nothing until the object - * is actually running. - * - * See Windows documentation for more details on IRunnableObject methods. - */ -static HRESULT WINAPI DefaultHandler_SetContainedObject( - IRunnableObject* iface, - BOOL fContained) -{ - TRACE("()\n"); - return S_OK; -} diff --git a/reactos/lib/ole32/errorinfo.c b/reactos/lib/ole32/errorinfo.c deleted file mode 100644 index bf3c02e3fac..00000000000 --- a/reactos/lib/ole32/errorinfo.c +++ /dev/null @@ -1,523 +0,0 @@ -/* - * ErrorInfo API - * - * Copyright 2000 Patrik Stridvall, Juergen Schmied - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * NOTES: - * - * The errorinfo is a per-thread object. The reference is stored in the - * TEB at offset 0xf80 - */ - -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "objbase.h" -#include "oleauto.h" -#include "winerror.h" - -#include "wine/unicode.h" -#include "compobj_private.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/* this code is from SysAllocStringLen (ole2disp.c in oleaut32) */ -static BSTR WINAPI ERRORINFO_SysAllocString(const OLECHAR* in) -{ - DWORD bufferSize; - DWORD* newBuffer; - WCHAR* stringBuffer; - DWORD len; - - if (in == NULL) - return NULL; - /* - * Find the lenth of the buffer passed-in in bytes. - */ - len = strlenW(in); - bufferSize = len * sizeof (WCHAR); - - /* - * Allocate a new buffer to hold the string. - * don't forget to keep an empty spot at the beginning of the - * buffer for the character count and an extra character at the - * end for the '\0'. - */ - newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(), - 0, - bufferSize + sizeof(WCHAR) + sizeof(DWORD)); - - /* - * If the memory allocation failed, return a null pointer. - */ - if (newBuffer==0) - return 0; - - /* - * Copy the length of the string in the placeholder. - */ - *newBuffer = bufferSize; - - /* - * Skip the byte count. - */ - newBuffer++; - - /* - * Copy the information in the buffer. - * Since it is valid to pass a NULL pointer here, we'll initialize the - * buffer to nul if it is the case. - */ - if (in != 0) - memcpy(newBuffer, in, bufferSize); - else - memset(newBuffer, 0, bufferSize); - - /* - * Make sure that there is a nul character at the end of the - * string. - */ - stringBuffer = (WCHAR*)newBuffer; - stringBuffer[len] = 0; - - return (LPWSTR)stringBuffer; -} - -/* this code is from SysFreeString (ole2disp.c in oleaut32)*/ -static VOID WINAPI ERRORINFO_SysFreeString(BSTR in) -{ - DWORD* bufferPointer; - - /* NULL is a valid parameter */ - if(!in) return; - - /* - * We have to be careful when we free a BSTR pointer, it points to - * the beginning of the string but it skips the byte count contained - * before the string. - */ - bufferPointer = (DWORD*)in; - - bufferPointer--; - - /* - * Free the memory from it's "real" origin. - */ - HeapFree(GetProcessHeap(), 0, bufferPointer); -} - - -typedef struct ErrorInfoImpl -{ - IErrorInfoVtbl *lpvtei; - ICreateErrorInfoVtbl *lpvtcei; - ISupportErrorInfoVtbl *lpvtsei; - DWORD ref; - - GUID m_Guid; - BSTR bstrSource; - BSTR bstrDescription; - BSTR bstrHelpFile; - DWORD m_dwHelpContext; -} ErrorInfoImpl; - -static IErrorInfoVtbl IErrorInfoImpl_VTable; -static ICreateErrorInfoVtbl ICreateErrorInfoImpl_VTable; -static ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable; - -/* - converts a objectpointer 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); - -#define _ISupportErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtsei))) -#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset); - -/* - converts This to a objectpointer - */ -#define _IErrorInfo_(This) (IErrorInfo*)&(This->lpvtei) -#define _ICreateErrorInfo_(This) (ICreateErrorInfo*)&(This->lpvtcei) -#define _ISupportErrorInfo_(This) (ISupportErrorInfo*)&(This->lpvtsei) - -IErrorInfo * IErrorInfoImpl_Constructor() -{ - ErrorInfoImpl * ei = HeapAlloc(GetProcessHeap(), 0, sizeof(ErrorInfoImpl)); - if (ei) - { - ei->lpvtei = &IErrorInfoImpl_VTable; - ei->lpvtcei = &ICreateErrorInfoImpl_VTable; - ei->lpvtsei = &ISupportErrorInfoImpl_VTable; - ei->ref = 1; - ei->bstrSource = NULL; - ei->bstrDescription = NULL; - ei->bstrHelpFile = NULL; - ei->m_dwHelpContext = 0; - } - return (IErrorInfo *)ei; -} - - -static HRESULT WINAPI IErrorInfoImpl_QueryInterface( - IErrorInfo* iface, - REFIID riid, - VOID** ppvoid) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvoid); - - *ppvoid = NULL; - - if(IsEqualIID(riid, &IID_IErrorInfo)) - { - *ppvoid = _IErrorInfo_(This); - } - else if(IsEqualIID(riid, &IID_ICreateErrorInfo)) - { - *ppvoid = _ICreateErrorInfo_(This); - } - else if(IsEqualIID(riid, &IID_ISupportErrorInfo)) - { - *ppvoid = _ISupportErrorInfo_(This); - } - - if(*ppvoid) - { - IUnknown_AddRef( (IUnknown*)*ppvoid ); - TRACE("-- Interface: (%p)->(%p)\n",ppvoid,*ppvoid); - return S_OK; - } - TRACE("-- Interface: E_NOINTERFACE\n"); - return E_NOINTERFACE; -} - -static ULONG WINAPI IErrorInfoImpl_AddRef( - IErrorInfo* iface) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(count=%lu)\n",This,This->ref); - return InterlockedIncrement(&This->ref); -} - -static ULONG WINAPI IErrorInfoImpl_Release( - IErrorInfo* iface) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(count=%lu)\n",This,This->ref); - - if (!InterlockedDecrement(&This->ref)) - { - TRACE("-- destroying IErrorInfo(%p)\n",This); - HeapFree(GetProcessHeap(),0,This); - return 0; - } - return This->ref; -} - -static HRESULT WINAPI IErrorInfoImpl_GetGUID( - IErrorInfo* iface, - GUID * pGUID) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(count=%lu)\n",This,This->ref); - if(!pGUID )return E_INVALIDARG; - memcpy(pGUID, &This->m_Guid, sizeof(GUID)); - return S_OK; -} - -static HRESULT WINAPI IErrorInfoImpl_GetSource( - IErrorInfo* iface, - BSTR *pBstrSource) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(pBstrSource=%p)\n",This,pBstrSource); - if (pBstrSource == NULL) - return E_INVALIDARG; - *pBstrSource = ERRORINFO_SysAllocString(This->bstrSource); - return S_OK; -} - -static HRESULT WINAPI IErrorInfoImpl_GetDescription( - IErrorInfo* iface, - BSTR *pBstrDescription) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - - TRACE("(%p)->(pBstrDescription=%p)\n",This,pBstrDescription); - if (pBstrDescription == NULL) - return E_INVALIDARG; - *pBstrDescription = ERRORINFO_SysAllocString(This->bstrDescription); - - return S_OK; -} - -static HRESULT WINAPI IErrorInfoImpl_GetHelpFile( - IErrorInfo* iface, - BSTR *pBstrHelpFile) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - - TRACE("(%p)->(pBstrHelpFile=%p)\n",This, pBstrHelpFile); - if (pBstrHelpFile == NULL) - return E_INVALIDARG; - *pBstrHelpFile = ERRORINFO_SysAllocString(This->bstrHelpFile); - - return S_OK; -} - -static HRESULT WINAPI IErrorInfoImpl_GetHelpContext( - IErrorInfo* iface, - DWORD *pdwHelpContext) -{ - _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(pdwHelpContext=%p)\n",This, pdwHelpContext); - if (pdwHelpContext == NULL) - return E_INVALIDARG; - *pdwHelpContext = This->m_dwHelpContext; - - return S_OK; -} - -static IErrorInfoVtbl IErrorInfoImpl_VTable = -{ - IErrorInfoImpl_QueryInterface, - IErrorInfoImpl_AddRef, - IErrorInfoImpl_Release, - - IErrorInfoImpl_GetGUID, - IErrorInfoImpl_GetSource, - IErrorInfoImpl_GetDescription, - IErrorInfoImpl_GetHelpFile, - IErrorInfoImpl_GetHelpContext -}; - - -static HRESULT WINAPI ICreateErrorInfoImpl_QueryInterface( - ICreateErrorInfo* iface, - REFIID riid, - VOID** ppvoid) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid); -} - -static ULONG WINAPI ICreateErrorInfoImpl_AddRef( - ICreateErrorInfo* iface) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - return IErrorInfo_AddRef(_IErrorInfo_(This)); -} - -static ULONG WINAPI ICreateErrorInfoImpl_Release( - ICreateErrorInfo* iface) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - return IErrorInfo_Release(_IErrorInfo_(This)); -} - - -static HRESULT WINAPI ICreateErrorInfoImpl_SetGUID( - ICreateErrorInfo* iface, - REFGUID rguid) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(%s)\n", This, debugstr_guid(rguid)); - memcpy(&This->m_Guid, rguid, sizeof(GUID)); - return S_OK; -} - -static HRESULT WINAPI ICreateErrorInfoImpl_SetSource( - ICreateErrorInfo* iface, - LPOLESTR szSource) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p): %s\n",This, debugstr_w(szSource)); - if (This->bstrSource != NULL) - ERRORINFO_SysFreeString(This->bstrSource); - This->bstrSource = ERRORINFO_SysAllocString(szSource); - - return S_OK; -} - -static HRESULT WINAPI ICreateErrorInfoImpl_SetDescription( - ICreateErrorInfo* iface, - LPOLESTR szDescription) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p): %s\n",This, debugstr_w(szDescription)); - if (This->bstrDescription != NULL) - ERRORINFO_SysFreeString(This->bstrDescription); - This->bstrDescription = ERRORINFO_SysAllocString(szDescription); - - return S_OK; -} - -static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpFile( - ICreateErrorInfo* iface, - LPOLESTR szHelpFile) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n",This); - if (This->bstrHelpFile != NULL) - ERRORINFO_SysFreeString(This->bstrHelpFile); - This->bstrHelpFile = ERRORINFO_SysAllocString(szHelpFile); - - return S_OK; -} - -static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpContext( - ICreateErrorInfo* iface, - DWORD dwHelpContext) -{ - _ICOM_THIS_From_ICreateErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n",This); - This->m_dwHelpContext = dwHelpContext; - - return S_OK; -} - -static ICreateErrorInfoVtbl ICreateErrorInfoImpl_VTable = -{ - ICreateErrorInfoImpl_QueryInterface, - ICreateErrorInfoImpl_AddRef, - ICreateErrorInfoImpl_Release, - - ICreateErrorInfoImpl_SetGUID, - ICreateErrorInfoImpl_SetSource, - ICreateErrorInfoImpl_SetDescription, - ICreateErrorInfoImpl_SetHelpFile, - ICreateErrorInfoImpl_SetHelpContext -}; - -static HRESULT WINAPI ISupportErrorInfoImpl_QueryInterface( - ISupportErrorInfo* iface, - REFIID riid, - VOID** ppvoid) -{ - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - - return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid); -} - -static ULONG WINAPI ISupportErrorInfoImpl_AddRef( - ISupportErrorInfo* iface) -{ - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - return IErrorInfo_AddRef(_IErrorInfo_(This)); -} - -static ULONG WINAPI ISupportErrorInfoImpl_Release( - ISupportErrorInfo* iface) -{ - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)\n", This); - return IErrorInfo_Release(_IErrorInfo_(This)); -} - - -static HRESULT WINAPI ISupportErrorInfoImpl_InterfaceSupportsErrorInfo( - ISupportErrorInfo* iface, - REFIID riid) -{ - _ICOM_THIS_From_ISupportErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(%s)\n", This, debugstr_guid(riid)); - return (IsEqualIID(riid, &This->m_Guid)) ? S_OK : S_FALSE; -} - -static ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable = -{ - ISupportErrorInfoImpl_QueryInterface, - ISupportErrorInfoImpl_AddRef, - ISupportErrorInfoImpl_Release, - - - ISupportErrorInfoImpl_InterfaceSupportsErrorInfo -}; -/*********************************************************************** - * CreateErrorInfo (OLE32.@) - */ -HRESULT WINAPI CreateErrorInfo(ICreateErrorInfo **pperrinfo) -{ - IErrorInfo * pei; - HRESULT res; - TRACE("(%p): stub:\n", pperrinfo); - if(! pperrinfo ) return E_INVALIDARG; - if(!(pei=IErrorInfoImpl_Constructor()))return E_OUTOFMEMORY; - - res = IErrorInfo_QueryInterface(pei, &IID_ICreateErrorInfo, (LPVOID*)pperrinfo); - IErrorInfo_Release(pei); - return res; -} - -/*********************************************************************** - * GetErrorInfo (OLE32.@) - */ -HRESULT WINAPI GetErrorInfo(ULONG dwReserved, IErrorInfo **pperrinfo) -{ - APARTMENT * apt = COM_CurrentInfo(); - - TRACE("(%ld, %p, %p)\n", dwReserved, pperrinfo, COM_CurrentInfo()->ErrorInfo); - - if(!pperrinfo) return E_INVALIDARG; - if (!apt || !apt->ErrorInfo) - { - *pperrinfo = NULL; - return S_FALSE; - } - - *pperrinfo = (IErrorInfo*)(apt->ErrorInfo); - /* clear thread error state */ - apt->ErrorInfo = NULL; - return S_OK; -} - -/*********************************************************************** - * SetErrorInfo (OLE32.@) - */ -HRESULT WINAPI SetErrorInfo(ULONG dwReserved, IErrorInfo *perrinfo) -{ - IErrorInfo * pei; - APARTMENT * apt = COM_CurrentInfo(); - - TRACE("(%ld, %p)\n", dwReserved, perrinfo); - - if (!apt) apt = COM_CreateApartment(COINIT_UNINITIALIZED); - - /* release old errorinfo */ - pei = (IErrorInfo*)apt->ErrorInfo; - if(pei) IErrorInfo_Release(pei); - - /* set to new value */ - apt->ErrorInfo = perrinfo; - if(perrinfo) IErrorInfo_AddRef(perrinfo); - return S_OK; -} diff --git a/reactos/lib/ole32/filemoniker.c b/reactos/lib/ole32/filemoniker.c deleted file mode 100644 index 8e71c3f7733..00000000000 --- a/reactos/lib/ole32/filemoniker.c +++ /dev/null @@ -1,1362 +0,0 @@ -/*************************************************************************************** - * FileMonikers implementation - * - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - ***************************************************************************************/ - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "winnls.h" -#include "wine/unicode.h" -#include "wine/debug.h" -#include "objbase.h" -#include "moniker.h" - -#include "compobj_private.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -const CLSID CLSID_FileMoniker = { - 0x303, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46} -}; - -/* filemoniker data structure */ -typedef struct FileMonikerImpl{ - - IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/ - - /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether - * two monikers are equal. That's whay IROTData interface is implemented by monikers. - */ - IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/ - - ULONG ref; /* reference counter for this object */ - - LPOLESTR filePathName; /* path string identified by this filemoniker */ - -} FileMonikerImpl; - -/********************************************************************************/ -/* FileMoniker prototype functions : */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface); -static ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface); - -/* IPersist prototype functions */ -static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID); - -/* IPersistStream prototype functions */ -static HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface); -static HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface, IStream* pStm); -static HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty); -static HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize); - -/* IMoniker prototype functions */ -static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced); -static HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite); -static HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker); -static HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker); -static HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash); -static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning); -static HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime); -static HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk); -static HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix); -static HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath); -static HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName); -static HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut); -static HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys); - -/********************************************************************************/ -/* IROTData prototype functions */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject); -static ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData* iface); -static ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface); - -/* IROTData prototype function */ -static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData); - -/* Local function used by filemoniker implementation */ -HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* iface, LPCOLESTR lpszPathName); -HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* iface); -int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** tabStr); - - -/********************************************************************************/ -/* Virtual function table for the FileMonikerImpl class which include IPersist,*/ -/* IPersistStream and IMoniker functions. */ -static IMonikerVtbl VT_FileMonikerImpl = -{ - FileMonikerImpl_QueryInterface, - FileMonikerImpl_AddRef, - FileMonikerImpl_Release, - FileMonikerImpl_GetClassID, - FileMonikerImpl_IsDirty, - FileMonikerImpl_Load, - FileMonikerImpl_Save, - FileMonikerImpl_GetSizeMax, - FileMonikerImpl_BindToObject, - FileMonikerImpl_BindToStorage, - FileMonikerImpl_Reduce, - FileMonikerImpl_ComposeWith, - FileMonikerImpl_Enum, - FileMonikerImpl_IsEqual, - FileMonikerImpl_Hash, - FileMonikerImpl_IsRunning, - FileMonikerImpl_GetTimeOfLastChange, - FileMonikerImpl_Inverse, - FileMonikerImpl_CommonPrefixWith, - FileMonikerImpl_RelativePathTo, - FileMonikerImpl_GetDisplayName, - FileMonikerImpl_ParseDisplayName, - FileMonikerImpl_IsSystemMoniker -}; - -/********************************************************************************/ -/* Virtual function table for the IROTData class. */ -static IROTDataVtbl VT_ROTDataImpl = -{ - FileMonikerROTDataImpl_QueryInterface, - FileMonikerROTDataImpl_AddRef, - FileMonikerROTDataImpl_Release, - FileMonikerROTDataImpl_GetComparaisonData -}; - -/******************************************************************************* - * FileMoniker_QueryInterface - *******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* Perform a sanity check on the parameters.*/ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* Initialize the return parameter */ - *ppvObject = 0; - - /* Compare the riid with the interface IDs implemented by this object.*/ - if (IsEqualIID(&IID_IUnknown, riid) || - IsEqualIID(&IID_IPersist, riid) || - IsEqualIID(&IID_IPersistStream,riid) || - IsEqualIID(&IID_IMoniker, riid) - ) - *ppvObject = iface; - - else if (IsEqualIID(&IID_IROTData, riid)) - *ppvObject = (IROTData*)&(This->lpvtbl2); - - /* Check that we obtained an interface.*/ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* Query Interface always increases the reference count by one when it is successful */ - FileMonikerImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_AddRef - ******************************************************************************/ -ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - TRACE("(%p)\n",iface); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * FileMoniker_Release - ******************************************************************************/ -ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - ULONG ref; - - TRACE("(%p)\n",iface); - - ref = InterlockedDecrement(&This->ref); - - /* destroy the object if there's no more reference on it */ - if (ref == 0) FileMonikerImpl_Destroy(This); - - return ref; -} - -/****************************************************************************** - * FileMoniker_GetClassID - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, - CLSID *pClassID)/* Pointer to CLSID of object */ -{ - TRACE("(%p,%p),stub!\n",iface,pClassID); - - if (pClassID==NULL) - return E_POINTER; - - *pClassID = CLSID_FileMoniker; - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_IsDirty - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface) -{ - /* Note that the OLE-provided implementations of the IPersistStream::IsDirty - method in the OLE-provided moniker interfaces always return S_FALSE because - their internal state never changes. */ - - TRACE("(%p)\n",iface); - - return S_FALSE; -} - -/****************************************************************************** - * FileMoniker_Load - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm) -{ - HRESULT res; - CHAR* filePathA; - WCHAR* filePathW; - ULONG bread; - WORD wbuffer; - DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec; - - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - TRACE("(%p,%p)\n",iface,pStm); - - /* this function locates and reads from the stream the filePath string written by FileMonikerImpl_Save */ - - /* first WORD is non significative */ - res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread); - if (bread!=sizeof(WORD) || wbuffer!=0) - return E_FAIL; - - /* read filePath string length (plus one) */ - res=IStream_Read(pStm,&length,sizeof(DWORD),&bread); - if (bread != sizeof(DWORD)) - return E_FAIL; - - /* read filePath string */ - filePathA=HeapAlloc(GetProcessHeap(),0,length); - res=IStream_Read(pStm,filePathA,length,&bread); - HeapFree(GetProcessHeap(),0,filePathA); - if (bread != length) - return E_FAIL; - - /* read the first constant */ - IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread); - if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF) - return E_FAIL; - - length--; - - for(i=0;i<10;i++){ - res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread); - if (bread!=sizeof(WORD) || wbuffer!=0) - return E_FAIL; - } - - if (length>8) - length=0; - - doubleLenHex=doubleLenDec=2*length; - if (length > 5) - doubleLenDec+=6; - - res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread); - if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec) - return E_FAIL; - - if (length==0) - return res; - - res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread); - if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex) - return E_FAIL; - - res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread); - if (bread!=sizeof(WORD) || wbuffer!=0x3) - return E_FAIL; - - filePathW=HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR)); - filePathW[length]=0; - res=IStream_Read(pStm,filePathW,doubleLenHex,&bread); - if (bread!=doubleLenHex) { - HeapFree(GetProcessHeap(), 0, filePathW); - return E_FAIL; - } - - if (This->filePathName!=NULL) - HeapFree(GetProcessHeap(),0,This->filePathName); - - This->filePathName=filePathW; - - return res; -} - -/****************************************************************************** - * FileMoniker_Save - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, - IStream* pStm,/* pointer to the stream where the object is to be saved */ - BOOL fClearDirty)/* Specifies whether to clear the dirty flag */ -{ - /* this function saves data of this object. In the beginning I thougth - * that I have just to write the filePath string on Stream. But, when I - * tested this function whith windows programs samples, I noticed that it - * was not the case. So I analysed data written by this function on - * Windows and what this did function exactly ! But I have no idea about - * its logic ! - * I guessed data which must be written on stream is: - * 1) WORD constant:zero - * 2) length of the path string ("\0" included) - * 3) path string type A - * 4) DWORD constant : 0xDEADFFFF - * 5) ten WORD constant: zero - * 6) DWORD: double-length of the the path string type W ("\0" not - * included) - * 7) WORD constant: 0x3 - * 8) filePath unicode string. - * if the length(filePath) > 8 or length(filePath) == 8 stop at step 5) - */ - - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - HRESULT res; - LPOLESTR filePathW=This->filePathName; - CHAR* filePathA; - DWORD len; - - DWORD constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure written by */ - WORD constant2 = 0x3; /* FileMoniker_Save function in a windows program system */ - - WORD zero=0; - DWORD doubleLenHex; - DWORD doubleLenDec; - int i=0; - - TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty); - - if (pStm==NULL) - return E_POINTER; - - /* write a DWORD set to 0 : constant */ - res=IStream_Write(pStm,&zero,sizeof(WORD),NULL); - - /* write length of filePath string ( "\0" included )*/ - len = WideCharToMultiByte( CP_ACP, 0, filePathW, -1, NULL, 0, NULL, NULL ); - res=IStream_Write(pStm,&len,sizeof(DWORD),NULL); - - /* write filePath string type A */ - filePathA=HeapAlloc(GetProcessHeap(),0,len); - WideCharToMultiByte( CP_ACP, 0, filePathW, -1, filePathA, len, NULL, NULL ); - res=IStream_Write(pStm,filePathA,len,NULL); - HeapFree(GetProcessHeap(),0,filePathA); - - /* write a DWORD set to 0xDEADFFFF: constant */ - res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL); - - len--; - /* write 10 times a DWORD set to 0 : constants */ - for(i=0;i<10;i++) - res=IStream_Write(pStm,&zero,sizeof(WORD),NULL); - - if (len>8) - len=0; - - doubleLenHex=doubleLenDec=2*len; - if (len > 5) - doubleLenDec+=6; - - /* write double-length of the path string ( "\0" included )*/ - res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL); - - if (len==0) - return res; - - /* write double-length (hexa representation) of the path string ( "\0" included ) */ - res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL); - - /* write a WORD set to 0x3: constant */ - res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL); - - /* write path unicode string */ - res=IStream_Write(pStm,filePathW,doubleLenHex,NULL); - - return res; -} - -/****************************************************************************** - * FileMoniker_GetSizeMax - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, - ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */ -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - DWORD len=lstrlenW(This->filePathName); - DWORD sizeMAx; - - TRACE("(%p,%p)\n",iface,pcbSize); - - if (pcbSize!=NULL) - return E_POINTER; - - /* for more details see FileMonikerImpl_Save coments */ - - sizeMAx = sizeof(WORD) + /* first WORD is 0 */ - sizeof(DWORD)+ /* length of filePath including "\0" in the end of the string */ - (len+1)+ /* filePath string */ - sizeof(DWORD)+ /* constant : 0xDEADFFFF */ - 10*sizeof(WORD)+ /* 10 zero WORD */ - sizeof(DWORD); /* size of the unicode filePath: "\0" not included */ - - if (len==0 || len > 8) - return S_OK; - - sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */ - sizeof(WORD)+ /* constant : 0x3 */ - len*sizeof(WCHAR); /* unicde filePath string */ - - pcbSize->u.LowPart=sizeMAx; - pcbSize->u.HighPart=0; - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_Construct (local function) - *******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName) -{ - int nb=0,i; - int sizeStr=lstrlenW(lpszPathName); - LPOLESTR *tabStr=0; - static const WCHAR twoPoint[]={'.','.',0}; - static const WCHAR bkSlash[]={'\\',0}; - BYTE addBkSlash; - - TRACE("(%p,%p)\n",This,lpszPathName); - - /* Initialize the virtual fgunction table. */ - This->lpvtbl1 = &VT_FileMonikerImpl; - This->lpvtbl2 = &VT_ROTDataImpl; - This->ref = 0; - - This->filePathName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1)); - - if (This->filePathName==NULL) - return E_OUTOFMEMORY; - - strcpyW(This->filePathName,lpszPathName); - - nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr); - - if (nb > 0 ){ - - addBkSlash=1; - if (lstrcmpW(tabStr[0],twoPoint)!=0) - addBkSlash=0; - else - for(i=0;ifilePathName=HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR)); - - *This->filePathName=0; - - for(i=0;tabStr[i]!=NULL;i++) - strcatW(This->filePathName,tabStr[i]); - - if (addBkSlash) - strcatW(This->filePathName,bkSlash); - } - - for(i=0; tabStr[i]!=NULL;i++) - CoTaskMemFree(tabStr[i]); - CoTaskMemFree(tabStr); - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_Destroy (local function) - *******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This) -{ - TRACE("(%p)\n",This); - - if (This->filePathName!=NULL) - HeapFree(GetProcessHeap(),0,This->filePathName); - - HeapFree(GetProcessHeap(),0,This); - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_BindToObject - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - HRESULT res=E_FAIL; - CLSID clsID; - IUnknown* pObj=0; - IRunningObjectTable *prot=0; - IPersistFile *ppf=0; - IClassFactory *pcf=0; - IClassActivator *pca=0; - - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - *ppvResult=0; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - - if(pmkToLeft==NULL){ - - res=IBindCtx_GetRunningObjectTable(pbc,&prot); - - if (SUCCEEDED(res)){ - /* if the requested class was loaded before ! we don't need to reload it */ - res = IRunningObjectTable_GetObject(prot,iface,&pObj); - - if (res==S_FALSE){ - /* first activation of this class */ - res=GetClassFile(This->filePathName,&clsID); - if (SUCCEEDED(res)){ - - res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf); - if (SUCCEEDED(res)){ - - res=IPersistFile_Load(ppf,This->filePathName,STGM_READ); - if (SUCCEEDED(res)){ - - pObj=(IUnknown*)ppf; - IUnknown_AddRef(pObj); - } - } - } - } - } - } - else{ - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf); - - if (res==E_NOINTERFACE){ - - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca); - - if (res==E_NOINTERFACE) - return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED; - } - if (pcf!=NULL){ - - IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf); - - res=IPersistFile_Load(ppf,This->filePathName,STGM_READ); - - if (SUCCEEDED(res)){ - - pObj=(IUnknown*)ppf; - IUnknown_AddRef(pObj); - } - } - if (pca!=NULL){ - - FIXME("()\n"); - - /*res=GetClassFile(This->filePathName,&clsID); - - if (SUCCEEDED(res)){ - - res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf); - - if (SUCCEEDED(res)){ - - pObj=(IUnknown*)ppf; - IUnknown_AddRef(pObj); - } - }*/ - } - } - - if (pObj!=NULL){ - /* get the requested interface from the loaded class */ - res= IUnknown_QueryInterface(pObj,riid,ppvResult); - - IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult); - - IUnknown_Release(pObj); - } - - if (prot!=NULL) - IRunningObjectTable_Release(prot); - - if (ppf!=NULL) - IPersistFile_Release(ppf); - - if (pca!=NULL) - IClassActivator_Release(pca); - - if (pcf!=NULL) - IClassFactory_Release(pcf); - - return res; -} - -/****************************************************************************** - * FileMoniker_BindToStorage - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvObject) -{ - LPOLESTR filePath=0; - IStorage *pstg=0; - HRESULT res; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject); - - if (pmkToLeft==NULL){ - - if (IsEqualIID(&IID_IStorage, riid)){ - - /* get the file name */ - FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath); - - /* verifie if the file contains a storage object */ - res=StgIsStorageFile(filePath); - - if(res==S_OK){ - - res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg); - - if (SUCCEEDED(res)){ - - *ppvObject=pstg; - - IStorage_AddRef(pstg); - - return res; - } - } - CoTaskMemFree(filePath); - } - else - if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) ) - return E_FAIL; - else - return E_NOINTERFACE; - } - else { - - FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject); - - return E_NOTIMPL; - } - return res; -} - -/****************************************************************************** - * FileMoniker_Reduce - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface, - IBindCtx* pbc, - DWORD dwReduceHowFar, - IMoniker** ppmkToLeft, - IMoniker** ppmkReduced) -{ - TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced); - - if (ppmkReduced==NULL) - return E_POINTER; - - FileMonikerImpl_AddRef(iface); - - *ppmkReduced=iface; - - return MK_S_REDUCED_TO_SELF; -} -/****************************************************************************** - * FileMoniker_ComposeWith - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface, - IMoniker* pmkRight, - BOOL fOnlyIfNotGeneric, - IMoniker** ppmkComposite) -{ - HRESULT res; - LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0; - static const WCHAR twoPoint[]={'.','.',0}; - static const WCHAR bkSlash[]={'\\',0}; - IBindCtx *bind=0; - int i=0,j=0,lastIdx1=0,lastIdx2=0; - DWORD mkSys; - - TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite); - - if (ppmkComposite==NULL) - return E_POINTER; - - if (pmkRight==NULL) - return E_INVALIDARG; - - *ppmkComposite=0; - - IMoniker_IsSystemMoniker(pmkRight,&mkSys); - - /* check if we have two filemonikers to compose or not */ - if(mkSys==MKSYS_FILEMONIKER){ - - CreateBindCtx(0,&bind); - - FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1); - IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2); - - /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */ - lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1; - lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1; - - if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0)) - return MK_E_SYNTAX; - - if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0) - lastIdx1--; - - /* for etch "..\" in the left of str2 remove the right element from str1 */ - for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){ - - lastIdx1-=2; - } - - /* the length of the composed path string is raised by the sum of the two paths lengths */ - newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1)); - - if (newStr==NULL) - return E_OUTOFMEMORY; - - /* new path is the concatenation of the rest of str1 and str2 */ - for(*newStr=0,j=0;j<=lastIdx1;j++) - strcatW(newStr,strDec1[j]); - - if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0) - strcatW(newStr,bkSlash); - - for(j=i;j<=lastIdx2;j++) - strcatW(newStr,strDec2[j]); - - /* create a new moniker with the new string */ - res=CreateFileMoniker(newStr,ppmkComposite); - - /* free all strings space memory used by this function */ - HeapFree(GetProcessHeap(),0,newStr); - - for(i=0; strDec1[i]!=NULL;i++) - CoTaskMemFree(strDec1[i]); - for(i=0; strDec2[i]!=NULL;i++) - CoTaskMemFree(strDec2[i]); - CoTaskMemFree(strDec1); - CoTaskMemFree(strDec2); - - CoTaskMemFree(str1); - CoTaskMemFree(str2); - - return res; - } - else if(mkSys==MKSYS_ANTIMONIKER){ - - *ppmkComposite=NULL; - return S_OK; - } - else if (fOnlyIfNotGeneric){ - - *ppmkComposite=NULL; - return MK_E_NEEDGENERIC; - } - else - - return CreateGenericComposite(iface,pmkRight,ppmkComposite); -} - -/****************************************************************************** - * FileMoniker_Enum - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker) -{ - TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker); - - if (ppenumMoniker == NULL) - return E_POINTER; - - *ppenumMoniker = NULL; - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_IsEqual - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - CLSID clsid; - LPOLESTR filePath; - IBindCtx* bind; - HRESULT res; - - TRACE("(%p,%p)\n",iface,pmkOtherMoniker); - - if (pmkOtherMoniker==NULL) - return S_FALSE; - - IMoniker_GetClassID(pmkOtherMoniker,&clsid); - - if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker)) - return S_FALSE; - - res = CreateBindCtx(0,&bind); - if (FAILED(res)) return res; - - if (SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath))) { - int result = lstrcmpiW(filePath, This->filePathName); - CoTaskMemFree(filePath); - if ( result == 0 ) return S_OK; - } - return S_FALSE; - -} - -/****************************************************************************** - * FileMoniker_Hash - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - int h = 0,i,skip,len; - int off = 0; - LPOLESTR val; - - if (pdwHash==NULL) - return E_POINTER; - - val = This->filePathName; - len = lstrlenW(val); - - if (len < 16) { - for (i = len ; i > 0; i--) { - h = (h * 37) + val[off++]; - } - } else { - /* only sample some characters */ - skip = len / 8; - for (i = len ; i > 0; i -= skip, off += skip) { - h = (h * 39) + val[off]; - } - } - - *pdwHash=h; - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_IsRunning - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - IMoniker* pmkNewlyRunning) -{ - IRunningObjectTable* rot; - HRESULT res; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); - - if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) ) - return S_OK; - - if (pbc==NULL) - return E_POINTER; - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - res = IRunningObjectTable_IsRunning(rot,iface); - - IRunningObjectTable_Release(rot); - - return res; -} - -/****************************************************************************** - * FileMoniker_GetTimeOfLastChange - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - FILETIME* pFileTime) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - IRunningObjectTable* rot; - HRESULT res; - WIN32_FILE_ATTRIBUTE_DATA info; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime); - - if (pFileTime==NULL) - return E_POINTER; - - if (pmkToLeft!=NULL) - return E_INVALIDARG; - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime); - - if (FAILED(res)){ /* the moniker is not registered */ - - if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info)) - return MK_E_NOOBJECT; - - *pFileTime=info.ftLastWriteTime; - } - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_Inverse - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk) -{ - - TRACE("(%p,%p)\n",iface,ppmk); - - return CreateAntiMoniker(ppmk); -} - -/****************************************************************************** - * FileMoniker_CommonPrefixWith - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix) -{ - - LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath; - IBindCtx *pbind; - DWORD mkSys; - ULONG nb1,nb2,i,sameIdx; - BOOL machimeNameCase=FALSE; - - if (ppmkPrefix==NULL) - return E_POINTER; - - if (pmkOther==NULL) - return E_INVALIDARG; - - *ppmkPrefix=0; - - /* check if we have the same type of moniker */ - IMoniker_IsSystemMoniker(pmkOther,&mkSys); - - if(mkSys==MKSYS_FILEMONIKER){ - HRESULT ret; - - CreateBindCtx(0,&pbind); - - /* create a string based on common part of the two paths */ - - IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis); - IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther); - - nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1); - nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2); - - if (nb1==0 || nb2==0) - return MK_E_NOPREFIX; - - commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1)); - - *commonPath=0; - - for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) && - (stringTable2[sameIdx]!=NULL) && - (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++); - - if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){ - - machimeNameCase=TRUE; - - for(i=2;i 3 || nb2 > 3) ) - ret = MK_E_NOPREFIX; - else - { - for(i=0;i0 && !(len1==1 && len2==1 && sameIdx==0)) - for(j=sameIdx;(tabStr1[j] != NULL); j++) - if (*tabStr1[j]!='\\') - strcatW(relPath,back); - - /* add items of the second path (similar items with the first path are not included) to the relativePath */ - for(j=sameIdx;tabStr2[j]!=NULL;j++) - strcatW(relPath,tabStr2[j]); - - res=CreateFileMoniker(relPath,ppmkRelPath); - - for(j=0; tabStr1[j]!=NULL;j++) - CoTaskMemFree(tabStr1[j]); - for(j=0; tabStr2[j]!=NULL;j++) - CoTaskMemFree(tabStr2[j]); - CoTaskMemFree(tabStr1); - CoTaskMemFree(tabStr2); - CoTaskMemFree(str1); - CoTaskMemFree(str2); - HeapFree(GetProcessHeap(),0,relPath); - - if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0)) - return MK_S_HIM; - - return res; -} - -/****************************************************************************** - * FileMoniker_GetDisplayName - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR *ppszDisplayName) -{ - FileMonikerImpl *This = (FileMonikerImpl *)iface; - - int len=lstrlenW(This->filePathName); - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName); - - if (ppszDisplayName==NULL) - return E_POINTER; - - if (pmkToLeft!=NULL) - return E_INVALIDARG; - - *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(len+1)); - if (*ppszDisplayName==NULL) - return E_OUTOFMEMORY; - - strcpyW(*ppszDisplayName,This->filePathName); - - return S_OK; -} - -/****************************************************************************** - * FileMoniker_ParseDisplayName - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR pszDisplayName, - ULONG* pchEaten, - IMoniker** ppmkOut) -{ - FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut); - return E_NOTIMPL; -} - -/****************************************************************************** - * FileMoniker_IsSystemMoniker - ******************************************************************************/ -HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys) -{ - TRACE("(%p,%p)\n",iface,pwdMksys); - - if (!pwdMksys) - return E_POINTER; - - (*pwdMksys)=MKSYS_FILEMONIKER; - - return S_OK; -} - -/******************************************************************************* - * FileMonikerIROTData_QueryInterface - *******************************************************************************/ -HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) -{ - - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - return FileMonikerImpl_QueryInterface(This, riid, ppvObject); -} - -/*********************************************************************** - * FileMonikerIROTData_AddRef - */ -ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",This); - - return FileMonikerImpl_AddRef(This); -} - -/*********************************************************************** - * FileMonikerIROTData_Release - */ -ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",This); - - return FileMonikerImpl_Release(This); -} - -/****************************************************************************** - * FileMonikerIROTData_GetComparaisonData - ******************************************************************************/ -HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface, - BYTE* pbData, - ULONG cbMax, - ULONG* pcbData) -{ - FIXME("(),stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * CreateFileMoniker (OLE32.@) - ******************************************************************************/ -HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk) -{ - FileMonikerImpl* newFileMoniker = 0; - HRESULT hr = E_FAIL; - IID riid=IID_IMoniker; - - TRACE("(%p,%p)\n",lpszPathName,ppmk); - - if (ppmk==NULL) - return E_POINTER; - - if(lpszPathName==NULL) - return MK_E_SYNTAX; - - *ppmk=0; - - newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl)); - - if (newFileMoniker == 0) - return E_OUTOFMEMORY; - - hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName); - - if (SUCCEEDED(hr)) - hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk); - else - HeapFree(GetProcessHeap(),0,newFileMoniker); - - return hr; -} diff --git a/reactos/lib/ole32/ftmarshal.c b/reactos/lib/ole32/ftmarshal.c deleted file mode 100644 index ee5f9a4839b..00000000000 --- a/reactos/lib/ole32/ftmarshal.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * free threaded marshaller - * - * Copyright 2002 Juergen Schmied - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "objbase.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -typedef struct _FTMarshalImpl { - IUnknownVtbl *lpVtbl; - DWORD ref; - IMarshalVtbl *lpvtblFTM; - - IUnknown *pUnkOuter; -} 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); - -/* inner IUnknown to handle aggregation */ -HRESULT WINAPI IiFTMUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppv) -{ - - FTMarshalImpl *This = (FTMarshalImpl *)iface; - - TRACE ("\n"); - *ppv = NULL; - - if (IsEqualIID (&IID_IUnknown, riid)) - *ppv = _IFTMUnknown_ (This); - else if (IsEqualIID (&IID_IMarshal, riid)) - *ppv = _IFTMarshal_ (This); - else { - FIXME ("No interface for %s.\n", debugstr_guid (riid)); - return E_NOINTERFACE; - } - IUnknown_AddRef ((IUnknown *) * ppv); - return S_OK; -} - -ULONG WINAPI IiFTMUnknown_fnAddRef (IUnknown * iface) -{ - - FTMarshalImpl *This = (FTMarshalImpl *)iface; - - TRACE ("\n"); - return InterlockedIncrement (&This->ref); -} - -ULONG WINAPI IiFTMUnknown_fnRelease (IUnknown * iface) -{ - - FTMarshalImpl *This = (FTMarshalImpl *)iface; - - TRACE ("\n"); - if (InterlockedDecrement (&This->ref)) - return This->ref; - HeapFree (GetProcessHeap (), 0, This); - return 0; -} - -static IUnknownVtbl iunkvt = -{ - IiFTMUnknown_fnQueryInterface, - IiFTMUnknown_fnAddRef, - IiFTMUnknown_fnRelease -}; - -HRESULT WINAPI FTMarshalImpl_QueryInterface (LPMARSHAL iface, REFIID riid, LPVOID * ppv) -{ - - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); - - TRACE ("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid (riid), ppv); - return IUnknown_QueryInterface (This->pUnkOuter, riid, ppv); -} - -ULONG WINAPI FTMarshalImpl_AddRef (LPMARSHAL iface) -{ - - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); - - TRACE ("\n"); - return IUnknown_AddRef (This->pUnkOuter); -} - -ULONG WINAPI FTMarshalImpl_Release (LPMARSHAL iface) -{ - - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); - - TRACE ("\n"); - return IUnknown_Release (This->pUnkOuter); -} - -HRESULT WINAPI FTMarshalImpl_GetUnmarshalClass (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext, - void *pvDestContext, DWORD mshlflags, CLSID * pCid) -{ - FIXME ("(), stub!\n"); - return S_OK; -} - -HRESULT WINAPI FTMarshalImpl_GetMarshalSizeMax (LPMARSHAL iface, REFIID riid, void *pv, DWORD dwDestContext, - void *pvDestContext, DWORD mshlflags, DWORD * pSize) -{ - - IMarshal *pMarshal = NULL; - HRESULT hres; - - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); - - FIXME ("(), stub!\n"); - - /* if the marshalling happens inside the same process the interface pointer is - copied between the apartments */ - if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) { - *pSize = sizeof (This); - return S_OK; - } - - /* use the standard marshaller to handle all other cases */ - CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal); - hres = IMarshal_GetMarshalSizeMax (pMarshal, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize); - IMarshal_Release (pMarshal); - return hres; - - return S_OK; -} - -HRESULT WINAPI FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv, - DWORD dwDestContext, void *pvDestContext, DWORD mshlflags) -{ - - IMarshal *pMarshal = NULL; - HRESULT hres; - - _ICOM_THIS_From_IFTMarshal (FTMarshalImpl, iface); - - FIXME ("(), stub!\n"); - - /* if the marshalling happens inside the same process the interface pointer is - copied between the apartments */ - if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) { - return IStream_Write (pStm, This, sizeof (This), 0); - } - - /* use the standard marshaler to handle all other cases */ - CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal); - hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags); - IMarshal_Release (pMarshal); - return hres; -} - -HRESULT WINAPI FTMarshalImpl_UnmarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void **ppv) -{ - FIXME ("(), stub!\n"); - return S_OK; -} - -HRESULT WINAPI FTMarshalImpl_ReleaseMarshalData (LPMARSHAL iface, IStream * pStm) -{ - FIXME ("(), stub!\n"); - return S_OK; -} - -HRESULT WINAPI FTMarshalImpl_DisconnectObject (LPMARSHAL iface, DWORD dwReserved) -{ - FIXME ("(), stub!\n"); - return S_OK; -} - -IMarshalVtbl ftmvtbl = -{ - FTMarshalImpl_QueryInterface, - FTMarshalImpl_AddRef, - FTMarshalImpl_Release, - FTMarshalImpl_GetUnmarshalClass, - FTMarshalImpl_GetMarshalSizeMax, - FTMarshalImpl_MarshalInterface, - FTMarshalImpl_UnmarshalInterface, - FTMarshalImpl_ReleaseMarshalData, - FTMarshalImpl_DisconnectObject -}; - -/*********************************************************************** - * CoCreateFreeThreadedMarshaler [OLE32.@] - * - */ -HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN * ppunkMarshal) -{ - - FTMarshalImpl *ftm; - - TRACE ("(%p %p)\n", punkOuter, ppunkMarshal); - - ftm = (FTMarshalImpl *) HeapAlloc (GetProcessHeap (), 0, sizeof (FTMarshalImpl)); - if (!ftm) - return E_OUTOFMEMORY; - - ftm->lpVtbl = &iunkvt; - ftm->lpvtblFTM = &ftmvtbl; - ftm->ref = 1; - ftm->pUnkOuter = punkOuter; - - *ppunkMarshal = _IFTMUnknown_ (ftm); - return S_OK; -} diff --git a/reactos/lib/ole32/git.c b/reactos/lib/ole32/git.c deleted file mode 100644 index 81f0986f4fd..00000000000 --- a/reactos/lib/ole32/git.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Implementation of the StdGlobalInterfaceTable object - * - * The GlobalInterfaceTable (GIT) object is used to marshal interfaces between - * threading apartments (contexts). When you want to pass an interface but not - * as a parameter, it wouldn't get marshalled automatically, so you can use this - * object to insert the interface into a table, and you get back a cookie. - * Then when it's retrieved, it'll be unmarshalled into the right apartment. - * - * Copyright 2003 Mike Hearn - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "winerror.h" -#include "winreg.h" -#include "winternl.h" - -#include "compobj_private.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/**************************************************************************** - * StdGlobalInterfaceTable definition - * - * This class implements IGlobalInterfaceTable and is a process-wide singleton - * used for marshalling interfaces between threading apartments using cookies. - */ - -/* Each entry in the linked list of GIT entries */ -typedef struct StdGITEntry -{ - DWORD cookie; - IID iid; /* IID of the interface */ - IStream* stream; /* Holds the marshalled interface */ - - struct StdGITEntry* next; - struct StdGITEntry* prev; -} StdGITEntry; - -/* Class data */ -typedef struct StdGlobalInterfaceTableImpl -{ - IGlobalInterfaceTableVtbl *lpVtbl; - - ULONG ref; - struct StdGITEntry* firstEntry; - struct StdGITEntry* lastEntry; - ULONG nextCookie; - -} StdGlobalInterfaceTableImpl; - -void* StdGlobalInterfaceTableInstance; - - -/* IUnknown */ -static HRESULT WINAPI StdGlobalInterfaceTable_QueryInterface(IGlobalInterfaceTable* iface, REFIID riid, void** ppvObject); -static ULONG WINAPI StdGlobalInterfaceTable_AddRef(IGlobalInterfaceTable* iface); -static ULONG WINAPI StdGlobalInterfaceTable_Release(IGlobalInterfaceTable* iface); -/* IGlobalInterfaceTable */ -static HRESULT WINAPI StdGlobalInterfaceTable_RegisterInterfaceInGlobal(IGlobalInterfaceTable* iface, IUnknown* pUnk, REFIID riid, DWORD* pdwCookie); -static HRESULT WINAPI StdGlobalInterfaceTable_RevokeInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie); -static HRESULT WINAPI StdGlobalInterfaceTable_GetInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie, REFIID riid, void **ppv); - -/* Virtual function table */ -static IGlobalInterfaceTableVtbl StdGlobalInterfaceTableImpl_Vtbl = -{ - StdGlobalInterfaceTable_QueryInterface, - StdGlobalInterfaceTable_AddRef, - StdGlobalInterfaceTable_Release, - StdGlobalInterfaceTable_RegisterInterfaceInGlobal, - StdGlobalInterfaceTable_RevokeInterfaceFromGlobal, - StdGlobalInterfaceTable_GetInterfaceFromGlobal -}; - -static CRITICAL_SECTION git_section; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &git_section, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { 0, (DWORD)(__FILE__ ": global interface table") } -}; -static CRITICAL_SECTION git_section = { &critsect_debug, -1, 0, 0, 0, 0 }; - - -/*** - * Let's go! Here is the constructor and destructor for the class. - * - */ - -/** This function constructs the GIT. It should only be called once **/ -void* StdGlobalInterfaceTable_Construct() { - StdGlobalInterfaceTableImpl* newGIT; - - newGIT = HeapAlloc(GetProcessHeap(), 0, sizeof(StdGlobalInterfaceTableImpl)); - if (newGIT == 0) return newGIT; - - newGIT->lpVtbl = &StdGlobalInterfaceTableImpl_Vtbl; - newGIT->ref = 1; /* Initialise the reference count */ - newGIT->firstEntry = NULL; /* we start with an empty table */ - newGIT->lastEntry = NULL; - newGIT->nextCookie = 0xf100; /* that's where windows starts, so that's where we start */ - TRACE("Created the GIT at %p\n", newGIT); - - return (void*)newGIT; -} - -/** This destroys it again. It should revoke all the held interfaces first **/ -void StdGlobalInterfaceTable_Destroy(void* self) { - TRACE("(%p)\n", self); - FIXME("Revoke held interfaces here\n"); - - HeapFree(GetProcessHeap(), 0, self); - StdGlobalInterfaceTableInstance = NULL; -} - -/*** - * A helper function to traverse the list and find the entry that matches the cookie. - * Returns NULL if not found - */ -StdGITEntry* StdGlobalInterfaceTable_FindEntry(IGlobalInterfaceTable* iface, DWORD cookie) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - StdGITEntry* e; - - TRACE("iface=%p, cookie=0x%x\n", iface, (UINT)cookie); - - EnterCriticalSection(&git_section); - e = self->firstEntry; - while (e != NULL) { - if (e->cookie == cookie) { - LeaveCriticalSection(&git_section); - return e; - } - e = e->next; - } - LeaveCriticalSection(&git_section); - - TRACE("Entry not found\n"); - return NULL; -} - -/*** - * Here's the boring boilerplate stuff for IUnknown - */ - -HRESULT WINAPI StdGlobalInterfaceTable_QueryInterface(IGlobalInterfaceTable* iface, REFIID riid, void** ppvObject) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - - /* Make sure silly coders can't crash us */ - if (ppvObject == 0) return E_INVALIDARG; - - *ppvObject = 0; /* assume we don't have the interface */ - - /* Do we implement that interface? */ - if (IsEqualIID(&IID_IUnknown, riid)) { - *ppvObject = (IGlobalInterfaceTable*) self; - } else if (IsEqualIID(&IID_IGlobalInterfaceTable, riid)) { - *ppvObject = (IGlobalInterfaceTable*) self; - } else return E_NOINTERFACE; - - /* Now inc the refcount */ - StdGlobalInterfaceTable_AddRef(iface); - return S_OK; -} - -ULONG WINAPI StdGlobalInterfaceTable_AddRef(IGlobalInterfaceTable* iface) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - - /* InterlockedIncrement(&self->ref); */ - return self->ref; -} - -ULONG WINAPI StdGlobalInterfaceTable_Release(IGlobalInterfaceTable* iface) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - - /* InterlockedDecrement(&self->ref); */ - if (self->ref == 0) { - /* Hey ho, it's time to go, so long again 'till next weeks show! */ - StdGlobalInterfaceTable_Destroy(self); - return 0; - } - - return self->ref; -} - -/*** - * Now implement the actual IGlobalInterfaceTable interface - */ - -HRESULT WINAPI StdGlobalInterfaceTable_RegisterInterfaceInGlobal(IGlobalInterfaceTable* iface, IUnknown* pUnk, REFIID riid, DWORD* pdwCookie) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - IStream* stream = NULL; - HRESULT hres; - StdGITEntry* entry; - - TRACE("iface=%p, pUnk=%p, riid=%s, pdwCookie=0x%p\n", iface, pUnk, debugstr_guid(riid), pdwCookie); - - if (pUnk == NULL) return E_INVALIDARG; - - /* marshal the interface */ - TRACE("About to marshal the interface\n"); - hres = CoMarshalInterThreadInterfaceInStream(riid, pUnk, &stream); - if (hres) return hres; - entry = HeapAlloc(GetProcessHeap(), 0, sizeof(StdGITEntry)); - if (entry == NULL) return E_OUTOFMEMORY; - - EnterCriticalSection(&git_section); - - entry->iid = *riid; - entry->stream = stream; - entry->cookie = self->nextCookie; - self->nextCookie++; /* inc the cookie count */ - - /* insert the new entry at the end of the list */ - entry->next = NULL; - entry->prev = self->lastEntry; - if (entry->prev) entry->prev->next = entry; - else self->firstEntry = entry; - self->lastEntry = entry; - - /* and return the cookie */ - *pdwCookie = entry->cookie; - - LeaveCriticalSection(&git_section); - - TRACE("Cookie is 0x%lx\n", entry->cookie); - return S_OK; -} - -HRESULT WINAPI StdGlobalInterfaceTable_RevokeInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie) { - StdGlobalInterfaceTableImpl* const self = (StdGlobalInterfaceTableImpl*) iface; - StdGITEntry* entry; - - TRACE("iface=%p, dwCookie=0x%x\n", iface, (UINT)dwCookie); - - entry = StdGlobalInterfaceTable_FindEntry(iface, dwCookie); - if (entry == NULL) { - TRACE("Entry not found\n"); - return E_INVALIDARG; /* not found */ - } - - /* Free the stream */ - IStream_Release(entry->stream); - - /* chop entry out of the list, and free the memory */ - EnterCriticalSection(&git_section); - if (entry->prev) entry->prev->next = entry->next; - else self->firstEntry = entry->next; - if (entry->next) entry->next->prev = entry->prev; - else self->lastEntry = entry->prev; - LeaveCriticalSection(&git_section); - - HeapFree(GetProcessHeap(), 0, entry); - return S_OK; -} - -HRESULT WINAPI StdGlobalInterfaceTable_GetInterfaceFromGlobal(IGlobalInterfaceTable* iface, DWORD dwCookie, REFIID riid, void **ppv) { - StdGITEntry* entry; - HRESULT hres; - LARGE_INTEGER move; - LPUNKNOWN lpUnk; - - TRACE("dwCookie=0x%lx, riid=%s, ppv=%p\n", dwCookie, debugstr_guid(riid), ppv); - - entry = StdGlobalInterfaceTable_FindEntry(iface, dwCookie); - if (entry == NULL) return E_INVALIDARG; - - if (!IsEqualIID(&entry->iid, riid)) { - WARN("entry->iid (%s) != riid\n", debugstr_guid(&entry->iid)); - return E_INVALIDARG; - } - TRACE("entry=%p\n", entry); - - /* unmarshal the interface */ - hres = CoUnmarshalInterface(entry->stream, riid, ppv); - if (hres) { - WARN("Failed to unmarshal stream\n"); - return hres; - } - - /* rewind stream, in case it's used again */ - move.u.LowPart = 0; - move.u.HighPart = 0; - IStream_Seek(entry->stream, move, STREAM_SEEK_SET, NULL); - - /* addref it */ - lpUnk = *ppv; - IUnknown_AddRef(lpUnk); - TRACE("ppv=%p\n", *ppv); - return S_OK; -} - -/* Classfactory definition - despite what MSDN says, some programs need this */ - -static HRESULT WINAPI GITCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IGlobalInterfaceTable)) { - *ppv = (LPVOID)iface; - return S_OK; - } - return E_NOINTERFACE; -} -static ULONG WINAPI GITCF_AddRef(LPCLASSFACTORY iface) { return 2; } -static ULONG WINAPI GITCF_Release(LPCLASSFACTORY iface) { return 1; } - -static HRESULT WINAPI GITCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv) { - if (IsEqualIID(riid,&IID_IGlobalInterfaceTable)) { - if (StdGlobalInterfaceTableInstance == NULL) - StdGlobalInterfaceTableInstance = StdGlobalInterfaceTable_Construct(); - return IGlobalInterfaceTable_QueryInterface( (IGlobalInterfaceTable*) StdGlobalInterfaceTableInstance, riid, ppv); - } - - FIXME("(%s), not supported.\n",debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static HRESULT WINAPI GITCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) { - FIXME("(%d), stub!\n",fLock); - return S_OK; -} - -static IClassFactoryVtbl GITClassFactoryVtbl = { - GITCF_QueryInterface, - GITCF_AddRef, - GITCF_Release, - GITCF_CreateInstance, - GITCF_LockServer -}; -static IClassFactoryVtbl *PGITClassFactoryVtbl = &GITClassFactoryVtbl; - -HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv) { - *ppv = &PGITClassFactoryVtbl; - TRACE("Returning GIT classfactory\n"); - return S_OK; -} diff --git a/reactos/lib/ole32/hglobalstream.c b/reactos/lib/ole32/hglobalstream.c deleted file mode 100644 index 1966a0abe02..00000000000 --- a/reactos/lib/ole32/hglobalstream.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - * HGLOBAL Stream implementation - * - * This file contains the implementation of the stream interface - * for streams contained supported by an HGLOBAL pointer. - * - * Copyright 1999 Francis Beaudet - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "winerror.h" -#include "winreg.h" -#include "winternl.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(storage); - -/**************************************************************************** - * HGLOBALStreamImpl definition. - * - * This class imlements the IStream inteface and represents a stream - * supported by an HGLOBAL pointer. - */ -struct HGLOBALStreamImpl -{ - IStreamVtbl *lpVtbl; /* Needs to be the first item in the stuct - * since we want to cast this in a IStream pointer */ - - /* - * Reference count - */ - ULONG ref; - - /* - * Support for the stream - */ - HGLOBAL supportHandle; - - /* - * This flag is TRUE if the HGLOBAL is destroyed when the stream - * is finally released. - */ - BOOL deleteOnRelease; - - /* - * Helper variable that contains the size of the stream - */ - ULARGE_INTEGER streamSize; - - /* - * This is the current position of the cursor in the stream - */ - ULARGE_INTEGER currentPosition; -}; - -typedef struct HGLOBALStreamImpl HGLOBALStreamImpl; - -/* - * Method definition for the StgStreamImpl class. - */ -HGLOBALStreamImpl* HGLOBALStreamImpl_Construct( - HGLOBAL hGlobal, - BOOL fDeleteOnRelease); - -void HGLOBALStreamImpl_Destroy( - HGLOBALStreamImpl* This); - -void HGLOBALStreamImpl_OpenBlockChain( - HGLOBALStreamImpl* This); - -HRESULT WINAPI HGLOBALStreamImpl_QueryInterface( - IStream* iface, - REFIID riid, /* [in] */ - void** ppvObject); /* [iid_is][out] */ - -ULONG WINAPI HGLOBALStreamImpl_AddRef( - IStream* iface); - -ULONG WINAPI HGLOBALStreamImpl_Release( - IStream* iface); - -HRESULT WINAPI HGLOBALStreamImpl_Read( - IStream* iface, - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead); /* [out] */ - -HRESULT WINAPI HGLOBALStreamImpl_Write( - IStream* iface, - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten); /* [out] */ - -HRESULT WINAPI HGLOBALStreamImpl_Seek( - IStream* iface, - LARGE_INTEGER dlibMove, /* [in] */ - DWORD dwOrigin, /* [in] */ - ULARGE_INTEGER* plibNewPosition); /* [out] */ - -HRESULT WINAPI HGLOBALStreamImpl_SetSize( - IStream* iface, - ULARGE_INTEGER libNewSize); /* [in] */ - -HRESULT WINAPI HGLOBALStreamImpl_CopyTo( - IStream* iface, - IStream* pstm, /* [unique][in] */ - ULARGE_INTEGER cb, /* [in] */ - ULARGE_INTEGER* pcbRead, /* [out] */ - ULARGE_INTEGER* pcbWritten); /* [out] */ - -HRESULT WINAPI HGLOBALStreamImpl_Commit( - IStream* iface, - DWORD grfCommitFlags); /* [in] */ - -HRESULT WINAPI HGLOBALStreamImpl_Revert( - IStream* iface); - -HRESULT WINAPI HGLOBALStreamImpl_LockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALStreamImpl_Stat( - IStream* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -HRESULT WINAPI HGLOBALStreamImpl_Clone( - IStream* iface, - IStream** ppstm); /* [out] */ - - -/* - * Virtual function table for the HGLOBALStreamImpl class. - */ -static IStreamVtbl HGLOBALStreamImpl_Vtbl = -{ - HGLOBALStreamImpl_QueryInterface, - HGLOBALStreamImpl_AddRef, - HGLOBALStreamImpl_Release, - HGLOBALStreamImpl_Read, - HGLOBALStreamImpl_Write, - HGLOBALStreamImpl_Seek, - HGLOBALStreamImpl_SetSize, - HGLOBALStreamImpl_CopyTo, - HGLOBALStreamImpl_Commit, - HGLOBALStreamImpl_Revert, - HGLOBALStreamImpl_LockRegion, - HGLOBALStreamImpl_UnlockRegion, - HGLOBALStreamImpl_Stat, - HGLOBALStreamImpl_Clone -}; - -/*********************************************************************** - * CreateStreamOnHGlobal [OLE32.@] - */ -HRESULT WINAPI CreateStreamOnHGlobal( - HGLOBAL hGlobal, - BOOL fDeleteOnRelease, - LPSTREAM* ppstm) -{ - HGLOBALStreamImpl* newStream; - - newStream = HGLOBALStreamImpl_Construct(hGlobal, - fDeleteOnRelease); - - if (newStream!=NULL) - { - return IUnknown_QueryInterface((IUnknown*)newStream, - &IID_IStream, - (void**)ppstm); - } - - return E_OUTOFMEMORY; -} - -/*********************************************************************** - * GetHGlobalFromStream [OLE32.@] - */ -HRESULT WINAPI GetHGlobalFromStream(IStream* pstm, HGLOBAL* phglobal) -{ - HGLOBALStreamImpl* pStream; - - if (pstm == NULL) - return E_INVALIDARG; - - pStream = (HGLOBALStreamImpl*) pstm; - - /* - * Verify that the stream object was created with CreateStreamOnHGlobal. - */ - if (pStream->lpVtbl == &HGLOBALStreamImpl_Vtbl) - *phglobal = pStream->supportHandle; - else - { - *phglobal = 0; - return E_INVALIDARG; - } - - return S_OK; -} - -/****************************************************************************** -** HGLOBALStreamImpl implementation -*/ - -/*** - * This is the constructor for the HGLOBALStreamImpl class. - * - * Params: - * hGlobal - Handle that will support the stream. can be NULL. - * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released - * when the IStream object is destroyed. - */ -HGLOBALStreamImpl* HGLOBALStreamImpl_Construct( - HGLOBAL hGlobal, - BOOL fDeleteOnRelease) -{ - HGLOBALStreamImpl* newStream; - - newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALStreamImpl)); - - if (newStream!=0) - { - /* - * Set-up the virtual function table and reference count. - */ - newStream->lpVtbl = &HGLOBALStreamImpl_Vtbl; - newStream->ref = 0; - - /* - * Initialize the support. - */ - newStream->supportHandle = hGlobal; - newStream->deleteOnRelease = fDeleteOnRelease; - - /* - * This method will allocate a handle if one is not supplied. - */ - if (!newStream->supportHandle) - { - newStream->supportHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD | - GMEM_SHARE, 0); - } - - /* - * Start the stream at the beginning. - */ - newStream->currentPosition.u.HighPart = 0; - newStream->currentPosition.u.LowPart = 0; - - /* - * Initialize the size of the stream to the size of the handle. - */ - newStream->streamSize.u.HighPart = 0; - newStream->streamSize.u.LowPart = GlobalSize(newStream->supportHandle); - } - - return newStream; -} - -/*** - * This is the destructor of the HGLOBALStreamImpl class. - * - * This method will clean-up all the resources used-up by the given HGLOBALStreamImpl - * class. The pointer passed-in to this function will be freed and will not - * be valid anymore. - */ -void HGLOBALStreamImpl_Destroy(HGLOBALStreamImpl* This) -{ - TRACE("(%p)\n", This); - - /* - * Release the HGlobal if the constructor asked for that. - */ - if (This->deleteOnRelease) - { - GlobalFree(This->supportHandle); - This->supportHandle=0; - } - - /* - * Finally, free the memory used-up by the class. - */ - HeapFree(GetProcessHeap(), 0, This); -} - -/*** - * This implements the IUnknown method QueryInterface for this - * class - */ -HRESULT WINAPI HGLOBALStreamImpl_QueryInterface( - IStream* iface, - REFIID riid, /* [in] */ - void** ppvObject) /* [iid_is][out] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - - /* - * Perform a sanity check on the parameters. - */ - if (ppvObject==0) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = (IStream*)This; - } - else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) - { - *ppvObject = (IStream*)This; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - HGLOBALStreamImpl_AddRef(iface); - - return S_OK; -} - -/*** - * This implements the IUnknown method AddRef for this - * class - */ -ULONG WINAPI HGLOBALStreamImpl_AddRef( - IStream* iface) -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - return InterlockedIncrement(&This->ref); -} - -/*** - * This implements the IUnknown method Release for this - * class - */ -ULONG WINAPI HGLOBALStreamImpl_Release( - IStream* iface) -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - ULONG newRef; - - newRef = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (newRef==0) - { - HGLOBALStreamImpl_Destroy(This); - } - - return newRef; -} - -/*** - * This method is part of the ISequentialStream interface. - * - * If reads a block of information from the stream at the current - * position. It then moves the current position at the end of the - * read block - * - * See the documentation of ISequentialStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Read( - IStream* iface, - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead) /* [out] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - - void* supportBuffer; - ULONG bytesReadBuffer; - ULONG bytesToReadFromBuffer; - - TRACE("(%p, %p, %ld, %p)\n", iface, - pv, cb, pcbRead); - - /* - * If the caller is not interested in the nubmer of bytes read, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbRead==0) - pcbRead = &bytesReadBuffer; - - /* - * Using the known size of the stream, calculate the number of bytes - * to read from the block chain - */ - bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb); - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock(This->supportHandle); - - memcpy(pv, (char *) supportBuffer+This->currentPosition.u.LowPart, bytesToReadFromBuffer); - - /* - * Move the current position to the new position - */ - This->currentPosition.u.LowPart+=bytesToReadFromBuffer; - - /* - * Return the number of bytes read. - */ - *pcbRead = bytesToReadFromBuffer; - - /* - * Cleanup - */ - GlobalUnlock(This->supportHandle); - - /* - * The function returns S_OK if the buffer was filled completely - * it returns S_FALSE if the end of the stream is reached before the - * buffer is filled - */ - if(*pcbRead == cb) - return S_OK; - - return S_FALSE; -} - -/*** - * This method is part of the ISequentialStream interface. - * - * It writes a block of information to the stream at the current - * position. It then moves the current position at the end of the - * written block. If the stream is too small to fit the block, - * the stream is grown to fit. - * - * See the documentation of ISequentialStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Write( - IStream* iface, - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten) /* [out] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - - void* supportBuffer; - ULARGE_INTEGER newSize; - ULONG bytesWritten = 0; - - TRACE("(%p, %p, %ld, %p)\n", iface, - pv, cb, pcbWritten); - - /* - * If the caller is not interested in the number of bytes written, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbWritten == 0) - pcbWritten = &bytesWritten; - - if (cb == 0) - { - return S_OK; - } - else - { - newSize.u.HighPart = 0; - newSize.u.LowPart = This->currentPosition.u.LowPart + cb; - } - - /* - * Verify if we need to grow the stream - */ - if (newSize.u.LowPart > This->streamSize.u.LowPart) - { - /* grow stream */ - IStream_SetSize(iface, newSize); - } - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock(This->supportHandle); - - memcpy((char *) supportBuffer+This->currentPosition.u.LowPart, pv, cb); - - /* - * Move the current position to the new position - */ - This->currentPosition.u.LowPart+=cb; - - /* - * Return the number of bytes read. - */ - *pcbWritten = cb; - - /* - * Cleanup - */ - GlobalUnlock(This->supportHandle); - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will move the current stream pointer according to the parameters - * given. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Seek( - IStream* iface, - LARGE_INTEGER dlibMove, /* [in] */ - DWORD dwOrigin, /* [in] */ - ULARGE_INTEGER* plibNewPosition) /* [out] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - - ULARGE_INTEGER newPosition; - - TRACE("(%p, %lx%08lx, %ld, %p)\n", iface, dlibMove.u.HighPart, - dlibMove.u.LowPart, dwOrigin, plibNewPosition); - - /* - * The file pointer is moved depending on the given "function" - * parameter. - */ - switch (dwOrigin) - { - case STREAM_SEEK_SET: - newPosition.u.HighPart = 0; - newPosition.u.LowPart = 0; - break; - case STREAM_SEEK_CUR: - newPosition = This->currentPosition; - break; - case STREAM_SEEK_END: - newPosition = This->streamSize; - break; - default: - return STG_E_INVALIDFUNCTION; - } - - /* - * Move the actual file pointer - * If the file pointer ends-up after the end of the stream, the next Write operation will - * make the file larger. This is how it is documented. - */ - newPosition.QuadPart = RtlLargeIntegerAdd(newPosition.QuadPart, dlibMove.QuadPart); - if (newPosition.QuadPart < 0) return STG_E_INVALIDFUNCTION; - - if (plibNewPosition) *plibNewPosition = newPosition; - This->currentPosition = newPosition; - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will change the size of a stream. - * - * TODO: Switch from small blocks to big blocks and vice versa. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_SetSize( - IStream* iface, - ULARGE_INTEGER libNewSize) /* [in] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - HGLOBAL supportHandle; - - TRACE("(%p, %ld)\n", iface, libNewSize.u.LowPart); - - /* - * As documented. - */ - if (libNewSize.u.HighPart != 0) - return STG_E_INVALIDFUNCTION; - - if (This->streamSize.u.LowPart == libNewSize.u.LowPart) - return S_OK; - - /* - * Re allocate the HGlobal to fit the new size of the stream. - */ - supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0); - - if (supportHandle == 0) - return STG_E_MEDIUMFULL; - - This->supportHandle = supportHandle; - This->streamSize.u.LowPart = libNewSize.u.LowPart; - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will copy the 'cb' Bytes to 'pstm' IStream. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_CopyTo( - IStream* iface, - IStream* pstm, /* [unique][in] */ - ULARGE_INTEGER cb, /* [in] */ - ULARGE_INTEGER* pcbRead, /* [out] */ - ULARGE_INTEGER* pcbWritten) /* [out] */ -{ - HRESULT hr = S_OK; - BYTE tmpBuffer[128]; - ULONG bytesRead, bytesWritten, copySize; - ULARGE_INTEGER totalBytesRead; - ULARGE_INTEGER totalBytesWritten; - - TRACE("(%p, %p, %ld, %p, %p)\n", iface, pstm, - cb.u.LowPart, pcbRead, pcbWritten); - - /* - * Sanity check - */ - if ( pstm == 0 ) - return STG_E_INVALIDPOINTER; - - totalBytesRead.u.LowPart = totalBytesRead.u.HighPart = 0; - totalBytesWritten.u.LowPart = totalBytesWritten.u.HighPart = 0; - - /* - * use stack to store data temporarly - * there is surely more performant way of doing it, for now this basic - * implementation will do the job - */ - while ( cb.u.LowPart > 0 ) - { - if ( cb.u.LowPart >= 128 ) - copySize = 128; - else - copySize = cb.u.LowPart; - - IStream_Read(iface, tmpBuffer, copySize, &bytesRead); - - totalBytesRead.u.LowPart += bytesRead; - - IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten); - - totalBytesWritten.u.LowPart += bytesWritten; - - /* - * Check that read & write operations were succesfull - */ - if (bytesRead != bytesWritten) - { - hr = STG_E_MEDIUMFULL; - break; - } - - if (bytesRead!=copySize) - cb.u.LowPart = 0; - else - cb.u.LowPart -= bytesRead; - } - - /* - * Update number of bytes read and written - */ - if (pcbRead) - { - pcbRead->u.LowPart = totalBytesRead.u.LowPart; - pcbRead->u.HighPart = totalBytesRead.u.HighPart; - } - - if (pcbWritten) - { - pcbWritten->u.LowPart = totalBytesWritten.u.LowPart; - pcbWritten->u.HighPart = totalBytesWritten.u.HighPart; - } - return hr; -} - -/*** - * This method is part of the IStream interface. - * - * For streams supported by HGLOBALS, this function does nothing. - * This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Commit( - IStream* iface, - DWORD grfCommitFlags) /* [in] */ -{ - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * For streams supported by HGLOBALS, this function does nothing. - * This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Revert( - IStream* iface) -{ - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * For streams supported by HGLOBALS, this function does nothing. - * This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_LockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return S_OK; -} - -/* - * This method is part of the IStream interface. - * - * For streams supported by HGLOBALS, this function does nothing. - * This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * This method returns information about the current - * stream. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI HGLOBALStreamImpl_Stat( - IStream* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - - memset(pstatstg, 0, sizeof(STATSTG)); - - pstatstg->pwcsName = NULL; - pstatstg->type = STGTY_STREAM; - pstatstg->cbSize = This->streamSize; - - return S_OK; -} - -HRESULT WINAPI HGLOBALStreamImpl_Clone( - IStream* iface, - IStream** ppstm) /* [out] */ -{ - ULARGE_INTEGER dummy; - LARGE_INTEGER offset; - HRESULT hr; - HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; - TRACE(" Cloning %p (deleteOnRelease=%d seek position=%ld)\n",iface,This->deleteOnRelease,(long)This->currentPosition.QuadPart); - hr=CreateStreamOnHGlobal(This->supportHandle, FALSE, ppstm); - if(FAILED(hr)) - return hr; - offset.QuadPart=(LONGLONG)This->currentPosition.QuadPart; - HGLOBALStreamImpl_Seek(*ppstm,offset,STREAM_SEEK_SET,&dummy); - return S_OK; -} diff --git a/reactos/lib/ole32/ifs.c b/reactos/lib/ole32/ifs.c deleted file mode 100644 index bb80208d952..00000000000 --- a/reactos/lib/ole32/ifs.c +++ /dev/null @@ -1,642 +0,0 @@ -/* - * basic interfaces - * - * Copyright 1997 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "ole2.h" -#include "winerror.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(olemalloc); - -/****************************************************************************** - * IMalloc32 implementation - * - * NOTES - * For supporting CoRegisterMallocSpy the IMalloc implementation must know if - * a given memory block was allocated with a spy active. - * - *****************************************************************************/ -/* set the vtable later */ -static IMallocVtbl VT_IMalloc32; - -typedef struct { - IMallocVtbl *lpVtbl; - DWORD dummy; /* nothing, we are static */ - IMallocSpy * pSpy; /* the spy when active */ - DWORD SpyedAllocationsLeft; /* number of spyed allocations left */ - BOOL SpyReleasePending; /* CoRevokeMallocSpy called with spyed allocations left*/ - LPVOID * SpyedBlocks; /* root of the table */ - int SpyedBlockTableLength; /* size of the table*/ -} _Malloc32; - -/* this is the static object instance */ -_Malloc32 Malloc32 = {&VT_IMalloc32, 0, NULL, 0, 0, NULL, 0}; - -/* with a spy active all calls from pre to post methods are threadsave */ -static CRITICAL_SECTION IMalloc32_SpyCS; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &IMalloc32_SpyCS, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { 0, (DWORD)(__FILE__ ": IMalloc32_SpyCS") } -}; -static CRITICAL_SECTION IMalloc32_SpyCS = { &critsect_debug, -1, 0, 0, 0, 0 }; - -/* resize the old table */ -static int SetSpyedBlockTableLength ( int NewLength ) -{ - LPVOID *NewSpyedBlocks; - - if (!Malloc32.SpyedBlocks) NewSpyedBlocks = LocalAlloc(GMEM_ZEROINIT, NewLength * sizeof(PVOID)); - else NewSpyedBlocks = LocalReAlloc(Malloc32.SpyedBlocks, NewLength * sizeof(PVOID), GMEM_ZEROINIT); - if (NewSpyedBlocks) { - Malloc32.SpyedBlocks = NewSpyedBlocks; - Malloc32.SpyedBlockTableLength = NewLength; - } - - return NewSpyedBlocks != NULL; -} - -/* add a location to the table */ -static int AddMemoryLocation(LPVOID * pMem) -{ - LPVOID * Current; - - /* allocate the table if not already allocated */ - if (!Malloc32.SpyedBlockTableLength) { - if (!SetSpyedBlockTableLength(0x1000)) return 0; - } - - /* find a free location */ - Current = Malloc32.SpyedBlocks; - while (*Current) { - Current++; - if (Current >= Malloc32.SpyedBlocks + Malloc32.SpyedBlockTableLength) { - /* no more space in table, grow it */ - if (!SetSpyedBlockTableLength( Malloc32.SpyedBlockTableLength + 0x1000 )) return 0; - } - }; - - /* put the location in our table */ - *Current = pMem; - Malloc32.SpyedAllocationsLeft++; - /*TRACE("%lu\n",Malloc32.SpyedAllocationsLeft);*/ - return 1; -} - -static int RemoveMemoryLocation(LPVOID * pMem) -{ - LPVOID * Current; - - /* allocate the table if not already allocated */ - if (!Malloc32.SpyedBlockTableLength) { - if (!SetSpyedBlockTableLength(0x1000)) return 0; - } - - Current = Malloc32.SpyedBlocks; - - /* find the location */ - while (*Current != pMem) { - Current++; - if (Current >= Malloc32.SpyedBlocks + Malloc32.SpyedBlockTableLength) return 0; /* not found */ - } - - /* location found */ - Malloc32.SpyedAllocationsLeft--; - /*TRACE("%lu\n",Malloc32.SpyedAllocationsLeft);*/ - *Current = NULL; - return 1; -} - -/****************************************************************************** - * IMalloc32_QueryInterface [VTABLE] - */ -static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) { - - TRACE("(%s,%p)\n",debugstr_guid(refiid),obj); - - if (IsEqualIID(&IID_IUnknown,refiid) || IsEqualIID(&IID_IMalloc,refiid)) { - *obj = (LPMALLOC)&Malloc32; - return S_OK; - } - return E_NOINTERFACE; -} - -/****************************************************************************** - * IMalloc32_AddRefRelease [VTABLE] - */ -static ULONG WINAPI IMalloc_fnAddRefRelease (LPMALLOC iface) { - return 1; -} - -/****************************************************************************** - * IMalloc32_Alloc [VTABLE] - */ -static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface, DWORD cb) { - - LPVOID addr; - - TRACE("(%ld)\n",cb); - - if(Malloc32.pSpy) { - DWORD preAllocResult; - - EnterCriticalSection(&IMalloc32_SpyCS); - preAllocResult = IMallocSpy_PreAlloc(Malloc32.pSpy, cb); - if ((cb != 0) && (preAllocResult == 0)) { - /* PreAlloc can force Alloc to fail, but not if cb == 0 */ - TRACE("returning null\n"); - LeaveCriticalSection(&IMalloc32_SpyCS); - return NULL; - } - } - - addr = HeapAlloc(GetProcessHeap(),0,cb); - - if(Malloc32.pSpy) { - addr = IMallocSpy_PostAlloc(Malloc32.pSpy, addr); - if (addr) AddMemoryLocation(addr); - LeaveCriticalSection(&IMalloc32_SpyCS); - } - - TRACE("--(%p)\n",addr); - return addr; -} - -/****************************************************************************** - * IMalloc32_Realloc [VTABLE] - */ -static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) { - - LPVOID pNewMemory; - - TRACE("(%p,%ld)\n",pv,cb); - - if(Malloc32.pSpy) { - LPVOID pRealMemory; - BOOL fSpyed; - - EnterCriticalSection(&IMalloc32_SpyCS); - fSpyed = RemoveMemoryLocation(pv); - cb = IMallocSpy_PreRealloc(Malloc32.pSpy, pv, cb, &pRealMemory, fSpyed); - - /* check if can release the spy */ - if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) { - IMallocSpy_Release(Malloc32.pSpy); - Malloc32.SpyReleasePending = FALSE; - Malloc32.pSpy = NULL; - } - - if (0==cb) { - /* PreRealloc can force Realloc to fail */ - LeaveCriticalSection(&IMalloc32_SpyCS); - return NULL; - } - pv = pRealMemory; - } - - if (!pv) pNewMemory = HeapAlloc(GetProcessHeap(),0,cb); - else if (cb) pNewMemory = HeapReAlloc(GetProcessHeap(),0,pv,cb); - else { - HeapFree(GetProcessHeap(),0,pv); - pNewMemory = NULL; - } - - if(Malloc32.pSpy) { - pNewMemory = IMallocSpy_PostRealloc(Malloc32.pSpy, pNewMemory, TRUE); - if (pNewMemory) AddMemoryLocation(pNewMemory); - LeaveCriticalSection(&IMalloc32_SpyCS); - } - - TRACE("--(%p)\n",pNewMemory); - return pNewMemory; -} - -/****************************************************************************** - * IMalloc32_Free [VTABLE] - */ -static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) { - - BOOL fSpyed = 0; - - TRACE("(%p)\n",pv); - - if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - fSpyed = RemoveMemoryLocation(pv); - pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed); - } - - HeapFree(GetProcessHeap(),0,pv); - - if(Malloc32.pSpy) { - IMallocSpy_PostFree(Malloc32.pSpy, fSpyed); - - /* check if can release the spy */ - if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) { - IMallocSpy_Release(Malloc32.pSpy); - Malloc32.SpyReleasePending = FALSE; - Malloc32.pSpy = NULL; - } - - LeaveCriticalSection(&IMalloc32_SpyCS); - } -} - -/****************************************************************************** - * IMalloc32_GetSize [VTABLE] - * - * NOTES - * FIXME returns: - * win95: size allocated (4 byte boundarys) - * win2k: size originally requested !!! (allocated on 8 byte boundarys) - */ -static DWORD WINAPI IMalloc_fnGetSize(LPMALLOC iface,LPVOID pv) { - - DWORD cb; - BOOL fSpyed = 0; - - TRACE("(%p)\n",pv); - - if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - pv = IMallocSpy_PreGetSize(Malloc32.pSpy, pv, fSpyed); - } - - cb = HeapSize(GetProcessHeap(),0,pv); - - if(Malloc32.pSpy) { - cb = IMallocSpy_PostGetSize(Malloc32.pSpy, cb, fSpyed); - LeaveCriticalSection(&IMalloc32_SpyCS); - } - - return cb; -} - -/****************************************************************************** - * IMalloc32_DidAlloc [VTABLE] - */ -static INT WINAPI IMalloc_fnDidAlloc(LPMALLOC iface,LPVOID pv) { - - BOOL fSpyed = 0; - int didAlloc; - - TRACE("(%p)\n",pv); - - if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - pv = IMallocSpy_PreDidAlloc(Malloc32.pSpy, pv, fSpyed); - } - - didAlloc = -1; - - if(Malloc32.pSpy) { - didAlloc = IMallocSpy_PostDidAlloc(Malloc32.pSpy, pv, fSpyed, didAlloc); - LeaveCriticalSection(&IMalloc32_SpyCS); - } - return didAlloc; -} - -/****************************************************************************** - * IMalloc32_HeapMinimize [VTABLE] - */ -static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) { - TRACE("()\n"); - - if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - IMallocSpy_PreHeapMinimize(Malloc32.pSpy); - } - - if(Malloc32.pSpy) { - IMallocSpy_PostHeapMinimize(Malloc32.pSpy); - LeaveCriticalSection(&IMalloc32_SpyCS); - } -} - -static IMallocVtbl VT_IMalloc32 = -{ - IMalloc_fnQueryInterface, - IMalloc_fnAddRefRelease, - IMalloc_fnAddRefRelease, - IMalloc_fnAlloc, - IMalloc_fnRealloc, - IMalloc_fnFree, - IMalloc_fnGetSize, - IMalloc_fnDidAlloc, - IMalloc_fnHeapMinimize -}; - -/****************************************************************************** - * IMallocSpy implementation - *****************************************************************************/ - -/* set the vtable later */ -static IMallocSpyVtbl VT_IMallocSpy; - -typedef struct { - IMallocSpyVtbl *lpVtbl; - DWORD ref; -} _MallocSpy; - -/* this is the static object instance */ -_MallocSpy MallocSpy = {&VT_IMallocSpy, 0}; - -/****************************************************************************** - * IMalloc32_QueryInterface [VTABLE] - */ -static HRESULT WINAPI IMallocSpy_fnQueryInterface(LPMALLOCSPY iface,REFIID refiid,LPVOID *obj) -{ - - TRACE("(%s,%p)\n",debugstr_guid(refiid),obj); - - if (IsEqualIID(&IID_IUnknown,refiid) || IsEqualIID(&IID_IMallocSpy,refiid)) { - *obj = (LPMALLOC)&MallocSpy; - return S_OK; - } - return E_NOINTERFACE; -} - -/****************************************************************************** - * IMalloc32_AddRef [VTABLE] - */ -static ULONG WINAPI IMallocSpy_fnAddRef (LPMALLOCSPY iface) -{ - - _MallocSpy *This = (_MallocSpy *)iface; - - TRACE ("(%p)->(count=%lu)\n", This, This->ref); - - return ++(This->ref); -} - -/****************************************************************************** - * IMalloc32_AddRelease [VTABLE] - * - * NOTES - * Our MallocSpy is static. If the count reaches 0 we dump the leaks - */ -static ULONG WINAPI IMallocSpy_fnRelease (LPMALLOCSPY iface) -{ - - _MallocSpy *This = (_MallocSpy *)iface; - - TRACE ("(%p)->(count=%lu)\n", This, This->ref); - - if (!--(This->ref)) { - /* our allocation list MUST be empty here */ - } - return This->ref; -} - -static ULONG WINAPI IMallocSpy_fnPreAlloc(LPMALLOCSPY iface, ULONG cbRequest) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%lu)\n", This, cbRequest); - return cbRequest; -} -static PVOID WINAPI IMallocSpy_fnPostAlloc(LPMALLOCSPY iface, void* pActual) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p)\n", This, pActual); - return pActual; -} - -static PVOID WINAPI IMallocSpy_fnPreFree(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed); - return pRequest; -} -static void WINAPI IMallocSpy_fnPostFree(LPMALLOCSPY iface, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%u)\n", This, fSpyed); -} - -static ULONG WINAPI IMallocSpy_fnPreRealloc(LPMALLOCSPY iface, void* pRequest, ULONG cbRequest, void** ppNewRequest, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %lu %u)\n", This, pRequest, cbRequest, fSpyed); - *ppNewRequest = pRequest; - return cbRequest; -} - -static PVOID WINAPI IMallocSpy_fnPostRealloc(LPMALLOCSPY iface, void* pActual, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %u)\n", This, pActual, fSpyed); - return pActual; -} - -static PVOID WINAPI IMallocSpy_fnPreGetSize(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed); - return pRequest; -} - -static ULONG WINAPI IMallocSpy_fnPostGetSize(LPMALLOCSPY iface, ULONG cbActual, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%lu %u)\n", This, cbActual, fSpyed); - return cbActual; -} - -static PVOID WINAPI IMallocSpy_fnPreDidAlloc(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed); - return pRequest; -} - -static int WINAPI IMallocSpy_fnPostDidAlloc(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed, int fActual) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->(%p %u %u)\n", This, pRequest, fSpyed, fActual); - return fActual; -} - -static void WINAPI IMallocSpy_fnPreHeapMinimize(LPMALLOCSPY iface) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->()\n", This); -} - -static void WINAPI IMallocSpy_fnPostHeapMinimize(LPMALLOCSPY iface) -{ - _MallocSpy *This = (_MallocSpy *)iface; - TRACE ("(%p)->()\n", This); -} - -static void MallocSpyDumpLeaks() { - TRACE("leaks: %lu\n", Malloc32.SpyedAllocationsLeft); -} - -static IMallocSpyVtbl VT_IMallocSpy = -{ - IMallocSpy_fnQueryInterface, - IMallocSpy_fnAddRef, - IMallocSpy_fnRelease, - IMallocSpy_fnPreAlloc, - IMallocSpy_fnPostAlloc, - IMallocSpy_fnPreFree, - IMallocSpy_fnPostFree, - IMallocSpy_fnPreRealloc, - IMallocSpy_fnPostRealloc, - IMallocSpy_fnPreGetSize, - IMallocSpy_fnPostGetSize, - IMallocSpy_fnPreDidAlloc, - IMallocSpy_fnPostDidAlloc, - IMallocSpy_fnPreHeapMinimize, - IMallocSpy_fnPostHeapMinimize -}; - -/****************************************************************************** - * CoGetMalloc [OLE32.@] - * - * RETURNS - * The win32 IMalloc - */ -HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, LPMALLOC *lpMalloc) -{ - *lpMalloc = (LPMALLOC)&Malloc32; - return S_OK; -} - -/*********************************************************************** - * CoTaskMemAlloc [OLE32.@] - * RETURNS - * pointer to newly allocated block - */ -LPVOID WINAPI CoTaskMemAlloc(ULONG size) -{ - return IMalloc_Alloc((LPMALLOC)&Malloc32,size); -} -/*********************************************************************** - * CoTaskMemFree [OLE32.@] - */ -VOID WINAPI CoTaskMemFree(LPVOID ptr) -{ - IMalloc_Free((LPMALLOC)&Malloc32, ptr); -} - -/*********************************************************************** - * CoTaskMemRealloc [OLE32.@] - * RETURNS - * pointer to newly allocated block - */ -LPVOID WINAPI CoTaskMemRealloc(LPVOID pvOld, ULONG size) -{ - return IMalloc_Realloc((LPMALLOC)&Malloc32, pvOld, size); -} - -/*********************************************************************** - * CoRegisterMallocSpy [OLE32.@] - * - * NOTES - * if a mallocspy is already registered, we can't do it again since - * only the spy knows, how to free a memory block - */ -HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy) -{ - IMallocSpy* pSpy; - HRESULT hres = E_INVALIDARG; - - TRACE("\n"); - - /* HACK TO ACTIVATE OUT SPY */ - if (pMallocSpy == (LPVOID)-1) pMallocSpy =(IMallocSpy*)&MallocSpy; - - if(Malloc32.pSpy) return CO_E_OBJISREG; - - EnterCriticalSection(&IMalloc32_SpyCS); - - if (SUCCEEDED(IUnknown_QueryInterface(pMallocSpy, &IID_IMallocSpy, (LPVOID*)&pSpy))) { - Malloc32.pSpy = pSpy; - hres = S_OK; - } - - LeaveCriticalSection(&IMalloc32_SpyCS); - - return hres; -} - -/*********************************************************************** - * CoRevokeMallocSpy [OLE32.@] - * - * NOTES - * we can't revoke a malloc spy as long as memory blocks allocated with - * the spy are active since only the spy knows how to free them - */ -HRESULT WINAPI CoRevokeMallocSpy(void) -{ - HRESULT hres = S_OK; - TRACE("\n"); - - EnterCriticalSection(&IMalloc32_SpyCS); - - /* if it's our spy it's time to dump the leaks */ - if (Malloc32.pSpy == (IMallocSpy*)&MallocSpy) { - MallocSpyDumpLeaks(); - } - - if (Malloc32.SpyedAllocationsLeft) { - TRACE("SpyReleasePending with %lu allocations left\n", Malloc32.SpyedAllocationsLeft); - Malloc32.SpyReleasePending = TRUE; - hres = E_ACCESSDENIED; - } else { - IMallocSpy_Release(Malloc32.pSpy); - Malloc32.pSpy = NULL; - } - LeaveCriticalSection(&IMalloc32_SpyCS); - - return S_OK; -} - -/****************************************************************************** - * IsValidInterface [OLE32.@] - * - * RETURNS - * True, if the passed pointer is a valid interface - */ -BOOL WINAPI IsValidInterface( - LPUNKNOWN punk /* [in] interface to be tested */ -) { - return !( - IsBadReadPtr(punk,4) || - IsBadReadPtr(punk->lpVtbl,4) || - IsBadReadPtr(punk->lpVtbl->QueryInterface,9) || - IsBadCodePtr((FARPROC)punk->lpVtbl->QueryInterface) - ); -} diff --git a/reactos/lib/ole32/ifs.h b/reactos/lib/ole32/ifs.h deleted file mode 100644 index 3a2698fc321..00000000000 --- a/reactos/lib/ole32/ifs.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 1997 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __WINE_OLE_IFS_H -#define __WINE_OLE_IFS_H - -#include - -#include "windef.h" -#include "winbase.h" -#include "objbase.h" - -typedef CHAR OLECHAR16; -typedef LPSTR LPOLESTR16; -typedef LPCSTR LPCOLESTR16; - -/*********************************************************************** - * IMalloc16 interface - */ - -#undef INTERFACE -#define INTERFACE IMalloc16 -DECLARE_INTERFACE_(IMalloc16,IUnknown) -{ - /*** IUnknown methods ***/ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IMalloc16 methods ***/ - STDMETHOD_(LPVOID,Alloc)(THIS_ DWORD cb) PURE; - STDMETHOD_(LPVOID,Realloc)(THIS_ LPVOID pv, DWORD cb) PURE; - STDMETHOD_(void,Free)(THIS_ LPVOID pv) PURE; - STDMETHOD_(DWORD,GetSize)(THIS_ LPVOID pv) PURE; - STDMETHOD_(INT16,DidAlloc)(THIS_ LPVOID pv) PURE; - STDMETHOD_(LPVOID,HeapMinimize)(THIS) PURE; -}; -#undef INTERFACE - -typedef struct IMalloc16 *LPMALLOC16; - -/**********************************************************************/ - -extern LPMALLOC16 IMalloc16_Constructor(); - -/**********************************************************************/ - -#define INTERFACE ILockBytes16 -DECLARE_INTERFACE_(ILockBytes16,IUnknown) -{ - /*** IUnknown methods ***/ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** ILockBytes16 methods ***/ - STDMETHOD(ReadAt)(THIS_ ULARGE_INTEGER ulOffset, void *pv, ULONG cb, ULONG *pcbRead) PURE; - STDMETHOD(WriteAt)(THIS_ ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten) PURE; - STDMETHOD(Flush)(THIS) PURE; - STDMETHOD(SetSize)(THIS_ ULARGE_INTEGER cb) PURE; - STDMETHOD(LockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE; - STDMETHOD(UnlockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE; - STDMETHOD(Stat)(THIS_ STATSTG *pstatstg, DWORD grfStatFlag) PURE; -}; -#undef INTERFACE - -/**********************************************************************/ - -typedef struct tagSTATSTG16 -{ - LPOLESTR16 pwcsName; - DWORD type; - ULARGE_INTEGER cbSize; - FILETIME mtime; - FILETIME ctime; - FILETIME atime; - DWORD grfMode; - DWORD grfLocksSupported; - CLSID clsid; - DWORD grfStateBits; - DWORD reserved; -} STATSTG16; - -#define INTERFACE IStream16 -DECLARE_INTERFACE_(IStream16,ISequentialStream) -{ - /*** IUnknown methods ***/ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** ISequentialStream methods ***/ - STDMETHOD_(HRESULT,Read)(THIS_ void* pv, ULONG cb, ULONG* pcbRead) PURE; - STDMETHOD_(HRESULT,Write)(THIS_ const void* pv, ULONG cb, ULONG* pcbWritten) PURE; - /*** IStream16 methods ***/ - STDMETHOD(Seek)(THIS_ LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) PURE; - STDMETHOD(SetSize)(THIS_ ULARGE_INTEGER libNewSize) PURE; - STDMETHOD(CopyTo)(THIS_ IStream16* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) PURE; - STDMETHOD(Commit)(THIS_ DWORD grfCommitFlags) PURE; - STDMETHOD(Revert)(THIS) PURE; - STDMETHOD(LockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE; - STDMETHOD(UnlockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE; - STDMETHOD(Stat)(THIS_ STATSTG* pstatstg, DWORD grfStatFlag) PURE; - STDMETHOD(Clone)(THIS_ IStream16** ppstm) PURE; -}; -#undef INTERFACE - -/**********************************************************************/ - -typedef OLECHAR16 **SNB16; - -#define INTERFACE IStorage16 -DECLARE_INTERFACE_(IStorage16,IUnknown) -{ - /*** IUnknown methods ***/ - STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - /*** IStorage16 methods ***/ - STDMETHOD_(HRESULT,CreateStream)(THIS_ LPCOLESTR16 pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream16** ppstm) PURE; - STDMETHOD_(HRESULT,OpenStream)(THIS_ LPCOLESTR16 pwcsName, void* reserved1, DWORD grfMode, DWORD reserved2, IStream16** ppstm) PURE; - STDMETHOD_(HRESULT,CreateStorage)(THIS_ LPCOLESTR16 pwcsName, DWORD grfMode, DWORD dwStgFmt, DWORD reserved2, IStorage16** ppstg) PURE; - STDMETHOD_(HRESULT,OpenStorage)(THIS_ LPCOLESTR16 pwcsName, IStorage16* pstgPriority, DWORD grfMode, SNB16 snbExclude, DWORD reserved, IStorage16** ppstg) PURE; - STDMETHOD_(HRESULT,CopyTo)(THIS_ DWORD ciidExclude, const IID* rgiidExclude, SNB16 snbExclude, IStorage16* pstgDest) PURE; - STDMETHOD_(HRESULT,MoveElementTo)(THIS_ LPCOLESTR16 pwcsName, IStorage16* pstgDest, LPCOLESTR16 pwcsNewName, DWORD grfFlags) PURE; - STDMETHOD_(HRESULT,Commit)(THIS_ DWORD grfCommitFlags) PURE; - STDMETHOD_(HRESULT,Revert)(THIS) PURE; - STDMETHOD_(HRESULT,EnumElements)(THIS_ DWORD reserved1, void* reserved2, DWORD reserved3, IEnumSTATSTG** ppenum) PURE; - STDMETHOD_(HRESULT,DestroyElement)(THIS_ LPCOLESTR16 pwcsName) PURE; - STDMETHOD_(HRESULT,RenameElement)(THIS_ LPCOLESTR16 pwcsOldName, LPCOLESTR16 pwcsNewName) PURE; - STDMETHOD_(HRESULT,SetElementTimes)(THIS_ LPCOLESTR16 pwcsName, const FILETIME* pctime, const FILETIME* patime, const FILETIME* pmtime) PURE; - STDMETHOD_(HRESULT,SetClass)(THIS_ REFCLSID clsid) PURE; - STDMETHOD_(HRESULT,SetStateBits)(THIS_ DWORD grfStateBits, DWORD grfMask) PURE; - STDMETHOD_(HRESULT,Stat)(THIS_ STATSTG* pstatstg, DWORD grfStatFlag) PURE; -}; -#undef INTERFACE - -#endif /* __WINE_OLE_IFS_H */ diff --git a/reactos/lib/ole32/itemmoniker.c b/reactos/lib/ole32/itemmoniker.c deleted file mode 100644 index c30c2b528d7..00000000000 --- a/reactos/lib/ole32/itemmoniker.c +++ /dev/null @@ -1,982 +0,0 @@ -/*************************************************************************************** - * ItemMonikers implementation - * - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - ***************************************************************************************/ - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "winerror.h" -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winnls.h" -#include "wine/debug.h" -#include "ole2.h" -#include "wine/unicode.h" -#include "moniker.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -const CLSID CLSID_ItemMoniker = { - 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46} -}; - -/* ItemMoniker data structure */ -typedef struct ItemMonikerImpl{ - - IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/ - - /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether - * two monikers are equal. That's whay IROTData interface is implemented by monikers. - */ - IROTDataVtbl* lpvtbl2; /* VTable relative to the IROTData interface.*/ - - ULONG ref; /* reference counter for this object */ - - LPOLESTR itemName; /* item name identified by this ItemMoniker */ - - LPOLESTR itemDelimiter; /* Delimiter string */ - -} ItemMonikerImpl; - -/********************************************************************************/ -/* ItemMoniker prototype functions : */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface); -static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface); - -/* IPersist prototype functions */ -static HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID); - -/* IPersistStream prototype functions */ -static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface); -static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface, IStream* pStm); -static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty); -static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize); - -/* IMoniker prototype functions */ -static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult); -static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced); -static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite); -static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker); -static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker); -static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash); -static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning); -static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pItemTime); -static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk); -static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix); -static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath); -static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName); -static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut); -static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys); - -/* Local function used by ItemMoniker implementation */ -HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* iface, LPCOLESTR lpszDelim,LPCOLESTR lpszPathName); -HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* iface); - -/********************************************************************************/ -/* IROTData prototype functions */ - -/* IUnknown prototype functions */ -static HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject); -static ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData* iface); -static ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface); - -/* IROTData prototype function */ -static HRESULT WINAPI ItemMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData); - -/********************************************************************************/ -/* Virtual function table for the ItemMonikerImpl class which include IPersist,*/ -/* IPersistStream and IMoniker functions. */ -static IMonikerVtbl VT_ItemMonikerImpl = - { - ItemMonikerImpl_QueryInterface, - ItemMonikerImpl_AddRef, - ItemMonikerImpl_Release, - ItemMonikerImpl_GetClassID, - ItemMonikerImpl_IsDirty, - ItemMonikerImpl_Load, - ItemMonikerImpl_Save, - ItemMonikerImpl_GetSizeMax, - ItemMonikerImpl_BindToObject, - ItemMonikerImpl_BindToStorage, - ItemMonikerImpl_Reduce, - ItemMonikerImpl_ComposeWith, - ItemMonikerImpl_Enum, - ItemMonikerImpl_IsEqual, - ItemMonikerImpl_Hash, - ItemMonikerImpl_IsRunning, - ItemMonikerImpl_GetTimeOfLastChange, - ItemMonikerImpl_Inverse, - ItemMonikerImpl_CommonPrefixWith, - ItemMonikerImpl_RelativePathTo, - ItemMonikerImpl_GetDisplayName, - ItemMonikerImpl_ParseDisplayName, - ItemMonikerImpl_IsSystemMoniker -}; - -/********************************************************************************/ -/* Virtual function table for the IROTData class. */ -static IROTDataVtbl VT_ROTDataImpl = -{ - ItemMonikerROTDataImpl_QueryInterface, - ItemMonikerROTDataImpl_AddRef, - ItemMonikerROTDataImpl_Release, - ItemMonikerROTDataImpl_GetComparaisonData -}; - -/******************************************************************************* - * ItemMoniker_QueryInterface - *******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* Perform a sanity check on the parameters.*/ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* Initialize the return parameter */ - *ppvObject = 0; - - /* Compare the riid with the interface IDs implemented by this object.*/ - if (IsEqualIID(&IID_IUnknown, riid) || - IsEqualIID(&IID_IPersist, riid) || - IsEqualIID(&IID_IPersistStream, riid) || - IsEqualIID(&IID_IMoniker, riid) - ) - *ppvObject = iface; - - else if (IsEqualIID(&IID_IROTData, riid)) - *ppvObject = (IROTData*)&(This->lpvtbl2); - - /* Check that we obtained an interface.*/ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* Query Interface always increases the reference count by one when it is successful */ - ItemMonikerImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_AddRef - ******************************************************************************/ -ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * ItemMoniker_Release - ******************************************************************************/ -ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* destroy the object if there's no more reference on it */ - if (ref == 0) ItemMonikerImpl_Destroy(This); - - return ref; -} - -/****************************************************************************** - * ItemMoniker_GetClassID - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID) -{ - TRACE("(%p,%p),stub!\n",iface,pClassID); - - if (pClassID==NULL) - return E_POINTER; - - *pClassID = CLSID_ItemMoniker; - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_IsDirty - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface) -{ - /* Note that the OLE-provided implementations of the IPersistStream::IsDirty - method in the OLE-provided moniker interfaces always return S_FALSE because - their internal state never changes. */ - - TRACE("(%p)\n",iface); - - return S_FALSE; -} - -/****************************************************************************** - * ItemMoniker_Load - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Load(IMoniker* iface,IStream* pStm) -{ - - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - HRESULT res; - DWORD delimiterLength,nameLength,lenW; - CHAR *itemNameA,*itemDelimiterA; - ULONG bread; - - /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */ - - /* read item delimiter string length + 1 */ - res=IStream_Read(pStm,&delimiterLength,sizeof(DWORD),&bread); - if (bread != sizeof(DWORD)) - return E_FAIL; - - /* read item delimiter string */ - if (!(itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength))) - return E_OUTOFMEMORY; - res=IStream_Read(pStm,itemDelimiterA,delimiterLength,&bread); - if (bread != delimiterLength) - { - HeapFree( GetProcessHeap(), 0, itemDelimiterA ); - return E_FAIL; - } - - lenW = MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, NULL, 0 ); - This->itemDelimiter=HeapReAlloc(GetProcessHeap(),0,This->itemDelimiter,lenW*sizeof(WCHAR)); - if (!This->itemDelimiter) - { - HeapFree( GetProcessHeap(), 0, itemDelimiterA ); - return E_OUTOFMEMORY; - } - MultiByteToWideChar( CP_ACP, 0, itemDelimiterA, -1, This->itemDelimiter, lenW ); - HeapFree( GetProcessHeap(), 0, itemDelimiterA ); - - /* read item name string length + 1*/ - res=IStream_Read(pStm,&nameLength,sizeof(DWORD),&bread); - if (bread != sizeof(DWORD)) - return E_FAIL; - - /* read item name string */ - if (!(itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength))) - return E_OUTOFMEMORY; - res=IStream_Read(pStm,itemNameA,nameLength,&bread); - if (bread != nameLength) - { - HeapFree( GetProcessHeap(), 0, itemNameA ); - return E_FAIL; - } - - lenW = MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, NULL, 0 ); - This->itemName=HeapReAlloc(GetProcessHeap(),0,This->itemName,lenW*sizeof(WCHAR)); - if (!This->itemName) - { - HeapFree( GetProcessHeap(), 0, itemNameA ); - return E_OUTOFMEMORY; - } - MultiByteToWideChar( CP_ACP, 0, itemNameA, -1, This->itemName, lenW ); - HeapFree( GetProcessHeap(), 0, itemNameA ); - - return res; -} - -/****************************************************************************** - * ItemMoniker_Save - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, - IStream* pStm,/* pointer to the stream where the object is to be saved */ - BOOL fClearDirty)/* Specifies whether to clear the dirty flag */ -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - HRESULT res; - CHAR *itemNameA,*itemDelimiterA; - - /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */ - /* 2) String (type A): item delimiter string ('\0' included) */ - /* 3) DWORD : size of item name string ('\0' included) */ - /* 4) String (type A): item name string ('\0' included) */ - - DWORD nameLength = WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL); - DWORD delimiterLength = WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL); - itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength); - itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength); - WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, itemNameA, nameLength, NULL, NULL); - WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, itemDelimiterA, delimiterLength, NULL, NULL); - - res=IStream_Write(pStm,&delimiterLength,sizeof(DWORD),NULL); - res=IStream_Write(pStm,itemDelimiterA,delimiterLength * sizeof(CHAR),NULL); - res=IStream_Write(pStm,&nameLength,sizeof(DWORD),NULL); - res=IStream_Write(pStm,itemNameA,nameLength * sizeof(CHAR),NULL); - - return res; -} - -/****************************************************************************** - * ItemMoniker_GetSizeMax - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, - ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */ -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - DWORD delimiterLength=lstrlenW(This->itemDelimiter)+1; - DWORD nameLength=lstrlenW(This->itemName)+1; - - TRACE("(%p,%p)\n",iface,pcbSize); - - if (pcbSize!=NULL) - return E_POINTER; - - /* for more details see ItemMonikerImpl_Save coments */ - - pcbSize->u.LowPart = sizeof(DWORD) + /* DWORD which contains delimiter length */ - delimiterLength + /* item delimiter string */ - sizeof(DWORD) + /* DWORD which contains item name length */ - nameLength + /* item name string */ - 34; /* this constant was added ! because when I tested this function it usually */ - /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */ - pcbSize->u.HighPart=0; - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_Construct (local function) - *******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Construct(ItemMonikerImpl* This, LPCOLESTR lpszDelim,LPCOLESTR lpszItem) -{ - - int sizeStr1=lstrlenW(lpszItem), sizeStr2; - static const OLECHAR emptystr[1]; - LPCOLESTR delim; - - TRACE("(%p,%p)\n",This,lpszItem); - - /* Initialize the virtual fgunction table. */ - This->lpvtbl1 = &VT_ItemMonikerImpl; - This->lpvtbl2 = &VT_ROTDataImpl; - This->ref = 0; - - This->itemName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr1+1)); - if (!This->itemName) - return E_OUTOFMEMORY; - lstrcpyW(This->itemName,lpszItem); - - if (!lpszDelim) - FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n"); - - delim = lpszDelim ? lpszDelim : emptystr; - - sizeStr2=lstrlenW(delim); - This->itemDelimiter=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr2+1)); - if (!This->itemDelimiter) { - HeapFree(GetProcessHeap(),0,This->itemName); - return E_OUTOFMEMORY; - } - lstrcpyW(This->itemDelimiter,delim); - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_Destroy (local function) - *******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Destroy(ItemMonikerImpl* This) -{ - TRACE("(%p)\n",This); - - if (This->itemName) - HeapFree(GetProcessHeap(),0,This->itemName); - - if (This->itemDelimiter) - HeapFree(GetProcessHeap(),0,This->itemDelimiter); - - HeapFree(GetProcessHeap(),0,This); - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_BindToObject - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - HRESULT res; - IID refid=IID_IOleItemContainer; - IOleItemContainer *poic=0; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - - if(ppvResult ==NULL) - return E_POINTER; - - if(pmkToLeft==NULL) - return E_INVALIDARG; - - *ppvResult=0; - - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&refid,(void**)&poic); - - if (SUCCEEDED(res)){ - - res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,riid,ppvResult); - - IOleItemContainer_Release(poic); - } - - return res; -} - -/****************************************************************************** - * ItemMoniker_BindToStorage - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - REFIID riid, - VOID** ppvResult) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - HRESULT res; - IOleItemContainer *poic=0; - - TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult); - - *ppvResult=0; - - if(pmkToLeft==NULL) - return E_INVALIDARG; - - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic); - - if (SUCCEEDED(res)){ - - res=IOleItemContainer_GetObjectStorage(poic,This->itemName,pbc,riid,ppvResult); - - IOleItemContainer_Release(poic); - } - - return res; -} - -/****************************************************************************** - * ItemMoniker_Reduce - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface, - IBindCtx* pbc, - DWORD dwReduceHowFar, - IMoniker** ppmkToLeft, - IMoniker** ppmkReduced) -{ - TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced); - - if (ppmkReduced==NULL) - return E_POINTER; - - ItemMonikerImpl_AddRef(iface); - - *ppmkReduced=iface; - - return MK_S_REDUCED_TO_SELF; -} -/****************************************************************************** - * ItemMoniker_ComposeWith - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface, - IMoniker* pmkRight, - BOOL fOnlyIfNotGeneric, - IMoniker** ppmkComposite) -{ - HRESULT res=S_OK; - DWORD mkSys,mkSys2; - IEnumMoniker* penumMk=0; - IMoniker *pmostLeftMk=0; - IMoniker* tempMkComposite=0; - - TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite); - - if ((ppmkComposite==NULL)||(pmkRight==NULL)) - return E_POINTER; - - *ppmkComposite=0; - - IMoniker_IsSystemMoniker(pmkRight,&mkSys); - - /* If pmkRight is an anti-moniker, the returned moniker is NULL */ - if(mkSys==MKSYS_ANTIMONIKER) - return res; - - else - /* if pmkRight is a composite whose leftmost component is an anti-moniker, */ - /* the returned moniker is the composite after the leftmost anti-moniker is removed. */ - - if(mkSys==MKSYS_GENERICCOMPOSITE){ - - res=IMoniker_Enum(pmkRight,TRUE,&penumMk); - - if (FAILED(res)) - return res; - - res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL); - - IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2); - - if(mkSys2==MKSYS_ANTIMONIKER){ - - IMoniker_Release(pmostLeftMk); - - tempMkComposite=iface; - IMoniker_AddRef(iface); - - while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){ - - res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite); - - IMoniker_Release(tempMkComposite); - IMoniker_Release(pmostLeftMk); - - tempMkComposite=*ppmkComposite; - IMoniker_AddRef(tempMkComposite); - } - return res; - } - else - return CreateGenericComposite(iface,pmkRight,ppmkComposite); - } - /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic - composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns - a NULL moniker and a return value of MK_E_NEEDGENERIC */ - else - if (!fOnlyIfNotGeneric) - return CreateGenericComposite(iface,pmkRight,ppmkComposite); - - else - return MK_E_NEEDGENERIC; -} - -/****************************************************************************** - * ItemMoniker_Enum - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker) -{ - TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker); - - if (ppenumMoniker == NULL) - return E_POINTER; - - *ppenumMoniker = NULL; - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_IsEqual - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker) -{ - - CLSID clsid; - LPOLESTR dispName1,dispName2; - IBindCtx* bind; - HRESULT res = S_FALSE; - - TRACE("(%p,%p)\n",iface,pmkOtherMoniker); - - if (!pmkOtherMoniker) return S_FALSE; - - - /* check if both are ItemMoniker */ - if(FAILED (IMoniker_GetClassID(pmkOtherMoniker,&clsid))) return S_FALSE; - if(!IsEqualCLSID(&clsid,&CLSID_ItemMoniker)) return S_FALSE; - - /* check if both displaynames are the same */ - if(SUCCEEDED ((res = CreateBindCtx(0,&bind)))) { - if(SUCCEEDED (IMoniker_GetDisplayName(iface,bind,NULL,&dispName1))) { - if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&dispName2))) { - if(lstrcmpW(dispName1,dispName2)==0) res = S_OK; - CoTaskMemFree(dispName2); - } - CoTaskMemFree(dispName1); - } - } - return res; -} - -/****************************************************************************** - * ItemMoniker_Hash - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - int h = 0,i,skip,len; - int off = 0; - LPOLESTR val; - - if (pdwHash==NULL) - return E_POINTER; - - val = This->itemName; - len = lstrlenW(val); - - if (len < 16) { - for (i = len ; i > 0; i--) { - h = (h * 37) + val[off++]; - } - } else { - /* only sample some characters */ - skip = len / 8; - for (i = len ; i > 0; i -= skip, off += skip) { - h = (h * 39) + val[off]; - } - } - - *pdwHash=h; - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_IsRunning - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - IMoniker* pmkNewlyRunning) -{ - IRunningObjectTable* rot; - HRESULT res; - IOleItemContainer *poic=0; - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning); - - /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */ - /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */ - if (pmkToLeft==NULL) - if ((pmkNewlyRunning!=NULL)&&(IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK)) - return S_OK; - else { - if (pbc==NULL) - return E_POINTER; - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (FAILED(res)) - return res; - - res = IRunningObjectTable_IsRunning(rot,iface); - - IRunningObjectTable_Release(rot); - } - else{ - - /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */ - /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/ - /* passing the string contained within this moniker. */ - - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic); - - if (SUCCEEDED(res)){ - - res=IOleItemContainer_IsRunning(poic,This->itemName); - - IOleItemContainer_Release(poic); - } - } - - return res; -} - -/****************************************************************************** - * ItemMoniker_GetTimeOfLastChange - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - FILETIME* pItemTime) -{ - IRunningObjectTable* rot; - HRESULT res; - IMoniker *compositeMk; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pItemTime); - - if (pItemTime==NULL) - return E_INVALIDARG; - - /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */ - if (pmkToLeft==NULL) - - return MK_E_NOTBINDABLE; - else { - - /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */ - /* the time of last change. If the object is not in the ROT, the method calls */ - /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */ - - res=CreateGenericComposite(pmkToLeft,iface,&compositeMk); - - res=IBindCtx_GetRunningObjectTable(pbc,&rot); - - if (IRunningObjectTable_GetTimeOfLastChange(rot,compositeMk,pItemTime)!=S_OK) - - res=IMoniker_GetTimeOfLastChange(pmkToLeft,pbc,NULL,pItemTime); - - IMoniker_Release(compositeMk); - } - - return res; -} - -/****************************************************************************** - * ItemMoniker_Inverse - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk) -{ - TRACE("(%p,%p)\n",iface,ppmk); - - if (ppmk==NULL) - return E_POINTER; - - return CreateAntiMoniker(ppmk); -} - -/****************************************************************************** - * ItemMoniker_CommonPrefixWith - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix) -{ - DWORD mkSys; - IMoniker_IsSystemMoniker(pmkOther,&mkSys); - /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */ - /* to this moniker and returns MK_S_US */ - - if((mkSys==MKSYS_ITEMMONIKER) && (IMoniker_IsEqual(iface,pmkOther)==S_OK) ){ - - *ppmkPrefix=iface; - - IMoniker_AddRef(iface); - - return MK_S_US; - } - else - /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */ - /* the case where the other moniker is a generic composite. */ - return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix); -} - -/****************************************************************************** - * ItemMoniker_RelativePathTo - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath) -{ - TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath); - - if (ppmkRelPath==NULL) - return E_POINTER; - - *ppmkRelPath=0; - - return MK_E_NOTBINDABLE; -} - -/****************************************************************************** - * ItemMoniker_GetDisplayName - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR *ppszDisplayName) -{ - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName); - - if (ppszDisplayName==NULL) - return E_POINTER; - - if (pmkToLeft!=NULL){ - return E_INVALIDARG; - } - - *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(lstrlenW(This->itemDelimiter)+lstrlenW(This->itemName)+1)); - - if (*ppszDisplayName==NULL) - return E_OUTOFMEMORY; - - lstrcpyW(*ppszDisplayName,This->itemDelimiter); - lstrcatW(*ppszDisplayName,This->itemName); - - return S_OK; -} - -/****************************************************************************** - * ItemMoniker_ParseDisplayName - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker* iface, - IBindCtx* pbc, - IMoniker* pmkToLeft, - LPOLESTR pszDisplayName, - ULONG* pchEaten, - IMoniker** ppmkOut) -{ - IOleItemContainer* poic=0; - IParseDisplayName* ppdn=0; - LPOLESTR displayName; - HRESULT res; - ItemMonikerImpl *This = (ItemMonikerImpl *)iface; - - /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */ - if (pmkToLeft==NULL) - - return MK_E_SYNTAX; - - else{ - /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */ - /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */ - /* name to IParseDisplayName::ParseDisplayName */ - res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IOleItemContainer,(void**)&poic); - - if (SUCCEEDED(res)){ - - res=IOleItemContainer_GetObject(poic,This->itemName,BINDSPEED_MODERATE,pbc,&IID_IParseDisplayName,(void**)&ppdn); - - res=IMoniker_GetDisplayName(iface,pbc,NULL,&displayName); - - res=IParseDisplayName_ParseDisplayName(ppdn,pbc,displayName,pchEaten,ppmkOut); - - IOleItemContainer_Release(poic); - IParseDisplayName_Release(ppdn); - } - } - return res; -} - -/****************************************************************************** - * ItemMoniker_IsSystemMoniker - ******************************************************************************/ -HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys) -{ - TRACE("(%p,%p)\n",iface,pwdMksys); - - if (!pwdMksys) - return E_POINTER; - - (*pwdMksys)=MKSYS_ITEMMONIKER; - - return S_OK; -} - -/******************************************************************************* - * ItemMonikerIROTData_QueryInterface - *******************************************************************************/ -HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject) -{ - - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p,%p,%p)\n",iface,riid,ppvObject); - - return ItemMonikerImpl_QueryInterface(This, riid, ppvObject); -} - -/*********************************************************************** - * ItemMonikerIROTData_AddRef - */ -ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",iface); - - return ItemMonikerImpl_AddRef(This); -} - -/*********************************************************************** - * ItemMonikerIROTData_Release - */ -ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface) -{ - ICOM_THIS_From_IROTData(IMoniker, iface); - - TRACE("(%p)\n",iface); - - return ItemMonikerImpl_Release(This); -} - -/****************************************************************************** - * ItemMonikerIROTData_GetComparaisonData - ******************************************************************************/ -HRESULT WINAPI ItemMonikerROTDataImpl_GetComparaisonData(IROTData* iface, - BYTE* pbData, - ULONG cbMax, - ULONG* pcbData) -{ - FIXME("(),stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * CreateItemMoniker [OLE32.@] - ******************************************************************************/ -HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim,LPCOLESTR lpszItem, LPMONIKER * ppmk) -{ - ItemMonikerImpl* newItemMoniker = 0; - HRESULT hr = S_OK; - IID riid=IID_IMoniker; - - TRACE("(%p,%p,%p)\n",lpszDelim,lpszItem,ppmk); - - newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl)); - - if (newItemMoniker == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem); - - if (FAILED(hr)){ - - HeapFree(GetProcessHeap(),0,newItemMoniker); - return hr; - } - - return ItemMonikerImpl_QueryInterface((IMoniker*)newItemMoniker,&riid,(void**)ppmk); -} diff --git a/reactos/lib/ole32/makefile b/reactos/lib/ole32/makefile deleted file mode 100644 index a3532d6343d..00000000000 --- a/reactos/lib/ole32/makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $Id: makefile,v 1.9 2004/01/02 19:49:45 gvg Exp $ - -PATH_TO_TOP = ../.. - -TARGET_TYPE = winedll - -include $(PATH_TO_TOP)/rules.mak - -include $(TOOLS_PATH)/helper.mk diff --git a/reactos/lib/ole32/marshal.c b/reactos/lib/ole32/marshal.c deleted file mode 100644 index b7330284cf4..00000000000 --- a/reactos/lib/ole32/marshal.c +++ /dev/null @@ -1,809 +0,0 @@ -/* - * Marshalling library - * - * Copyright 2002 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "ole2ver.h" -#include "rpc.h" -#include "winerror.h" -#include "winreg.h" -#include "wownt32.h" -#include "wtypes.h" -#include "wine/unicode.h" -#include "wine/winbase16.h" -#include "compobj_private.h" -#include "ifs.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -extern const CLSID CLSID_DfMarshal; - -/* Marshalling just passes a unique identifier to the remote client, - * that makes it possible to find the passed interface again. - * - * So basically we need a set of values that make it unique. - * - * Process Identifier, Object IUnknown ptr, IID - * - * Note that the IUnknown_QI(ob,xiid,&ppv) always returns the SAME ppv value! - */ - -inline static HRESULT -get_facbuf_for_iid(REFIID riid,IPSFactoryBuffer **facbuf) { - HRESULT hres; - CLSID pxclsid; - - if ((hres = CoGetPSClsid(riid,&pxclsid))) - return hres; - return CoGetClassObject(&pxclsid,CLSCTX_INPROC_SERVER,NULL,&IID_IPSFactoryBuffer,(LPVOID*)facbuf); -} - -typedef struct _wine_marshal_data { - DWORD dwDestContext; - DWORD mshlflags; -} wine_marshal_data; - -typedef struct _mid2unknown { - wine_marshal_id mid; - LPUNKNOWN pUnk; -} mid2unknown; - -typedef struct _mid2stub { - wine_marshal_id mid; - IRpcStubBuffer *stub; - LPUNKNOWN pUnkServer; - BOOL valid; -} mid2stub; - -static mid2stub *stubs = NULL; -static int nrofstubs = 0; - -static mid2unknown *proxies = NULL; -static int nrofproxies = 0; - -void MARSHAL_Invalidate_Stub_From_MID(wine_marshal_id *mid) { - int i; - - for (i=0;iobjectid,debugstr_guid(&(mid->iid))); - return S_OK; - } - if (nrofstubs) - stubs=HeapReAlloc(GetProcessHeap(),0,stubs,sizeof(stubs[0])*(nrofstubs+1)); - else - stubs=HeapAlloc(GetProcessHeap(),0,sizeof(stubs[0])); - if (!stubs) return E_OUTOFMEMORY; - stubs[nrofstubs].stub = stub; - stubs[nrofstubs].pUnkServer = pUnk; - memcpy(&(stubs[nrofstubs].mid),mid,sizeof(*mid)); - stubs[nrofstubs].valid = TRUE; /* set to false when released by ReleaseMarshalData */ - nrofstubs++; - return S_OK; -} - -HRESULT -MARSHAL_Disconnect_Proxies() { - int i; - - TRACE("Disconnecting %d proxies\n", nrofproxies); - - for (i = 0; i < nrofproxies; i++) - IRpcProxyBuffer_Disconnect((IRpcProxyBuffer*)proxies[i].pUnk); - - return S_OK; -} - -static HRESULT -MARSHAL_Register_Proxy(wine_marshal_id *mid,LPUNKNOWN punk) { - int i; - - for (i=0;iref); -} - -static ULONG WINAPI -StdMarshalImpl_Release(LPMARSHAL iface) { - StdMarshalImpl *This = (StdMarshalImpl *)iface; - ULONG ref = InterlockedDecrement(&This->ref); - - if (!ref) HeapFree(GetProcessHeap(),0,This); - return ref; -} - -static HRESULT WINAPI -StdMarshalImpl_GetUnmarshalClass( - LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, - void* pvDestContext, DWORD mshlflags, CLSID* pCid -) { - memcpy(pCid,&CLSID_DfMarshal,sizeof(CLSID_DfMarshal)); - return S_OK; -} - -static HRESULT WINAPI -StdMarshalImpl_GetMarshalSizeMax( - LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, - void* pvDestContext, DWORD mshlflags, DWORD* pSize -) { - *pSize = sizeof(wine_marshal_id)+sizeof(wine_marshal_data); - return S_OK; -} - -static HRESULT WINAPI -StdMarshalImpl_MarshalInterface( - LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext, - void* pvDestContext, DWORD mshlflags -) { - wine_marshal_id mid; - wine_marshal_data md; - IUnknown *pUnk; - ULONG res; - HRESULT hres; - IRpcStubBuffer *stub; - IPSFactoryBuffer *psfacbuf; - - TRACE("(...,%s,...)\n",debugstr_guid(riid)); - - IUnknown_QueryInterface((LPUNKNOWN)pv,&IID_IUnknown,(LPVOID*)&pUnk); - mid.processid = GetCurrentProcessId(); - mid.objectid = (DWORD)pUnk; /* FIXME */ - IUnknown_Release(pUnk); - memcpy(&mid.iid,riid,sizeof(mid.iid)); - md.dwDestContext = dwDestContext; - md.mshlflags = mshlflags; - hres = IStream_Write(pStm,&mid,sizeof(mid),&res); - if (hres) return hres; - hres = IStream_Write(pStm,&md,sizeof(md),&res); - if (hres) return hres; - - if (SUCCEEDED(MARSHAL_Find_Stub_Buffer(&mid,&stub))) { - /* Find_Stub_Buffer gives us a ref but we want to keep it, as if we'd created a new one */ - TRACE("Found RpcStubBuffer %p\n", stub); - return S_OK; - } - hres = get_facbuf_for_iid(riid,&psfacbuf); - if (hres) return hres; - - hres = IPSFactoryBuffer_CreateStub(psfacbuf,riid,pv,&stub); - IPSFactoryBuffer_Release(psfacbuf); - if (hres) { - FIXME("Failed to create a stub for %s\n",debugstr_guid(riid)); - return hres; - } - IUnknown_QueryInterface((LPUNKNOWN)pv,riid,(LPVOID*)&pUnk); - MARSHAL_Register_Stub(&mid,pUnk,stub); - IUnknown_Release(pUnk); - return S_OK; -} - -static HRESULT WINAPI -StdMarshalImpl_UnmarshalInterface( - LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv -) { - wine_marshal_id mid; - wine_marshal_data md; - ULONG res; - HRESULT hres; - IPSFactoryBuffer *psfacbuf; - IRpcProxyBuffer *rpcproxy; - IRpcChannelBuffer *chanbuf; - - TRACE("(...,%s,....)\n",debugstr_guid(riid)); - hres = IStream_Read(pStm,&mid,sizeof(mid),&res); - if (hres) return hres; - hres = IStream_Read(pStm,&md,sizeof(md),&res); - if (hres) return hres; - if (SUCCEEDED(MARSHAL_Find_Stub(&mid,(LPUNKNOWN*)ppv))) { - FIXME("Calling back to ourselves for %s!\n",debugstr_guid(riid)); - return S_OK; - } - if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_NULL)) { - /* should return proxy manager IUnknown object */ - FIXME("Special treatment required for IID of %s\n", debugstr_guid(riid)); - } - hres = get_facbuf_for_iid(riid,&psfacbuf); - if (hres) return hres; - hres = IPSFactoryBuffer_CreateProxy(psfacbuf,NULL,riid,&rpcproxy,ppv); - if (hres) { - FIXME("Failed to create a proxy for %s\n",debugstr_guid(riid)); - return hres; - } - - MARSHAL_Register_Proxy(&mid, (LPUNKNOWN) rpcproxy); - - hres = PIPE_GetNewPipeBuf(&mid,&chanbuf); - IPSFactoryBuffer_Release(psfacbuf); - if (hres) { - ERR("Failed to get an rpc channel buffer for %s\n",debugstr_guid(riid)); - } else { - /* Connect the channel buffer to the proxy and release the no longer - * needed proxy. - * NOTE: The proxy should have taken an extra reference because it also - * aggregates the object, so we can safely release our reference to it. */ - IRpcProxyBuffer_Connect(rpcproxy,chanbuf); - IRpcProxyBuffer_Release(rpcproxy); - /* IRpcProxyBuffer takes a reference on the channel buffer and - * we no longer need it, so release it */ - IRpcChannelBuffer_Release(chanbuf); - } - return hres; -} - -static HRESULT WINAPI -StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm) { - wine_marshal_id mid; - ULONG res; - HRESULT hres; - IRpcStubBuffer *stub = NULL; - int i; - - hres = IStream_Read(pStm,&mid,sizeof(mid),&res); - if (hres) return hres; - - for (i=0; i < nrofstubs; i++) - { - if (!stubs[i].valid) continue; - - if (MARSHAL_Compare_Mids(&mid, &(stubs[i].mid))) - { - stub = stubs[i].stub; - break; - } - } - - if (!stub) - { - FIXME("Could not map MID to stub??\n"); - return E_FAIL; - } - - res = IRpcStubBuffer_Release(stub); - stubs[i].valid = FALSE; - TRACE("stub refcount of %p is %ld\n", stub, res); - - return S_OK; -} - -static HRESULT WINAPI -StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved) { - FIXME("(), stub!\n"); - return S_OK; -} - -IMarshalVtbl stdmvtbl = { - StdMarshalImpl_QueryInterface, - StdMarshalImpl_AddRef, - StdMarshalImpl_Release, - StdMarshalImpl_GetUnmarshalClass, - StdMarshalImpl_GetMarshalSizeMax, - StdMarshalImpl_MarshalInterface, - StdMarshalImpl_UnmarshalInterface, - StdMarshalImpl_ReleaseMarshalData, - StdMarshalImpl_DisconnectObject -}; - -/*********************************************************************** - * CoGetStandardMarshal [OLE32.@] - * - * When the COM library in the client process receives a marshalled - * interface pointer, it looks for a CLSID to be used in creating a proxy - * for the purposes of unmarshalling the packet. If the packet does not - * contain a CLSID for the proxy, COM calls CoGetStandardMarshal, passing a - * NULL pUnk value. - * This function creates a standard proxy in the client process and returns - * a pointer to that proxy's implementation of IMarshal. - * COM uses this pointer to call CoUnmarshalInterface to retrieve the pointer - * to the requested interface. - */ -HRESULT WINAPI -CoGetStandardMarshal( - REFIID riid,IUnknown *pUnk,DWORD dwDestContext,LPVOID pvDestContext, - DWORD mshlflags, LPMARSHAL *pMarshal -) { - StdMarshalImpl *dm; - - if (pUnk == NULL) { - FIXME("(%s,NULL,%lx,%p,%lx,%p), unimplemented yet.\n", - debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,pMarshal - ); - return E_FAIL; - } - TRACE("(%s,%p,%lx,%p,%lx,%p)\n", - debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,pMarshal - ); - *pMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl)); - dm = (StdMarshalImpl*) *pMarshal; - if (!dm) return E_FAIL; - dm->lpvtbl = &stdmvtbl; - dm->ref = 1; - - memcpy(&dm->iid,riid,sizeof(dm->iid)); - dm->dwDestContext = dwDestContext; - dm->pvDestContext = pvDestContext; - dm->mshlflags = mshlflags; - return S_OK; -} - -/* Helper function for getting Marshaler */ -static HRESULT WINAPI -_GetMarshaller(REFIID riid, IUnknown *pUnk,DWORD dwDestContext, - void *pvDestContext, DWORD mshlFlags, LPMARSHAL *pMarshal -) { - HRESULT hres; - - if (!pUnk) - return E_POINTER; - hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)pMarshal); - if (hres) - hres = CoGetStandardMarshal(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pMarshal); - return hres; -} - -/*********************************************************************** - * CoGetMarshalSizeMax [OLE32.@] - */ -HRESULT WINAPI -CoGetMarshalSizeMax(ULONG *pulSize, REFIID riid, IUnknown *pUnk, - DWORD dwDestContext, void *pvDestContext, DWORD mshlFlags -) { - HRESULT hres; - LPMARSHAL pMarshal; - - hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlFlags,&pMarshal); - if (hres) - return hres; - hres = IMarshal_GetMarshalSizeMax(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlFlags,pulSize); - *pulSize += sizeof(wine_marshal_id)+sizeof(wine_marshal_data)+sizeof(CLSID); - IMarshal_Release(pMarshal); - return hres; -} - - -/*********************************************************************** - * CoMarshalInterface [OLE32.@] - */ -HRESULT WINAPI -CoMarshalInterface( IStream *pStm, REFIID riid, IUnknown *pUnk, - DWORD dwDestContext, void *pvDestContext, DWORD mshlflags -) { - HRESULT hres; - LPMARSHAL pMarshal; - CLSID xclsid; - ULONG writeres; - wine_marshal_id mid; - wine_marshal_data md; - ULONG res; - IUnknown *pUnknown; - - TRACE("(%p, %s, %p, %lx, %p, %lx)\n", - pStm,debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags - ); - - if (pUnk == NULL) - return E_INVALIDARG; - - STUBMGR_Start(); /* Just to be sure we have one running. */ - mid.processid = GetCurrentProcessId(); - IUnknown_QueryInterface(pUnk,&IID_IUnknown,(LPVOID*)&pUnknown); - mid.objectid = (DWORD)pUnknown; - IUnknown_Release(pUnknown); - memcpy(&mid.iid,riid,sizeof(mid.iid)); - md.dwDestContext = dwDestContext; - md.mshlflags = mshlflags; - hres = IStream_Write(pStm,&mid,sizeof(mid),&res); - if (hres) return hres; - hres = IStream_Write(pStm,&md,sizeof(md),&res); - if (hres) return hres; - hres = _GetMarshaller(riid,pUnk,dwDestContext,pvDestContext,mshlflags,&pMarshal); - if (hres) { - FIXME("Failed to get marshaller, %lx?\n",hres); - return hres; - } - hres = IMarshal_GetUnmarshalClass(pMarshal,riid,pUnk,dwDestContext,pvDestContext,mshlflags,&xclsid); - if (hres) { - FIXME("IMarshal:GetUnmarshalClass failed, %lx\n",hres); - goto release_marshal; - } - hres = IStream_Write(pStm,&xclsid,sizeof(xclsid),&writeres); - if (hres) { - FIXME("Stream write failed, %lx\n",hres); - goto release_marshal; - } - - TRACE("Calling IMarshal::MarshalInterace\n"); - hres = IMarshal_MarshalInterface(pMarshal,pStm,riid,pUnk,dwDestContext,pvDestContext,mshlflags); - - if (hres) { - if (IsEqualGUID(riid,&IID_IOleObject)) { - ERR("WINE currently cannot marshal IOleObject interfaces. This means you cannot embed/link OLE objects between applications.\n"); - } else { - FIXME("Failed to marshal the interface %s, %lx?\n",debugstr_guid(riid),hres); - } - } -release_marshal: - IMarshal_Release(pMarshal); - return hres; -} - - -/*********************************************************************** - * CoUnmarshalInterface [OLE32.@] - */ -HRESULT WINAPI -CoUnmarshalInterface(IStream *pStm, REFIID riid, LPVOID *ppv) { - HRESULT hres; - wine_marshal_id mid; - wine_marshal_data md; - ULONG res; - LPMARSHAL pMarshal; - LPUNKNOWN pUnk; - CLSID xclsid; - - TRACE("(%p,%s,%p)\n",pStm,debugstr_guid(riid),ppv); - - hres = IStream_Read(pStm,&mid,sizeof(mid),&res); - if (hres) { - FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid)); - return hres; - } - hres = IStream_Read(pStm,&md,sizeof(md),&res); - if (hres) { - FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md)); - return hres; - } - hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res); - if (hres) { - FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid)); - return hres; - } - hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)&pUnk); - if (hres) { - FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid)); - return hres; - } - hres = _GetMarshaller(riid,pUnk,md.dwDestContext,NULL,md.mshlflags,&pMarshal); - if (hres) { - FIXME("Failed to get unmarshaller, %lx?\n",hres); - return hres; - } - hres = IMarshal_UnmarshalInterface(pMarshal,pStm,riid,ppv); - if (hres) { - FIXME("Failed to Unmarshal the interface, %lx?\n",hres); - goto release_marshal; - } -release_marshal: - IMarshal_Release(pMarshal); - return hres; -} - -/*********************************************************************** - * CoReleaseMarshalData [OLE32.@] - */ -HRESULT WINAPI -CoReleaseMarshalData(IStream *pStm) { - HRESULT hres; - wine_marshal_id mid; - wine_marshal_data md; - ULONG res; - LPMARSHAL pMarshal; - LPUNKNOWN pUnk; - CLSID xclsid; - - TRACE("(%p)\n",pStm); - - hres = IStream_Read(pStm,&mid,sizeof(mid),&res); - if (hres) { - FIXME("Stream read 1 failed, %lx, (%ld of %d)\n",hres,res,sizeof(mid)); - return hres; - } - hres = IStream_Read(pStm,&md,sizeof(md),&res); - if (hres) { - FIXME("Stream read 2 failed, %lx, (%ld of %d)\n",hres,res,sizeof(md)); - return hres; - } - hres = IStream_Read(pStm,&xclsid,sizeof(xclsid),&res); - if (hres) { - FIXME("Stream read 3 failed, %lx, (%ld of %d)\n",hres,res,sizeof(xclsid)); - return hres; - } - hres=CoCreateInstance(&xclsid,NULL,CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,&IID_IMarshal,(void**)(char*)&pUnk); - if (hres) { - FIXME("Failed to create instance of unmarshaller %s.\n",debugstr_guid(&xclsid)); - return hres; - } - hres = IUnknown_QueryInterface(pUnk,&IID_IMarshal,(LPVOID*)(char*)&pMarshal); - if (hres) { - FIXME("Failed to get IMarshal iface, %lx?\n",hres); - return hres; - } - hres = IMarshal_ReleaseMarshalData(pMarshal,pStm); - if (hres) { - FIXME("Failed to releasemarshaldata the interface, %lx?\n",hres); - } - IMarshal_Release(pMarshal); - IUnknown_Release(pUnk); - return hres; -} - - -/*********************************************************************** - * CoMarshalInterThreadInterfaceInStream [OLE32.@] - * - * Marshal an interface across threads in the same process. - * - * PARAMS - * riid [I] Identifier of the interface to be marshalled. - * pUnk [I] Pointer to IUnknown-derived interface that will be marshalled. - * ppStm [O] Pointer to IStream object that is created and then used to store the marshalled inteface. - * - * RETURNS - * Success: S_OK - * Failure: E_OUTOFMEMORY and other COM error codes - * - * SEE - * CoMarshalInterface(), CoUnmarshalInterface() and CoGetInterfaceAndReleaseStream() - */ -HRESULT WINAPI -CoMarshalInterThreadInterfaceInStream( - REFIID riid, LPUNKNOWN pUnk, LPSTREAM * ppStm) -{ - ULARGE_INTEGER xpos; - LARGE_INTEGER seekto; - HRESULT hres; - - TRACE("(%s, %p, %p)\n",debugstr_guid(riid), pUnk, ppStm); - - hres = CreateStreamOnHGlobal(0, TRUE, ppStm); - if (FAILED(hres)) return hres; - hres = CoMarshalInterface(*ppStm, riid, pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); - - /* FIXME: is this needed? */ - memset(&seekto,0,sizeof(seekto)); - IStream_Seek(*ppStm,seekto,SEEK_SET,&xpos); - - return hres; -} - -/*********************************************************************** - * CoGetInterfaceAndReleaseStream [OLE32.@] - * - * Unmarshalls an inteface from a stream and then releases the stream. - * - * PARAMS - * pStm [I] Stream that contains the marshalled inteface. - * riid [I] Interface identifier of the object to unmarshall. - * ppv [O] Address of pointer where the requested interface object will be stored. - * - * RETURNS - * Success: S_OK - * Failure: A COM error code - * - * SEE - * CoMarshalInterThreadInterfaceInStream() and CoUnmarshalInteface() - */ -HRESULT WINAPI -CoGetInterfaceAndReleaseStream(LPSTREAM pStm,REFIID riid, LPVOID *ppv) -{ - HRESULT hres; - - TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv); - - hres = CoUnmarshalInterface(pStm, riid, ppv); - IStream_Release(pStm); - return hres; -} - -static HRESULT WINAPI -SMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IClassFactory)) { - *ppv = (LPVOID)iface; - return S_OK; - } - return E_NOINTERFACE; -} -static ULONG WINAPI SMCF_AddRef(LPCLASSFACTORY iface) { return 2; } -static ULONG WINAPI SMCF_Release(LPCLASSFACTORY iface) { return 1; } - -static HRESULT WINAPI -SMCF_CreateInstance( - LPCLASSFACTORY iface, LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv -) { - if (IsEqualIID(riid,&IID_IMarshal)) { - StdMarshalImpl *dm; - dm=(StdMarshalImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl)); - if (!dm) - return E_FAIL; - dm->lpvtbl = &stdmvtbl; - dm->ref = 1; - *ppv = (LPVOID)dm; - return S_OK; - } - FIXME("(%s), not supported.\n",debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static HRESULT WINAPI -SMCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) { - FIXME("(%d), stub!\n",fLock); - return S_OK; -} - -static IClassFactoryVtbl dfmarshalcfvtbl = { - SMCF_QueryInterface, - SMCF_AddRef, - SMCF_Release, - SMCF_CreateInstance, - SMCF_LockServer -}; -static IClassFactoryVtbl *pdfmarshalcfvtbl = &dfmarshalcfvtbl; - -HRESULT -MARSHAL_GetStandardMarshalCF(LPVOID *ppv) { - *ppv = &pdfmarshalcfvtbl; - return S_OK; -} - -/*********************************************************************** - * CoMarshalHresult [OLE32.@] - * - * Marshals an HRESULT value into a stream. - * - * PARAMS - * pStm [I] Stream that hresult will be marshaled into. - * hresult [I] HRESULT to be marshaled. - * - * RETURNS - * Success: S_OK - * Failure: A COM error code - * - * SEE - * CoUnmarshalHresult(). - */ -HRESULT WINAPI -CoMarshalHresult(LPSTREAM pStm, HRESULT hresult) -{ - return IStream_Write(pStm, &hresult, sizeof(hresult), NULL); -} - -/*********************************************************************** - * CoUnmarshalHresult [OLE32.@] - * - * Unmarshals an HRESULT value from a stream. - * - * PARAMS - * pStm [I] Stream that hresult will be unmarshaled from. - * phresult [I] Pointer to HRESULT where the value will be unmarshaled to. - * - * RETURNS - * Success: S_OK - * Failure: A COM error code - * - * SEE - * CoMarshalHresult(). - */ -HRESULT WINAPI -CoUnmarshalHresult(LPSTREAM pStm, HRESULT * phresult) -{ - return IStream_Read(pStm, phresult, sizeof(*phresult), NULL); -} diff --git a/reactos/lib/ole32/memlockbytes.c b/reactos/lib/ole32/memlockbytes.c deleted file mode 100644 index 8c0677410b7..00000000000 --- a/reactos/lib/ole32/memlockbytes.c +++ /dev/null @@ -1,622 +0,0 @@ -/****************************************************************************** - * - * Global memory implementation of ILockBytes. - * - * Copyright 1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "wine/winbase16.h" -#include "objbase.h" -#include "ole2.h" -#include "winerror.h" - -#include "ifs.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/****************************************************************************** - * HGLOBALLockBytesImpl definition. - * - * This class imlements the ILockBytes inteface and represents a byte array - * object supported by an HGLOBAL pointer. - */ -struct HGLOBALLockBytesImpl -{ - /* - * Needs to be the first item in the stuct - * since we want to cast this in an ILockBytes pointer - */ - ILockBytesVtbl *lpVtbl; - - /* - * Reference count - */ - ULONG ref; - - /* - * Support for the LockBytes object - */ - HGLOBAL supportHandle; - - /* - * This flag is TRUE if the HGLOBAL is destroyed when the object - * is finally released. - */ - BOOL deleteOnRelease; - - /* - * Helper variable that contains the size of the byte array - */ - ULARGE_INTEGER byteArraySize; -}; - -typedef struct HGLOBALLockBytesImpl HGLOBALLockBytesImpl; - -/* - * Method definition for the HGLOBALLockBytesImpl class. - */ -HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct( - HGLOBAL hGlobal, - BOOL fDeleteOnRelease); - -void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This); - -HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface( - ILockBytes* iface, - REFIID riid, /* [in] */ - void** ppvObject); /* [iid_is][out] */ - -ULONG WINAPI HGLOBALLockBytesImpl_AddRef( - ILockBytes* iface); - -ULONG WINAPI HGLOBALLockBytesImpl_Release( - ILockBytes* iface); - -HRESULT WINAPI HGLOBALLockBytesImpl_ReadAt( - ILockBytes* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead); /* [out] */ - -HRESULT WINAPI HGLOBALLockBytesImpl_WriteAt( - ILockBytes* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten); /* [out] */ - -HRESULT WINAPI HGLOBALLockBytesImpl_Flush( - ILockBytes* iface); - -HRESULT WINAPI HGLOBALLockBytesImpl_SetSize( - ILockBytes* iface, - ULARGE_INTEGER libNewSize); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl_LockRegion( - ILockBytes* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl_UnlockRegion( - ILockBytes* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl_Stat( - ILockBytes* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -/* - * Virtual function table for the HGLOBALLockBytesImpl class. - */ -static ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl = -{ - HGLOBALLockBytesImpl_QueryInterface, - HGLOBALLockBytesImpl_AddRef, - HGLOBALLockBytesImpl_Release, - HGLOBALLockBytesImpl_ReadAt, - HGLOBALLockBytesImpl_WriteAt, - HGLOBALLockBytesImpl_Flush, - HGLOBALLockBytesImpl_SetSize, - HGLOBALLockBytesImpl_LockRegion, - HGLOBALLockBytesImpl_UnlockRegion, - HGLOBALLockBytesImpl_Stat, -}; - -/****************************************************************************** - * CreateILockBytesOnHGlobal [OLE32.@] - */ -HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL hGlobal, - BOOL fDeleteOnRelease, - LPLOCKBYTES* ppLkbyt) -{ - HGLOBALLockBytesImpl* newLockBytes; - - newLockBytes = HGLOBALLockBytesImpl_Construct(hGlobal, fDeleteOnRelease); - - if (newLockBytes != NULL) - { - return IUnknown_QueryInterface((IUnknown*)newLockBytes, - &IID_ILockBytes, - (void**)ppLkbyt); - } - - return E_OUTOFMEMORY; -} - -/****************************************************************************** - * GetHGlobalFromILockBytes [OLE32.@] - */ -HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* plkbyt, HGLOBAL* phglobal) -{ - HGLOBALLockBytesImpl* const pMemLockBytes = (HGLOBALLockBytesImpl*)plkbyt; - STATSTG stbuf; - HRESULT hres; - ULARGE_INTEGER start; - ULONG xread; - - *phglobal = 0; - if (pMemLockBytes->lpVtbl == &HGLOBALLockBytesImpl_Vtbl) { - *phglobal = pMemLockBytes->supportHandle; - if (*phglobal == 0) - return E_INVALIDARG; - return S_OK; - } - /* It is not our lockbytes implementation, so use a more generic way */ - hres = ILockBytes_Stat(plkbyt,&stbuf,0); - if (hres != S_OK) { - ERR("Cannot ILockBytes_Stat, %lx\n",hres); - return hres; - } - FIXME("cbSize is %ld\n",stbuf.cbSize.u.LowPart); - *phglobal = GlobalAlloc( GMEM_MOVEABLE|GMEM_SHARE, stbuf.cbSize.u.LowPart); - if (!*phglobal) - return E_INVALIDARG; - memset(&start,0,sizeof(start)); - hres = ILockBytes_ReadAt(plkbyt, start, GlobalLock(*phglobal), stbuf.cbSize.u.LowPart, &xread); - GlobalUnlock(*phglobal); - if (hres != S_OK) { - FIXME("%p->ReadAt failed with %lx\n",plkbyt,hres); - return hres; - } - if (stbuf.cbSize.u.LowPart != xread) { - FIXME("Read size is not requested size %ld vs %ld?\n",stbuf.cbSize.u.LowPart, xread); - } - return S_OK; -} - -/****************************************************************************** - * - * HGLOBALLockBytesImpl implementation - * - */ - -/****************************************************************************** - * This is the constructor for the HGLOBALLockBytesImpl class. - * - * Params: - * hGlobal - Handle that will support the stream. can be NULL. - * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released - * when the IStream object is destroyed. - */ -HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct(HGLOBAL hGlobal, - BOOL fDeleteOnRelease) -{ - HGLOBALLockBytesImpl* newLockBytes; - newLockBytes = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALLockBytesImpl)); - - if (newLockBytes!=0) - { - /* - * Set up the virtual function table and reference count. - */ - newLockBytes->lpVtbl = &HGLOBALLockBytesImpl_Vtbl; - newLockBytes->ref = 0; - - /* - * Initialize the support. - */ - newLockBytes->supportHandle = hGlobal; - newLockBytes->deleteOnRelease = fDeleteOnRelease; - - /* - * This method will allocate a handle if one is not supplied. - */ - if (newLockBytes->supportHandle == 0) - { - newLockBytes->supportHandle = GlobalAlloc(GMEM_MOVEABLE | - GMEM_NODISCARD, - 0); - } - - /* - * Initialize the size of the array to the size of the handle. - */ - newLockBytes->byteArraySize.u.HighPart = 0; - newLockBytes->byteArraySize.u.LowPart = GlobalSize( - newLockBytes->supportHandle); - } - - return newLockBytes; -} - -/****************************************************************************** - * This is the destructor of the HGLOBALStreamImpl class. - * - * This method will clean-up all the resources used-up by the given - * HGLOBALLockBytesImpl class. The pointer passed-in to this function will be - * freed and will not be valid anymore. - */ -void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This) -{ - /* - * Release the HGlobal if the constructor asked for that. - */ - if (This->deleteOnRelease) - { - GlobalFree(This->supportHandle); - This->supportHandle = 0; - } - - /* - * Finally, free the memory used-up by the class. - */ - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** - * This implements the IUnknown method QueryInterface for this - * class - */ -HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface( - ILockBytes* iface, - REFIID riid, /* [in] */ - void** ppvObject) /* [iid_is][out] */ -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - - /* - * Perform a sanity check on the parameters. - */ - if (ppvObject==0) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = (ILockBytes*)This; - } - else if (memcmp(&IID_ILockBytes, riid, sizeof(IID_ILockBytes)) == 0) - { - *ppvObject = (ILockBytes*)This; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - HGLOBALLockBytesImpl_AddRef(iface); - - return S_OK; -} - -/****************************************************************************** - * This implements the IUnknown method AddRef for this - * class - */ -ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface) -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * This implements the IUnknown method Release for this - * class - */ -ULONG WINAPI HGLOBALLockBytesImpl_Release(ILockBytes* iface) -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - ULONG ref; - - ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref==0) - { - HGLOBALLockBytesImpl_Destroy(This); - } - - return ref; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It reads a block of information from the byte array at the specified - * offset. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_ReadAt( - ILockBytes* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead) /* [out] */ -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - - void* supportBuffer; - ULONG bytesReadBuffer = 0; - ULONG bytesToReadFromBuffer; - - /* - * If the caller is not interested in the number of bytes read, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbRead == 0) - pcbRead = &bytesReadBuffer; - - /* - * Make sure the offset is valid. - */ - if (ulOffset.u.LowPart > This->byteArraySize.u.LowPart) - return E_FAIL; - - /* - * Using the known size of the array, calculate the number of bytes - * to read. - */ - bytesToReadFromBuffer = min(This->byteArraySize.u.LowPart - - ulOffset.u.LowPart, cb); - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock(This->supportHandle); - - memcpy(pv, - (char *) supportBuffer + ulOffset.u.LowPart, - bytesToReadFromBuffer); - - /* - * Return the number of bytes read. - */ - *pcbRead = bytesToReadFromBuffer; - - /* - * Cleanup - */ - GlobalUnlock(This->supportHandle); - - /* - * The function returns S_OK if the specified number of bytes were read - * or the end of the array was reached. - * It returns STG_E_READFAULT if the number of bytes to read does not equal - * the number of bytes actually read. - */ - if(*pcbRead == cb) - return S_OK; - - return STG_E_READFAULT; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It writes the specified bytes at the specified offset. - * position. If the array is too small, it will be resized. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_WriteAt( - ILockBytes* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten) /* [out] */ -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - - void* supportBuffer; - ULARGE_INTEGER newSize; - ULONG bytesWritten = 0; - - /* - * If the caller is not interested in the number of bytes written, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbWritten == 0) - pcbWritten = &bytesWritten; - - if (cb == 0) - { - return S_OK; - } - else - { - newSize.u.HighPart = 0; - newSize.u.LowPart = ulOffset.u.LowPart + cb; - } - - /* - * Verify if we need to grow the stream - */ - if (newSize.u.LowPart > This->byteArraySize.u.LowPart) - { - /* grow stream */ - if (HGLOBALLockBytesImpl_SetSize(iface, newSize) == STG_E_MEDIUMFULL) - return STG_E_MEDIUMFULL; - } - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock(This->supportHandle); - - memcpy((char *) supportBuffer + ulOffset.u.LowPart, pv, cb); - - /* - * Return the number of bytes written. - */ - *pcbWritten = cb; - - /* - * Cleanup - */ - GlobalUnlock(This->supportHandle); - - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_Flush(ILockBytes* iface) -{ - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It will change the size of the byte array. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_SetSize( - ILockBytes* iface, - ULARGE_INTEGER libNewSize) /* [in] */ -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - HGLOBAL supportHandle; - - /* - * As documented. - */ - if (libNewSize.u.HighPart != 0) - return STG_E_INVALIDFUNCTION; - - if (This->byteArraySize.u.LowPart == libNewSize.u.LowPart) - return S_OK; - - /* - * Re allocate the HGlobal to fit the new size of the stream. - */ - supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0); - - if (supportHandle == 0) - return STG_E_MEDIUMFULL; - - This->supportHandle = supportHandle; - This->byteArraySize.u.LowPart = libNewSize.u.LowPart; - - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * The global memory implementation of ILockBytes does not support locking. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_LockRegion( - ILockBytes* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return STG_E_INVALIDFUNCTION; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * The global memory implementation of ILockBytes does not support locking. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_UnlockRegion( - ILockBytes* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return STG_E_INVALIDFUNCTION; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * This method returns information about the current - * byte array object. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl_Stat( - ILockBytes* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface; - - memset(pstatstg, 0, sizeof(STATSTG)); - - pstatstg->pwcsName = NULL; - pstatstg->type = STGTY_LOCKBYTES; - pstatstg->cbSize = This->byteArraySize; - - return S_OK; -} diff --git a/reactos/lib/ole32/memlockbytes16.c b/reactos/lib/ole32/memlockbytes16.c deleted file mode 100644 index 0320b4524fc..00000000000 --- a/reactos/lib/ole32/memlockbytes16.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * Global memory implementation of ILockBytes. - * - * Copyright 1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include - -#define NONAMELESSUNION -#define NONAMELESSSTRUCT -#include "windef.h" -#include "winbase.h" -#include "wine/winbase16.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "winerror.h" - -#include "ifs.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/****************************************************************************** - * HGLOBALLockBytesImpl16 definition. - * - * This class imlements the ILockBytes inteface and represents a byte array - * object supported by an HGLOBAL pointer. - */ -struct HGLOBALLockBytesImpl16 -{ - /* - * Needs to be the first item in the stuct - * since we want to cast this in an ILockBytes pointer - */ - ILockBytes16Vtbl *lpVtbl; - ULONG ref; - - /* - * Support for the LockBytes object - */ - HGLOBAL16 supportHandle; - - /* - * This flag is TRUE if the HGLOBAL is destroyed when the object - * is finally released. - */ - BOOL deleteOnRelease; - /* - * Helper variable that contains the size of the byte array - */ - ULARGE_INTEGER byteArraySize; -}; - -typedef struct HGLOBALLockBytesImpl16 HGLOBALLockBytesImpl16; - -HGLOBALLockBytesImpl16* HGLOBALLockBytesImpl16_Construct( - HGLOBAL16 hGlobal, - BOOL16 fDeleteOnRelease); - -void HGLOBALLockBytesImpl16_Destroy(HGLOBALLockBytesImpl16* This); - -HRESULT WINAPI HGLOBALLockBytesImpl16_QueryInterface( - ILockBytes16* iface, - REFIID riid, /* [in] */ - void** ppvObject); /* [out][iid_is] */ - -ULONG WINAPI HGLOBALLockBytesImpl16_AddRef( - ILockBytes16* iface); - -ULONG WINAPI HGLOBALLockBytesImpl16_Release( - ILockBytes16* iface); - -HRESULT WINAPI HGLOBALLockBytesImpl16_ReadAt( - ILockBytes16* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - void* pv, /* [out][length_is][size_is] */ - ULONG cb, /* [in] */ - ULONG* pcbRead); /* [out] */ - -HRESULT WINAPI HGLOBALLockBytesImpl16_WriteAt( - ILockBytes16* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - const void* pv, /* [in][size_is] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten); /* [out] */ - -HRESULT WINAPI HGLOBALLockBytesImpl16_Flush( - ILockBytes16* iface); - -HRESULT WINAPI HGLOBALLockBytesImpl16_SetSize( - ILockBytes16* iface, - ULARGE_INTEGER libNewSize); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl16_LockRegion( - ILockBytes16* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl16_UnlockRegion( - ILockBytes16* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI HGLOBALLockBytesImpl16_Stat( - ILockBytes16* iface, - STATSTG16* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -/****************************************************************************** - * - * HGLOBALLockBytesImpl16 implementation - * - */ - -/****************************************************************************** - * This is the constructor for the HGLOBALLockBytesImpl16 class. - * - * Params: - * hGlobal - Handle that will support the stream. can be NULL. - * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL16 will be released - * when the IStream object is destroyed. - */ -HGLOBALLockBytesImpl16* -HGLOBALLockBytesImpl16_Construct(HGLOBAL16 hGlobal, - BOOL16 fDeleteOnRelease) -{ - HGLOBALLockBytesImpl16* newLockBytes; - - static ILockBytes16Vtbl vt16; - static SEGPTR msegvt16; - HMODULE16 hcomp = GetModuleHandle16("OLE2"); - - - TRACE("(%x,%d)\n",hGlobal,fDeleteOnRelease); - newLockBytes = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALLockBytesImpl16)); - if (newLockBytes == NULL) - return NULL; - - /* - * Set up the virtual function table and reference count. - */ - if (!msegvt16) - { -#define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"HGLOBALLockBytesImpl16_"#x);assert(vt16.x) - VTENT(QueryInterface); - VTENT(AddRef); - VTENT(Release); - VTENT(ReadAt); - VTENT(WriteAt); - VTENT(Flush); - VTENT(SetSize); - VTENT(LockRegion); - VTENT(UnlockRegion); -#undef VTENT - msegvt16 = MapLS( &vt16 ); - } - newLockBytes->lpVtbl = (ILockBytes16Vtbl*)msegvt16; - newLockBytes->ref = 0; - /* - * Initialize the support. - */ - newLockBytes->supportHandle = hGlobal; - newLockBytes->deleteOnRelease = fDeleteOnRelease; - - /* - * This method will allocate a handle if one is not supplied. - */ - if (newLockBytes->supportHandle == 0) - newLockBytes->supportHandle = GlobalAlloc16(GMEM_MOVEABLE | GMEM_NODISCARD, 0); - - /* - * Initialize the size of the array to the size of the handle. - */ - newLockBytes->byteArraySize.u.HighPart = 0; - newLockBytes->byteArraySize.u.LowPart = GlobalSize16( - newLockBytes->supportHandle); - - return (HGLOBALLockBytesImpl16*)MapLS(newLockBytes); -} - -/****************************************************************************** - * This is the destructor of the HGLOBALStreamImpl class. - * - * This method will clean-up all the resources used-up by the given - * HGLOBALLockBytesImpl16 class. The pointer passed-in to this function will be - * freed and will not be valid anymore. - */ -void HGLOBALLockBytesImpl16_Destroy(HGLOBALLockBytesImpl16* This) -{ - TRACE("()\n"); - /* - * Release the HGlobal if the constructor asked for that. - */ - if (This->deleteOnRelease) - { - GlobalFree16(This->supportHandle); - This->supportHandle = 0; - } - - /* - * Finally, free the memory used-up by the class. - */ - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** - * This implements the IUnknown method QueryInterface for this - * class - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_QueryInterface( - ILockBytes16* iface, /* [in] SEGPTR */ - REFIID riid, /* [in] */ - void** ppvObject) /* [out][iid_is] (ptr to SEGPTR!) */ -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)MapSL((SEGPTR)iface); - - TRACE("(%p,%s,%p)\n",iface,debugstr_guid(riid),ppvObject); - /* - * Perform a sanity check on the parameters. - */ - if (ppvObject==0) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if ( !memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) || - !memcmp(&IID_ILockBytes, riid, sizeof(IID_ILockBytes)) - ) - *ppvObject = (void*)iface; - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - HGLOBALLockBytesImpl16_AddRef((ILockBytes16*)This); - - return S_OK; -} - -/****************************************************************************** - * This implements the IUnknown method AddRef for this - * class - */ -ULONG WINAPI HGLOBALLockBytesImpl16_AddRef(ILockBytes16* iface) -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * This implements the IUnknown method Release for this - * class - */ -ULONG WINAPI HGLOBALLockBytesImpl16_Release(ILockBytes16* iface) -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref==0) - HGLOBALLockBytesImpl16_Destroy(This); - return ref; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It reads a block of information from the byte array at the specified - * offset. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_ReadAt( - ILockBytes16* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - void* pv, /* [out][length_is][size_is] */ - ULONG cb, /* [in] */ - ULONG* pcbRead) /* [out] */ -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - - void* supportBuffer; - ULONG bytesReadBuffer = 0; - ULONG bytesToReadFromBuffer; - - TRACE("(%p,%ld,%p,%ld,%p)\n",This,ulOffset.u.LowPart,pv,cb,pcbRead); - /* - * If the caller is not interested in the number of bytes read, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbRead == 0) - pcbRead = &bytesReadBuffer; - - /* - * Make sure the offset is valid. - */ - if (ulOffset.u.LowPart > This->byteArraySize.u.LowPart) - return E_FAIL; - - /* - * Using the known size of the array, calculate the number of bytes - * to read. - */ - bytesToReadFromBuffer = min(This->byteArraySize.u.LowPart - - ulOffset.u.LowPart, cb); - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock16(This->supportHandle); - - memcpy(pv, - (char *) supportBuffer + ulOffset.u.LowPart, - bytesToReadFromBuffer); - - /* - * Return the number of bytes read. - */ - *pcbRead = bytesToReadFromBuffer; - - /* - * Cleanup - */ - GlobalUnlock16(This->supportHandle); - - /* - * The function returns S_OK if the specified number of bytes were read - * or the end of the array was reached. - * It returns STG_E_READFAULT if the number of bytes to read does not equal - * the number of bytes actually read. - */ - if(*pcbRead == cb) - return S_OK; - - return STG_E_READFAULT; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It writes the specified bytes at the specified offset. - * position. If the array is too small, it will be resized. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_WriteAt( - ILockBytes16* iface, - ULARGE_INTEGER ulOffset, /* [in] */ - const void* pv, /* [in][size_is] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten) /* [out] */ -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - - void* supportBuffer; - ULARGE_INTEGER newSize; - ULONG bytesWritten = 0; - - TRACE("(%p,%ld,%p,%ld,%p)\n",This,ulOffset.u.LowPart,pv,cb,pcbWritten); - /* - * If the caller is not interested in the number of bytes written, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbWritten == 0) - pcbWritten = &bytesWritten; - - if (cb == 0) - return S_OK; - - newSize.u.HighPart = 0; - newSize.u.LowPart = ulOffset.u.LowPart + cb; - - /* - * Verify if we need to grow the stream - */ - if (newSize.u.LowPart > This->byteArraySize.u.LowPart) - { - /* grow stream */ - if (HGLOBALLockBytesImpl16_SetSize(iface, newSize) == STG_E_MEDIUMFULL) - return STG_E_MEDIUMFULL; - } - - /* - * Lock the buffer in position and copy the data. - */ - supportBuffer = GlobalLock16(This->supportHandle); - - memcpy((char *) supportBuffer + ulOffset.u.LowPart, pv, cb); - - /* - * Return the number of bytes written. - */ - *pcbWritten = cb; - - /* - * Cleanup - */ - GlobalUnlock16(This->supportHandle); - - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_Flush(ILockBytes16* iface) -{ - TRACE("(%p)\n",iface); - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * It will change the size of the byte array. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_SetSize( - ILockBytes16* iface, - ULARGE_INTEGER libNewSize) /* [in] */ -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - HGLOBAL16 supportHandle; - - TRACE("(%p,%ld)\n",This,libNewSize.u.LowPart); - /* - * As documented. - */ - if (libNewSize.u.HighPart != 0) - return STG_E_INVALIDFUNCTION; - - if (This->byteArraySize.u.LowPart == libNewSize.u.LowPart) - return S_OK; - - /* - * Re allocate the HGlobal to fit the new size of the stream. - */ - supportHandle = GlobalReAlloc16(This->supportHandle, libNewSize.u.LowPart, 0); - - if (supportHandle == 0) - return STG_E_MEDIUMFULL; - - This->supportHandle = supportHandle; - This->byteArraySize.u.LowPart = libNewSize.u.LowPart; - - return S_OK; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * The global memory implementation of ILockBytes does not support locking. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_LockRegion( - ILockBytes16* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return STG_E_INVALIDFUNCTION; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * The global memory implementation of ILockBytes does not support locking. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_UnlockRegion( - ILockBytes16* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - return STG_E_INVALIDFUNCTION; -} - -/****************************************************************************** - * This method is part of the ILockBytes interface. - * - * This method returns information about the current - * byte array object. - * - * See the documentation of ILockBytes for more info. - */ -HRESULT WINAPI HGLOBALLockBytesImpl16_Stat( - ILockBytes16*iface, - STATSTG16* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface; - - memset(pstatstg, 0, sizeof(STATSTG16)); - - pstatstg->pwcsName = NULL; - pstatstg->type = STGTY_LOCKBYTES; - pstatstg->cbSize = This->byteArraySize; - - return S_OK; -} - -/****************************************************************************** - * CreateILockBytesOnHGlobal [OLE2.54] - * - * Creates an ILockBytes interface for a HGLOBAL handle. - * - * Params: - * hGlobal the global handle (16bit) - * fDeleteOnRelease delete handle on release. - * ppLkbyt pointer to ILockBytes interface. - * - * Returns: - * Staddard OLE error return codes. - * - */ -HRESULT WINAPI CreateILockBytesOnHGlobal16( - HGLOBAL16 hGlobal, /* [in] */ - BOOL16 fDeleteOnRelease, /* [in] */ - LPLOCKBYTES16 *ppLkbyt) /* [out] (ptr to SEGPTR!) */ -{ - HGLOBALLockBytesImpl16* newLockBytes; /* SEGPTR */ - - newLockBytes = HGLOBALLockBytesImpl16_Construct(hGlobal, fDeleteOnRelease); - - if (newLockBytes != NULL) - return HGLOBALLockBytesImpl16_QueryInterface((ILockBytes16*)newLockBytes, - &IID_ILockBytes, - (void**)ppLkbyt); - return E_OUTOFMEMORY; -} diff --git a/reactos/lib/ole32/moniker.c b/reactos/lib/ole32/moniker.c deleted file mode 100644 index 57f05740821..00000000000 --- a/reactos/lib/ole32/moniker.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Monikers - * - * Copyright 1998 Marcus Meissner - * Copyright 1999 Noomen Hamza - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * TODO: - * - IRunningObjectTable should work interprocess, but currently doesn't. - * Native (on Win2k at least) uses an undocumented RPC interface, IROT, to - * communicate with RPCSS which contains the table of marshalled data. - * - IRunningObjectTable should use marshalling instead of simple ref - * counting as there is the possibility of using the running object table - * to access objects in other apartments. - */ - -#include -#include -#include - -#define COBJMACROS - -#include "winerror.h" -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "wtypes.h" -#include "wine/debug.h" -#include "ole2.h" - -#include "compobj_private.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -#define BLOCK_TAB_SIZE 20 /* represent the first size table and it's increment block size */ - -/* define the structure of the running object table elements */ -typedef struct RunObject{ - - IUnknown* pObj; /* points on a running object*/ - IMoniker* pmkObj; /* points on a moniker who identifies this object */ - FILETIME lastModifObj; - DWORD identRegObj; /* registration key relative to this object */ - DWORD regTypeObj; /* registration type : strong or weak */ -}RunObject; - -/* define the RunningObjectTableImpl structure */ -typedef struct RunningObjectTableImpl{ - - IRunningObjectTableVtbl *lpVtbl; - ULONG ref; - - RunObject* runObjTab; /* pointer to the first object in the table */ - DWORD runObjTabSize; /* current table size */ - DWORD runObjTabLastIndx; /* first free index element in the table. */ - DWORD runObjTabRegister; /* registration key of the next registered object */ - -} RunningObjectTableImpl; - -RunningObjectTableImpl* runningObjectTableInstance=0; - -/* IRunningObjectTable prototype functions : */ -/* IUnknown functions*/ -static HRESULT WINAPI RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,REFIID riid,void** ppvObject); -static ULONG WINAPI RunningObjectTableImpl_AddRef(IRunningObjectTable* iface); -static ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable* iface); -/* IRunningObjectTable functions */ -static HRESULT WINAPI RunningObjectTableImpl_Register(IRunningObjectTable* iface, DWORD grfFlags,IUnknown* punkObject,IMoniker* pmkObjectName,DWORD* pdwRegister); -static HRESULT WINAPI RunningObjectTableImpl_Revoke(IRunningObjectTable* iface, DWORD dwRegister); -static HRESULT WINAPI RunningObjectTableImpl_IsRunning(IRunningObjectTable* iface, IMoniker* pmkObjectName); -static HRESULT WINAPI RunningObjectTableImpl_GetObject(IRunningObjectTable* iface, IMoniker* pmkObjectName,IUnknown** ppunkObject); -static HRESULT WINAPI RunningObjectTableImpl_NoteChangeTime(IRunningObjectTable* iface, DWORD dwRegister,FILETIME* pfiletime); -static HRESULT WINAPI RunningObjectTableImpl_GetTimeOfLastChange(IRunningObjectTable* iface, IMoniker* pmkObjectName,FILETIME* pfiletime); -static HRESULT WINAPI RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface, IEnumMoniker** ppenumMoniker); -/* Local functions*/ -HRESULT WINAPI RunningObjectTableImpl_Initialize(); -HRESULT WINAPI RunningObjectTableImpl_UnInitialize(); -HRESULT WINAPI RunningObjectTableImpl_Destroy(); -HRESULT WINAPI RunningObjectTableImpl_GetObjectIndex(RunningObjectTableImpl* This,DWORD identReg,IMoniker* pmk,DWORD *indx); - -/* Virtual function table for the IRunningObjectTable class. */ -static IRunningObjectTableVtbl VT_RunningObjectTableImpl = -{ - RunningObjectTableImpl_QueryInterface, - RunningObjectTableImpl_AddRef, - RunningObjectTableImpl_Release, - RunningObjectTableImpl_Register, - RunningObjectTableImpl_Revoke, - RunningObjectTableImpl_IsRunning, - RunningObjectTableImpl_GetObject, - RunningObjectTableImpl_NoteChangeTime, - RunningObjectTableImpl_GetTimeOfLastChange, - RunningObjectTableImpl_EnumRunning -}; - -/*********************************************************************** - * RunningObjectTable_QueryInterface - */ -HRESULT WINAPI RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,REFIID riid,void** ppvObject) -{ - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,riid,ppvObject); - - /* validate arguments */ - if (This==0) - return CO_E_NOTINITIALIZED; - - if (ppvObject==0) - return E_INVALIDARG; - - *ppvObject = 0; - - if (IsEqualIID(&IID_IUnknown, riid)) - *ppvObject = (IRunningObjectTable*)This; - else - if (IsEqualIID(&IID_IRunningObjectTable, riid)) - *ppvObject = (IRunningObjectTable*)This; - - if ((*ppvObject)==0) - return E_NOINTERFACE; - - RunningObjectTableImpl_AddRef(iface); - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_AddRef - */ -ULONG WINAPI RunningObjectTableImpl_AddRef(IRunningObjectTable* iface) -{ - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p)\n",This); - - return InterlockedIncrement(&This->ref); -} - -/*********************************************************************** - * RunningObjectTable_Initialize - */ -HRESULT WINAPI RunningObjectTableImpl_Destroy() -{ - TRACE("()\n"); - - if (runningObjectTableInstance==NULL) - return E_INVALIDARG; - - /* free the ROT table memory */ - HeapFree(GetProcessHeap(),0,runningObjectTableInstance->runObjTab); - - /* free the ROT structure memory */ - HeapFree(GetProcessHeap(),0,runningObjectTableInstance); - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_Release - */ -ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable* iface) -{ - DWORD i; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - ULONG ref; - - TRACE("(%p)\n",This); - - ref = InterlockedDecrement(&This->ref); - - /* unitialize ROT structure if there's no more reference to it*/ - if (ref == 0) { - - /* release all registered objects */ - for(i=0;irunObjTabLastIndx;i++) - { - if (( This->runObjTab[i].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0) - IUnknown_Release(This->runObjTab[i].pObj); - - IMoniker_Release(This->runObjTab[i].pmkObj); - } - /* RunningObjectTable data structure will be not destroyed here ! the destruction will be done only - * when RunningObjectTableImpl_UnInitialize function is called - */ - - /* there's no more elements in the table */ - This->runObjTabRegister=0; - This->runObjTabLastIndx=0; - } - - return ref; -} - -/*********************************************************************** - * RunningObjectTable_Initialize - */ -HRESULT WINAPI RunningObjectTableImpl_Initialize() -{ - TRACE("()\n"); - - /* create the unique instance of the RunningObjectTableImpl structure */ - runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl)); - - if (runningObjectTableInstance == 0) - return E_OUTOFMEMORY; - - /* initialize the virtual table function */ - runningObjectTableInstance->lpVtbl = &VT_RunningObjectTableImpl; - - /* the initial reference is set to "1" ! because if set to "0" it will be not practis when */ - /* the ROT referred many times not in the same time (all the objects in the ROT will */ - /* be removed every time the ROT is removed ) */ - runningObjectTableInstance->ref = 1; - - /* allocate space memory for the table which contains all the running objects */ - runningObjectTableInstance->runObjTab = HeapAlloc(GetProcessHeap(), 0, sizeof(RunObject[BLOCK_TAB_SIZE])); - - if (runningObjectTableInstance->runObjTab == NULL) - return E_OUTOFMEMORY; - - runningObjectTableInstance->runObjTabSize=BLOCK_TAB_SIZE; - runningObjectTableInstance->runObjTabRegister=1; - runningObjectTableInstance->runObjTabLastIndx=0; - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_UnInitialize - */ -HRESULT WINAPI RunningObjectTableImpl_UnInitialize() -{ - TRACE("()\n"); - - if (runningObjectTableInstance==NULL) - return E_POINTER; - - RunningObjectTableImpl_Release((IRunningObjectTable*)runningObjectTableInstance); - - RunningObjectTableImpl_Destroy(); - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_Register - */ -HRESULT WINAPI RunningObjectTableImpl_Register(IRunningObjectTable* iface, - DWORD grfFlags, /* Registration options */ - IUnknown *punkObject, /* Pointer to the object being registered */ - IMoniker *pmkObjectName, /* Pointer to the moniker of the object being registered */ - DWORD *pdwRegister) /* Pointer to the value identifying the registration */ -{ - HRESULT res=S_OK; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%ld,%p,%p,%p)\n",This,grfFlags,punkObject,pmkObjectName,pdwRegister); - - /* there's only two types of register : strong and or weak registration (only one must be passed on parameter) */ - if ( ( (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || !(grfFlags & ROTFLAGS_ALLOWANYCLIENT)) && - (!(grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || (grfFlags & ROTFLAGS_ALLOWANYCLIENT)) && - (grfFlags) ) - return E_INVALIDARG; - - if (punkObject==NULL || pmkObjectName==NULL || pdwRegister==NULL) - return E_INVALIDARG; - - /* verify if the object to be registered was registered before */ - if (RunningObjectTableImpl_GetObjectIndex(This,-1,pmkObjectName,NULL)==S_OK) - res = MK_S_MONIKERALREADYREGISTERED; - - /* put the new registered object in the first free element in the table */ - This->runObjTab[This->runObjTabLastIndx].pObj = punkObject; - This->runObjTab[This->runObjTabLastIndx].pmkObj = pmkObjectName; - This->runObjTab[This->runObjTabLastIndx].regTypeObj = grfFlags; - This->runObjTab[This->runObjTabLastIndx].identRegObj = This->runObjTabRegister; - CoFileTimeNow(&(This->runObjTab[This->runObjTabLastIndx].lastModifObj)); - - /* gives a registration identifier to the registered object*/ - (*pdwRegister)= This->runObjTabRegister; - - if (This->runObjTabRegister == 0xFFFFFFFF){ - - FIXME("runObjTabRegister: %ld is out of data limite \n",This->runObjTabRegister); - return E_FAIL; - } - This->runObjTabRegister++; - This->runObjTabLastIndx++; - - if (This->runObjTabLastIndx == This->runObjTabSize){ /* table is full ! so it must be resized */ - - This->runObjTabSize+=BLOCK_TAB_SIZE; /* newsize table */ - This->runObjTab=HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->runObjTab, - This->runObjTabSize * sizeof(RunObject)); - if (!This->runObjTab) - return E_OUTOFMEMORY; - } - /* add a reference to the object in the strong registration case */ - if ((grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) !=0 ) { - TRACE("strong registration, reffing %p\n", punkObject); - /* this is wrong; we should always add a reference to the object */ - IUnknown_AddRef(punkObject); - } - - IMoniker_AddRef(pmkObjectName); - - return res; -} - -/*********************************************************************** - * RunningObjectTable_Revoke - */ -HRESULT WINAPI RunningObjectTableImpl_Revoke( IRunningObjectTable* iface, - DWORD dwRegister) /* Value identifying registration to be revoked*/ -{ - - DWORD index,j; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%ld)\n",This,dwRegister); - - /* verify if the object to be revoked was registered before or not */ - if (RunningObjectTableImpl_GetObjectIndex(This,dwRegister,NULL,&index)==S_FALSE) - - return E_INVALIDARG; - - /* release the object if it was registered with a strong registrantion option */ - if ((This->runObjTab[index].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE)!=0) { - TRACE("releasing %p\n", This->runObjTab[index].pObj); - /* this is also wrong; we should always release the object (see above) */ - IUnknown_Release(This->runObjTab[index].pObj); - } - - IMoniker_Release(This->runObjTab[index].pmkObj); - - /* remove the object from the table */ - for(j=index; jrunObjTabLastIndx-1; j++) - This->runObjTab[j]= This->runObjTab[j+1]; - - This->runObjTabLastIndx--; - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_IsRunning - */ -HRESULT WINAPI RunningObjectTableImpl_IsRunning( IRunningObjectTable* iface, - IMoniker *pmkObjectName) /* Pointer to the moniker of the object whose status is desired */ -{ - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%p)\n",This,pmkObjectName); - - return RunningObjectTableImpl_GetObjectIndex(This,-1,pmkObjectName,NULL); -} - -/*********************************************************************** - * RunningObjectTable_GetObject - */ -HRESULT WINAPI RunningObjectTableImpl_GetObject( IRunningObjectTable* iface, - IMoniker *pmkObjectName,/* Pointer to the moniker on the object */ - IUnknown **ppunkObject) /* Address of output variable that receives the IUnknown interface pointer */ -{ - DWORD index; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,pmkObjectName,ppunkObject); - - if (ppunkObject==NULL) - return E_POINTER; - - *ppunkObject=0; - - /* verify if the object was registered before or not */ - if (RunningObjectTableImpl_GetObjectIndex(This,-1,pmkObjectName,&index)==S_FALSE) { - WARN("Moniker unavailable - needs to work interprocess?\n"); - return MK_E_UNAVAILABLE; - } - - /* add a reference to the object then set output object argument */ - IUnknown_AddRef(This->runObjTab[index].pObj); - *ppunkObject=This->runObjTab[index].pObj; - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_NoteChangeTime - */ -HRESULT WINAPI RunningObjectTableImpl_NoteChangeTime(IRunningObjectTable* iface, - DWORD dwRegister, /* Value identifying registration being updated */ - FILETIME *pfiletime) /* Pointer to structure containing object's last change time */ -{ - DWORD index=-1; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%ld,%p)\n",This,dwRegister,pfiletime); - - /* verify if the object to be changed was registered before or not */ - if (RunningObjectTableImpl_GetObjectIndex(This,dwRegister,NULL,&index)==S_FALSE) - return E_INVALIDARG; - - /* set the new value of the last time change */ - This->runObjTab[index].lastModifObj= (*pfiletime); - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_GetTimeOfLastChange - */ -HRESULT WINAPI RunningObjectTableImpl_GetTimeOfLastChange(IRunningObjectTable* iface, - IMoniker *pmkObjectName, /* Pointer to moniker on the object whose status is desired */ - FILETIME *pfiletime) /* Pointer to structure that receives object's last change time */ -{ - DWORD index=-1; - RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface; - - TRACE("(%p,%p,%p)\n",This,pmkObjectName,pfiletime); - - if (pmkObjectName==NULL || pfiletime==NULL) - return E_INVALIDARG; - - /* verify if the object was registered before or not */ - if (RunningObjectTableImpl_GetObjectIndex(This,-1,pmkObjectName,&index)==S_FALSE) - return MK_E_UNAVAILABLE; - - (*pfiletime)= This->runObjTab[index].lastModifObj; - - return S_OK; -} - -/*********************************************************************** - * RunningObjectTable_EnumRunning - */ -HRESULT WINAPI RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface, - IEnumMoniker **ppenumMoniker) /* Address of output variable that receives the IEnumMoniker interface pointer */ -{ - FIXME("(%p,%p) needs the IEnumMoniker implementation \n",iface,ppenumMoniker); - return E_NOTIMPL; -} - -/*********************************************************************** - * GetObjectIndex - */ -HRESULT WINAPI RunningObjectTableImpl_GetObjectIndex(RunningObjectTableImpl* This, - DWORD identReg, - IMoniker* pmk, - DWORD *indx) -{ - - DWORD i; - - TRACE("(%p,%ld,%p,%p)\n",This,identReg,pmk,indx); - - if (pmk!=NULL) - /* search object identified by a moniker */ - for(i=0 ; (i < This->runObjTabLastIndx) &&(!IMoniker_IsEqual(This->runObjTab[i].pmkObj,pmk)==S_OK);i++); - else - /* search object identified by a register identifier */ - for(i=0;((irunObjTabLastIndx)&&(This->runObjTab[i].identRegObj!=identReg));i++); - - if (i==This->runObjTabLastIndx) return S_FALSE; - - if (indx != NULL) *indx=i; - - return S_OK; -} - -/****************************************************************************** - * GetRunningObjectTable (OLE2.30) - */ -HRESULT WINAPI GetRunningObjectTable16(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot) -{ - FIXME("(%ld,%p),stub!\n",reserved,pprot); - return E_NOTIMPL; -} - -/*********************************************************************** - * GetRunningObjectTable (OLE32.@) - */ -HRESULT WINAPI GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot) -{ - IID riid=IID_IRunningObjectTable; - HRESULT res; - - TRACE("()\n"); - - if (reserved!=0) - return E_UNEXPECTED; - - if(runningObjectTableInstance==NULL) - return CO_E_NOTINITIALIZED; - - res = RunningObjectTableImpl_QueryInterface((IRunningObjectTable*)runningObjectTableInstance,&riid,(void**)pprot); - - return res; -} - -/****************************************************************************** - * OleRun [OLE32.@] - */ -HRESULT WINAPI OleRun(LPUNKNOWN pUnknown) -{ - IRunnableObject *runable; - IRunnableObject *This = (IRunnableObject *)pUnknown; - LRESULT ret; - - ret = IRunnableObject_QueryInterface(This,&IID_IRunnableObject,(LPVOID*)&runable); - if (ret) - return 0; /* Appears to return no error. */ - ret = IRunnableObject_Run(runable,NULL); - IRunnableObject_Release(runable); - return ret; -} - -/****************************************************************************** - * MkParseDisplayName [OLE32.@] - */ -HRESULT WINAPI MkParseDisplayName(LPBC pbc, LPCOLESTR szUserName, - LPDWORD pchEaten, LPMONIKER *ppmk) -{ - FIXME("(%p, %s, %p, %p): stub.\n", pbc, debugstr_w(szUserName), pchEaten, *ppmk); - if (!(IsValidInterface((LPUNKNOWN) pbc))) - return E_INVALIDARG; - - return MK_E_SYNTAX; -} - -/****************************************************************************** - * CreateClassMoniker [OLE32.@] - */ - HRESULT WINAPI CreateClassMoniker(REFCLSID rclsid, IMoniker ** ppmk) - { - FIXME("%s\n", debugstr_guid( rclsid )); - if( ppmk ) - *ppmk = NULL; - return E_NOTIMPL; - } diff --git a/reactos/lib/ole32/moniker.h b/reactos/lib/ole32/moniker.h deleted file mode 100644 index 8e4c6ca3ce8..00000000000 --- a/reactos/lib/ole32/moniker.h +++ /dev/null @@ -1,11 +0,0 @@ -#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; -extern const CLSID CLSID_CompositeMoniker; - -#endif /* __WINE_MONIKER_H__ */ diff --git a/reactos/lib/ole32/ole16.c b/reactos/lib/ole32/ole16.c deleted file mode 100644 index 3c21c6e0f16..00000000000 --- a/reactos/lib/ole32/ole16.c +++ /dev/null @@ -1,527 +0,0 @@ -/* - * 16 bit ole functions - * - * Copyright 1995 Martin von Loewis - * Copyright 1998 Justin Bradford - * Copyright 1999 Francis Beaudet - * Copyright 1999 Sylvain St-Germain - * Copyright 2002 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "ole2ver.h" -#include "rpc.h" -#include "winerror.h" -#include "winreg.h" -#include "wownt32.h" -#include "wtypes.h" -#include "wine/unicode.h" -#include "wine/winbase16.h" -#include "compobj_private.h" -#include "ifs.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -HINSTANCE16 COMPOBJ_hInstance = 0; -static int COMPOBJ_Attach = 0; - -HTASK16 hETask = 0; -WORD Table_ETask[62]; - -LPMALLOC16 currentMalloc16=NULL; - -/* --- IMalloc16 implementation */ - - -typedef struct -{ - /* IUnknown fields */ - IMalloc16Vtbl *lpVtbl; - DWORD ref; - /* IMalloc16 fields */ -} IMalloc16Impl; - -/****************************************************************************** - * IMalloc16_QueryInterface [COMPOBJ.500] - */ -HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) { - IMalloc16Impl *This = (IMalloc16Impl *)iface; - - TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj); - if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) || - !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc)) - ) { - *obj = This; - return 0; - } - return OLE_E_ENUM_NOMORE; -} - -/****************************************************************************** - * IMalloc16_AddRef [COMPOBJ.501] - */ -ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) { - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->AddRef()\n",This); - return 1; /* cannot be freed */ -} - -/****************************************************************************** - * IMalloc16_Release [COMPOBJ.502] - */ -ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) { - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->Release()\n",This); - return 1; /* cannot be freed */ -} - -/****************************************************************************** - * IMalloc16_Alloc [COMPOBJ.503] - */ -SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) { - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->Alloc(%ld)\n",This,cb); - return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) ); -} - -/****************************************************************************** - * IMalloc16_Free [COMPOBJ.505] - */ -VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv) -{ - void *ptr = MapSL(pv); - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->Free(%08lx)\n",This,pv); - UnMapLS(pv); - HeapFree( GetProcessHeap(), 0, ptr ); -} - -/****************************************************************************** - * IMalloc16_Realloc [COMPOBJ.504] - */ -SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) -{ - SEGPTR ret; - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb); - if (!pv) - ret = IMalloc16_fnAlloc(iface, cb); - else if (cb) { - ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) ); - UnMapLS(pv); - } else { - IMalloc16_fnFree(iface, pv); - ret = 0; - } - return ret; -} - -/****************************************************************************** - * IMalloc16_GetSize [COMPOBJ.506] - */ -DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv) -{ - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->GetSize(%08lx)\n",This,pv); - return HeapSize( GetProcessHeap(), 0, MapSL(pv) ); -} - -/****************************************************************************** - * IMalloc16_DidAlloc [COMPOBJ.507] - */ -INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) { - IMalloc16 *This = (IMalloc16 *)iface; - TRACE("(%p)->DidAlloc(%p)\n",This,pv); - return (INT16)-1; -} - -/****************************************************************************** - * IMalloc16_HeapMinimize [COMPOBJ.508] - */ -LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) { - IMalloc16Impl *This = (IMalloc16Impl *)iface; - TRACE("(%p)->HeapMinimize()\n",This); - return NULL; -} - -/****************************************************************************** - * IMalloc16_Constructor [VTABLE] - */ -LPMALLOC16 -IMalloc16_Constructor() -{ - static IMalloc16Vtbl vt16; - static SEGPTR msegvt16; - IMalloc16Impl* This; - HMODULE16 hcomp = GetModuleHandle16("COMPOBJ"); - - This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) ); - if (!msegvt16) - { -#define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x) - VTENT(QueryInterface); - VTENT(AddRef); - VTENT(Release); - VTENT(Alloc); - VTENT(Realloc); - VTENT(Free); - VTENT(GetSize); - VTENT(DidAlloc); - VTENT(HeapMinimize); -#undef VTENT - msegvt16 = MapLS( &vt16 ); - } - This->lpVtbl = (IMalloc16Vtbl*)msegvt16; - This->ref = 1; - return (LPMALLOC16)MapLS( This ); -} - - -/*********************************************************************** - * CoGetMalloc [COMPOBJ.4] - * RETURNS - * The current win16 IMalloc - */ -HRESULT WINAPI CoGetMalloc16( - DWORD dwMemContext, /* [in] unknown */ - LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */ -) { - if(!currentMalloc16) - currentMalloc16 = IMalloc16_Constructor(); - *lpMalloc = currentMalloc16; - return S_OK; -} - -/*********************************************************************** - * CoCreateStandardMalloc [COMPOBJ.71] - */ -HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext, - LPMALLOC16 *lpMalloc) -{ - /* FIXME: docu says we shouldn't return the same allocator as in - * CoGetMalloc16 */ - *lpMalloc = IMalloc16_Constructor(); - return S_OK; -} - -/****************************************************************************** - * CoInitialize [COMPOBJ.2] - * Set the win16 IMalloc used for memory management - */ -HRESULT WINAPI CoInitialize16( - LPVOID lpReserved /* [in] pointer to win16 malloc interface */ -) { - currentMalloc16 = (LPMALLOC16)lpReserved; - return S_OK; -} - -/*********************************************************************** - * CoUninitialize [COMPOBJ.3] - * Don't know what it does. - * 3-Nov-98 -- this was originally misspelled, I changed it to what I - * believe is the correct spelling - */ -void WINAPI CoUninitialize16(void) -{ - TRACE("()\n"); - CoFreeAllLibraries(); -} - -/*********************************************************************** - * IsEqualGUID [COMPOBJ.18] - * - * Compares two Unique Identifiers. - * - * RETURNS - * TRUE if equal - */ -BOOL16 WINAPI IsEqualGUID16( - GUID* g1, /* [in] unique id 1 */ - GUID* g2) /* [in] unique id 2 */ -{ - return !memcmp( g1, g2, sizeof(GUID) ); -} - -/****************************************************************************** - * CLSIDFromString [COMPOBJ.20] - * Converts a unique identifier from its string representation into - * the GUID struct. - * - * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6] - * - * RETURNS - * the converted GUID - */ -HRESULT WINAPI CLSIDFromString16( - LPCOLESTR16 idstr, /* [in] string representation of guid */ - CLSID *id) /* [out] GUID converted from string */ -{ - - 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. - * - * RETURNS - * the allocated segmented pointer and a HRESULT - */ -HRESULT -_xmalloc16(DWORD size, SEGPTR *ptr) { - LPMALLOC16 mllc; - DWORD args[2]; - - if (CoGetMalloc16(0,&mllc)) - return E_OUTOFMEMORY; - - args[0] = (DWORD)mllc; - args[1] = size; - /* No need for a Callback entry, we have WOWCallback16Ex which does - * everything we need. - */ - if (!K32WOWCallback16Ex( - (DWORD)((IMalloc16Vtbl*)MapSL( - (SEGPTR)((LPMALLOC16)MapSL((SEGPTR)mllc))->lpVtbl ) - )->Alloc, - WCB16_CDECL, - 2*sizeof(DWORD), - (LPVOID)args, - (LPDWORD)ptr - )) { - ERR("CallTo16 IMalloc16 (%ld) failed\n",size); - return E_FAIL; - } - return S_OK; -} - -/****************************************************************************** - * StringFromCLSID [COMPOBJ.19] - * Converts a GUID into the respective string representation. - * The target string is allocated using the OLE IMalloc. - * - * RETURNS - * the string representation and HRESULT - */ - -HRESULT WINAPI StringFromCLSID16( - REFCLSID id, /* [in] the GUID to be converted */ - LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */ - -) { - HRESULT ret; - - ret = _xmalloc16(40,(SEGPTR*)idstr); - if (ret != S_OK) - return ret; - return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr)); -} - -/****************************************************************************** - * ProgIDFromCLSID [COMPOBJ.62] - * Converts a class id into the respective Program ID. (By using a registry lookup) - * RETURNS S_OK on success - * riid associated with the progid - */ -HRESULT WINAPI ProgIDFromCLSID16( - REFCLSID clsid, /* [in] class id as found in registry */ - LPOLESTR16 *lplpszProgID/* [out] associated Prog ID */ -) { - char strCLSID[50], *buf, *buf2; - DWORD buf2len; - HKEY xhkey; - HRESULT ret = S_OK; - - WINE_StringFromCLSID(clsid, strCLSID); - - buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14); - sprintf(buf,"CLSID\\%s\\ProgID", strCLSID); - if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey)) - ret = REGDB_E_CLASSNOTREG; - - HeapFree(GetProcessHeap(), 0, buf); - - if (ret == S_OK) - { - buf2 = HeapAlloc(GetProcessHeap(), 0, 255); - buf2len = 255; - if (RegQueryValueA(xhkey, NULL, buf2, &buf2len)) - ret = REGDB_E_CLASSNOTREG; - - if (ret == S_OK) - { - ret = _xmalloc16(buf2len+1, (SEGPTR*)lplpszProgID); - if (ret == S_OK) - strcpy(MapSL((SEGPTR)*lplpszProgID),buf2); - } - HeapFree(GetProcessHeap(), 0, buf2); - } - RegCloseKey(xhkey); - return ret; -} - -/*********************************************************************** - * LookupETask (COMPOBJ.94) - */ -HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) { - FIXME("(%p,%p),stub!\n",hTask,p); - if ((*hTask = GetCurrentTask()) == hETask) { - memcpy(p, Table_ETask, sizeof(Table_ETask)); - } - return 0; -} - -/*********************************************************************** - * SetETask (COMPOBJ.95) - */ -HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) { - FIXME("(%04x,%p),stub!\n",hTask,p); - hETask = hTask; - return 0; -} - -/*********************************************************************** - * CALLOBJECTINWOW (COMPOBJ.201) - */ -HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) { - FIXME("(%p,%p),stub!\n",p1,p2); - return 0; -} - -/****************************************************************************** - * CoRegisterClassObject [COMPOBJ.5] - * - * Don't know where it registers it ... - */ -HRESULT WINAPI CoRegisterClassObject16( - REFCLSID rclsid, - LPUNKNOWN pUnk, - DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */ - DWORD flags, /* [in] REGCLS flags indicating how connections are made */ - LPDWORD lpdwRegister -) { - char buf[80]; - - WINE_StringFromCLSID(rclsid,buf); - - FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n", - buf,pUnk,dwClsContext,flags,lpdwRegister - ); - return 0; -} - -/****************************************************************************** - * CoRevokeClassObject [COMPOBJ.6] - * - */ -HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */ -{ - FIXME("(0x%08lx),stub!\n", dwRegister); - return 0; -} - -/****************************************************************************** - * CoFileTimeToDosDateTime [COMPOBJ.30] - */ -BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime) -{ - return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime); -} - -/****************************************************************************** - * CoDosDateTimeToFileTime [COMPOBJ.31] - */ -BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft) -{ - return DosDateTimeToFileTime(wDosDate, wDosTime, ft); -} - -/****************************************************************************** - * CoRegisterMessageFilter [COMPOBJ.27] - */ -HRESULT WINAPI CoRegisterMessageFilter16( - LPMESSAGEFILTER lpMessageFilter, - LPMESSAGEFILTER *lplpMessageFilter -) { - FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter); - return 0; -} - -/****************************************************************************** - * CoLockObjectExternal [COMPOBJ.63] - */ -HRESULT WINAPI CoLockObjectExternal16( - LPUNKNOWN pUnk, /* [in] object to be locked */ - BOOL16 fLock, /* [in] do lock */ - BOOL16 fLastUnlockReleases /* [in] ? */ -) { - FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases); - return S_OK; -} - -/*********************************************************************** - * CoGetState [COMPOBJ.115] - */ -HRESULT WINAPI CoGetState16(LPDWORD state) -{ - FIXME("(%p),stub!\n", state); - - *state = 0; - return S_OK; -} - -/*********************************************************************** - * DllEntryPoint [COMPOBJ.116] - * - * Initialization code for the COMPOBJ DLL - * - * RETURNS: - */ -BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2) -{ - TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize, res1, res2); - switch(Reason) - { - case DLL_PROCESS_ATTACH: - if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst; - break; - - case DLL_PROCESS_DETACH: - if(!--COMPOBJ_Attach) - COMPOBJ_hInstance = 0; - break; - } - return TRUE; -} diff --git a/reactos/lib/ole32/ole2.c b/reactos/lib/ole32/ole2.c deleted file mode 100644 index 90aa1e83eed..00000000000 --- a/reactos/lib/ole32/ole2.c +++ /dev/null @@ -1,2618 +0,0 @@ -/* - * OLE2 library - * - * Copyright 1995 Martin von Loewis - * Copyright 1999 Francis Beaudet - * Copyright 1999 Noel Borthwick - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "wingdi.h" -#include "winuser.h" -#include "winnls.h" -#include "winreg.h" -#include "commctrl.h" -#include "ole2.h" -#include "ole2ver.h" -#include "wownt32.h" - -#include "wine/winbase16.h" -#include "wine/wingdi16.h" -#include "wine/winuser16.h" -#include "ole32_main.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); -WINE_DECLARE_DEBUG_CHANNEL(accel); - -#define HICON_16(h32) (LOWORD(h32)) -#define HICON_32(h16) ((HICON)(ULONG_PTR)(h16)) -#define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16)) - -/****************************************************************************** - * These are static/global variables and internal data structures that the - * OLE module uses to maintain it's state. - */ -typedef struct tagDropTargetNode -{ - HWND hwndTarget; - IDropTarget* dropTarget; - struct tagDropTargetNode* prevDropTarget; - struct tagDropTargetNode* nextDropTarget; -} DropTargetNode; - -typedef struct tagTrackerWindowInfo -{ - IDataObject* dataObject; - IDropSource* dropSource; - DWORD dwOKEffect; - DWORD* pdwEffect; - BOOL trackingDone; - HRESULT returnValue; - - BOOL escPressed; - HWND curTargetHWND; /* window the mouse is hovering over */ - HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */ - IDropTarget* curDragTarget; -} TrackerWindowInfo; - -typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */ -{ - HWND hwndFrame; /* The containers frame window */ - HWND hwndActiveObject; /* The active objects window */ - OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */ - HMENU hmenuCombined; /* The combined menu */ - BOOL bIsServerItem; /* True if the currently open popup belongs to the server */ -} OleMenuDescriptor; - -typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */ -{ - DWORD tid; /* Thread Id */ - HANDLE hHeap; /* Heap this is allocated from */ - HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */ - HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */ - struct tagOleMenuHookItem *next; -} OleMenuHookItem; - -static OleMenuHookItem *hook_list; - -/* - * This is the lock count on the OLE library. It is controlled by the - * OLEInitialize/OLEUninitialize methods. - */ -static ULONG OLE_moduleLockCount = 0; - -/* - * Name of our registered window class. - */ -static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32"; - -/* - * This is the head of the Drop target container. - */ -static DropTargetNode* targetListHead = NULL; - -/****************************************************************************** - * These are the prototypes of miscelaneous utility methods - */ -static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue); - -/****************************************************************************** - * These are the prototypes of the utility methods used to manage a shared menu - */ -static void OLEMenu_Initialize(); -static void OLEMenu_UnInitialize(); -BOOL OLEMenu_InstallHooks( DWORD tid ); -BOOL OLEMenu_UnInstallHooks( DWORD tid ); -OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid ); -static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos ); -BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor ); -LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam); -LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam); - -/****************************************************************************** - * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c) - */ -void OLEClipbrd_UnInitialize(); -void OLEClipbrd_Initialize(); - -/****************************************************************************** - * These are the prototypes of the utility methods used for OLE Drag n Drop - */ -static void OLEDD_Initialize(); -static void OLEDD_UnInitialize(); -static void OLEDD_InsertDropTarget( - DropTargetNode* nodeToAdd); -static DropTargetNode* OLEDD_ExtractDropTarget( - HWND hwndOfTarget); -static DropTargetNode* OLEDD_FindDropTarget( - HWND hwndOfTarget); -static LRESULT WINAPI OLEDD_DragTrackerWindowProc( - HWND hwnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam); -static void OLEDD_TrackMouseMove( - TrackerWindowInfo* trackerInfo, - POINT mousePos, - DWORD keyState); -static void OLEDD_TrackStateChange( - TrackerWindowInfo* trackerInfo, - POINT mousePos, - DWORD keyState); -static DWORD OLEDD_GetButtonState(); - - -/****************************************************************************** - * OleBuildVersion [OLE2.1] - * OleBuildVersion [OLE32.@] - */ -DWORD WINAPI OleBuildVersion(void) -{ - TRACE("Returning version %d, build %d.\n", rmm, rup); - return (rmm<<16)+rup; -} - -/*********************************************************************** - * OleInitialize (OLE2.2) - * OleInitialize (OLE32.@) - */ -HRESULT WINAPI OleInitialize(LPVOID reserved) -{ - HRESULT hr; - - TRACE("(%p)\n", reserved); - - /* - * The first duty of the OleInitialize is to initialize the COM libraries. - */ - hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - - /* - * If the CoInitializeEx call failed, the OLE libraries can't be - * initialized. - */ - if (FAILED(hr)) - return hr; - - /* - * Then, it has to initialize the OLE specific modules. - * This includes: - * Clipboard - * Drag and Drop - * Object linking and Embedding - * In-place activation - */ - if (OLE_moduleLockCount==0) - { - /* - * Initialize the libraries. - */ - TRACE("() - Initializing the OLE libraries\n"); - - /* - * OLE Clipboard - */ - OLEClipbrd_Initialize(); - - /* - * Drag and Drop - */ - OLEDD_Initialize(); - - /* - * OLE shared menu - */ - OLEMenu_Initialize(); - } - - /* - * Then, we increase the lock count on the OLE module. - */ - OLE_moduleLockCount++; - - return hr; -} - -/****************************************************************************** - * CoGetCurrentProcess [COMPOBJ.34] - * CoGetCurrentProcess [OLE32.@] - * - * NOTES - * Is DWORD really the correct return type for this function? - */ -DWORD WINAPI CoGetCurrentProcess(void) -{ - return GetCurrentProcessId(); -} - -/****************************************************************************** - * OleUninitialize [OLE2.3] - * OleUninitialize [OLE32.@] - */ -void WINAPI OleUninitialize(void) -{ - TRACE("()\n"); - - /* - * Decrease the lock count on the OLE module. - */ - OLE_moduleLockCount--; - - /* - * If we hit the bottom of the lock stack, free the libraries. - */ - if (OLE_moduleLockCount==0) - { - /* - * Actually free the libraries. - */ - TRACE("() - Freeing the last reference count\n"); - - /* - * OLE Clipboard - */ - OLEClipbrd_UnInitialize(); - - /* - * Drag and Drop - */ - OLEDD_UnInitialize(); - - /* - * OLE shared menu - */ - OLEMenu_UnInitialize(); - } - - /* - * Then, uninitialize the COM libraries. - */ - CoUninitialize(); -} - -/****************************************************************************** - * CoRegisterMessageFilter [OLE32.@] - */ -HRESULT WINAPI CoRegisterMessageFilter( - LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */ - LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */ -) { - FIXME("stub\n"); - if (lplpMessageFilter) { - *lplpMessageFilter = NULL; - } - return S_OK; -} - -/****************************************************************************** - * OleInitializeWOW [OLE32.@] - */ -HRESULT WINAPI OleInitializeWOW(DWORD x) { - FIXME("(0x%08lx),stub!\n",x); - return 0; -} - -/*********************************************************************** - * RegisterDragDrop (OLE32.@) - */ -HRESULT WINAPI RegisterDragDrop( - HWND hwnd, - LPDROPTARGET pDropTarget) -{ - DropTargetNode* dropTargetInfo; - - TRACE("(%p,%p)\n", hwnd, pDropTarget); - - if (!pDropTarget) - return E_INVALIDARG; - - /* - * First, check if the window is already registered. - */ - dropTargetInfo = OLEDD_FindDropTarget(hwnd); - - if (dropTargetInfo!=NULL) - return DRAGDROP_E_ALREADYREGISTERED; - - /* - * If it's not there, we can add it. We first create a node for it. - */ - dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode)); - - if (dropTargetInfo==NULL) - return E_OUTOFMEMORY; - - dropTargetInfo->hwndTarget = hwnd; - dropTargetInfo->prevDropTarget = NULL; - dropTargetInfo->nextDropTarget = NULL; - - /* - * Don't forget that this is an interface pointer, need to nail it down since - * we keep a copy of it. - */ - dropTargetInfo->dropTarget = pDropTarget; - IDropTarget_AddRef(dropTargetInfo->dropTarget); - - OLEDD_InsertDropTarget(dropTargetInfo); - - return S_OK; -} - -/*********************************************************************** - * RevokeDragDrop (OLE32.@) - */ -HRESULT WINAPI RevokeDragDrop( - HWND hwnd) -{ - DropTargetNode* dropTargetInfo; - - TRACE("(%p)\n", hwnd); - - /* - * First, check if the window is already registered. - */ - dropTargetInfo = OLEDD_ExtractDropTarget(hwnd); - - /* - * If it ain't in there, it's an error. - */ - if (dropTargetInfo==NULL) - return DRAGDROP_E_NOTREGISTERED; - - /* - * If it's in there, clean-up it's used memory and - * references - */ - IDropTarget_Release(dropTargetInfo->dropTarget); - HeapFree(GetProcessHeap(), 0, dropTargetInfo); - - return S_OK; -} - -/*********************************************************************** - * OleRegGetUserType (OLE32.@) - * - * This implementation of OleRegGetUserType ignores the dwFormOfType - * parameter and always returns the full name of the object. This is - * not too bad since this is the case for many objects because of the - * way they are registered. - */ -HRESULT WINAPI OleRegGetUserType( - REFCLSID clsid, - DWORD dwFormOfType, - LPOLESTR* pszUserType) -{ - char keyName[60]; - DWORD dwKeyType; - DWORD cbData; - HKEY clsidKey; - LONG hres; - LPBYTE buffer; - HRESULT retVal; - /* - * Initialize the out parameter. - */ - *pszUserType = NULL; - - /* - * Build the key name we're looking for - */ - sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\", - clsid->Data1, clsid->Data2, clsid->Data3, - clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], - clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] ); - - TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType); - - /* - * Open the class id Key - */ - hres = RegOpenKeyA(HKEY_CLASSES_ROOT, - keyName, - &clsidKey); - - if (hres != ERROR_SUCCESS) - return REGDB_E_CLASSNOTREG; - - /* - * Retrieve the size of the name string. - */ - cbData = 0; - - hres = RegQueryValueExA(clsidKey, - "", - NULL, - &dwKeyType, - NULL, - &cbData); - - if (hres!=ERROR_SUCCESS) - { - RegCloseKey(clsidKey); - return REGDB_E_READREGDB; - } - - /* - * Allocate a buffer for the registry value. - */ - *pszUserType = CoTaskMemAlloc(cbData*2); - - if (*pszUserType==NULL) - { - RegCloseKey(clsidKey); - return E_OUTOFMEMORY; - } - - buffer = HeapAlloc(GetProcessHeap(), 0, cbData); - - if (buffer == NULL) - { - RegCloseKey(clsidKey); - CoTaskMemFree(*pszUserType); - *pszUserType=NULL; - return E_OUTOFMEMORY; - } - - hres = RegQueryValueExA(clsidKey, - "", - NULL, - &dwKeyType, - buffer, - &cbData); - - RegCloseKey(clsidKey); - - - if (hres!=ERROR_SUCCESS) - { - CoTaskMemFree(*pszUserType); - *pszUserType=NULL; - - retVal = REGDB_E_READREGDB; - } - else - { - MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ ); - retVal = S_OK; - } - HeapFree(GetProcessHeap(), 0, buffer); - - return retVal; -} - -/*********************************************************************** - * DoDragDrop [OLE32.@] - */ -HRESULT WINAPI DoDragDrop ( - IDataObject *pDataObject, /* [in] ptr to the data obj */ - IDropSource* pDropSource, /* [in] ptr to the source obj */ - DWORD dwOKEffect, /* [in] effects allowed by the source */ - DWORD *pdwEffect) /* [out] ptr to effects of the source */ -{ - TrackerWindowInfo trackerInfo; - HWND hwndTrackWindow; - MSG msg; - - TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource); - - /* - * Setup the drag n drop tracking window. - */ - if (!IsValidInterface((LPUNKNOWN)pDropSource)) - return E_INVALIDARG; - - trackerInfo.dataObject = pDataObject; - trackerInfo.dropSource = pDropSource; - trackerInfo.dwOKEffect = dwOKEffect; - trackerInfo.pdwEffect = pdwEffect; - trackerInfo.trackingDone = FALSE; - trackerInfo.escPressed = FALSE; - trackerInfo.curDragTargetHWND = 0; - trackerInfo.curTargetHWND = 0; - trackerInfo.curDragTarget = 0; - - hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS, - "TrackerWindow", - WS_POPUP, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, - 0, - 0, - (LPVOID)&trackerInfo); - - if (hwndTrackWindow!=0) - { - /* - * Capture the mouse input - */ - SetCapture(hwndTrackWindow); - - /* - * Pump messages. All mouse input should go the the capture window. - */ - while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) ) - { - if ( (msg.message >= WM_KEYFIRST) && - (msg.message <= WM_KEYLAST) ) - { - /* - * When keyboard messages are sent to windows on this thread, we - * want to ignore notify the drop source that the state changed. - * in the case of the Escape key, we also notify the drop source - * we give it a special meaning. - */ - if ( (msg.message==WM_KEYDOWN) && - (msg.wParam==VK_ESCAPE) ) - { - trackerInfo.escPressed = TRUE; - } - - /* - * Notify the drop source. - */ - OLEDD_TrackStateChange(&trackerInfo, - msg.pt, - OLEDD_GetButtonState()); - } - else - { - /* - * Dispatch the messages only when it's not a keyboard message. - */ - DispatchMessageA(&msg); - } - } - - /* - * Destroy the temporary window. - */ - DestroyWindow(hwndTrackWindow); - - return trackerInfo.returnValue; - } - - return E_FAIL; -} - -/*********************************************************************** - * OleQueryLinkFromData [OLE32.@] - */ -HRESULT WINAPI OleQueryLinkFromData( - IDataObject* pSrcDataObject) -{ - FIXME("(%p),stub!\n", pSrcDataObject); - return S_OK; -} - -/*********************************************************************** - * OleRegGetMiscStatus [OLE32.@] - */ -HRESULT WINAPI OleRegGetMiscStatus( - REFCLSID clsid, - DWORD dwAspect, - DWORD* pdwStatus) -{ - char keyName[60]; - HKEY clsidKey; - HKEY miscStatusKey; - HKEY aspectKey; - LONG result; - - /* - * Initialize the out parameter. - */ - *pdwStatus = 0; - - /* - * Build the key name we're looking for - */ - sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\", - clsid->Data1, clsid->Data2, clsid->Data3, - clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], - clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] ); - - TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus); - - /* - * Open the class id Key - */ - result = RegOpenKeyA(HKEY_CLASSES_ROOT, - keyName, - &clsidKey); - - if (result != ERROR_SUCCESS) - return REGDB_E_CLASSNOTREG; - - /* - * Get the MiscStatus - */ - result = RegOpenKeyA(clsidKey, - "MiscStatus", - &miscStatusKey); - - - if (result != ERROR_SUCCESS) - { - RegCloseKey(clsidKey); - return REGDB_E_READREGDB; - } - - /* - * Read the default value - */ - OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus); - - /* - * Open the key specific to the requested aspect. - */ - sprintf(keyName, "%ld", dwAspect); - - result = RegOpenKeyA(miscStatusKey, - keyName, - &aspectKey); - - if (result == ERROR_SUCCESS) - { - OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus); - RegCloseKey(aspectKey); - } - - /* - * Cleanup - */ - RegCloseKey(miscStatusKey); - RegCloseKey(clsidKey); - - return S_OK; -} - -/****************************************************************************** - * OleSetContainedObject [OLE32.@] - */ -HRESULT WINAPI OleSetContainedObject( - LPUNKNOWN pUnknown, - BOOL fContained) -{ - IRunnableObject* runnable = NULL; - HRESULT hres; - - TRACE("(%p,%x), stub!\n", pUnknown, fContained); - - hres = IUnknown_QueryInterface(pUnknown, - &IID_IRunnableObject, - (void**)&runnable); - - if (SUCCEEDED(hres)) - { - hres = IRunnableObject_SetContainedObject(runnable, fContained); - - IRunnableObject_Release(runnable); - - return hres; - } - - return S_OK; -} - -/****************************************************************************** - * OleLoad [OLE32.@] - */ -HRESULT WINAPI OleLoad( - LPSTORAGE pStg, - REFIID riid, - LPOLECLIENTSITE pClientSite, - LPVOID* ppvObj) -{ - IPersistStorage* persistStorage = NULL; - IOleObject* oleObject = NULL; - STATSTG storageInfo; - HRESULT hres; - - TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj); - - /* - * TODO, Conversion ... OleDoAutoConvert - */ - - /* - * Get the class ID for the object. - */ - hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME); - - /* - * Now, try and create the handler for the object - */ - hres = CoCreateInstance(&storageInfo.clsid, - NULL, - CLSCTX_INPROC_HANDLER, - &IID_IOleObject, - (void**)&oleObject); - - /* - * If that fails, as it will most times, load the default - * OLE handler. - */ - if (FAILED(hres)) - { - hres = OleCreateDefaultHandler(&storageInfo.clsid, - NULL, - &IID_IOleObject, - (void**)&oleObject); - } - - /* - * If we couldn't find a handler... this is bad. Abort the whole thing. - */ - if (FAILED(hres)) - return hres; - - /* - * Inform the new object of it's client site. - */ - hres = IOleObject_SetClientSite(oleObject, pClientSite); - - /* - * Initialize the object with it's IPersistStorage interface. - */ - hres = IOleObject_QueryInterface(oleObject, - &IID_IPersistStorage, - (void**)&persistStorage); - - if (SUCCEEDED(hres)) - { - IPersistStorage_Load(persistStorage, pStg); - - IPersistStorage_Release(persistStorage); - persistStorage = NULL; - } - - /* - * Return the requested interface to the caller. - */ - hres = IOleObject_QueryInterface(oleObject, riid, ppvObj); - - /* - * Cleanup interfaces used internally - */ - IOleObject_Release(oleObject); - - return hres; -} - -/*********************************************************************** - * OleSave [OLE32.@] - */ -HRESULT WINAPI OleSave( - LPPERSISTSTORAGE pPS, - LPSTORAGE pStg, - BOOL fSameAsLoad) -{ - HRESULT hres; - CLSID objectClass; - - TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad); - - /* - * First, we transfer the class ID (if available) - */ - hres = IPersistStorage_GetClassID(pPS, &objectClass); - - if (SUCCEEDED(hres)) - { - WriteClassStg(pStg, &objectClass); - } - - /* - * Then, we ask the object to save itself to the - * storage. If it is successful, we commit the storage. - */ - hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad); - - if (SUCCEEDED(hres)) - { - IStorage_Commit(pStg, - STGC_DEFAULT); - } - - return hres; -} - - -/****************************************************************************** - * OleLockRunning [OLE32.@] - */ -HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses) -{ - IRunnableObject* runnable = NULL; - HRESULT hres; - - TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses); - - hres = IUnknown_QueryInterface(pUnknown, - &IID_IRunnableObject, - (void**)&runnable); - - if (SUCCEEDED(hres)) - { - hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses); - - IRunnableObject_Release(runnable); - - return hres; - } - else - return E_INVALIDARG; -} - - -/************************************************************************** - * Internal methods to manage the shared OLE menu in response to the - * OLE***MenuDescriptor API - */ - -/*** - * OLEMenu_Initialize() - * - * Initializes the OLEMENU data structures. - */ -static void OLEMenu_Initialize() -{ -} - -/*** - * OLEMenu_UnInitialize() - * - * Releases the OLEMENU data structures. - */ -static void OLEMenu_UnInitialize() -{ -} - -/************************************************************************* - * OLEMenu_InstallHooks - * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC - * - * RETURNS: TRUE if message hooks were successfully installed - * FALSE on failure - */ -BOOL OLEMenu_InstallHooks( DWORD tid ) -{ - OleMenuHookItem *pHookItem = NULL; - - /* Create an entry for the hook table */ - if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0, - sizeof(OleMenuHookItem)) ) ) - return FALSE; - - pHookItem->tid = tid; - pHookItem->hHeap = GetProcessHeap(); - - /* Install a thread scope message hook for WH_GETMESSAGE */ - pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc, - 0, GetCurrentThreadId() ); - if ( !pHookItem->GetMsg_hHook ) - goto CLEANUP; - - /* Install a thread scope message hook for WH_CALLWNDPROC */ - pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc, - 0, GetCurrentThreadId() ); - if ( !pHookItem->CallWndProc_hHook ) - goto CLEANUP; - - /* Insert the hook table entry */ - pHookItem->next = hook_list; - hook_list = pHookItem; - - return TRUE; - -CLEANUP: - /* Unhook any hooks */ - if ( pHookItem->GetMsg_hHook ) - UnhookWindowsHookEx( pHookItem->GetMsg_hHook ); - if ( pHookItem->CallWndProc_hHook ) - UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ); - /* Release the hook table entry */ - HeapFree(pHookItem->hHeap, 0, pHookItem ); - - return FALSE; -} - -/************************************************************************* - * OLEMenu_UnInstallHooks - * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC - * - * RETURNS: TRUE if message hooks were successfully installed - * FALSE on failure - */ -BOOL OLEMenu_UnInstallHooks( DWORD tid ) -{ - OleMenuHookItem *pHookItem = NULL; - OleMenuHookItem **ppHook = &hook_list; - - while (*ppHook) - { - if ((*ppHook)->tid == tid) - { - pHookItem = *ppHook; - *ppHook = pHookItem->next; - break; - } - ppHook = &(*ppHook)->next; - } - if (!pHookItem) return FALSE; - - /* Uninstall the hooks installed for this thread */ - if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) ) - goto CLEANUP; - if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) ) - goto CLEANUP; - - /* Release the hook table entry */ - HeapFree(pHookItem->hHeap, 0, pHookItem ); - - return TRUE; - -CLEANUP: - /* Release the hook table entry */ - if (pHookItem) - HeapFree(pHookItem->hHeap, 0, pHookItem ); - - return FALSE; -} - -/************************************************************************* - * OLEMenu_IsHookInstalled - * Tests if OLEMenu hooks have been installed for a thread - * - * RETURNS: The pointer and index of the hook table entry for the tid - * NULL and -1 for the index if no hooks were installed for this thread - */ -OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid ) -{ - OleMenuHookItem *pHookItem = NULL; - - /* Do a simple linear search for an entry whose tid matches ours. - * We really need a map but efficiency is not a concern here. */ - for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next) - { - if ( tid == pHookItem->tid ) - return pHookItem; - } - - return NULL; -} - -/*********************************************************************** - * OLEMenu_FindMainMenuIndex - * - * Used by OLEMenu API to find the top level group a menu item belongs to. - * On success pnPos contains the index of the item in the top level menu group - * - * RETURNS: TRUE if the ID was found, FALSE on failure - */ -static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos ) -{ - UINT i, nItems; - - nItems = GetMenuItemCount( hMainMenu ); - - for (i = 0; i < nItems; i++) - { - HMENU hsubmenu; - - /* Is the current item a submenu? */ - if ( (hsubmenu = GetSubMenu(hMainMenu, i)) ) - { - /* If the handle is the same we're done */ - if ( hsubmenu == hPopupMenu ) - { - if (pnPos) - *pnPos = i; - return TRUE; - } - /* Recursively search without updating pnPos */ - else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) ) - { - if (pnPos) - *pnPos = i; - return TRUE; - } - } - } - - return FALSE; -} - -/*********************************************************************** - * OLEMenu_SetIsServerMenu - * - * Checks whether a popup menu belongs to a shared menu group which is - * owned by the server, and sets the menu descriptor state accordingly. - * All menu messages from these groups should be routed to the server. - * - * RETURNS: TRUE if the popup menu is part of a server owned group - * FASE if the popup menu is part of a container owned group - */ -BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor ) -{ - UINT nPos = 0, nWidth, i; - - pOleMenuDescriptor->bIsServerItem = FALSE; - - /* Don't bother searching if the popup is the combined menu itself */ - if ( hmenu == pOleMenuDescriptor->hmenuCombined ) - return FALSE; - - /* Find the menu item index in the shared OLE menu that this item belongs to */ - if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) ) - return FALSE; - - /* The group widths array has counts for the number of elements - * in the groups File, Edit, Container, Object, Window, Help. - * The Edit, Object & Help groups belong to the server object - * and the other three belong to the container. - * Loop through the group widths and locate the group we are a member of. - */ - for ( i = 0, nWidth = 0; i < 6; i++ ) - { - nWidth += pOleMenuDescriptor->mgw.width[i]; - if ( nPos < nWidth ) - { - /* Odd elements are server menu widths */ - pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE; - break; - } - } - - return pOleMenuDescriptor->bIsServerItem; -} - -/************************************************************************* - * OLEMenu_CallWndProc - * Thread scope WH_CALLWNDPROC hook proc filter function (callback) - * This is invoked from a message hook installed in OleSetMenuDescriptor. - */ -LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam) -{ - LPCWPSTRUCT pMsg = NULL; - HOLEMENU hOleMenu = 0; - OleMenuDescriptor *pOleMenuDescriptor = NULL; - OleMenuHookItem *pHookItem = NULL; - WORD fuFlags; - - TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam ); - - /* Check if we're being asked to process the message */ - if ( HC_ACTION != code ) - goto NEXTHOOK; - - /* Retrieve the current message being dispatched from lParam */ - pMsg = (LPCWPSTRUCT)lParam; - - /* Check if the message is destined for a window we are interested in: - * If the window has an OLEMenu property we may need to dispatch - * the menu message to its active objects window instead. */ - - hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" ); - if ( !hOleMenu ) - goto NEXTHOOK; - - /* Get the menu descriptor */ - pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu ); - if ( !pOleMenuDescriptor ) /* Bad descriptor! */ - goto NEXTHOOK; - - /* Process menu messages */ - switch( pMsg->message ) - { - case WM_INITMENU: - { - /* Reset the menu descriptor state */ - pOleMenuDescriptor->bIsServerItem = FALSE; - - /* Send this message to the server as well */ - SendMessageA( pOleMenuDescriptor->hwndActiveObject, - pMsg->message, pMsg->wParam, pMsg->lParam ); - goto NEXTHOOK; - } - - case WM_INITMENUPOPUP: - { - /* Save the state for whether this is a server owned menu */ - OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor ); - break; - } - - case WM_MENUSELECT: - { - fuFlags = HIWORD(pMsg->wParam); /* Get flags */ - if ( fuFlags & MF_SYSMENU ) - goto NEXTHOOK; - - /* Save the state for whether this is a server owned popup menu */ - else if ( fuFlags & MF_POPUP ) - OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor ); - - break; - } - - case WM_DRAWITEM: - { - LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam; - if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU ) - goto NEXTHOOK; /* Not a menu message */ - - break; - } - - default: - goto NEXTHOOK; - } - - /* If the message was for the server dispatch it accordingly */ - if ( pOleMenuDescriptor->bIsServerItem ) - { - SendMessageA( pOleMenuDescriptor->hwndActiveObject, - pMsg->message, pMsg->wParam, pMsg->lParam ); - } - -NEXTHOOK: - if ( pOleMenuDescriptor ) - GlobalUnlock( hOleMenu ); - - /* Lookup the hook item for the current thread */ - if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) ) - { - /* This should never fail!! */ - WARN("could not retrieve hHook for current thread!\n" ); - return 0; - } - - /* Pass on the message to the next hooker */ - return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam ); -} - -/************************************************************************* - * OLEMenu_GetMsgProc - * Thread scope WH_GETMESSAGE hook proc filter function (callback) - * This is invoked from a message hook installed in OleSetMenuDescriptor. - */ -LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam) -{ - LPMSG pMsg = NULL; - HOLEMENU hOleMenu = 0; - OleMenuDescriptor *pOleMenuDescriptor = NULL; - OleMenuHookItem *pHookItem = NULL; - WORD wCode; - - TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam ); - - /* Check if we're being asked to process a messages */ - if ( HC_ACTION != code ) - goto NEXTHOOK; - - /* Retrieve the current message being dispatched from lParam */ - pMsg = (LPMSG)lParam; - - /* Check if the message is destined for a window we are interested in: - * If the window has an OLEMenu property we may need to dispatch - * the menu message to its active objects window instead. */ - - hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" ); - if ( !hOleMenu ) - goto NEXTHOOK; - - /* Process menu messages */ - switch( pMsg->message ) - { - case WM_COMMAND: - { - wCode = HIWORD(pMsg->wParam); /* Get notification code */ - if ( wCode ) - goto NEXTHOOK; /* Not a menu message */ - break; - } - default: - goto NEXTHOOK; - } - - /* Get the menu descriptor */ - pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu ); - if ( !pOleMenuDescriptor ) /* Bad descriptor! */ - goto NEXTHOOK; - - /* If the message was for the server dispatch it accordingly */ - if ( pOleMenuDescriptor->bIsServerItem ) - { - /* Change the hWnd in the message to the active objects hWnd. - * The message loop which reads this message will automatically - * dispatch it to the embedded objects window. */ - pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject; - } - -NEXTHOOK: - if ( pOleMenuDescriptor ) - GlobalUnlock( hOleMenu ); - - /* Lookup the hook item for the current thread */ - if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) ) - { - /* This should never fail!! */ - WARN("could not retrieve hHook for current thread!\n" ); - return FALSE; - } - - /* Pass on the message to the next hooker */ - return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam ); -} - -/*********************************************************************** - * OleCreateMenuDescriptor [OLE32.@] - * Creates an OLE menu descriptor for OLE to use when dispatching - * menu messages and commands. - * - * PARAMS: - * hmenuCombined - Handle to the objects combined menu - * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group - * - */ -HOLEMENU WINAPI OleCreateMenuDescriptor( - HMENU hmenuCombined, - LPOLEMENUGROUPWIDTHS lpMenuWidths) -{ - HOLEMENU hOleMenu; - OleMenuDescriptor *pOleMenuDescriptor; - int i; - - if ( !hmenuCombined || !lpMenuWidths ) - return 0; - - /* Create an OLE menu descriptor */ - if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, - sizeof(OleMenuDescriptor) ) ) ) - return 0; - - pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu ); - if ( !pOleMenuDescriptor ) - return 0; - - /* Initialize menu group widths and hmenu */ - for ( i = 0; i < 6; i++ ) - pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i]; - - pOleMenuDescriptor->hmenuCombined = hmenuCombined; - pOleMenuDescriptor->bIsServerItem = FALSE; - GlobalUnlock( hOleMenu ); - - return hOleMenu; -} - -/*********************************************************************** - * OleDestroyMenuDescriptor [OLE32.@] - * Destroy the shared menu descriptor - */ -HRESULT WINAPI OleDestroyMenuDescriptor( - HOLEMENU hmenuDescriptor) -{ - if ( hmenuDescriptor ) - GlobalFree( hmenuDescriptor ); - return S_OK; -} - -/*********************************************************************** - * OleSetMenuDescriptor [OLE32.@] - * Installs or removes OLE dispatching code for the containers frame window - * FIXME: The lpFrame and lpActiveObject parameters are currently ignored - * OLE should install context sensitive help F1 filtering for the app when - * these are non null. - * - * PARAMS: - * hOleMenu Handle to composite menu descriptor - * hwndFrame Handle to containers frame window - * hwndActiveObject Handle to objects in-place activation window - * lpFrame Pointer to IOleInPlaceFrame on containers window - * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object - * - * RETURNS: - * S_OK - menu installed correctly - * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure - */ -HRESULT WINAPI OleSetMenuDescriptor( - HOLEMENU hOleMenu, - HWND hwndFrame, - HWND hwndActiveObject, - LPOLEINPLACEFRAME lpFrame, - LPOLEINPLACEACTIVEOBJECT lpActiveObject) -{ - OleMenuDescriptor *pOleMenuDescriptor = NULL; - - /* Check args */ - if ( !hwndFrame || (hOleMenu && !hwndActiveObject) ) - return E_INVALIDARG; - - if ( lpFrame || lpActiveObject ) - { - FIXME("(%x, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n", - (unsigned int)hOleMenu, - hwndFrame, - hwndActiveObject, - lpFrame, - lpActiveObject); - } - - /* Set up a message hook to intercept the containers frame window messages. - * The message filter is responsible for dispatching menu messages from the - * shared menu which are intended for the object. - */ - - if ( hOleMenu ) /* Want to install dispatching code */ - { - /* If OLEMenu hooks are already installed for this thread, fail - * Note: This effectively means that OleSetMenuDescriptor cannot - * be called twice in succession on the same frame window - * without first calling it with a null hOleMenu to uninstall */ - if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) - return E_FAIL; - - /* Get the menu descriptor */ - pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu ); - if ( !pOleMenuDescriptor ) - return E_UNEXPECTED; - - /* Update the menu descriptor */ - pOleMenuDescriptor->hwndFrame = hwndFrame; - pOleMenuDescriptor->hwndActiveObject = hwndActiveObject; - - GlobalUnlock( hOleMenu ); - pOleMenuDescriptor = NULL; - - /* Add a menu descriptor windows property to the frame window */ - SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu ); - - /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */ - if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) ) - return E_FAIL; - } - else /* Want to uninstall dispatching code */ - { - /* Uninstall the hooks */ - if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) ) - return E_FAIL; - - /* Remove the menu descriptor property from the frame window */ - RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" ); - } - - return S_OK; -} - -/****************************************************************************** - * IsAccelerator [OLE32.@] - * Mostly copied from controls/menu.c TranslateAccelerator implementation - */ -BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd) -{ - LPACCEL lpAccelTbl; - int i; - - if(!lpMsg) return FALSE; - if (!hAccel) - { - WARN_(accel)("NULL accel handle\n"); - return FALSE; - } - if((lpMsg->message != WM_KEYDOWN && - lpMsg->message != WM_KEYUP && - lpMsg->message != WM_SYSKEYDOWN && - lpMsg->message != WM_SYSKEYUP && - lpMsg->message != WM_CHAR)) return FALSE; - lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL)); - if (NULL == lpAccelTbl) - { - return FALSE; - } - if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries) - { - WARN_(accel)("CopyAcceleratorTableW failed\n"); - HeapFree(GetProcessHeap(), 0, lpAccelTbl); - return FALSE; - } - - TRACE_(accel)("hAccel=%p, cAccelEntries=%d," - "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n", - hAccel, cAccelEntries, - lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam); - for(i = 0; i < cAccelEntries; i++) - { - if(lpAccelTbl[i].key != lpMsg->wParam) - continue; - - if(lpMsg->message == WM_CHAR) - { - if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY)) - { - TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff); - goto found; - } - } - else - { - if(lpAccelTbl[i].fVirt & FVIRTKEY) - { - INT mask = 0; - TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n", - lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff); - if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT; - if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL; - if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT; - if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found; - TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n"); - } - else - { - if(!(lpMsg->lParam & 0x01000000)) /* no special_key */ - { - if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000)) - { /* ^^ ALT pressed */ - TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff); - goto found; - } - } - } - } - } - - WARN_(accel)("couldn't translate accelerator key\n"); - HeapFree(GetProcessHeap(), 0, lpAccelTbl); - return FALSE; - -found: - if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd; - HeapFree(GetProcessHeap(), 0, lpAccelTbl); - return TRUE; -} - -/*********************************************************************** - * ReleaseStgMedium [OLE32.@] - */ -void WINAPI ReleaseStgMedium( - STGMEDIUM* pmedium) -{ - switch (pmedium->tymed) - { - case TYMED_HGLOBAL: - { - if ( (pmedium->pUnkForRelease==0) && - (pmedium->u.hGlobal!=0) ) - GlobalFree(pmedium->u.hGlobal); - break; - } - case TYMED_FILE: - { - if (pmedium->u.lpszFileName!=0) - { - if (pmedium->pUnkForRelease==0) - { - DeleteFileW(pmedium->u.lpszFileName); - } - - CoTaskMemFree(pmedium->u.lpszFileName); - } - break; - } - case TYMED_ISTREAM: - { - if (pmedium->u.pstm!=0) - { - IStream_Release(pmedium->u.pstm); - } - break; - } - case TYMED_ISTORAGE: - { - if (pmedium->u.pstg!=0) - { - IStorage_Release(pmedium->u.pstg); - } - break; - } - case TYMED_GDI: - { - if ( (pmedium->pUnkForRelease==0) && - (pmedium->u.hBitmap!=0) ) - DeleteObject(pmedium->u.hBitmap); - break; - } - case TYMED_MFPICT: - { - if ( (pmedium->pUnkForRelease==0) && - (pmedium->u.hMetaFilePict!=0) ) - { - LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict); - DeleteMetaFile(pMP->hMF); - GlobalUnlock(pmedium->u.hMetaFilePict); - GlobalFree(pmedium->u.hMetaFilePict); - } - break; - } - case TYMED_ENHMF: - { - if ( (pmedium->pUnkForRelease==0) && - (pmedium->u.hEnhMetaFile!=0) ) - { - DeleteEnhMetaFile(pmedium->u.hEnhMetaFile); - } - break; - } - case TYMED_NULL: - default: - break; - } - pmedium->tymed=TYMED_NULL; - - /* - * After cleaning up, the unknown is released - */ - if (pmedium->pUnkForRelease!=0) - { - IUnknown_Release(pmedium->pUnkForRelease); - pmedium->pUnkForRelease = 0; - } -} - -/*** - * OLEDD_Initialize() - * - * Initializes the OLE drag and drop data structures. - */ -static void OLEDD_Initialize() -{ - WNDCLASSA wndClass; - - ZeroMemory (&wndClass, sizeof(WNDCLASSA)); - wndClass.style = CS_GLOBALCLASS; - wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc; - wndClass.cbClsExtra = 0; - wndClass.cbWndExtra = sizeof(TrackerWindowInfo*); - wndClass.hCursor = 0; - wndClass.hbrBackground = 0; - wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS; - - RegisterClassA (&wndClass); -} - -/*** - * OLEDD_UnInitialize() - * - * Releases the OLE drag and drop data structures. - */ -static void OLEDD_UnInitialize() -{ - /* - * Simply empty the list. - */ - while (targetListHead!=NULL) - { - RevokeDragDrop(targetListHead->hwndTarget); - } -} - -/*** - * OLEDD_InsertDropTarget() - * - * Insert the target node in the tree. - */ -static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd) -{ - DropTargetNode* curNode; - DropTargetNode** parentNodeLink; - - /* - * Iterate the tree to find the insertion point. - */ - curNode = targetListHead; - parentNodeLink = &targetListHead; - - while (curNode!=NULL) - { - if (nodeToAdd->hwndTargethwndTarget) - { - /* - * If the node we want to add has a smaller HWND, go left - */ - parentNodeLink = &curNode->prevDropTarget; - curNode = curNode->prevDropTarget; - } - else if (nodeToAdd->hwndTarget>curNode->hwndTarget) - { - /* - * If the node we want to add has a larger HWND, go right - */ - parentNodeLink = &curNode->nextDropTarget; - curNode = curNode->nextDropTarget; - } - else - { - /* - * The item was found in the list. It shouldn't have been there - */ - assert(FALSE); - return; - } - } - - /* - * If we get here, we have found a spot for our item. The parentNodeLink - * pointer points to the pointer that we have to modify. - * The curNode should be NULL. We just have to establish the link and Voila! - */ - assert(curNode==NULL); - assert(parentNodeLink!=NULL); - assert(*parentNodeLink==NULL); - - *parentNodeLink=nodeToAdd; -} - -/*** - * OLEDD_ExtractDropTarget() - * - * Removes the target node from the tree. - */ -static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget) -{ - DropTargetNode* curNode; - DropTargetNode** parentNodeLink; - - /* - * Iterate the tree to find the insertion point. - */ - curNode = targetListHead; - parentNodeLink = &targetListHead; - - while (curNode!=NULL) - { - if (hwndOfTargethwndTarget) - { - /* - * If the node we want to add has a smaller HWND, go left - */ - parentNodeLink = &curNode->prevDropTarget; - curNode = curNode->prevDropTarget; - } - else if (hwndOfTarget>curNode->hwndTarget) - { - /* - * If the node we want to add has a larger HWND, go right - */ - parentNodeLink = &curNode->nextDropTarget; - curNode = curNode->nextDropTarget; - } - else - { - /* - * The item was found in the list. Detach it from it's parent and - * re-insert it's kids in the tree. - */ - assert(parentNodeLink!=NULL); - assert(*parentNodeLink==curNode); - - /* - * We arbitrately re-attach the left sub-tree to the parent. - */ - *parentNodeLink = curNode->prevDropTarget; - - /* - * And we re-insert the right subtree - */ - if (curNode->nextDropTarget!=NULL) - { - OLEDD_InsertDropTarget(curNode->nextDropTarget); - } - - /* - * The node we found is still a valid node once we complete - * the unlinking of the kids. - */ - curNode->nextDropTarget=NULL; - curNode->prevDropTarget=NULL; - - return curNode; - } - } - - /* - * If we get here, the node is not in the tree - */ - return NULL; -} - -/*** - * OLEDD_FindDropTarget() - * - * Finds information about the drop target. - */ -static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget) -{ - DropTargetNode* curNode; - - /* - * Iterate the tree to find the HWND value. - */ - curNode = targetListHead; - - while (curNode!=NULL) - { - if (hwndOfTargethwndTarget) - { - /* - * If the node we want to add has a smaller HWND, go left - */ - curNode = curNode->prevDropTarget; - } - else if (hwndOfTarget>curNode->hwndTarget) - { - /* - * If the node we want to add has a larger HWND, go right - */ - curNode = curNode->nextDropTarget; - } - else - { - /* - * The item was found in the list. - */ - return curNode; - } - } - - /* - * If we get here, the item is not in the list - */ - return NULL; -} - -/*** - * OLEDD_DragTrackerWindowProc() - * - * This method is the WindowProcedure of the drag n drop tracking - * window. During a drag n Drop operation, an invisible window is created - * to receive the user input and act upon it. This procedure is in charge - * of this behavior. - */ -static LRESULT WINAPI OLEDD_DragTrackerWindowProc( - HWND hwnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) -{ - switch (uMsg) - { - case WM_CREATE: - { - LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam; - - SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams); - - - break; - } - case WM_MOUSEMOVE: - { - TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0); - POINT mousePos; - - /* - * Get the current mouse position in screen coordinates. - */ - mousePos.x = LOWORD(lParam); - mousePos.y = HIWORD(lParam); - ClientToScreen(hwnd, &mousePos); - - /* - * Track the movement of the mouse. - */ - OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam); - - break; - } - case WM_LBUTTONUP: - case WM_MBUTTONUP: - case WM_RBUTTONUP: - case WM_LBUTTONDOWN: - case WM_MBUTTONDOWN: - case WM_RBUTTONDOWN: - { - TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0); - POINT mousePos; - - /* - * Get the current mouse position in screen coordinates. - */ - mousePos.x = LOWORD(lParam); - mousePos.y = HIWORD(lParam); - ClientToScreen(hwnd, &mousePos); - - /* - * Notify everyone that the button state changed - * TODO: Check if the "escape" key was pressed. - */ - OLEDD_TrackStateChange(trackerInfo, mousePos, wParam); - - break; - } - } - - /* - * This is a window proc after all. Let's call the default. - */ - return DefWindowProcA (hwnd, uMsg, wParam, lParam); -} - -/*** - * OLEDD_TrackMouseMove() - * - * This method is invoked while a drag and drop operation is in effect. - * it will generate the appropriate callbacks in the drop source - * and drop target. It will also provide the expected feedback to - * the user. - * - * params: - * trackerInfo - Pointer to the structure identifying the - * drag & drop operation that is currently - * active. - * mousePos - Current position of the mouse in screen - * coordinates. - * keyState - Contains the state of the shift keys and the - * mouse buttons (MK_LBUTTON and the like) - */ -static void OLEDD_TrackMouseMove( - TrackerWindowInfo* trackerInfo, - POINT mousePos, - DWORD keyState) -{ - HWND hwndNewTarget = 0; - HRESULT hr = S_OK; - - /* - * Get the handle of the window under the mouse - */ - hwndNewTarget = WindowFromPoint(mousePos); - - /* - * Every time, we re-initialize the effects passed to the - * IDropTarget to the effects allowed by the source. - */ - *trackerInfo->pdwEffect = trackerInfo->dwOKEffect; - - /* - * If we are hovering over the same target as before, send the - * DragOver notification - */ - if ( (trackerInfo->curDragTarget != 0) && - (trackerInfo->curTargetHWND == hwndNewTarget) ) - { - POINTL mousePosParam; - - /* - * The documentation tells me that the coordinate should be in the target - * window's coordinate space. However, the tests I made tell me the - * coordinates should be in screen coordinates. - */ - mousePosParam.x = mousePos.x; - mousePosParam.y = mousePos.y; - - IDropTarget_DragOver(trackerInfo->curDragTarget, - keyState, - mousePosParam, - trackerInfo->pdwEffect); - } - else - { - DropTargetNode* newDropTargetNode = 0; - - /* - * If we changed window, we have to notify our old target and check for - * the new one. - */ - if (trackerInfo->curDragTarget!=0) - { - IDropTarget_DragLeave(trackerInfo->curDragTarget); - } - - /* - * Make sure we're hovering over a window. - */ - if (hwndNewTarget!=0) - { - /* - * Find-out if there is a drag target under the mouse - */ - HWND nexttar = hwndNewTarget; - trackerInfo->curTargetHWND = hwndNewTarget; - - do { - newDropTargetNode = OLEDD_FindDropTarget(nexttar); - } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0); - if(nexttar) hwndNewTarget = nexttar; - - trackerInfo->curDragTargetHWND = hwndNewTarget; - trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0; - - /* - * If there is, notify it that we just dragged-in - */ - if (trackerInfo->curDragTarget!=0) - { - POINTL mousePosParam; - - /* - * The documentation tells me that the coordinate should be in the target - * window's coordinate space. However, the tests I made tell me the - * coordinates should be in screen coordinates. - */ - mousePosParam.x = mousePos.x; - mousePosParam.y = mousePos.y; - - IDropTarget_DragEnter(trackerInfo->curDragTarget, - trackerInfo->dataObject, - keyState, - mousePosParam, - trackerInfo->pdwEffect); - } - } - else - { - /* - * The mouse is not over a window so we don't track anything. - */ - trackerInfo->curDragTargetHWND = 0; - trackerInfo->curTargetHWND = 0; - trackerInfo->curDragTarget = 0; - } - } - - /* - * Now that we have done that, we have to tell the source to give - * us feedback on the work being done by the target. If we don't - * have a target, simulate no effect. - */ - if (trackerInfo->curDragTarget==0) - { - *trackerInfo->pdwEffect = DROPEFFECT_NONE; - } - - hr = IDropSource_GiveFeedback(trackerInfo->dropSource, - *trackerInfo->pdwEffect); - - /* - * When we ask for feedback from the drop source, sometimes it will - * do all the necessary work and sometimes it will not handle it - * when that's the case, we must display the standard drag and drop - * cursors. - */ - if (hr==DRAGDROP_S_USEDEFAULTCURSORS) - { - if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE) - { - SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1))); - } - else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY) - { - SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2))); - } - else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK) - { - SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3))); - } - else - { - SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0))); - } - } -} - -/*** - * OLEDD_TrackStateChange() - * - * This method is invoked while a drag and drop operation is in effect. - * It is used to notify the drop target/drop source callbacks when - * the state of the keyboard or mouse button change. - * - * params: - * trackerInfo - Pointer to the structure identifying the - * drag & drop operation that is currently - * active. - * mousePos - Current position of the mouse in screen - * coordinates. - * keyState - Contains the state of the shift keys and the - * mouse buttons (MK_LBUTTON and the like) - */ -static void OLEDD_TrackStateChange( - TrackerWindowInfo* trackerInfo, - POINT mousePos, - DWORD keyState) -{ - /* - * Ask the drop source what to do with the operation. - */ - trackerInfo->returnValue = IDropSource_QueryContinueDrag( - trackerInfo->dropSource, - trackerInfo->escPressed, - keyState); - - /* - * All the return valued will stop the operation except the S_OK - * return value. - */ - if (trackerInfo->returnValue!=S_OK) - { - /* - * Make sure the message loop in DoDragDrop stops - */ - trackerInfo->trackingDone = TRUE; - - /* - * Release the mouse in case the drop target decides to show a popup - * or a menu or something. - */ - ReleaseCapture(); - - /* - * If we end-up over a target, drop the object in the target or - * inform the target that the operation was cancelled. - */ - if (trackerInfo->curDragTarget!=0) - { - switch (trackerInfo->returnValue) - { - /* - * If the source wants us to complete the operation, we tell - * the drop target that we just dropped the object in it. - */ - case DRAGDROP_S_DROP: - { - POINTL mousePosParam; - - /* - * The documentation tells me that the coordinate should be - * in the target window's coordinate space. However, the tests - * I made tell me the coordinates should be in screen coordinates. - */ - mousePosParam.x = mousePos.x; - mousePosParam.y = mousePos.y; - - IDropTarget_Drop(trackerInfo->curDragTarget, - trackerInfo->dataObject, - keyState, - mousePosParam, - trackerInfo->pdwEffect); - break; - } - /* - * If the source told us that we should cancel, fool the drop - * target by telling it that the mouse left it's window. - * Also set the drop effect to "NONE" in case the application - * ignores the result of DoDragDrop. - */ - case DRAGDROP_S_CANCEL: - IDropTarget_DragLeave(trackerInfo->curDragTarget); - *trackerInfo->pdwEffect = DROPEFFECT_NONE; - break; - } - } - } -} - -/*** - * OLEDD_GetButtonState() - * - * This method will use the current state of the keyboard to build - * a button state mask equivalent to the one passed in the - * WM_MOUSEMOVE wParam. - */ -static DWORD OLEDD_GetButtonState() -{ - BYTE keyboardState[256]; - DWORD keyMask = 0; - - GetKeyboardState(keyboardState); - - if ( (keyboardState[VK_SHIFT] & 0x80) !=0) - keyMask |= MK_SHIFT; - - if ( (keyboardState[VK_CONTROL] & 0x80) !=0) - keyMask |= MK_CONTROL; - - if ( (keyboardState[VK_LBUTTON] & 0x80) !=0) - keyMask |= MK_LBUTTON; - - if ( (keyboardState[VK_RBUTTON] & 0x80) !=0) - keyMask |= MK_RBUTTON; - - if ( (keyboardState[VK_MBUTTON] & 0x80) !=0) - keyMask |= MK_MBUTTON; - - return keyMask; -} - -/*** - * OLEDD_GetButtonState() - * - * This method will read the default value of the registry key in - * parameter and extract a DWORD value from it. The registry key value - * can be in a string key or a DWORD key. - * - * params: - * regKey - Key to read the default value from - * pdwValue - Pointer to the location where the DWORD - * value is returned. This value is not modified - * if the value is not found. - */ - -static void OLEUTL_ReadRegistryDWORDValue( - HKEY regKey, - DWORD* pdwValue) -{ - char buffer[20]; - DWORD dwKeyType; - DWORD cbData = 20; - LONG lres; - - lres = RegQueryValueExA(regKey, - "", - NULL, - &dwKeyType, - (LPBYTE)buffer, - &cbData); - - if (lres==ERROR_SUCCESS) - { - switch (dwKeyType) - { - case REG_DWORD: - *pdwValue = *(DWORD*)buffer; - break; - case REG_EXPAND_SZ: - case REG_MULTI_SZ: - case REG_SZ: - *pdwValue = (DWORD)strtoul(buffer, NULL, 10); - break; - } - } -} - -/****************************************************************************** - * OleDraw (OLE32.@) - * - * The operation of this function is documented literally in the WinAPI - * documentation to involve a QueryInterface for the IViewObject interface, - * followed by a call to IViewObject::Draw. - */ -HRESULT WINAPI OleDraw( - IUnknown *pUnk, - DWORD dwAspect, - HDC hdcDraw, - LPCRECT lprcBounds) -{ - HRESULT hres; - IViewObject *viewobject; - - hres = IUnknown_QueryInterface(pUnk, - &IID_IViewObject, - (void**)&viewobject); - - if (SUCCEEDED(hres)) - { - RECTL rectl; - - rectl.left = lprcBounds->left; - rectl.right = lprcBounds->right; - rectl.top = lprcBounds->top; - rectl.bottom = lprcBounds->bottom; - hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0); - - IViewObject_Release(viewobject); - return hres; - } - else - { - return DV_E_NOIVIEWOBJECT; - } -} - -/*********************************************************************** - * OleTranslateAccelerator [OLE32.@] - */ -HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame, - LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg) -{ - WORD wID; - - TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg); - - if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID)) - return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID); - - return S_FALSE; -} - -/****************************************************************************** - * OleCreate [OLE32.@] - * - */ -HRESULT WINAPI OleCreate( - REFCLSID rclsid, - REFIID riid, - DWORD renderopt, - LPFORMATETC pFormatEtc, - LPOLECLIENTSITE pClientSite, - LPSTORAGE pStg, - LPVOID* ppvObj) -{ - HRESULT hres, hres1; - IUnknown * pUnk = NULL; - - FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid)); - - if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk)))) - { - if (pClientSite) - { - IOleObject * pOE; - IPersistStorage * pPS; - if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE)))) - { - TRACE("trying to set clientsite %p\n", pClientSite); - hres1 = IOleObject_SetClientSite(pOE, pClientSite); - TRACE("-- result 0x%08lx\n", hres1); - IOleObject_Release(pOE); - } - if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS)))) - { - TRACE("trying to set stg %p\n", pStg); - hres1 = IPersistStorage_InitNew(pPS, pStg); - TRACE("-- result 0x%08lx\n", hres1); - IPersistStorage_Release(pPS); - } - } - } - - *ppvObj = pUnk; - - TRACE("-- %p \n", pUnk); - return hres; -} - -/*********************************************************************** - * OLE_FreeClipDataArray [internal] - * - * NOTES: - * frees the data associated with an array of CLIPDATAs - */ -static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray) -{ - ULONG i; - for (i = 0; i < count; i++) - if (pClipDataArray[i].pClipData) - CoTaskMemFree(pClipDataArray[i].pClipData); -} - -/****************************************************************************** - * Check if a PROPVARIANT's type is valid. - */ -static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt) -{ - switch (vt) - { - case VT_EMPTY: - case VT_NULL: - case VT_I2: - case VT_I4: - case VT_R4: - case VT_R8: - case VT_CY: - case VT_DATE: - case VT_BSTR: - case VT_ERROR: - case VT_BOOL: - case VT_UI1: - case VT_UI2: - case VT_UI4: - case VT_I8: - case VT_UI8: - case VT_LPSTR: - case VT_LPWSTR: - case VT_FILETIME: - case VT_BLOB: - case VT_STREAM: - case VT_STORAGE: - case VT_STREAMED_OBJECT: - case VT_STORED_OBJECT: - case VT_BLOB_OBJECT: - case VT_CF: - case VT_CLSID: - case VT_I2|VT_VECTOR: - case VT_I4|VT_VECTOR: - case VT_R4|VT_VECTOR: - case VT_R8|VT_VECTOR: - case VT_CY|VT_VECTOR: - case VT_DATE|VT_VECTOR: - case VT_BSTR|VT_VECTOR: - case VT_ERROR|VT_VECTOR: - case VT_BOOL|VT_VECTOR: - case VT_VARIANT|VT_VECTOR: - case VT_UI1|VT_VECTOR: - case VT_UI2|VT_VECTOR: - case VT_UI4|VT_VECTOR: - case VT_I8|VT_VECTOR: - case VT_UI8|VT_VECTOR: - case VT_LPSTR|VT_VECTOR: - case VT_LPWSTR|VT_VECTOR: - case VT_FILETIME|VT_VECTOR: - case VT_CF|VT_VECTOR: - case VT_CLSID|VT_VECTOR: - return S_OK; - } - WARN("Bad type %d\n", vt); - return STG_E_INVALIDPARAMETER; -} - -/*********************************************************************** - * PropVariantClear [OLE32.@] - */ -HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */ -{ - HRESULT hr; - - TRACE("(%p)\n", pvar); - - if (!pvar) - return S_OK; - - hr = PROPVARIANT_ValidateType(pvar->vt); - if (FAILED(hr)) - return hr; - - switch(pvar->vt) - { - case VT_STREAM: - case VT_STREAMED_OBJECT: - case VT_STORAGE: - case VT_STORED_OBJECT: - if (pvar->u.pStream) - IUnknown_Release(pvar->u.pStream); - break; - case VT_CLSID: - case VT_LPSTR: - case VT_LPWSTR: - /* pick an arbitary typed pointer - we don't care about the type - * as we are just freeing it */ - CoTaskMemFree(pvar->u.puuid); - break; - case VT_BLOB: - case VT_BLOB_OBJECT: - CoTaskMemFree(pvar->u.blob.pBlobData); - break; - case VT_BSTR: - if (pvar->u.bstrVal) - { - FIXME("Need to load OLEAUT32 for SysFreeString\n"); - /* SysFreeString(pvar->u.bstrVal); */ - } - break; - case VT_CF: - if (pvar->u.pclipdata) - { - OLE_FreeClipDataArray(1, pvar->u.pclipdata); - CoTaskMemFree(pvar->u.pclipdata); - } - break; - default: - switch (pvar->vt & ~VT_VECTOR) - { - case VT_VARIANT: - FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems); - break; - case VT_CF: - OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems); - break; - case VT_BSTR: - case VT_LPSTR: - case VT_LPWSTR: - case VT_CLSID: - FIXME("Freeing of vector sub-type not supported yet\n"); - } - if (pvar->vt & ~VT_VECTOR) - { - /* pick an arbitary VT_VECTOR structure - they all have the same - * memory layout */ - CoTaskMemFree(pvar->u.capropvar.pElems); - } - } - - ZeroMemory(pvar, sizeof(*pvar)); - - return S_OK; -} - -/*********************************************************************** - * PropVariantCopy [OLE32.@] - */ -HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */ - const PROPVARIANT *pvarSrc) /* [in] */ -{ - ULONG len; - HRESULT hr; - - TRACE("(%p, %p)\n", pvarDest, pvarSrc); - - hr = PROPVARIANT_ValidateType(pvarSrc->vt); - if (FAILED(hr)) - return hr; - - /* this will deal with most cases */ - CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest)); - - switch(pvarSrc->vt) - { - case VT_STREAM: - case VT_STREAMED_OBJECT: - case VT_STORAGE: - case VT_STORED_OBJECT: - IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream); - break; - case VT_CLSID: - pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID)); - CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID)); - break; - case VT_LPSTR: - len = strlen(pvarSrc->u.pszVal); - pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR)); - CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR)); - break; - case VT_LPWSTR: - len = lstrlenW(pvarSrc->u.pwszVal); - pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR)); - CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR)); - break; - case VT_BLOB: - case VT_BLOB_OBJECT: - if (pvarSrc->u.blob.pBlobData) - { - len = pvarSrc->u.blob.cbSize; - pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len); - CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len); - } - break; - case VT_BSTR: - FIXME("Need to copy BSTR\n"); - break; - case VT_CF: - if (pvarSrc->u.pclipdata) - { - len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt); - CoTaskMemAlloc(len); - CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len); - } - break; - default: - if (pvarSrc->vt & VT_VECTOR) - { - int elemSize; - switch(pvarSrc->vt & VT_VECTOR) - { - case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break; - case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break; - case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break; - case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break; - case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break; - case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break; - case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break; - case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break; - case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break; - case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break; - case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break; - case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break; - case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break; - case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break; - case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break; - case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break; - case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break; - - case VT_BSTR: - case VT_LPSTR: - case VT_LPWSTR: - case VT_VARIANT: - default: - FIXME("Invalid element type: %ul\n", pvarSrc->vt & VT_VECTOR); - return E_INVALIDARG; - } - len = pvarSrc->u.capropvar.cElems; - pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize); - if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT)) - { - ULONG i; - for (i = 0; i < len; i++) - PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_CF)) - { - FIXME("Copy clipformats\n"); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR)) - { - FIXME("Copy BSTRs\n"); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR)) - { - FIXME("Copy LPSTRs\n"); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR)) - { - FIXME("Copy LPWSTRs\n"); - } - else - CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize); - } - } - - return S_OK; -} - -/*********************************************************************** - * FreePropVariantArray [OLE32.@] - */ -HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */ - PROPVARIANT *rgvars) /* [in/out] */ -{ - ULONG i; - - TRACE("(%lu, %p)\n", cVariants, rgvars); - - for(i = 0; i < cVariants; i++) - PropVariantClear(&rgvars[i]); - - return S_OK; -} - -/****************************************************************************** - * DllDebugObjectRPCHook (OLE32.@) - * turns on and off internal debugging, pointer is only used on macintosh - */ - -BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy) -{ - FIXME("stub\n"); - return TRUE; -} diff --git a/reactos/lib/ole32/ole2.spec b/reactos/lib/ole32/ole2.spec deleted file mode 100644 index e4c7ae48e27..00000000000 --- a/reactos/lib/ole32/ole2.spec +++ /dev/null @@ -1,158 +0,0 @@ -1 pascal OleBuildVersion() OleBuildVersion -2 pascal OleInitialize(ptr) OleInitialize -3 pascal OleUninitialize() OleUninitialize -4 pascal DllGetClassObject(ptr ptr ptr) DllGetClassObject16 -#5 WEP -6 stub OLEQUERYLINKFROMDATA -7 stub OLEQUERYCREATEFROMDATA -8 stub OLECREATEFROMDATA -9 stub OLECREATELINKFROMDATA -10 stub OLECREATE -11 stub OLECREATELINK -12 stub OLELOAD -13 stub OLESAVE -14 stub OLERUN -#15 ___EXPORTEDSTUB -16 stub OLEISRUNNING -17 stub OLELOCKRUNNING -18 stub READCLASSSTG -19 stub WRITECLASSSTG -20 stub READCLASSSTM -21 stub WRITECLASSSTM -22 stub BINDMONIKER -23 stub MKPARSEDISPLAYNAME -24 stub OLESAVETOSTREAM -25 stub OLELOADFROMSTREAM -26 stub CREATEBINDCTX -27 pascal CreateItemMoniker(str str ptr) CreateItemMoniker16 -28 pascal CreateFileMoniker(str ptr) CreateFileMoniker16 -29 stub CREATEGENERICCOMPOSITE -30 pascal GetRunningObjectTable(long ptr) GetRunningObjectTable16 -31 stub OLEGETMALLOC -32 stub RELEASESTGMEDIUM -33 stub READSTRINGSTREAM -34 stub WRITESTRINGSTREAM -35 pascal RegisterDragDrop(word segptr) RegisterDragDrop16 -36 pascal RevokeDragDrop(word) RevokeDragDrop16 -37 stub DODRAGDROP -38 stub CREATEOLEADVISEHOLDER -39 stub CREATEDATAADVISEHOLDER -40 stub OLECREATEMENUDESCRIPTOR -41 stub OLESETMENUDESCRIPTOR -42 stub OLEDESTROYMENUDESCRIPTOR -43 stub OPENORCREATESTREAM -44 stub CREATEANTIMONIKER -45 stub CREATEPOINTERMONIKER -46 stub MONIKERRELATIVEPATHTO -47 stub MONIKERCOMMONPREFIXWITH -48 stub ISACCELERATOR -49 pascal OleSetClipboard(ptr) OleSetClipboard16 -50 pascal OleGetClipboard(ptr) OleGetClipboard16 -51 stub OLEDUPLICATEDATA -52 stub OLEGETICONOFFILE -53 stub OLEGETICONOFCLASS -54 pascal CreateILockBytesOnHGlobal(word word ptr) CreateILockBytesOnHGlobal16 -55 stub GETHGLOBALFROMILOCKBYTES -56 pascal -ret16 OleMetaFilePictFromIconAndLabel(word str str word) OleMetaFilePictFromIconAndLabel16 -57 stub GETCLASSFILE -58 stub OLEDRAW -59 stub OLECREATEDEFAULTHANDLER -60 stub OLECREATEEMBEDDINGHELPER -61 stub OLECONVERTISTORAGETOOLESTREAMEX -62 stub OLECONVERTOLESTREAMTOISTORAGEEX -63 stub SETDOCUMENTBITSTG -64 stub GETDOCUMENTBITSTG -65 stub WRITEOLESTG -66 stub READOLESTG -67 stub OLECREATEFROMFILE -68 stub OLECREATELINKTOFILE -69 stub CREATEDATACACHE -70 stub OLECONVERTISTORAGETOOLESTREAM -71 stub OLECONVERTOLESTREAMTOISTORAGE -74 stub READFMTUSERTYPESTG -75 stub WRITEFMTUSERTYPESTG -76 pascal -ret16 OleFlushClipboard() OleFlushClipboard16 -77 stub OLEISCURRENTCLIPBOARD -78 stub OLETRANSLATEACCELERATOR -79 stub OLEDOAUTOCONVERT -80 stub OLEGETAUTOCONVERT -81 stub OLESETAUTOCONVERT -82 stub GETCONVERTSTG -83 stub SETCONVERTSTG -84 stub CREATESTREAMONHGLOBAL -85 stub GETHGLOBALFROMSTREAM -86 stub OLESETCONTAINEDOBJECT -87 stub OLENOTEOBJECTVISIBLE -88 stub OLECREATESTATICFROMDATA -89 stub OLEREGGETUSERTYPE -90 stub OLEREGGETMISCSTATUS -91 stub OLEREGENUMFORMATETC -92 stub OLEREGENUMVERBS -93 stub OLEGETENUMFORMATETC -100 stub MAKEDEBUGSTREAM -104 stub DBGLOGOPEN -105 stub DBGLOGCLOSE -106 stub DBGLOGOUTPUTDEBUGSTRING -107 stub DBGLOGWRITE -108 stub DBGLOGTIMESTAMP -109 stub DBGLOGWRITEBANNER -110 stub DBGDUMPOBJECT -111 stub DBGISOBJECTVALID -112 stub DUMPALLOBJECTS -113 stub VALIDATEALLOBJECTS -114 stub DBGDUMPCLASSNAME -115 stub DBGDUMPEXTERNALOBJECT -120 stub _IID_IENUMUNKNOWN -121 stub _IID_IENUMSTRING -122 stub _IID_IENUMMONIKER -123 stub _IID_IENUMFORMATETC -124 stub _IID_IENUMOLEVERB -125 stub _IID_IENUMSTATDATA -126 stub _IID_IENUMGENERIC -127 stub _IID_IENUMHOLDER -128 stub _IID_IENUMCALLBACK -129 stub _IID_IPERSISTSTREAM -130 stub _IID_IPERSISTSTORAGE -131 stub _IID_IPERSISTFILE -132 stub _IID_IPERSIST -133 stub _IID_IVIEWOBJECT -134 stub _IID_IDATAOBJECT -135 stub _IID_IADVISESINK -136 stub _IID_IDATAADVISEHOLDER -137 stub _IID_IOLEADVISEHOLDER -138 stub _IID_IOLEOBJECT -139 stub _IID_IOLEINPLACEOBJECT -140 stub _IID_IOLEWINDOW -141 stub _IID_IOLEINPLACEUIWINDOW -142 stub _IID_IOLEINPLACEFRAME -143 stub _IID_IOLEINPLACEACTIVEOBJECT -144 stub _IID_IOLECLIENTSITE -145 stub _IID_IOLEINPLACESITE -146 stub _IID_IPARSEDISPLAYNAME -147 stub _IID_IOLECONTAINER -148 stub _IID_IOLEITEMCONTAINER -149 stub _IID_IOLELINK -150 stub _IID_IOLECACHE -151 stub _IID_IOLEMANAGER -152 stub _IID_IOLEPRESOBJ -153 stub _IID_IDROPSOURCE -154 stub _IID_IDROPTARGET -155 stub _IID_IDEBUG -156 stub _IID_IDEBUGSTREAM -157 stub _IID_IADVISESINK2 -158 stub _IID_IVIEWOBJECT2 -159 stub _IID_IOLECACHE2 -160 stub _IID_IOLECACHECONTROL -161 stub _IID_IRUNNABLEOBJECT - -# WINE MemLockBytes implementation. -500 cdecl HGLOBALLockBytesImpl16_QueryInterface(segptr ptr ptr) HGLOBALLockBytesImpl16_QueryInterface -501 cdecl HGLOBALLockBytesImpl16_AddRef(ptr) HGLOBALLockBytesImpl16_AddRef -502 cdecl HGLOBALLockBytesImpl16_Release(ptr) HGLOBALLockBytesImpl16_Release -503 cdecl HGLOBALLockBytesImpl16_ReadAt(ptr long long ptr long ptr) HGLOBALLockBytesImpl16_ReadAt -504 cdecl HGLOBALLockBytesImpl16_WriteAt(ptr long long ptr long ptr) HGLOBALLockBytesImpl16_WriteAt -505 cdecl HGLOBALLockBytesImpl16_Flush(ptr) HGLOBALLockBytesImpl16_Flush -506 cdecl HGLOBALLockBytesImpl16_SetSize(ptr long long) HGLOBALLockBytesImpl16_SetSize -507 cdecl HGLOBALLockBytesImpl16_LockRegion(ptr long long long long long) HGLOBALLockBytesImpl16_LockRegion -508 cdecl HGLOBALLockBytesImpl16_UnlockRegion(ptr long long long long long) HGLOBALLockBytesImpl16_UnlockRegion -509 cdecl HGLOBALLockBytesImpl16_Stat(ptr ptr long) HGLOBALLockBytesImpl16_Stat diff --git a/reactos/lib/ole32/ole2_16.c b/reactos/lib/ole32/ole2_16.c deleted file mode 100644 index 67514ead801..00000000000 --- a/reactos/lib/ole32/ole2_16.c +++ /dev/null @@ -1,144 +0,0 @@ - -/* - * OLE2 library - 16 bit only interfaces - * - * Copyright 1995 Martin von Loewis - * Copyright 1999 Francis Beaudet - * Copyright 1999 Noel Borthwick - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define NONAMELESSUNION -#define NONAMELESSSTRUCT -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winnls.h" -#include "commctrl.h" -#include "ole2.h" -#include "ole2ver.h" -#include "winerror.h" -#include "wownt32.h" - -#include "wine/winbase16.h" -#include "wine/wingdi16.h" -#include "wine/winuser16.h" -#include "ole32_main.h" -#include "ifs.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); -WINE_DECLARE_DEBUG_CHANNEL(accel); - -#define HICON_16(h32) (LOWORD(h32)) -#define HICON_32(h16) ((HICON)(ULONG_PTR)(h16)) -#define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16)) - -/*********************************************************************** - * RegisterDragDrop (OLE2.35) - */ -HRESULT WINAPI RegisterDragDrop16( - HWND16 hwnd, - LPDROPTARGET pDropTarget -) { - FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget); - return S_OK; -} - -/*********************************************************************** - * RevokeDragDrop (OLE2.36) - */ -HRESULT WINAPI RevokeDragDrop16( - HWND16 hwnd -) { - FIXME("(0x%04x),stub!\n",hwnd); - return S_OK; -} - -/****************************************************************************** - * OleMetaFilePictFromIconAndLabel (OLE2.56) - * - * Returns a global memory handle to a metafile which contains the icon and - * label given. - * I guess the result of that should look somehow like desktop icons. - * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex. - * This code might be wrong at some places. - */ -HGLOBAL16 WINAPI OleMetaFilePictFromIconAndLabel16( - HICON16 hIcon, - LPCOLESTR16 lpszLabel, - LPCOLESTR16 lpszSourceFile, - UINT16 iIconIndex -) { - METAFILEPICT16 *mf; - HGLOBAL16 hmf; - HDC hdc; - - FIXME("(%04x, '%s', '%s', %d): incorrect metrics, please try to correct them !\n\n\n", hIcon, lpszLabel, lpszSourceFile, iIconIndex); - - if (!hIcon) { - if (lpszSourceFile) { - HINSTANCE16 hInstance = LoadLibrary16(lpszSourceFile); - - /* load the icon at index from lpszSourceFile */ - hIcon = HICON_16(LoadIconA(HINSTANCE_32(hInstance), (LPCSTR)(DWORD)iIconIndex)); - FreeLibrary16(hInstance); - } else - return 0; - } - - hdc = CreateMetaFileA(NULL); - DrawIcon(hdc, 0, 0, HICON_32(hIcon)); /* FIXME */ - TextOutA(hdc, 0, 0, lpszLabel, 1); /* FIXME */ - hmf = GlobalAlloc16(0, sizeof(METAFILEPICT16)); - mf = (METAFILEPICT16 *)GlobalLock16(hmf); - mf->mm = MM_ANISOTROPIC; - mf->xExt = 20; /* FIXME: bogus */ - mf->yExt = 20; /* dito */ - mf->hMF = CloseMetaFile16(HDC_16(hdc)); - return hmf; -} - - -/****************************************************************************** - * CreateItemMoniker (OLE2.27) - */ -HRESULT WINAPI CreateItemMoniker16(LPCOLESTR16 lpszDelim,LPCOLESTR16 lpszItem,LPMONIKER* ppmk) -{ - FIXME("(%s,%p),stub!\n",lpszDelim,ppmk); - *ppmk = NULL; - return E_NOTIMPL; -} - - -/****************************************************************************** - * CreateFileMoniker (OLE2.28) - */ -HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk) -{ - FIXME("(%s,%p),stub!\n",lpszPathName,ppmk); - return E_NOTIMPL; -} diff --git a/reactos/lib/ole32/ole2conv.spec b/reactos/lib/ole32/ole2conv.spec deleted file mode 100644 index 0a457e5b702..00000000000 --- a/reactos/lib/ole32/ole2conv.spec +++ /dev/null @@ -1,9 +0,0 @@ -1 stub GETFILTERINFO -2 stub IMPORTGR -3 stub GETFILTERPREF -4 stub IMPORTEMBEDDEDGR -5 stub QD2GDI -6 stub STATUSPROC -7 stub ENUMFONTFUNC -#8 WEP -#9 ___EXPORTEDSTUB diff --git a/reactos/lib/ole32/ole2impl.c b/reactos/lib/ole32/ole2impl.c deleted file mode 100644 index 160e0e1396c..00000000000 --- a/reactos/lib/ole32/ole2impl.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Ole 2 Create functions implementation - * - * Copyright (C) 1999-2000 Abey George - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "wine/debug.h" -#include "ole2.h" -#include "olestd.h" -#include "winreg.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -#define MAX_CLIPFORMAT_NAME 80 - -/****************************************************************************** - * OleQueryCreateFromData [OLE32.@] - * - * Author : Abey George - * Checks whether an object can become an embedded object. - * the clipboard or OLE drag and drop. - * Returns : S_OK - Format that supports Embedded object creation are present. - * OLE_E_STATIC - Format that supports static object creation are present. - * S_FALSE - No acceptable format is available. - */ - -HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject) -{ - IEnumFORMATETC *pfmt; - FORMATETC fmt; - CHAR szFmtName[MAX_CLIPFORMAT_NAME]; - BOOL bFoundStatic = FALSE; - - HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt); - - if (hr == S_OK) - hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL); - - while (hr == S_OK) - { - GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1); - - /* first, Check for Embedded Object, Embed Source or Filename */ - - if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME)) - return S_OK; - - /* Check for Metafile, Bitmap or DIB */ - - if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB) - bFoundStatic = TRUE; - - hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL); - } - - /* Found a static format, but no embed format */ - - if (bFoundStatic) - return OLE_S_STATIC; - - return S_FALSE; -} - -/****************************************************************************** - * OleCreateFromData [OLE32.@] - * - * Author : Abey George - * Creates an embedded object from data transfer object retrieved from - * the clipboard or OLE drag and drop. - * Returns : S_OK - Embedded object was created successfully. - * OLE_E_STATIC - OLE can create only a static object - * DV_E_FORMATETC - No acceptable format is available (only error return code) - * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored. - */ - -HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid, - DWORD renderopt, LPFORMATETC pFormatEtc, - LPOLECLIENTSITE pClientSite, LPSTORAGE pStg, - LPVOID* ppvObj) -{ - IEnumFORMATETC *pfmt; - FORMATETC fmt; - CHAR szFmtName[MAX_CLIPFORMAT_NAME]; - STGMEDIUM std; - HRESULT hr; - HRESULT hr1; - - hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt); - - if (hr == S_OK) - { - memset(&std, 0, sizeof(STGMEDIUM)); - - hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL); - while (hr == S_OK) - { - GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1); - - /* first, Check for Embedded Object, Embed Source or Filename */ - /* TODO: Currently checks only for Embed Source. */ - - if (!strcmp(szFmtName, CF_EMBEDSOURCE)) - { - std.tymed = TYMED_HGLOBAL; - - if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK) - { - ILockBytes *ptrILockBytes = 0; - IStorage *pStorage = 0; - IOleObject *pOleObject = 0; - IPersistStorage *pPersistStorage = 0; - CLSID clsID; - - /* Create ILock bytes */ - - hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes); - - /* Open storage on the ILock bytes */ - - if (hr1 == S_OK) - hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage); - - /* Get Class ID from the opened storage */ - - if (hr1 == S_OK) - hr1 = ReadClassStg(pStorage, &clsID); - - /* Create default handler for Persist storage */ - - if (hr1 == S_OK) - hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage); - - /* Load the storage to Persist storage */ - - if (hr1 == S_OK) - hr1 = IPersistStorage_Load(pPersistStorage, pStorage); - - /* Query for IOleObject */ - - if (hr1 == S_OK) - hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject); - - /* Set client site with the IOleObject */ - - if (hr1 == S_OK) - hr1 = IOleObject_SetClientSite(pOleObject, pClientSite); - - IPersistStorage_Release(pPersistStorage); - /* Query for the requested interface */ - - if (hr1 == S_OK) - hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj); - - IPersistStorage_Release(pPersistStorage); - - IStorage_Release(pStorage); - - if (hr1 == S_OK) - return S_OK; - } - - /* Return error */ - - return DV_E_FORMATETC; - } - - hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL); - } - } - - return DV_E_FORMATETC; -} - - -/****************************************************************************** - * OleDuplicateData [OLE32.@] - * - * Duplicates clipboard data. - * - * PARAMS - * hSrc [I] Handle of the source clipboard data. - * cfFormat [I] The clipboard format of hSrc. - * uiFlags [I] Flags to pass to GlobalAlloc. - * - * RETURNS - * Success: handle to the duplicated data. - * Failure: NULL. - */ -HANDLE WINAPI OleDuplicateData(HANDLE hSrc, CLIPFORMAT cfFormat, - UINT uiFlags) -{ - HANDLE hDst = NULL; - - TRACE("(%p,%x,%x)\n", hSrc, cfFormat, uiFlags); - - if (!uiFlags) uiFlags = GMEM_MOVEABLE; - - switch (cfFormat) - { - case CF_ENHMETAFILE: - hDst = CopyEnhMetaFileW(hSrc, NULL); - break; - case CF_METAFILEPICT: - hDst = CopyMetaFileW(hSrc, NULL); - break; - case CF_PALETTE: - { - LOGPALETTE * logpalette; - UINT nEntries = GetPaletteEntries(hSrc, 0, 0, NULL); - if (!nEntries) return NULL; - logpalette = HeapAlloc(GetProcessHeap(), 0, - FIELD_OFFSET(LOGPALETTE, palPalEntry[nEntries])); - if (!logpalette) return NULL; - if (!GetPaletteEntries(hSrc, 0, nEntries, logpalette->palPalEntry)) - { - HeapFree(GetProcessHeap(), 0, logpalette); - return NULL; - } - logpalette->palVersion = 0x300; - logpalette->palNumEntries = (WORD)nEntries; - - hDst = CreatePalette(logpalette); - - HeapFree(GetProcessHeap(), 0, logpalette); - break; - } - case CF_BITMAP: - { - LONG size; - BITMAP bm; - if (!GetObjectW(hSrc, sizeof(bm), &bm)) - return NULL; - size = GetBitmapBits(hSrc, 0, NULL); - if (!size) return NULL; - bm.bmBits = HeapAlloc(GetProcessHeap(), 0, size); - if (!bm.bmBits) return NULL; - if (!GetBitmapBits(hSrc, size, bm.bmBits)) - return NULL; - hDst = CreateBitmapIndirect(&bm); - HeapFree(GetProcessHeap(), 0, bm.bmBits); - break; - } - default: - { - SIZE_T size = GlobalSize(hSrc); - LPVOID pvSrc = NULL; - LPVOID pvDst = NULL; - - /* allocate space for object */ - if (!size) return NULL; - hDst = GlobalAlloc(uiFlags, size); - if (!hDst) return NULL; - - /* lock pointers */ - pvSrc = GlobalLock(hSrc); - if (!pvSrc) - { - GlobalFree(hDst); - return NULL; - } - pvDst = GlobalLock(hDst); - if (!pvDst) - { - GlobalUnlock(hSrc); - GlobalFree(hDst); - return NULL; - } - /* copy data */ - memcpy(pvDst, pvSrc, size); - - /* cleanup */ - GlobalUnlock(hDst); - GlobalUnlock(hSrc); - } - } - - TRACE("returning %p\n", hDst); - return hDst; -} diff --git a/reactos/lib/ole32/ole2nls.c b/reactos/lib/ole32/ole2nls.c deleted file mode 100644 index 82dff4b6b93..00000000000 --- a/reactos/lib/ole32/ole2nls.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * OLE2NLS library - * - * Copyright 1995 Martin von Loewis - * Copyright 1998 David Lee Lambert - * Copyright 2000 Julio César Gázquez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "winnls.h" -#include "winreg.h" -#include "winuser.h" -#include "winver.h" - -#include "wine/winbase16.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -static LPVOID lpNLSInfo = NULL; - -/****************************************************************************** - * GetLocaleInfoA [OLE2NLS.5] - * Is the last parameter really WORD for Win16? - */ -INT16 WINAPI GetLocaleInfo16(LCID lcid,LCTYPE LCType,LPSTR buf,INT16 len) -{ - return GetLocaleInfoA(lcid,LCType,buf,len); -} - -/****************************************************************************** - * GetStringTypeA [OLE2NLS.7] - */ -BOOL16 WINAPI GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src, - INT16 cchSrc,LPWORD chartype) -{ - return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype); -} - -/****************************************************************************** - * GetUserDefaultLCID [OLE2NLS.1] - */ -LCID WINAPI GetUserDefaultLCID16(void) -{ - return GetUserDefaultLCID(); -} - -/****************************************************************************** - * GetSystemDefaultLCID [OLE2NLS.2] - */ -LCID WINAPI GetSystemDefaultLCID16(void) -{ - return GetSystemDefaultLCID(); -} - -/****************************************************************************** - * GetUserDefaultLangID [OLE2NLS.3] - */ -LANGID WINAPI GetUserDefaultLangID16(void) -{ - return GetUserDefaultLangID(); -} - -/****************************************************************************** - * GetSystemDefaultLangID [OLE2NLS.4] - */ -LANGID WINAPI GetSystemDefaultLangID16(void) -{ - return GetSystemDefaultLangID(); -} - -/****************************************************************************** - * LCMapStringA [OLE2NLS.6] - */ -INT16 LCMapString16(LCID lcid, DWORD mapflags, LPCSTR srcstr, INT16 srclen, - LPSTR dststr, INT16 dstlen) -{ - return LCMapStringA(lcid, mapflags, srcstr, srclen, dststr, dstlen); -} - -/*********************************************************************** - * CompareStringA (OLE2NLS.8) - */ -UINT16 WINAPI CompareString16(DWORD lcid,DWORD fdwStyle, - LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2) -{ - return (UINT16)CompareStringA(lcid,fdwStyle,s1,l1,s2,l2); -} - -/****************************************************************************** - * RegisterNLSInfoChanged [OLE2NLS.9] - */ -BOOL16 WINAPI RegisterNLSInfoChanged16(LPVOID lpNewNLSInfo) /* [???] FIXME */ -{ - FIXME("Fully implemented, but doesn't effect anything.\n"); - - if (!lpNewNLSInfo) { - lpNLSInfo = NULL; - return TRUE; - } - else { - if (!lpNLSInfo) { - lpNLSInfo = lpNewNLSInfo; - return TRUE; - } - } - - return FALSE; /* ptr not set */ -} - diff --git a/reactos/lib/ole32/ole2nls.spec b/reactos/lib/ole32/ole2nls.spec deleted file mode 100644 index d3fc613473c..00000000000 --- a/reactos/lib/ole32/ole2nls.spec +++ /dev/null @@ -1,12 +0,0 @@ -1 pascal GetUserDefaultLCID() GetUserDefaultLCID16 -2 pascal GetSystemDefaultLCID() GetSystemDefaultLCID16 -3 pascal -ret16 GetUserDefaultLangID() GetUserDefaultLangID16 -4 pascal -ret16 GetSystemDefaultLangID() GetSystemDefaultLangID16 -5 pascal GetLocaleInfoA(long long ptr word) GetLocaleInfo16 -6 pascal -ret16 LCMapStringA(word long ptr word ptr word) LCMapString16 -7 pascal -ret16 GetStringTypeA(long long str word ptr) GetStringType16 -8 pascal -ret16 CompareStringA(long long str word str word) CompareString16 -9 pascal -ret16 RegisterNLSInfoChanged(ptr) RegisterNLSInfoChanged16 -#10 stub WEP -11 stub LIBMAIN -12 stub NOTIFYWINDOWPROC diff --git a/reactos/lib/ole32/ole2prox.spec b/reactos/lib/ole32/ole2prox.spec deleted file mode 100644 index 3d05d2e26b9..00000000000 --- a/reactos/lib/ole32/ole2prox.spec +++ /dev/null @@ -1,3 +0,0 @@ -1 stub DLLGETCLASSOBJECT -#2 WEP -#3 ___EXPORTEDSTUB diff --git a/reactos/lib/ole32/ole2stubs.c b/reactos/lib/ole32/ole2stubs.c deleted file mode 100644 index 6680135d608..00000000000 --- a/reactos/lib/ole32/ole2stubs.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Temporary place for ole2 stubs. - * - * Copyright (C) 1999 Corel Corporation - * Move these functions to dlls/ole32/ole2impl.c when you implement them. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#define NONAMELESSUNION -#define NONAMELESSSTRUCT -#include - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "ole2.h" -#include "objidl.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/****************************************************************************** - * OleCreateLinkToFile [OLE32.@] - */ -HRESULT WINAPI OleCreateLinkToFile(LPCOLESTR lpszFileName, REFIID riid, - DWORD renderopt, LPFORMATETC lpFormatEtc, - LPOLECLIENTSITE pClientSite, LPSTORAGE pStg, LPVOID* ppvObj) -{ - FIXME("(%p,%p,%li,%p,%p,%p,%p), stub!\n",lpszFileName, riid, renderopt, lpFormatEtc, pClientSite, pStg, ppvObj); - return E_NOTIMPL; -} - -/****************************************************************************** - * SetConvertStg [OLE32.@] - */ -HRESULT WINAPI SetConvertStg(LPSTORAGE pStg, BOOL fConvert) -{ - FIXME("(%p,%x), stub!\n", pStg, fConvert); - return E_NOTIMPL; -} - -/****************************************************************************** - * OleCreateLink [OLE32.@] - */ -HRESULT WINAPI OleCreateLink(LPMONIKER pmkLinkSrc, REFIID riid, DWORD renderopt, LPFORMATETC lpFormatEtc, - LPOLECLIENTSITE pClientSite, LPSTORAGE pStg, LPVOID* ppvObj) -{ - FIXME("(not shown), stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * OleCreateFromFile [OLE32.@] - */ -HRESULT WINAPI OleCreateFromFile(REFCLSID rclsid, LPCOLESTR lpszFileName, REFIID riid, - DWORD renderopt, LPFORMATETC lpFormatEtc, LPOLECLIENTSITE pClientSite, LPSTORAGE pStg, LPVOID* ppvObj) -{ - FIXME("(not shown), stub!\n"); - return E_NOTIMPL; -} - - -/****************************************************************************** - * OleGetIconOfClass [OLE32.@] - */ -HGLOBAL WINAPI OleGetIconOfClass(REFCLSID rclsid, LPOLESTR lpszLabel, BOOL fUseTypeAsLabel) -{ - FIXME("(%p,%p,%x), stub!\n", rclsid, lpszLabel, fUseTypeAsLabel); - return NULL; -} - - -/****************************************************************************** - * OleCreateStaticFromData [OLE32.@] - */ -HRESULT WINAPI OleCreateStaticFromData(LPDATAOBJECT pSrcDataObj, REFIID iid, - DWORD renderopt, LPFORMATETC pFormatEtc, LPOLECLIENTSITE pClientSite, - LPSTORAGE pStg, LPVOID* ppvObj) -{ - FIXME("(not shown), stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * OleCreateLinkFromData [OLE32.@] - */ - -HRESULT WINAPI OleCreateLinkFromData(LPDATAOBJECT pSrcDataObj, REFIID riid, - DWORD renderopt, LPFORMATETC pFormatEtc, - LPOLECLIENTSITE pClientSite, LPSTORAGE pStg, - LPVOID* ppvObj) -{ - FIXME("(not shown), stub!\n"); - return E_NOTIMPL; -} - -/****************************************************************************** - * OleIsRunning [OLE32.@] - */ -BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject) -{ - FIXME("(%p), stub!\n", pObject); - return TRUE; -} - -/*********************************************************************** - * OleRegEnumVerbs [OLE32.@] - */ -HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum) -{ - FIXME("(%p,%p), stub!\n", clsid, ppenum); - return OLEOBJ_E_NOVERBS; -} - -/*********************************************************************** - * OleRegEnumFormatEtc [OLE32.@] - */ -HRESULT WINAPI OleRegEnumFormatEtc ( - REFCLSID clsid, - DWORD dwDirection, - LPENUMFORMATETC* ppenumFormatetc) -{ - FIXME("(%p, %ld, %p), stub!\n", clsid, dwDirection, ppenumFormatetc); - - return E_NOTIMPL; -} - -/*********************************************************************** - * CoIsOle1Class [OLE32.@] - */ -BOOL WINAPI CoIsOle1Class(REFCLSID clsid) -{ - FIXME("%s\n", debugstr_guid(clsid)); - return FALSE; -} - -/*********************************************************************** - * DllGetClassObject [OLE2.4] - */ -HRESULT WINAPI DllGetClassObject16(REFCLSID rclsid, REFIID iid, LPVOID *ppv) -{ - FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv); - return E_NOTIMPL; -} - -/*********************************************************************** - * OleSetClipboard [OLE2.49] - */ -HRESULT WINAPI OleSetClipboard16(IDataObject* pDataObj) -{ - FIXME("(%p): stub\n", pDataObj); - return S_OK; -} - -/*********************************************************************** - * OleGetClipboard [OLE2.50] - */ -HRESULT WINAPI OleGetClipboard16(IDataObject** ppDataObj) -{ - FIXME("(%p): stub\n", ppDataObj); - return E_NOTIMPL; -} diff --git a/reactos/lib/ole32/ole2thk.spec b/reactos/lib/ole32/ole2thk.spec deleted file mode 100644 index 7ce7dc11508..00000000000 --- a/reactos/lib/ole32/ole2thk.spec +++ /dev/null @@ -1,7 +0,0 @@ -1 stub WEP -2 stub ROT16_ISRUNNING16 -3 stub ISWIN32SHANDLE -4 stub ___EXPORTEDSTUB -5 stub COTHKCOMMON -6 stub ROT16_GETTIMEOFLASTCHANGE16 -7 stub ROT16_GETOBJECT16 diff --git a/reactos/lib/ole32/ole32.spec b/reactos/lib/ole32/ole32.spec deleted file mode 100644 index 2dcb5cb2f4d..00000000000 --- a/reactos/lib/ole32/ole32.spec +++ /dev/null @@ -1,266 +0,0 @@ -@ stdcall BindMoniker(ptr long ptr ptr) -@ stub CLIPFORMAT_UserFree -@ stub CLIPFORMAT_UserMarshal -@ stub CLIPFORMAT_UserSize -@ stub CLIPFORMAT_UserUnmarshal -@ stdcall CLSIDFromProgID(wstr ptr) -@ stdcall CLSIDFromString(wstr ptr) -@ stdcall CoAddRefServerProcess() -@ stdcall CoBuildVersion() -@ stub CoCopyProxy #@ stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED -@ stdcall CoCreateFreeThreadedMarshaler(ptr ptr) -@ stdcall CoCreateGuid(ptr) -@ stdcall CoCreateInstance(ptr ptr long ptr ptr) -@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) -@ stdcall CoDisconnectObject(ptr long) -@ stdcall CoDosDateTimeToFileTime(long long ptr) kernel32.DosDateTimeToFileTime -@ stdcall CoFileTimeNow(ptr) -@ stdcall CoFileTimeToDosDateTime(ptr ptr ptr) kernel32.FileTimeToDosDateTime -@ stdcall CoFreeAllLibraries() -@ stdcall CoFreeLibrary(long) -@ stdcall CoFreeUnusedLibraries() -@ stub CoGetCallContext #@ stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED -@ stub CoGetCallerTID -@ stdcall CoGetClassObject(ptr long ptr ptr ptr) -@ stub CoGetCurrentLogicalThreadId -@ stdcall CoGetCurrentProcess() -@ stub CoGetInstanceFromFile #@ stdcall (ptr ptr ptr long wstr long ptr) return 0,ERR_NOTIMPLEMENTED -@ stub CoGetInstanceFromIStorage #@ stdcall (ptr ptr ptr long ptr long ptr) return 0,ERR_NOTIMPLEMENTED -@ stdcall CoGetInterfaceAndReleaseStream(ptr ptr ptr) -@ stdcall CoGetMalloc(long ptr) -@ stdcall CoGetMarshalSizeMax(ptr ptr ptr long ptr long) -@ stub CoGetObject -@ stdcall CoGetPSClsid(ptr ptr) -@ stdcall CoGetStandardMarshal(ptr ptr long ptr long ptr) -@ stdcall CoGetState(ptr) -@ stub CoGetTIDFromIPID -@ stdcall CoGetTreatAsClass(ptr ptr) -@ stub CoImpersonateClient -@ stdcall CoInitialize(ptr) -@ stdcall CoInitializeEx(ptr long) -@ stdcall CoInitializeSecurity(ptr long ptr ptr long long ptr long ptr) -@ stdcall CoInitializeWOW(long long) -@ stub CoIsHandlerConnected #@ stdcall (ptr) return 0,ERR_NOTIMPLEMENTED -@ stdcall CoIsOle1Class (ptr) -@ stdcall CoLoadLibrary(wstr long) -@ stdcall CoLockObjectExternal(ptr long long) -@ stdcall CoMarshalHresult(ptr long) -@ stdcall CoMarshalInterThreadInterfaceInStream(ptr ptr ptr) -@ stdcall CoMarshalInterface(ptr ptr ptr long ptr long) -@ stub CoQueryAuthenticationServices -@ stub CoQueryClientBlanket -@ stub CoQueryProxyBlanket -@ stub CoQueryReleaseObject -@ stub CoRegisterChannelHook -@ stdcall CoRegisterClassObject(ptr ptr long long ptr) -@ stdcall CoRegisterMallocSpy (ptr) -@ stdcall CoRegisterMessageFilter(ptr ptr) -@ stub CoRegisterPSClsid #@ stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED -@ stub CoRegisterSurrogate -@ stdcall CoReleaseMarshalData(ptr) -@ stdcall CoReleaseServerProcess() -@ stdcall CoResumeClassObjects() -@ stub CoRevertToSelf #@ stdcall () return 0,ERR_NOTIMPLEMENTED -@ stdcall CoRevokeClassObject(long) -@ stdcall CoRevokeMallocSpy() -@ stub CoSetProxyBlanket #@ stdcall (ptr long long wstr long long ptr long) return 0,ERR_NOTIMPLEMENTED -@ stdcall CoSetState(ptr) -@ stub CoSwitchCallContext -@ stdcall CoSuspendClassObjects() -@ stdcall CoTaskMemAlloc(long) -@ stdcall CoTaskMemFree(ptr) -@ stdcall CoTaskMemRealloc(ptr long) -@ stdcall CoTreatAsClass(ptr ptr) -@ stdcall CoUninitialize() -@ stub CoUnloadingWOW -@ stdcall CoUnmarshalHresult(ptr ptr) -@ stdcall CoUnmarshalInterface(ptr ptr ptr) -@ stdcall CreateAntiMoniker(ptr) -@ stdcall CreateBindCtx(long ptr) -@ stdcall CreateClassMoniker(ptr ptr) -@ stdcall CreateDataAdviseHolder(ptr) -@ stdcall CreateDataCache(ptr ptr ptr ptr) -@ stdcall CreateErrorInfo(ptr) -@ stdcall CreateFileMoniker(wstr ptr) -@ stdcall CreateGenericComposite(ptr ptr ptr) -@ stdcall CreateILockBytesOnHGlobal(ptr long ptr) -@ stdcall CreateItemMoniker(wstr wstr ptr) -@ stub CreateObjrefMoniker -@ stdcall CreateOleAdviseHolder(ptr) -@ 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 -@ stub DllGetClassObjectWOW -@ stdcall -private DllRegisterServer() OLE32_DllRegisterServer -@ stdcall -private DllUnregisterServer() OLE32_DllUnregisterServer -@ stdcall DoDragDrop(ptr ptr long ptr) -@ stub EnableHookObject -@ stdcall FreePropVariantArray(long ptr) -@ stdcall GetClassFile(wstr ptr) -@ stdcall GetConvertStg(ptr) -@ stub GetDocumentBitStg -@ stdcall GetErrorInfo(long ptr) -@ stdcall GetHGlobalFromILockBytes(ptr ptr) -@ stdcall GetHGlobalFromStream(ptr ptr) -@ stub GetHookInterface -@ stdcall GetRunningObjectTable(long ptr) -@ stub HACCEL_UserFree -@ stub HACCEL_UserMarshal -@ stub HACCEL_UserSize -@ stub HACCEL_UserUnmarshal -@ stub HBITMAP_UserFree -@ stub HBITMAP_UserMarshal -@ stub HBITMAP_UserSize -@ stub HBITMAP_UserUnmarshal -@ stub HBRUSH_UserFree -@ stub HBRUSH_UserMarshal -@ stub HBRUSH_UserSize -@ stub HBRUSH_UserUnmarshal -@ stub HENHMETAFILE_UserFree -@ stub HENHMETAFILE_UserMarshal -@ stub HENHMETAFILE_UserSize -@ stub HENHMETAFILE_UserUnmarshal -@ stub HGLOBAL_UserFree -@ stub HGLOBAL_UserMarshal -@ stub HGLOBAL_UserSize -@ stub HGLOBAL_UserUnmarshal -@ stub HMENU_UserFree -@ stub HMENU_UserMarshal -@ stub HMENU_UserSize -@ stub HMENU_UserUnmarshal -@ stub HMETAFILEPICT_UserFree -@ stub HMETAFILEPICT_UserMarshal -@ stub HMETAFILEPICT_UserSize -@ stub HMETAFILEPICT_UserUnmarshal -@ stub HMETAFILE_UserFree -@ stub HMETAFILE_UserMarshal -@ stub HMETAFILE_UserSize -@ stub HMETAFILE_UserUnmarshal -@ stub HPALETTE_UserFree -@ stub HPALETTE_UserMarshal -@ stub HPALETTE_UserSize -@ stub HPALETTE_UserUnmarshal -@ stub HWND_UserFree -@ stub HWND_UserMarshal -@ stub HWND_UserSize -@ stub HWND_UserUnmarshal -@ stub I_RemoteMain -@ stdcall IIDFromString(wstr ptr) CLSIDFromString -@ stdcall IsAccelerator(long long ptr long) -@ stdcall IsEqualGUID(ptr ptr) -@ stub IsValidIid -@ stdcall IsValidInterface(ptr) -@ stub IsValidPtrIn -@ stub IsValidPtrOut -@ stdcall MkParseDisplayName(ptr ptr ptr ptr) -@ stdcall MonikerCommonPrefixWith(ptr ptr ptr) -@ stub MonikerRelativePathTo -@ stdcall OleBuildVersion() -@ stdcall OleConvertIStorageToOLESTREAM(ptr ptr) -@ stub OleConvertIStorageToOLESTREAMEx -@ stdcall OleConvertOLESTREAMToIStorage(ptr ptr ptr) -@ stub OleConvertOLESTREAMToIStorageEx -@ stdcall OleCreate(ptr ptr long ptr ptr ptr ptr) -@ stdcall OleCreateDefaultHandler(ptr ptr ptr ptr) -@ stub OleCreateEmbeddingHelper -@ stub OleCreateEx -@ stdcall OleCreateFromData(ptr ptr long ptr ptr ptr ptr) -@ stub OleCreateFromDataEx -@ stdcall OleCreateFromFile(ptr ptr ptr long ptr ptr ptr ptr) -@ stub OleCreateFromFileEx -@ stdcall OleCreateLink(ptr ptr long ptr ptr ptr ptr) -@ stub OleCreateLinkEx -@ stdcall OleCreateLinkFromData(ptr ptr long ptr ptr ptr ptr) -@ stub OleCreateLinkFromDataEx -@ stdcall OleCreateLinkToFile(ptr ptr long ptr ptr ptr ptr) -@ stub OleCreateLinkToFileEx -@ stdcall OleCreateMenuDescriptor(long ptr) -@ stdcall OleCreateStaticFromData(ptr ptr long ptr ptr ptr ptr) -@ stdcall OleDestroyMenuDescriptor(long) -@ stdcall OleDoAutoConvert(ptr ptr) -@ stdcall OleDraw(ptr long long ptr) -@ stdcall OleDuplicateData(long long long) -@ stdcall OleFlushClipboard() -@ stdcall OleGetAutoConvert(ptr ptr) -@ stdcall OleGetClipboard(ptr) -@ stdcall OleGetIconOfClass(ptr ptr long) -@ stub OleGetIconOfFile -@ stdcall OleInitialize(ptr) -@ stdcall OleInitializeWOW(long) -@ stdcall OleIsCurrentClipboard(ptr) -@ stdcall OleIsRunning(ptr) -@ stdcall OleLoad(ptr ptr ptr ptr) -@ stdcall OleLoadFromStream(ptr ptr ptr) -@ stdcall OleLockRunning(ptr long long) -@ stdcall OleMetafilePictFromIconAndLabel(long ptr ptr long) -@ stub OleNoteObjectVisible -@ stdcall OleQueryCreateFromData(ptr) -@ stdcall OleQueryLinkFromData(ptr) -@ stdcall OleRegEnumFormatEtc(ptr long ptr) -@ stdcall OleRegEnumVerbs(long ptr) -@ stdcall OleRegGetMiscStatus(ptr long ptr) -@ stdcall OleRegGetUserType(long long ptr) -@ stdcall OleRun(ptr) -@ stdcall OleSave(ptr ptr long) -@ stdcall OleSaveToStream(ptr ptr) -@ stdcall OleSetAutoConvert(ptr ptr) -@ stdcall OleSetClipboard(ptr) -@ stdcall OleSetContainedObject(ptr long) -@ stdcall OleSetMenuDescriptor(long long long ptr ptr) -@ stdcall OleTranslateAccelerator(ptr ptr ptr) -@ stdcall OleUninitialize() -@ stub OpenOrCreateStream -@ stdcall ProgIDFromCLSID(ptr ptr) -@ stub PropSysAllocString -@ stub PropSysFreeString -@ stdcall PropVariantClear(ptr) -@ stdcall PropVariantCopy(ptr ptr) -@ stdcall ReadClassStg(ptr ptr) -@ stdcall ReadClassStm(ptr ptr) -@ stdcall ReadFmtUserTypeStg(ptr ptr ptr) -@ stub ReadOleStg -@ stub ReadStringStream -@ stdcall RegisterDragDrop(long ptr) -@ stdcall ReleaseStgMedium(ptr) -@ stdcall RevokeDragDrop(long) -@ stdcall SetConvertStg(ptr long) -@ stub SetDocumentBitStg -@ stdcall SetErrorInfo(long ptr) -@ stub SNB_UserFree -@ stub SNB_UserMarshal -@ stub SNB_UserSize -@ stub SNB_UserUnmarshal -@ stdcall StgCreateDocfile(wstr long long ptr) -@ stdcall StgCreateDocfileOnILockBytes(ptr long long ptr) -@ stdcall StgCreateStorageEx(wstr long long long ptr ptr ptr ptr) -@ stub StgGetIFillLockBytesOnFile -@ stub StgGetIFillLockBytesOnILockBytes -@ stdcall StgIsStorageFile(wstr) -@ stdcall StgIsStorageILockBytes(ptr) -@ stub STGMEDIUM_UserFree -@ stub STGMEDIUM_UserMarshal -@ stub STGMEDIUM_UserSize -@ stub STGMEDIUM_UserUnmarshal -@ stub StgOpenAsyncDocfileOnIFillLockBytes -@ stdcall StgOpenStorage(wstr ptr long ptr long ptr) -@ stub StgOpenStorageEx -@ stdcall StgOpenStorageOnILockBytes(ptr ptr long long long ptr) -@ stdcall StgSetTimes(wstr ptr ptr ptr ) -@ stdcall StringFromCLSID(ptr ptr) -@ stdcall StringFromGUID2(ptr ptr long) -@ stdcall StringFromIID(ptr ptr) StringFromCLSID -@ stub UpdateDCOMSettings -@ stub UtConvertDvtd16toDvtd32 -@ stub UtConvertDvtd32toDvtd16 -@ stub UtGetDvtd16Info -@ stub UtGetDvtd32Info -@ stub WdtpInterfacePointer_UserFree -@ stub WdtpInterfacePointer_UserMarshal -@ stub WdtpInterfacePointer_UserSize -@ stub WdtpInterfacePointer_UserUnmarshal -@ stdcall WriteClassStg(ptr ptr) -@ stdcall WriteClassStm(ptr ptr) -@ stdcall WriteFmtUserTypeStg(ptr long ptr) -@ stub WriteOleStg -@ stub WriteStringStream diff --git a/reactos/lib/ole32/ole32_main.c b/reactos/lib/ole32/ole32_main.c deleted file mode 100644 index 3dd9067ed8c..00000000000 --- a/reactos/lib/ole32/ole32_main.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * OLE32 Initialization - * - * Copyright 2000 Huw D M Davies for CodeWeavers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include "windef.h" -#include "winerror.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winnls.h" -#include "ole32_main.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -HINSTANCE OLE32_hInstance = 0; - -/*********************************************************************** - * OleMetafilePictFromIconAndLabel (OLE32.@) - */ -HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel, - LPOLESTR lpszSourceFile, UINT iIconIndex) -{ - METAFILEPICT mfp; - HDC hdc; - UINT dy; - HGLOBAL hmem = NULL; - LPVOID mfdata; - static const char szIconOnly[] = "IconOnly"; - - TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex); - - if( !hIcon ) - return NULL; - - hdc = CreateMetaFileW(NULL); - if( !hdc ) - return NULL; - - ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL); - - /* FIXME: things are drawn in the wrong place */ - DrawIcon(hdc, 0, 0, hIcon); - dy = GetSystemMetrics(SM_CXICON); - if(lpszLabel) - TextOutW(hdc, 0, dy, lpszLabel, lstrlenW(lpszLabel)); - - if (lpszSourceFile) - { - char szIconIndex[10]; - int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL); - if (path_length > 1) - { - char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR)); - if (szPath) - { - WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL); - ExtEscape(hdc, MFCOMMENT, path_length, szPath, 0, NULL); - CoTaskMemFree(szPath); - } - } - snprintf(szIconIndex, 10, "%u", iIconIndex); - ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL); - } - - mfp.mm = MM_ISOTROPIC; - mfp.xExt = mfp.yExt = 0; /* FIXME ? */ - mfp.hMF = CloseMetaFile(hdc); - if( !mfp.hMF ) - return NULL; - - hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) ); - if( !hmem ) - { - DeleteMetaFile(mfp.hMF); - return NULL; - } - - mfdata = GlobalLock( hmem ); - if( !mfdata ) - { - GlobalFree( hmem ); - DeleteMetaFile(mfp.hMF); - return NULL; - } - - memcpy(mfdata,&mfp,sizeof(mfp)); - GlobalUnlock( hmem ); - - TRACE("returning %p\n",hmem); - - return hmem; -} - - -/*********************************************************************** - * DllMain (OLE32.@) - */ -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) -{ - TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad); - - switch(fdwReason) { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hinstDLL); - OLE32_hInstance = hinstDLL; - COMPOBJ_InitProcess(); - if (TRACE_ON(ole)) CoRegisterMallocSpy((LPVOID)-1); - break; - - case DLL_PROCESS_DETACH: - if (TRACE_ON(ole)) CoRevokeMallocSpy(); - COMPOBJ_UninitProcess(); - OLE32_hInstance = 0; - break; - } - return TRUE; -} - -/* NOTE: DllRegisterServer and DllUnregisterServer are in regsvr.c */ diff --git a/reactos/lib/ole32/ole32_main.h b/reactos/lib/ole32/ole32_main.h deleted file mode 100644 index f488b07fe50..00000000000 --- a/reactos/lib/ole32/ole32_main.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000 Huw D M Davies for CodeWeavers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __WINE_OLE32_MAIN_H -#define __WINE_OLE32_MAIN_H - -#include - -#include "windef.h" -#include "winbase.h" -#include "objbase.h" - -extern HINSTANCE OLE32_hInstance; - -void COMPOBJ_InitProcess( void ); -void COMPOBJ_UninitProcess( void ); - -#endif /* __WINE_OLE32_MAIN_H */ diff --git a/reactos/lib/ole32/ole32res.rc b/reactos/lib/ole32/ole32res.rc deleted file mode 100644 index cc4c0b25254..00000000000 --- a/reactos/lib/ole32/ole32res.rc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Top level resource file for OLE32 - * - * Copyright 2000 Huw D M Davies for CodeWeavers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winnls.h" - -#include "version.rc" - -/* - * Everything that does not depend on language, - * like textless bitmaps etc, go into the - * neutral language. This will prevent them from - * being duplicated for each language. - */ -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL - -/* BINRES nodrop.cur */ -0 CURSOR nodrop.cur -/* { - '00 00 02 00 01 00 20 20 00 00 0F 00 0F 00 30 01' - '00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' - '00 00 01 00 01 00 00 00 00 00 80 00 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07' - 'E0 00 00 18 18 00 00 20 04 00 00 43 E2 00 00 8C' - '11 00 01 10 20 80 01 20 44 80 02 20 8C 40 02 41' - '12 40 02 42 22 40 02 44 42 40 02 48 82 40 02 31' - '04 40 01 22 04 80 01 04 08 80 00 8C 31 00 00 43' - 'C2 00 00 20 04 00 00 18 18 00 00 07 E0 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF' - 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F8' - '1F FF FF E0 07 FF FF C0 03 FF FF 80 01 FF FF 03' - 'E0 FF FE 0F C0 7F FE 1F 80 7F FC 1F 00 3F FC 3E' - '0C 3F FC 3C 1C 3F FC 38 3C 3F FC 30 7C 3F FC 00' - 'F8 3F FE 01 F8 7F FE 03 F0 7F FF 03 C0 FF FF 80' - '01 FF FF C0 03 FF FF E0 07 FF FF F8 1F FF FF FF' - 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF' - 'FF FF FF FF FF FF' -} */ - -/* BINRES drag_move.cur */ -1 CURSOR drag_move.cur -/* { - '00 00 02 00 01 00 20 20 00 00 12 00 16 00 30 01' - '00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' - '00 00 01 00 01 00 00 00 00 00 00 01 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 05 55 00 00 0A AA 80 00 04 01 00 00 08 00' - '80 00 04 01 00 00 08 00 80 00 05 55 00 00 0A EA' - '80 00 00 C0 00 00 01 80 00 00 01 80 00 00 03 00' - '00 00 23 00 00 00 36 00 00 00 3E 00 00 00 3F C0' - '00 00 3F 80 00 00 3F 00 00 00 3E 00 00 00 3C 00' - '00 00 38 00 00 00 30 00 00 00 20 00 00 00 00 00' - '00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF' - 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF' - 'FF FF FA AA FF FF F5 55 7F FF FB FE FF FF F7 FF' - '7F FF FB FE FF FF F7 FF 7F FF FA AA FF FF F5 15' - '7F FF FE 1F FF FF FC 3F FF FF BC 3F FF FF 98 7F' - 'FF FF 88 7F FF FF 80 FF FF FF 80 0F FF FF 80 1F' - 'FF FF 80 3F FF FF 80 7F FF FF 80 FF FF FF 81 FF' - 'FF FF 83 FF FF FF 87 FF FF FF 8F FF FF FF 9F FF' - 'FF FF FF FF FF FF' -} */ - -/* BINRES drag_copy.cur */ -2 CURSOR drag_copy.cur -/* { - '00 00 02 00 01 00 20 20 00 00 01 00 01 00 30 01' - '00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' - '00 00 01 00 01 00 00 00 00 00 00 01 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' - '00 00 00 00 00 00 00 07 F0 00 00 07 70 00 00 07' - '70 00 05 54 10 00 0A A7 70 00 04 07 70 00 08 07' - 'F0 00 04 00 00 00 08 00 80 00 05 55 00 00 0A EA' - '80 00 00 C0 00 00 01 80 00 00 01 80 00 00 03 00' - '00 00 23 00 00 00 36 00 00 00 3E 00 00 00 3F C0' - '00 00 3F 80 00 00 3F 00 00 00 3E 00 00 00 3C 00' - '00 00 38 00 00 00 30 00 00 00 20 00 00 00 00 00' - '00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF' - 'FF FF FF F0 07 FF FF F0 07 FF FF F0 07 FF FF F0' - '07 FF FA A0 07 FF F5 50 07 FF FB F0 07 FF F7 F0' - '07 FF FB F0 07 FF F7 FF 7F FF FA AA FF FF F5 15' - '7F FF FE 1F FF FF FC 3F FF FF BC 3F FF FF 98 7F' - 'FF FF 88 7F FF FF 80 FF FF FF 80 0F FF FF 80 1F' - 'FF FF 80 3F FF FF 80 7F FF FF 80 FF FF FF 81 FF' - 'FF FF 83 FF FF FF 87 FF FF FF 8F FF FF FF 9F FF' - 'FF FF FF FF FF FF' -} */ - -/* BINRES drag_link.cur */ -3 CURSOR drag_link.cur -/* { - '00 00 02 00 01 00 20 20 00 00 12 00 16 00 30 01' - '00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' - '00 00 01 00 01 00 00 00 00 00 00 01 00 00 00 00' - '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' - '00 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 00' - '00 00 00 00 00 00 00 07 F0 00 00 06 F0 00 00 06' - 'F0 00 05 57 50 00 0A A7 90 00 04 07 10 00 08 07' - 'F0 00 04 00 00 00 08 00 80 00 05 55 00 00 0A EA' - '80 00 00 C0 00 00 01 80 00 00 01 80 00 00 03 00' - '00 00 23 00 00 00 36 00 00 00 3E 00 00 00 3F C0' - '00 00 3F 80 00 00 3F 00 00 00 3E 00 00 00 3C 00' - '00 00 38 00 00 00 30 00 00 00 20 00 00 00 00 00' - '00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF' - 'FF FF FF F0 07 FF FF F0 07 FF FF F0 07 FF FF F0' - '07 FF FA A0 07 FF F5 50 07 FF FB F0 07 FF F7 F0' - '07 FF FB F0 07 FF F7 FF 7F FF FA AA FF FF F5 15' - '7F FF FE 1F FF FF FC 3F FF FF BC 3F FF FF 98 7F' - 'FF FF 88 7F FF FF 80 FF FF FF 80 0F FF FF 80 1F' - 'FF FF 80 3F FF FF 80 7F FF FF 80 FF FF FF 81 FF' - 'FF FF 83 FF FF FF 87 FF FF FF 8F FF FF FF 9F FF' - 'FF FF FF FF FF FF' -} */ - - -/* - * Everything specific to any language goes - * in one of the specific files. - * Note that you can and may override resources - * which also have a neutral version. This is to - * get localized bitmaps for example. - */ diff --git a/reactos/lib/ole32/oleobj.c b/reactos/lib/ole32/oleobj.c deleted file mode 100644 index bfda94b90cc..00000000000 --- a/reactos/lib/ole32/oleobj.c +++ /dev/null @@ -1,752 +0,0 @@ -/* - * OLE2 COM objects - * - * Copyright 1998 Eric Kohl - * Copyright 1999 Francis Beaudet - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include -#include - -#define COBJMACROS - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winerror.h" -#include "wine/debug.h" -#include "ole2.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -#define INITIAL_SINKS 10 - -/************************************************************************** - * OleAdviseHolderImpl Implementation - */ -typedef struct OleAdviseHolderImpl -{ - IOleAdviseHolderVtbl *lpVtbl; - - DWORD ref; - - DWORD maxSinks; - IAdviseSink** arrayOfSinks; - -} OleAdviseHolderImpl; - -static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor(); -static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl* ptrToDestroy); -static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(LPOLEADVISEHOLDER,REFIID,LPVOID*); -static ULONG WINAPI OleAdviseHolderImpl_AddRef(LPOLEADVISEHOLDER); -static ULONG WINAPI OleAdviseHolderImpl_Release(LPOLEADVISEHOLDER); -static HRESULT WINAPI OleAdviseHolderImpl_Advise(LPOLEADVISEHOLDER, IAdviseSink*, DWORD*); -static HRESULT WINAPI OleAdviseHolderImpl_Unadvise (LPOLEADVISEHOLDER, DWORD); -static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER, IEnumSTATDATA **); -static HRESULT WINAPI OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER, IMoniker *); -static HRESULT WINAPI OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER); -static HRESULT WINAPI OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER); - - -/************************************************************************** - * OleAdviseHolderImpl_VTable - */ -static struct IOleAdviseHolderVtbl oahvt = -{ - OleAdviseHolderImpl_QueryInterface, - OleAdviseHolderImpl_AddRef, - OleAdviseHolderImpl_Release, - OleAdviseHolderImpl_Advise, - OleAdviseHolderImpl_Unadvise, - OleAdviseHolderImpl_EnumAdvise, - OleAdviseHolderImpl_SendOnRename, - OleAdviseHolderImpl_SendOnSave, - OleAdviseHolderImpl_SendOnClose -}; - -/************************************************************************** - * OleAdviseHolderImpl_Constructor - */ - -static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor() -{ - OleAdviseHolderImpl* lpoah; - DWORD index; - - lpoah= (OleAdviseHolderImpl*)HeapAlloc(GetProcessHeap(), - 0, - sizeof(OleAdviseHolderImpl)); - - lpoah->lpVtbl = &oahvt; - lpoah->ref = 1; - lpoah->maxSinks = INITIAL_SINKS; - lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(), - 0, - lpoah->maxSinks * sizeof(IAdviseSink*)); - - for (index = 0; index < lpoah->maxSinks; index++) - lpoah->arrayOfSinks[index]=0; - - TRACE("returning %p\n", lpoah); - return (LPOLEADVISEHOLDER)lpoah; -} - -/************************************************************************** - * OleAdviseHolderImpl_Destructor - */ -static void OleAdviseHolderImpl_Destructor( - OleAdviseHolderImpl* ptrToDestroy) -{ - DWORD index; - TRACE("%p\n", ptrToDestroy); - - for (index = 0; index < ptrToDestroy->maxSinks; index++) - { - if (ptrToDestroy->arrayOfSinks[index]!=0) - { - IAdviseSink_Release(ptrToDestroy->arrayOfSinks[index]); - ptrToDestroy->arrayOfSinks[index] = NULL; - } - } - - HeapFree(GetProcessHeap(), - 0, - ptrToDestroy->arrayOfSinks); - - - HeapFree(GetProcessHeap(), - 0, - ptrToDestroy); -} - -/************************************************************************** - * OleAdviseHolderImpl_QueryInterface - */ -static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface( - LPOLEADVISEHOLDER iface, - REFIID riid, - LPVOID* ppvObj) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObj); - /* - * Sanity check - */ - if (ppvObj==NULL) - return E_POINTER; - - *ppvObj = NULL; - - if (IsEqualIID(riid, &IID_IUnknown)) - { - /* IUnknown */ - *ppvObj = This; - } - else if(IsEqualIID(riid, &IID_IOleAdviseHolder)) - { - /* IOleAdviseHolder */ - *ppvObj = (IOleAdviseHolder*) This; - } - - if(*ppvObj == NULL) - return E_NOINTERFACE; - - /* - * A successful QI always increments the reference count. - */ - IUnknown_AddRef((IUnknown*)*ppvObj); - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_AddRef - */ -static ULONG WINAPI OleAdviseHolderImpl_AddRef( - LPOLEADVISEHOLDER iface) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - TRACE("(%p)->(ref=%ld)\n", This, This->ref); - return ++(This->ref); -} - -/****************************************************************************** - * OleAdviseHolderImpl_Release - */ -static ULONG WINAPI OleAdviseHolderImpl_Release( - LPOLEADVISEHOLDER iface) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - ULONG ref; - TRACE("(%p)->(ref=%ld)\n", This, This->ref); - ref = InterlockedDecrement(&This->ref); - - if (ref == 0) OleAdviseHolderImpl_Destructor(This); - - return ref; -} - -/****************************************************************************** - * OleAdviseHolderImpl_Advise - */ -static HRESULT WINAPI OleAdviseHolderImpl_Advise( - LPOLEADVISEHOLDER iface, - IAdviseSink* pAdvise, - DWORD* pdwConnection) -{ - DWORD index; - - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - - TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection); - - /* - * Sanity check - */ - if (pdwConnection==NULL) - return E_POINTER; - - *pdwConnection = 0; - - /* - * Find a free spot in the array. - */ - for (index = 0; index < This->maxSinks; index++) - { - if (This->arrayOfSinks[index]==NULL) - break; - } - - /* - * If the array is full, we need to grow it. - */ - if (index == This->maxSinks) - { - DWORD i; - - This->maxSinks+=INITIAL_SINKS; - - This->arrayOfSinks = HeapReAlloc(GetProcessHeap(), - 0, - This->arrayOfSinks, - This->maxSinks*sizeof(IAdviseSink*)); - - for (i=index;i < This->maxSinks; i++) - This->arrayOfSinks[i]=0; - } - - /* - * Store the new sink - */ - This->arrayOfSinks[index] = pAdvise; - - if (This->arrayOfSinks[index]!=NULL) - IAdviseSink_AddRef(This->arrayOfSinks[index]); - - /* - * Return the index as the cookie. - * Since 0 is not a valid cookie, we will increment by - * 1 the index in the table. - */ - *pdwConnection = index+1; - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_Unadvise - */ -static HRESULT WINAPI OleAdviseHolderImpl_Unadvise( - LPOLEADVISEHOLDER iface, - DWORD dwConnection) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - - TRACE("(%p)->(%lu)\n", This, dwConnection); - - /* - * So we don't return 0 as a cookie, the index was - * incremented by 1 in OleAdviseHolderImpl_Advise - * we have to compensate. - */ - dwConnection--; - - /* - * Check for invalid cookies. - */ - if (dwConnection >= This->maxSinks) - return OLE_E_NOCONNECTION; - - if (This->arrayOfSinks[dwConnection] == NULL) - return OLE_E_NOCONNECTION; - - /* - * Release the sink and mark the spot in the list as free. - */ - IAdviseSink_Release(This->arrayOfSinks[dwConnection]); - This->arrayOfSinks[dwConnection] = NULL; - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_EnumAdvise - */ -static HRESULT WINAPI -OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface, IEnumSTATDATA **ppenumAdvise) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - FIXME("(%p)->(%p)\n", This, ppenumAdvise); - - *ppenumAdvise = NULL; - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_SendOnRename - */ -static HRESULT WINAPI -OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface, IMoniker *pmk) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - FIXME("(%p)->(%p)\n", This, pmk); - - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_SendOnSave - */ -static HRESULT WINAPI -OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - FIXME("(%p)\n", This); - - return S_OK; -} - -/****************************************************************************** - * OleAdviseHolderImpl_SendOnClose - */ -static HRESULT WINAPI -OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER iface) -{ - OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - FIXME("(%p)\n", This); - - - return S_OK; -} - -/************************************************************************** - * DataAdviseHolder Implementation - */ -typedef struct DataAdviseConnection { - IAdviseSink *sink; - FORMATETC fmat; - DWORD advf; -} DataAdviseConnection; - -typedef struct DataAdviseHolder -{ - IDataAdviseHolderVtbl *lpVtbl; - - DWORD ref; - DWORD maxCons; - DataAdviseConnection* Connections; -} DataAdviseHolder; - -/************************************************************************** - * DataAdviseHolder method prototypes - */ -static IDataAdviseHolder* DataAdviseHolder_Constructor(); -static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy); -static HRESULT WINAPI DataAdviseHolder_QueryInterface( - IDataAdviseHolder* iface, - REFIID riid, - void** ppvObject); -static ULONG WINAPI DataAdviseHolder_AddRef( - IDataAdviseHolder* iface); -static ULONG WINAPI DataAdviseHolder_Release( - IDataAdviseHolder* iface); -static HRESULT WINAPI DataAdviseHolder_Advise( - IDataAdviseHolder* iface, - IDataObject* pDataObject, - FORMATETC* pFetc, - DWORD advf, - IAdviseSink* pAdvise, - DWORD* pdwConnection); -static HRESULT WINAPI DataAdviseHolder_Unadvise( - IDataAdviseHolder* iface, - DWORD dwConnection); -static HRESULT WINAPI DataAdviseHolder_EnumAdvise( - IDataAdviseHolder* iface, - IEnumSTATDATA** ppenumAdvise); -static HRESULT WINAPI DataAdviseHolder_SendOnDataChange( - IDataAdviseHolder* iface, - IDataObject* pDataObject, - DWORD dwReserved, - DWORD advf); - -/************************************************************************** - * DataAdviseHolderImpl_VTable - */ -static struct IDataAdviseHolderVtbl DataAdviseHolderImpl_VTable = -{ - DataAdviseHolder_QueryInterface, - DataAdviseHolder_AddRef, - DataAdviseHolder_Release, - DataAdviseHolder_Advise, - DataAdviseHolder_Unadvise, - DataAdviseHolder_EnumAdvise, - DataAdviseHolder_SendOnDataChange -}; - -/****************************************************************************** - * DataAdviseHolder_Constructor - */ -static IDataAdviseHolder* DataAdviseHolder_Constructor() -{ - DataAdviseHolder* newHolder; - - newHolder = (DataAdviseHolder*)HeapAlloc(GetProcessHeap(), - 0, - sizeof(DataAdviseHolder)); - - newHolder->lpVtbl = &DataAdviseHolderImpl_VTable; - newHolder->ref = 1; - newHolder->maxCons = INITIAL_SINKS; - newHolder->Connections = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - newHolder->maxCons * - sizeof(DataAdviseConnection)); - - TRACE("returning %p\n", newHolder); - return (IDataAdviseHolder*)newHolder; -} - -/****************************************************************************** - * DataAdviseHolder_Destructor - */ -static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy) -{ - DWORD index; - TRACE("%p\n", ptrToDestroy); - - for (index = 0; index < ptrToDestroy->maxCons; index++) - { - if (ptrToDestroy->Connections[index].sink != NULL) - { - IAdviseSink_Release(ptrToDestroy->Connections[index].sink); - ptrToDestroy->Connections[index].sink = NULL; - } - } - - HeapFree(GetProcessHeap(), 0, ptrToDestroy->Connections); - HeapFree(GetProcessHeap(), 0, ptrToDestroy); -} - -/************************************************************************ - * DataAdviseHolder_QueryInterface (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static HRESULT WINAPI DataAdviseHolder_QueryInterface( - IDataAdviseHolder* iface, - REFIID riid, - void** ppvObject) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject); - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if ( (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) || - (memcmp(&IID_IDataAdviseHolder, riid, sizeof(IID_IDataAdviseHolder)) == 0) ) - { - *ppvObject = iface; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - { - return E_NOINTERFACE; - } - - /* - * Query Interface always increases the reference count by one when it is - * successful. - */ - IUnknown_AddRef((IUnknown*)*ppvObject); - - return S_OK; -} - -/************************************************************************ - * DataAdviseHolder_AddRef (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataAdviseHolder_AddRef( - IDataAdviseHolder* iface) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - TRACE("(%p) (ref=%ld)\n", This, This->ref); - return InterlockedIncrement(&This->ref); -} - -/************************************************************************ - * DataAdviseHolder_Release (IUnknown) - * - * See Windows documentation for more details on IUnknown methods. - */ -static ULONG WINAPI DataAdviseHolder_Release( - IDataAdviseHolder* iface) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - ULONG ref; - TRACE("(%p) (ref=%ld)\n", This, This->ref); - - /* - * Decrease the reference count on this object. - */ - ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref==0) DataAdviseHolder_Destructor(This); - - return ref; -} - -/************************************************************************ - * DataAdviseHolder_Advise - * - */ -static HRESULT WINAPI DataAdviseHolder_Advise( - IDataAdviseHolder* iface, - IDataObject* pDataObject, - FORMATETC* pFetc, - DWORD advf, - IAdviseSink* pAdvise, - DWORD* pdwConnection) -{ - DWORD index; - - DataAdviseHolder *This = (DataAdviseHolder *)iface; - - TRACE("(%p)->(%p, %p, %08lx, %p, %p)\n", This, pDataObject, pFetc, advf, - pAdvise, pdwConnection); - /* - * Sanity check - */ - if (pdwConnection==NULL) - return E_POINTER; - - *pdwConnection = 0; - - /* - * Find a free spot in the array. - */ - for (index = 0; index < This->maxCons; index++) - { - if (This->Connections[index].sink == NULL) - break; - } - - /* - * If the array is full, we need to grow it. - */ - if (index == This->maxCons) - { - This->maxCons+=INITIAL_SINKS; - This->Connections = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - This->Connections, - This->maxCons*sizeof(DataAdviseConnection)); - } - /* - * Store the new sink - */ - This->Connections[index].sink = pAdvise; - memcpy(&(This->Connections[index].fmat), pFetc, sizeof(FORMATETC)); - This->Connections[index].advf = advf; - - if (This->Connections[index].sink != NULL) { - IAdviseSink_AddRef(This->Connections[index].sink); - if(advf & ADVF_PRIMEFIRST) { - DataAdviseHolder_SendOnDataChange(iface, pDataObject, 0, advf); - } - } - /* - * Return the index as the cookie. - * Since 0 is not a valid cookie, we will increment by - * 1 the index in the table. - */ - *pdwConnection = index+1; - - return S_OK; -} - -/****************************************************************************** - * DataAdviseHolder_Unadvise - */ -static HRESULT WINAPI DataAdviseHolder_Unadvise( - IDataAdviseHolder* iface, - DWORD dwConnection) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - - TRACE("(%p)->(%lu)\n", This, dwConnection); - - /* - * So we don't return 0 as a cookie, the index was - * incremented by 1 in OleAdviseHolderImpl_Advise - * we have to compensate. - */ - dwConnection--; - - /* - * Check for invalid cookies. - */ - if (dwConnection >= This->maxCons) - return OLE_E_NOCONNECTION; - - if (This->Connections[dwConnection].sink == NULL) - return OLE_E_NOCONNECTION; - - /* - * Release the sink and mark the spot in the list as free. - */ - IAdviseSink_Release(This->Connections[dwConnection].sink); - memset(&(This->Connections[dwConnection]), 0, sizeof(DataAdviseConnection)); - return S_OK; -} - -static HRESULT WINAPI DataAdviseHolder_EnumAdvise( - IDataAdviseHolder* iface, - IEnumSTATDATA** ppenumAdvise) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - - FIXME("(%p)->(%p)\n", This, ppenumAdvise); - return E_NOTIMPL; -} - -/****************************************************************************** - * DataAdviseHolder_SendOnDataChange - */ -static HRESULT WINAPI DataAdviseHolder_SendOnDataChange( - IDataAdviseHolder* iface, - IDataObject* pDataObject, - DWORD dwReserved, - DWORD advf) -{ - DataAdviseHolder *This = (DataAdviseHolder *)iface; - DWORD index; - STGMEDIUM stg; - HRESULT res; - - TRACE("(%p)->(%p,%08lx,%08lx)\n", This, pDataObject, dwReserved, advf); - - for(index = 0; index < This->maxCons; index++) { - if(This->Connections[index].sink != NULL) { - if(!(This->Connections[index].advf & ADVF_NODATA)) { - TRACE("Calling IDataObject_GetData\n"); - res = IDataObject_GetData(pDataObject, - &(This->Connections[index].fmat), - &stg); - TRACE("returns %08lx\n", res); - } - TRACE("Calling IAdviseSink_OnDataChange\n"); - IAdviseSink_OnDataChange(This->Connections[index].sink, - &(This->Connections[index].fmat), - &stg); - TRACE("Done IAdviseSink_OnDataChange\n"); - if(This->Connections[index].advf & ADVF_ONLYONCE) { - TRACE("Removing connection\n"); - DataAdviseHolder_Unadvise(iface, index+1); - } - } - } - return S_OK; -} - -/*********************************************************************** - * API functions - */ - -/*********************************************************************** - * CreateOleAdviseHolder [OLE32.@] - */ -HRESULT WINAPI CreateOleAdviseHolder( - LPOLEADVISEHOLDER *ppOAHolder) -{ - TRACE("(%p)\n", ppOAHolder); - - /* - * Sanity check, - */ - if (ppOAHolder==NULL) - return E_POINTER; - - *ppOAHolder = OleAdviseHolderImpl_Constructor (); - - if (*ppOAHolder != NULL) - return S_OK; - - return E_OUTOFMEMORY; -} - -/****************************************************************************** - * CreateDataAdviseHolder [OLE32.@] - */ -HRESULT WINAPI CreateDataAdviseHolder( - LPDATAADVISEHOLDER* ppDAHolder) -{ - TRACE("(%p)\n", ppDAHolder); - - /* - * Sanity check, - */ - if (ppDAHolder==NULL) - return E_POINTER; - - *ppDAHolder = DataAdviseHolder_Constructor(); - - if (*ppDAHolder != NULL) - return S_OK; - - return E_OUTOFMEMORY; -} diff --git a/reactos/lib/ole32/oleproxy.c b/reactos/lib/ole32/oleproxy.c deleted file mode 100644 index 8984164085a..00000000000 --- a/reactos/lib/ole32/oleproxy.c +++ /dev/null @@ -1,526 +0,0 @@ -/* - * OLE32 proxy/stub handler - * - * Copyright 2002 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* Documentation on MSDN: - * - * (Top level COM documentation) - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/componentdevelopmentank.asp - * - * (COM Proxy) - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1q0p.asp - * - * (COM Stub) - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1lia.asp - * - * (Marshal) - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/comext_1gfn.asp - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "rpc.h" -#include "winerror.h" -#include "winreg.h" -#include "wtypes.h" - -#include "compobj_private.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -const CLSID CLSID_DfMarshal = { 0x0000030b, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} }; -const CLSID CLSID_PSFactoryBuffer = { 0x00000320, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} }; - -/* From: http://msdn.microsoft.com/library/en-us/com/cmi_m_4lda.asp - * - * The first time a client requests a pointer to an interface on a - * particular object, COM loads an IClassFactory stub in the server - * process and uses it to marshal the first pointer back to the - * client. In the client process, COM loads the generic proxy for the - * class factory object and calls its implementation of IMarshal to - * unmarshal that first pointer. COM then creates the first interface - * proxy and hands it a pointer to the RPC channel. Finally, COM returns - * the IClassFactory pointer to the client, which uses it to call - * IClassFactory::CreateInstance, passing it a reference to the interface. - * - * Back in the server process, COM now creates a new instance of the - * object, along with a stub for the requested interface. This stub marshals - * the interface pointer back to the client process, where another object - * proxy is created, this time for the object itself. Also created is a - * proxy for the requested interface, a pointer to which is returned to - * the client. With subsequent calls to other interfaces on the object, - * COM will load the appropriate interface stubs and proxies as needed. - */ -typedef struct _CFStub { - IRpcStubBufferVtbl *lpvtbl; - DWORD ref; - - LPUNKNOWN pUnkServer; -} CFStub; - -static HRESULT WINAPI -CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) { - if (IsEqualIID(&IID_IUnknown,riid)||IsEqualIID(&IID_IRpcStubBuffer,riid)) { - *ppv = (LPVOID)iface; - IUnknown_AddRef(iface); - return S_OK; - } - FIXME("(%s), interface not supported.\n",debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI -CFStub_AddRef(LPRPCSTUBBUFFER iface) { - CFStub *This = (CFStub *)iface; - return InterlockedIncrement(&This->ref); -} - -static ULONG WINAPI -CFStub_Release(LPRPCSTUBBUFFER iface) { - CFStub *This = (CFStub *)iface; - ULONG ref; - - ref = InterlockedDecrement(&This->ref); - if (!ref) HeapFree(GetProcessHeap(),0,This); - return ref; -} - -static HRESULT WINAPI -CFStub_Connect(LPRPCSTUBBUFFER iface, IUnknown *pUnkServer) { - CFStub *This = (CFStub *)iface; - - This->pUnkServer = pUnkServer; - IUnknown_AddRef(pUnkServer); - return S_OK; -} - -static void WINAPI -CFStub_Disconnect(LPRPCSTUBBUFFER iface) { - CFStub *This = (CFStub *)iface; - - IUnknown_Release(This->pUnkServer); - This->pUnkServer = NULL; -} -static HRESULT WINAPI -CFStub_Invoke( - LPRPCSTUBBUFFER iface,RPCOLEMESSAGE* msg,IRpcChannelBuffer* chanbuf -) { - CFStub *This = (CFStub *)iface; - HRESULT hres; - - if (msg->iMethod == 3) { /* CreateInstance */ - IID iid; - IClassFactory *classfac; - IUnknown *ppv; - IStream *pStm; - STATSTG ststg; - ULARGE_INTEGER newpos; - LARGE_INTEGER seekto; - ULONG res; - - if (msg->cbBuffer < sizeof(IID)) { - FIXME("Not enough bytes in buffer (%ld instead of %d)?\n",msg->cbBuffer,sizeof(IID)); - return E_FAIL; - } - memcpy(&iid,msg->Buffer,sizeof(iid)); - TRACE("->CreateInstance(%s)\n",debugstr_guid(&iid)); - hres = IUnknown_QueryInterface(This->pUnkServer,&IID_IClassFactory,(LPVOID*)&classfac); - if (hres) { - FIXME("Ole server does not provide a IClassFactory?\n"); - return hres; - } - hres = IClassFactory_CreateInstance(classfac,NULL,&iid,(LPVOID*)&ppv); - IClassFactory_Release(classfac); - if (hres) { - msg->cbBuffer = 0; - FIXME("Failed to create an instance of %s\n",debugstr_guid(&iid)); - return hres; - } - hres = CreateStreamOnHGlobal(0,TRUE,&pStm); - if (hres) { - FIXME("Failed to create stream on hglobal\n"); - return hres; - } - hres = CoMarshalInterface(pStm,&iid,ppv,0,NULL,0); - if (hres) { - FIXME("CoMarshalInterface failed, %lx!\n",hres); - msg->cbBuffer = 0; - return hres; - } - hres = IStream_Stat(pStm,&ststg,0); - if (hres) { - FIXME("Stat failed.\n"); - return hres; - } - - msg->cbBuffer = ststg.cbSize.u.LowPart; - - if (msg->Buffer) - msg->Buffer = HeapReAlloc(GetProcessHeap(),0,msg->Buffer,ststg.cbSize.u.LowPart); - else - msg->Buffer = HeapAlloc(GetProcessHeap(),0,ststg.cbSize.u.LowPart); - - seekto.u.LowPart = 0;seekto.u.HighPart = 0; - hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos); - if (hres) { - FIXME("IStream_Seek failed, %lx\n",hres); - return hres; - } - hres = IStream_Read(pStm,msg->Buffer,msg->cbBuffer,&res); - if (hres) { - FIXME("Stream Read failed, %lx\n",hres); - return hres; - } - IStream_Release(pStm); - return S_OK; - } - FIXME("(%p,%p), stub!\n",msg,chanbuf); - FIXME("iMethod is %ld\n",msg->iMethod); - FIXME("cbBuffer is %ld\n",msg->cbBuffer); - return E_FAIL; -} - -static LPRPCSTUBBUFFER WINAPI -CFStub_IsIIDSupported(LPRPCSTUBBUFFER iface,REFIID riid) { - FIXME("(%s), stub!\n",debugstr_guid(riid)); - return NULL; -} - -static ULONG WINAPI -CFStub_CountRefs(LPRPCSTUBBUFFER iface) { - FIXME("(), stub!\n"); - return 1; -} - -static HRESULT WINAPI -CFStub_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,void** ppv) { - FIXME("(%p), stub!\n",ppv); - return E_FAIL; -} -static void WINAPI -CFStub_DebugServerRelease(LPRPCSTUBBUFFER iface,void *pv) { - FIXME("(%p), stub!\n",pv); -} - -static IRpcStubBufferVtbl cfstubvt = { - CFStub_QueryInterface, - CFStub_AddRef, - CFStub_Release, - CFStub_Connect, - CFStub_Disconnect, - CFStub_Invoke, - CFStub_IsIIDSupported, - CFStub_CountRefs, - CFStub_DebugServerQueryInterface, - CFStub_DebugServerRelease -}; - -static HRESULT -CFStub_Construct(LPRPCSTUBBUFFER *ppv) { - CFStub *cfstub; - cfstub = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFStub)); - if (!cfstub) - return E_OUTOFMEMORY; - *ppv = (LPRPCSTUBBUFFER)cfstub; - cfstub->lpvtbl = &cfstubvt; - cfstub->ref = 1; - return S_OK; -} - -/* Since we create proxy buffers and classfactory in a pair, there is - * no need for 2 separate structs. Just put them in one, but remember - * the refcount. - */ -typedef struct _CFProxy { - IClassFactoryVtbl *lpvtbl_cf; - IRpcProxyBufferVtbl *lpvtbl_proxy; - DWORD ref; - - IRpcChannelBuffer *chanbuf; -} CFProxy; - -static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) { - *ppv = NULL; - if (IsEqualIID(riid,&IID_IRpcProxyBuffer)||IsEqualIID(riid,&IID_IUnknown)) { - IRpcProxyBuffer_AddRef(iface); - *ppv = (LPVOID)iface; - return S_OK; - } - FIXME("(%s), no interface.\n",debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface); - return InterlockedIncrement(&This->ref); -} - -static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface); - ULONG ref = InterlockedDecrement(&This->ref); - - if (!ref) { - IRpcChannelBuffer_Release(This->chanbuf);This->chanbuf = NULL; - HeapFree(GetProcessHeap(),0,This); - } - return ref; -} - -static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface); - - This->chanbuf = pRpcChannelBuffer; - IRpcChannelBuffer_AddRef(This->chanbuf); - return S_OK; -} -static void WINAPI IRpcProxyBufferImpl_Disconnect(LPRPCPROXYBUFFER iface) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface); - if (This->chanbuf) { - IRpcChannelBuffer_Release(This->chanbuf); - This->chanbuf = NULL; - } -} - -static HRESULT WINAPI -CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) { - *ppv = NULL; - if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) { - *ppv = (LPVOID)iface; - IClassFactory_AddRef(iface); - return S_OK; - } - if (IsEqualIID(riid,&IID_IMarshal)) /* just to avoid debug output */ - return E_NOINTERFACE; - FIXME("Unhandled interface: %s\n",debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface); - return InterlockedIncrement(&This->ref); -} - -static ULONG WINAPI CFProxy_Release(LPCLASSFACTORY iface) { - ULONG ref; - ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface); - - ref = InterlockedDecrement(&This->ref); - if (!ref) HeapFree(GetProcessHeap(),0,This); - return ref; -} - -static HRESULT WINAPI CFProxy_CreateInstance( - LPCLASSFACTORY iface, - LPUNKNOWN pUnkOuter,/* [in] */ - REFIID riid, /* [in] */ - LPVOID *ppv /* [out] */ -) { - ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface); - HRESULT hres; - LPSTREAM pStream; - HGLOBAL hGlobal; - ULONG srstatus; - RPCOLEMESSAGE msg; - - TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv); - - /* Send CreateInstance to the remote classfactory. - * - * Data: Only the 'IID'. - */ - msg.iMethod = 3; - msg.cbBuffer = sizeof(*riid); - msg.Buffer = NULL; - hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory); - if (hres) { - FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres); - return hres; - } - memcpy(msg.Buffer,riid,sizeof(*riid)); - hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus); - if (hres) { - FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres); - return hres; - } - - if (!msg.cbBuffer) /* interface not found on remote */ - return srstatus; - - /* We got back: [Marshalled Interface data] */ - TRACE("got %ld bytes data.\n",msg.cbBuffer); - hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer); - memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer); - hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream); - if (hres) { - FIXME("CreateStreamOnHGlobal failed with %lx\n",hres); - return hres; - } - hres = CoUnmarshalInterface( - pStream, - riid, - ppv - ); - IStream_Release(pStream); /* Does GlobalFree hGlobal too. */ - if (hres) { - FIXME("CoMarshalInterface failed, %lx\n",hres); - return hres; - } - return S_OK; -} - -static HRESULT WINAPI CFProxy_LockServer(LPCLASSFACTORY iface,BOOL fLock) { - /*ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);*/ - FIXME("(%d), stub!\n",fLock); - /* basically: write BOOL, read empty */ - return S_OK; -} - -static IRpcProxyBufferVtbl pspbvtbl = { - IRpcProxyBufferImpl_QueryInterface, - IRpcProxyBufferImpl_AddRef, - IRpcProxyBufferImpl_Release, - IRpcProxyBufferImpl_Connect, - IRpcProxyBufferImpl_Disconnect -}; -static IClassFactoryVtbl cfproxyvt = { - CFProxy_QueryInterface, - CFProxy_AddRef, - CFProxy_Release, - CFProxy_CreateInstance, - CFProxy_LockServer -}; - -static HRESULT -CFProxy_Construct(LPVOID *ppv,LPVOID *ppProxy) { - CFProxy *cf; - - cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy)); - if (!cf) - return E_OUTOFMEMORY; - - cf->lpvtbl_cf = &cfproxyvt; - cf->lpvtbl_proxy = &pspbvtbl; - /* 1 reference for the proxy and 1 for the object */ - cf->ref = 2; - *ppv = &(cf->lpvtbl_cf); - *ppProxy = &(cf->lpvtbl_proxy); - return S_OK; -} - - -/********************* OLE Proxy/Stub Factory ********************************/ -static HRESULT WINAPI -PSFacBuf_QueryInterface(LPPSFACTORYBUFFER iface, REFIID iid, LPVOID *ppv) { - if (IsEqualIID(iid,&IID_IPSFactoryBuffer)||IsEqualIID(iid,&IID_IUnknown)) { - *ppv = (LPVOID)iface; - /* No ref counting, static class */ - return S_OK; - } - FIXME("(%s) unknown IID?\n",debugstr_guid(iid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI PSFacBuf_AddRef(LPPSFACTORYBUFFER iface) { return 2; } -static ULONG WINAPI PSFacBuf_Release(LPPSFACTORYBUFFER iface) { return 1; } - -static HRESULT WINAPI -PSFacBuf_CreateProxy( - LPPSFACTORYBUFFER iface, IUnknown* pUnkOuter, REFIID riid, - IRpcProxyBuffer **ppProxy, LPVOID *ppv -) { - if (IsEqualIID(&IID_IClassFactory,riid) || - IsEqualIID(&IID_IUnknown,riid) - ) - return CFProxy_Construct(ppv,(LPVOID*)ppProxy); - FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid)); - return E_FAIL; -} - -static HRESULT WINAPI -PSFacBuf_CreateStub( - LPPSFACTORYBUFFER iface, REFIID riid,IUnknown *pUnkServer, - IRpcStubBuffer** ppStub -) { - HRESULT hres; - - TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub); - - if (IsEqualIID(&IID_IClassFactory,riid) || - IsEqualIID(&IID_IUnknown,riid) - ) { - hres = CFStub_Construct(ppStub); - if (!hres) - IRpcStubBuffer_Connect((*ppStub),pUnkServer); - return hres; - } - FIXME("stubbing not implemented for (%s) yet!\n",debugstr_guid(riid)); - return E_FAIL; -} - -static IPSFactoryBufferVtbl psfacbufvtbl = { - PSFacBuf_QueryInterface, - PSFacBuf_AddRef, - PSFacBuf_Release, - PSFacBuf_CreateProxy, - PSFacBuf_CreateStub -}; - -/* This is the whole PSFactoryBuffer object, just the vtableptr */ -static IPSFactoryBufferVtbl *lppsfac = &psfacbufvtbl; - -/*********************************************************************** - * DllGetClassObject [OLE32.@] - */ -HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) -{ - *ppv = NULL; - if (IsEqualIID(rclsid,&CLSID_PSFactoryBuffer)) { - *ppv = &lppsfac; - return S_OK; - } - if (IsEqualIID(rclsid,&CLSID_DfMarshal)&&( - IsEqualIID(iid,&IID_IClassFactory) || - IsEqualIID(iid,&IID_IUnknown) - ) - ) - return MARSHAL_GetStandardMarshalCF(ppv); - if (IsEqualIID(rclsid,&CLSID_StdGlobalInterfaceTable) && (IsEqualIID(iid,&IID_IClassFactory) || IsEqualIID(iid,&IID_IUnknown))) - return StdGlobalInterfaceTable_GetFactory(ppv); - - FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid)); - return CLASS_E_CLASSNOTAVAILABLE; -} diff --git a/reactos/lib/ole32/olestd.h b/reactos/lib/ole32/olestd.h deleted file mode 100644 index b5814fad4a4..00000000000 --- a/reactos/lib/ole32/olestd.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000 Abey George - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#if !defined( __WINE_OLESTD_H_ ) -#define __WINE_OLESTD_H_ - -#if !defined(__cplusplus) && !defined( __TURBOC__) -#define NONAMELESSUNION /* use strict ANSI standard (for DVOBJ.H) */ -#endif - -/* Clipboard format strings */ -#define CF_EMBEDSOURCE "Embed Source" -#define CF_EMBEDDEDOBJECT "Embedded Object" -#define CF_LINKSOURCE "Link Source" -#define CF_CUSTOMLINKSOURCE "Custom Link Source" -#define CF_OBJECTDESCRIPTOR "Object Descriptor" -#define CF_LINKSRCDESCRIPTOR "Link Source Descriptor" -#define CF_OWNERLINK "OwnerLink" -#define CF_FILENAME "FileName" - -#define OleStdQueryOleObjectData(lpformatetc) \ - (((lpformatetc)->tymed & TYMED_ISTORAGE) ? \ - NOERROR : ResultFromScode(DV_E_FORMATETC)) - -#define OleStdQueryLinkSourceData(lpformatetc) \ - (((lpformatetc)->tymed & TYMED_ISTREAM) ? \ - NOERROR : ResultFromScode(DV_E_FORMATETC)) - -#define OleStdQueryObjectDescriptorData(lpformatetc) \ - (((lpformatetc)->tymed & TYMED_HGLOBAL) ? \ - NOERROR : ResultFromScode(DV_E_FORMATETC)) - -#define OleStdQueryFormatMedium(lpformatetc, tymd) \ - (((lpformatetc)->tymed & tymd) ? \ - NOERROR : ResultFromScode(DV_E_FORMATETC)) - -/* Make an independent copy of a MetafilePict */ -#define OleStdCopyMetafilePict(hpictin, phpictout) \ - (*(phpictout) = OleDuplicateData(hpictin,CF_METAFILEPICT,GHND|GMEM_SHARE)) - -#endif /* __WINE_OLESTD_H_ */ diff --git a/reactos/lib/ole32/regsvr.c b/reactos/lib/ole32/regsvr.c deleted file mode 100644 index e624d5a59d7..00000000000 --- a/reactos/lib/ole32/regsvr.c +++ /dev/null @@ -1,865 +0,0 @@ -/* - * self-registerable dll functions for ole32.dll - * - * Copyright (C) 2003 John K. Hohm - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winreg.h" -#include "winerror.h" - -#include "ole2.h" -#include "olectl.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -/* - * Near the bottom of this file are the exported DllRegisterServer and - * DllUnregisterServer, which make all this worthwhile. - */ - -/*********************************************************************** - * interface for self-registering - */ -struct regsvr_interface -{ - IID const *iid; /* NULL for end of list */ - LPCSTR name; /* can be NULL to omit */ - IID const *base_iid; /* can be NULL to omit */ - int num_methods; /* can be <0 to omit */ - CLSID const *ps_clsid; /* can be NULL to omit */ - CLSID const *ps_clsid32; /* can be NULL to omit */ -}; - -static HRESULT register_interfaces(struct regsvr_interface const *list); -static HRESULT unregister_interfaces(struct regsvr_interface const *list); - -struct regsvr_coclass -{ - CLSID const *clsid; /* NULL for end of list */ - LPCSTR name; /* can be NULL to omit */ - LPCSTR ips; /* can be NULL to omit */ - LPCSTR ips32; /* can be NULL to omit */ - LPCSTR ips32_tmodel; /* can be NULL to omit */ -}; - -static HRESULT register_coclasses(struct regsvr_coclass const *list); -static HRESULT unregister_coclasses(struct regsvr_coclass const *list); - -/*********************************************************************** - * static string constants - */ -static WCHAR const interface_keyname[10] = { - 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 }; -static WCHAR const base_ifa_keyname[14] = { - 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', - 'e', 0 }; -static WCHAR const num_methods_keyname[11] = { - 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 }; -static WCHAR const ps_clsid_keyname[15] = { - 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', - 'i', 'd', 0 }; -static WCHAR const ps_clsid32_keyname[17] = { - 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', - 'i', 'd', '3', '2', 0 }; -static WCHAR const clsid_keyname[6] = { - 'C', 'L', 'S', 'I', 'D', 0 }; -static WCHAR const ips_keyname[13] = { - 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', - 0 }; -static WCHAR const ips32_keyname[15] = { - 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', - '3', '2', 0 }; -static char const tmodel_valuename[] = "ThreadingModel"; - -/*********************************************************************** - * static helper functions - */ -static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid); -static LONG register_key_defvalueW(HKEY base, WCHAR const *name, - WCHAR const *value); -static LONG register_key_defvalueA(HKEY base, WCHAR const *name, - char const *value); -static LONG recursive_delete_key(HKEY key); - - -/*********************************************************************** - * register_interfaces - */ -static HRESULT register_interfaces(struct regsvr_interface const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY interface_key; - - res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &interface_key, NULL); - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->iid; ++list) { - WCHAR buf[39]; - HKEY iid_key; - - StringFromGUID2(list->iid, buf, 39); - res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &iid_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_interface_key; - - if (list->name) { - res = RegSetValueExA(iid_key, NULL, 0, REG_SZ, - (CONST BYTE*)(list->name), - strlen(list->name) + 1); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->base_iid) { - register_key_guid(iid_key, base_ifa_keyname, list->base_iid); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (0 <= list->num_methods) { - static WCHAR const fmt[3] = { '%', 'd', 0 }; - HKEY key; - - res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - - wsprintfW(buf, fmt, list->num_methods); - res = RegSetValueExW(key, NULL, 0, REG_SZ, - (CONST BYTE*)buf, - (lstrlenW(buf) + 1) * sizeof(WCHAR)); - RegCloseKey(key); - - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->ps_clsid) { - register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - if (list->ps_clsid32) { - register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32); - if (res != ERROR_SUCCESS) goto error_close_iid_key; - } - - error_close_iid_key: - RegCloseKey(iid_key); - } - -error_close_interface_key: - RegCloseKey(interface_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * unregister_interfaces - */ -static HRESULT unregister_interfaces(struct regsvr_interface const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY interface_key; - - res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, - KEY_READ | KEY_WRITE, &interface_key); - if (res == ERROR_FILE_NOT_FOUND) return S_OK; - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->iid; ++list) { - WCHAR buf[39]; - HKEY iid_key; - - StringFromGUID2(list->iid, buf, 39); - res = RegOpenKeyExW(interface_key, buf, 0, - KEY_READ | KEY_WRITE, &iid_key); - if (res == ERROR_FILE_NOT_FOUND) { - res = ERROR_SUCCESS; - continue; - } - if (res != ERROR_SUCCESS) goto error_close_interface_key; - res = recursive_delete_key(iid_key); - RegCloseKey(iid_key); - if (res != ERROR_SUCCESS) goto error_close_interface_key; - } - -error_close_interface_key: - RegCloseKey(interface_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * register_coclasses - */ -static HRESULT register_coclasses(struct regsvr_coclass const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY coclass_key; - - res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL); - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->clsid; ++list) { - WCHAR buf[39]; - HKEY clsid_key; - - StringFromGUID2(list->clsid, buf, 39); - res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - - if (list->name) { - res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, - (CONST BYTE*)(list->name), - strlen(list->name) + 1); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->ips) { - res = register_key_defvalueA(clsid_key, ips_keyname, list->ips); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - if (list->ips32) { - HKEY ips32_key; - - res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, - &ips32_key, NULL); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - - res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, - (CONST BYTE*)list->ips32, - lstrlenA(list->ips32) + 1); - if (res == ERROR_SUCCESS && list->ips32_tmodel) - res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ, - (CONST BYTE*)list->ips32_tmodel, - strlen(list->ips32_tmodel) + 1); - RegCloseKey(ips32_key); - if (res != ERROR_SUCCESS) goto error_close_clsid_key; - } - - error_close_clsid_key: - RegCloseKey(clsid_key); - } - -error_close_coclass_key: - RegCloseKey(coclass_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * unregister_coclasses - */ -static HRESULT unregister_coclasses(struct regsvr_coclass const *list) -{ - LONG res = ERROR_SUCCESS; - HKEY coclass_key; - - res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, - KEY_READ | KEY_WRITE, &coclass_key); - if (res == ERROR_FILE_NOT_FOUND) return S_OK; - if (res != ERROR_SUCCESS) goto error_return; - - for (; res == ERROR_SUCCESS && list->clsid; ++list) { - WCHAR buf[39]; - HKEY clsid_key; - - StringFromGUID2(list->clsid, buf, 39); - res = RegOpenKeyExW(coclass_key, buf, 0, - KEY_READ | KEY_WRITE, &clsid_key); - if (res == ERROR_FILE_NOT_FOUND) { - res = ERROR_SUCCESS; - continue; - } - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - res = recursive_delete_key(clsid_key); - RegCloseKey(clsid_key); - if (res != ERROR_SUCCESS) goto error_close_coclass_key; - } - -error_close_coclass_key: - RegCloseKey(coclass_key); -error_return: - return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; -} - -/*********************************************************************** - * regsvr_key_guid - */ -static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid) -{ - WCHAR buf[39]; - - StringFromGUID2(guid, buf, 39); - return register_key_defvalueW(base, name, buf); -} - -/*********************************************************************** - * regsvr_key_defvalueW - */ -static LONG register_key_defvalueW( - HKEY base, - WCHAR const *name, - WCHAR const *value) -{ - LONG res; - HKEY key; - - res = RegCreateKeyExW(base, name, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) return res; - res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value, - (lstrlenW(value) + 1) * sizeof(WCHAR)); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * regsvr_key_defvalueA - */ -static LONG register_key_defvalueA( - HKEY base, - WCHAR const *name, - char const *value) -{ - LONG res; - HKEY key; - - res = RegCreateKeyExW(base, name, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL); - if (res != ERROR_SUCCESS) return res; - res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value, - lstrlenA(value) + 1); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * recursive_delete_key - */ -static LONG recursive_delete_key(HKEY key) -{ - LONG res; - WCHAR subkey_name[MAX_PATH]; - DWORD cName; - HKEY subkey; - - for (;;) { - cName = sizeof(subkey_name) / sizeof(WCHAR); - res = RegEnumKeyExW(key, 0, subkey_name, &cName, - NULL, NULL, NULL, NULL); - if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) { - res = ERROR_SUCCESS; /* presumably we're done enumerating */ - break; - } - res = RegOpenKeyExW(key, subkey_name, 0, - KEY_READ | KEY_WRITE, &subkey); - if (res == ERROR_FILE_NOT_FOUND) continue; - if (res != ERROR_SUCCESS) break; - - res = recursive_delete_key(subkey); - RegCloseKey(subkey); - if (res != ERROR_SUCCESS) break; - } - - if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0); - return res; -} - -/*********************************************************************** - * coclass list - */ -static GUID const CLSID_FileMoniker = { - 0x00000303, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} }; - -static GUID const CLSID_ItemMoniker = { - 0x00000304, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} }; - -/* FIXME: DfMarshal and PSFactoryBuffer are defined elsewhere too */ - -static GUID const CLSID_DfMarshal = { - 0x0000030B, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} }; - -static GUID const CLSID_PSFactoryBuffer = { - 0x00000320, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} }; - -static struct regsvr_coclass const coclass_list[] = { - { &CLSID_FileMoniker, - "FileMoniker", - NULL, - "ole32.dll", - "Both" - }, - { &CLSID_ItemMoniker, - "ItemMoniker", - NULL, - "ole32.dll", - "Both" - }, - { &CLSID_DfMarshal, - "DfMarshal", - NULL, - "ole32.dll", - "Both" - }, - { &CLSID_PSFactoryBuffer, - "PSFactoryBuffer", - NULL, - "ole32.dll", - "Both" - }, - { &CLSID_StdGlobalInterfaceTable, - "StdGlobalInterfaceTable", - NULL, - "ole32.dll", - "Apartment" - }, - { NULL } /* list terminator */ -}; - -/*********************************************************************** - * interface list - */ - -/* FIXME: perhaps the interfaces that are proxied by another dll - * should be registered in that dll? Or maybe the choice of proxy is - * arbitrary at this point? */ - -static GUID const CLSID_PSFactoryBuffer_ole2disp = { - 0x00020420, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} }; - -static GUID const CLSID_PSFactoryBuffer_oleaut32 = { - 0xB196B286, 0xBAB4, 0x101A, {0xB6,0x9C,0x00,0xAA,0x00,0x34,0x1D,0x07} }; - -/* FIXME: these interfaces should be defined in ocidl.idl */ - -static IID const IID_IFontEventsDisp = { - 0x4EF6100A, 0xAF88, 0x11D0, {0x98,0x46,0x00,0xC0,0x4F,0xC2,0x99,0x93} }; - -static IID const IID_IProvideMultipleClassInfo = { - 0xA7ABA9C1, 0x8983, 0x11CF, {0x8F,0x20,0x00,0x80,0x5F,0x2C,0xD0,0x64} }; - -static struct regsvr_interface const interface_list[] = { - { &IID_IUnknown, - "IUnknown", - NULL, - 3, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IClassFactory, - "IClassFactory", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IStorage, - "IStorage", - NULL, - 18, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IStream, - "IStream", - NULL, - 14, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IPersistStorage, - "IPersistStorage", - &IID_IPersist, - 10, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IDataObject, - "IDataObject", - NULL, - 12, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IAdviseSink, - "IAdviseSink", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IOleObject, - "IOleObject", - NULL, - 24, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IOleClientSite, - "IOleClientSite", - NULL, - 9, - NULL, - &CLSID_PSFactoryBuffer - }, - { &IID_IDispatch, - "IDispatch", - NULL, - 7, - &CLSID_PSFactoryBuffer_ole2disp, - &CLSID_PSFactoryBuffer_ole2disp - }, - { &IID_ITypeLib2, - "ITypeLib2", - NULL, - 16, - NULL, - &CLSID_PSFactoryBuffer_ole2disp - }, - { &IID_ITypeInfo2, - "ITypeInfo2", - NULL, - 32, - NULL, - &CLSID_PSFactoryBuffer_ole2disp - }, - { &IID_IPropertyPage2, - "IPropertyPage2", - NULL, - 15, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IErrorInfo, - "IErrorInfo", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_ICreateErrorInfo, - "ICreateErrorInfo", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPersistPropertyBag2, - "IPersistPropertyBag2", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPropertyBag2, - "IPropertyBag2", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IErrorLog, - "IErrorLog", - NULL, - 4, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPerPropertyBrowsing, - "IPerPropertyBrowsing", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPersistPropertyBag, - "IPersistPropertyBag", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IAdviseSinkEx, - "IAdviseSinkEx", - NULL, - 9, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IFontEventsDisp, - "IFontEventsDisp", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPropertyBag, - "IPropertyBag", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPointerInactive, - "IPointerInactive", - NULL, - 6, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_ISimpleFrameSite, - "ISimpleFrameSite", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPicture, - "IPicture", - NULL, - 17, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPictureDisp, - "IPictureDisp", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPersistStreamInit, - "IPersistStreamInit", - NULL, - 9, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleUndoUnit, - "IOleUndoUnit", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPropertyNotifySink, - "IPropertyNotifySink", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleInPlaceSiteEx, - "IOleInPlaceSiteEx", - NULL, - 18, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleParentUndoUnit, - "IOleParentUndoUnit", - NULL, - 12, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IProvideClassInfo2, - "IProvideClassInfo2", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IProvideMultipleClassInfo, - "IProvideMultipleClassInfo", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IProvideClassInfo, - "IProvideClassInfo", - NULL, - 4, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IConnectionPointContainer, - "IConnectionPointContainer", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IEnumConnectionPoints, - "IEnumConnectionPoints", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IConnectionPoint, - "IConnectionPoint", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IEnumConnections, - "IEnumConnections", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleControl, - "IOleControl", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleControlSite, - "IOleControlSite", - NULL, - 10, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_ISpecifyPropertyPages, - "ISpecifyPropertyPages", - NULL, - 4, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPropertyPageSite, - "IPropertyPageSite", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPropertyPage, - "IPropertyPage", - NULL, - 14, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IClassFactory2, - "IClassFactory2", - NULL, - 8, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IEnumOleUndoUnits, - "IEnumOleUndoUnits", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IPersistMemory, - "IPersistMemory", - NULL, - 9, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IFont, - "IFont", - NULL, - 27, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IFontDisp, - "IFontDisp", - NULL, - 7, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IQuickActivate, - "IQuickActivate", - NULL, - 6, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IOleUndoManager, - "IOleUndoManager", - NULL, - 15, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { &IID_IObjectWithSite, - "IObjectWithSite", - NULL, - 5, - NULL, - &CLSID_PSFactoryBuffer_oleaut32 - }, - { NULL } /* list terminator */ -}; - -/*********************************************************************** - * DllRegisterServer (OLE32.@) - */ -HRESULT WINAPI OLE32_DllRegisterServer() -{ - HRESULT hr; - - TRACE("\n"); - - hr = register_coclasses(coclass_list); - if (SUCCEEDED(hr)) - hr = register_interfaces(interface_list); - return hr; -} - -/*********************************************************************** - * DllUnregisterServer (OLE32.@) - */ -HRESULT WINAPI OLE32_DllUnregisterServer() -{ - HRESULT hr; - - TRACE("\n"); - - hr = unregister_coclasses(coclass_list); - if (SUCCEEDED(hr)) - hr = unregister_interfaces(interface_list); - return hr; -} diff --git a/reactos/lib/ole32/rpc.c b/reactos/lib/ole32/rpc.c deleted file mode 100644 index 2dd08623908..00000000000 --- a/reactos/lib/ole32/rpc.c +++ /dev/null @@ -1,805 +0,0 @@ -/* - * (Local) RPC Stuff - * - * Copyright 2002 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "objbase.h" -#include "ole2.h" -#include "ole2ver.h" -#include "rpc.h" -#include "winerror.h" -#include "winreg.h" -#include "wownt32.h" -#include "wtypes.h" -#include "wine/unicode.h" -#include "wine/winbase16.h" -#include "compobj_private.h" -#include "ifs.h" - -#include "compobj_private.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); - -#define REQTYPE_REQUEST 0 -typedef struct _wine_rpc_request_header { - DWORD reqid; - wine_marshal_id mid; - DWORD iMethod; - DWORD cbBuffer; -} wine_rpc_request_header; - -#define REQTYPE_RESPONSE 1 -typedef struct _wine_rpc_response_header { - DWORD reqid; - DWORD cbBuffer; - DWORD retval; -} wine_rpc_response_header; - -/* used when shutting down a pipe, e.g. at the end of a process */ -#define REQTYPE_DISCONNECT 2 -typedef struct _wine_rpc_disconnect_header { - DWORD reqid; - wine_marshal_id mid; /* mid of stub to delete */ -} wine_rpc_disconnect_header; - - -#define REQSTATE_START 0 -#define REQSTATE_REQ_QUEUED 1 -#define REQSTATE_REQ_WAITING_FOR_REPLY 2 -#define REQSTATE_REQ_GOT 3 -#define REQSTATE_INVOKING 4 -#define REQSTATE_RESP_QUEUED 5 -#define REQSTATE_RESP_GOT 6 -#define REQSTATE_DONE 6 - -typedef struct _wine_rpc_request { - int state; - HANDLE hPipe; /* temp copy of handle */ - wine_rpc_request_header reqh; - wine_rpc_response_header resph; - LPBYTE Buffer; -} wine_rpc_request; - -static wine_rpc_request **reqs = NULL; -static int nrofreqs = 0; - -/* This pipe is _thread_ based, each thread which talks to a remote - * apartment (mid) has its own pipe */ -typedef struct _wine_pipe { - wine_marshal_id mid; /* target mid */ - DWORD tid; /* thread which owns this outgoing pipe */ - HANDLE hPipe; - - int pending; - HANDLE hThread; - CRITICAL_SECTION crit; -} wine_pipe; - -static wine_pipe *pipes = NULL; -static int nrofpipes = 0; - -typedef struct _PipeBuf { - IRpcChannelBufferVtbl *lpVtbl; - DWORD ref; - - wine_marshal_id mid; - wine_pipe *pipe; -} PipeBuf; - -static HRESULT WINAPI -read_pipe(HANDLE hf, LPVOID ptr, DWORD size) { - DWORD res; - if (!ReadFile(hf,ptr,size,&res,NULL)) { - FIXME("Failed to read from %p, le is %lx\n",hf,GetLastError()); - return E_FAIL; - } - if (res!=size) { - FIXME("Read only %ld of %ld bytes from %p.\n",res,size,hf); - return E_FAIL; - } - return S_OK; -} - -static void -drs(LPCSTR where) { -#if 0 - static int nrofreaders = 0; - - int i, states[10]; - - memset(states,0,sizeof(states)); - for (i=nrofreqs;i--;) - states[reqs[i]->state]++; - FIXME("%lx/%s/%d: rq %d, w %d, rg %d, rsq %d, rsg %d, d %d\n", - GetCurrentProcessId(), - where, - nrofreaders, - states[REQSTATE_REQ_QUEUED], - states[REQSTATE_REQ_WAITING_FOR_REPLY], - states[REQSTATE_REQ_GOT], - states[REQSTATE_RESP_QUEUED], - states[REQSTATE_RESP_GOT], - states[REQSTATE_DONE] - ); -#endif - - return ; -} - -static HRESULT WINAPI -write_pipe(HANDLE hf, LPVOID ptr, DWORD size) { - DWORD res; - if (!WriteFile(hf,ptr,size,&res,NULL)) { - FIXME("Failed to write to %p, le is %lx\n",hf,GetLastError()); - return E_FAIL; - } - if (res!=size) { - FIXME("Wrote only %ld of %ld bytes to %p.\n",res,size,hf); - return E_FAIL; - } - return S_OK; -} - -static DWORD WINAPI _StubReaderThread(LPVOID); - -static HRESULT -PIPE_RegisterPipe(wine_marshal_id *mid, HANDLE hPipe, BOOL startreader) { - int i; - char pipefn[100]; - wine_pipe *new_pipes; - - for (i=0;iprocessid) - return S_OK; - if (pipes) - new_pipes=(wine_pipe*)HeapReAlloc(GetProcessHeap(),0,pipes,sizeof(pipes[0])*(nrofpipes+1)); - else - new_pipes=(wine_pipe*)HeapAlloc(GetProcessHeap(),0,sizeof(pipes[0])); - if (!new_pipes) return E_OUTOFMEMORY; - pipes = new_pipes; - sprintf(pipefn,OLESTUBMGR"_%08lx",mid->processid); - memcpy(&(pipes[nrofpipes].mid),mid,sizeof(*mid)); - pipes[nrofpipes].hPipe = hPipe; - InitializeCriticalSection(&(pipes[nrofpipes].crit)); - nrofpipes++; - if (startreader) { - pipes[nrofpipes-1].hThread = CreateThread(NULL,0,_StubReaderThread,(LPVOID)(pipes+(nrofpipes-1)),0,&(pipes[nrofpipes-1].tid)); - } else { - pipes[nrofpipes-1].tid = GetCurrentThreadId(); - } - return S_OK; -} - -static HANDLE -PIPE_FindByMID(wine_marshal_id *mid) { - int i; - for (i=0;iprocessid) && - (GetCurrentThreadId()==pipes[i].tid) - ) - return pipes[i].hPipe; - return INVALID_HANDLE_VALUE; -} - -static wine_pipe* -PIPE_GetFromMID(wine_marshal_id *mid) { - int i; - for (i=0;iprocessid) && - (GetCurrentThreadId()==pipes[i].tid) - ) - return pipes+i; - } - return NULL; -} - -static HRESULT -RPC_GetRequest(wine_rpc_request **req) { - static int reqid = 0xdeadbeef; - int i; - - for (i=0;istate == REQSTATE_DONE) { - reqs[i]->reqh.reqid = reqid++; - reqs[i]->resph.reqid = reqs[i]->reqh.reqid; - reqs[i]->hPipe = INVALID_HANDLE_VALUE; - *req = reqs[i]; - reqs[i]->state = REQSTATE_START; - return S_OK; - } - } - /* create new */ - if (reqs) - reqs = (wine_rpc_request**)HeapReAlloc( - GetProcessHeap(), - HEAP_ZERO_MEMORY, - reqs, - sizeof(wine_rpc_request*)*(nrofreqs+1) - ); - else - reqs = (wine_rpc_request**)HeapAlloc( - GetProcessHeap(), - HEAP_ZERO_MEMORY, - sizeof(wine_rpc_request*) - ); - if (!reqs) - return E_OUTOFMEMORY; - reqs[nrofreqs] = (wine_rpc_request*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(wine_rpc_request)); - reqs[nrofreqs]->reqh.reqid = reqid++; - reqs[nrofreqs]->resph.reqid = reqs[nrofreqs]->reqh.reqid; - reqs[nrofreqs]->hPipe = INVALID_HANDLE_VALUE; - *req = reqs[nrofreqs]; - reqs[nrofreqs]->state = REQSTATE_START; - nrofreqs++; - return S_OK; -} - -static void -RPC_FreeRequest(wine_rpc_request *req) { - req->state = REQSTATE_DONE; /* Just reuse slot. */ - return; -} - -static HRESULT WINAPI -PipeBuf_QueryInterface( - LPRPCCHANNELBUFFER iface,REFIID riid,LPVOID *ppv -) { - *ppv = NULL; - if (IsEqualIID(riid,&IID_IRpcChannelBuffer) || IsEqualIID(riid,&IID_IUnknown)) { - *ppv = (LPVOID)iface; - IUnknown_AddRef(iface); - return S_OK; - } - return E_NOINTERFACE; -} - -static ULONG WINAPI -PipeBuf_AddRef(LPRPCCHANNELBUFFER iface) { - PipeBuf *This = (PipeBuf *)iface; - return InterlockedIncrement(&This->ref); -} - -static ULONG WINAPI -PipeBuf_Release(LPRPCCHANNELBUFFER iface) { - PipeBuf *This = (PipeBuf *)iface; - ULONG ref; - wine_rpc_disconnect_header header; - HANDLE pipe; - DWORD reqtype = REQTYPE_DISCONNECT; - - ref = InterlockedDecrement(&This->ref); - if (ref) - return ref; - - FIXME("Free all stuff\n"); - - memcpy(&header.mid, &This->mid, sizeof(wine_marshal_id)); - - pipe = PIPE_FindByMID(&This->mid); - - write_pipe(pipe, &reqtype, sizeof(reqtype)); - write_pipe(pipe, &header, sizeof(wine_rpc_disconnect_header)); - - TRACE("written disconnect packet\n"); - - HeapFree(GetProcessHeap(),0,This); - return 0; -} - -static HRESULT WINAPI -PipeBuf_GetBuffer( - LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg,REFIID riid -) { - /*PipeBuf *This = (PipeBuf *)iface;*/ - - TRACE("(%p,%s)\n",msg,debugstr_guid(riid)); - /* probably reuses IID in real. */ - if (msg->cbBuffer && (msg->Buffer == NULL)) - msg->Buffer = HeapAlloc(GetProcessHeap(),0,msg->cbBuffer); - return S_OK; -} - -static HRESULT -COM_InvokeAndRpcSend(wine_rpc_request *req) { - IRpcStubBuffer *stub; - RPCOLEMESSAGE msg; - HRESULT hres; - DWORD reqtype; - - hres = MARSHAL_Find_Stub_Buffer(&(req->reqh.mid),&stub); - if (hres) { - ERR("Stub not found?\n"); - return hres; - } - msg.Buffer = req->Buffer; - msg.iMethod = req->reqh.iMethod; - msg.cbBuffer = req->reqh.cbBuffer; - msg.dataRepresentation = NDR_LOCAL_DATA_REPRESENTATION; - req->state = REQSTATE_INVOKING; - req->resph.retval = IRpcStubBuffer_Invoke(stub,&msg,NULL); - IUnknown_Release(stub); - req->Buffer = msg.Buffer; - req->resph.cbBuffer = msg.cbBuffer; - reqtype = REQTYPE_RESPONSE; - hres = write_pipe(req->hPipe,&reqtype,sizeof(reqtype)); - if (hres) return hres; - hres = write_pipe(req->hPipe,&(req->resph),sizeof(req->resph)); - if (hres) return hres; - hres = write_pipe(req->hPipe,req->Buffer,req->resph.cbBuffer); - if (hres) return hres; - req->state = REQSTATE_DONE; - drs("invoke"); - return S_OK; -} - -static HRESULT COM_RpcReceive(wine_pipe *xpipe); - -static HRESULT -RPC_QueueRequestAndWait(wine_rpc_request *req) { - int i; - wine_rpc_request *xreq; - HRESULT hres; - DWORD reqtype; - wine_pipe *xpipe = PIPE_GetFromMID(&(req->reqh.mid)); - - if (!xpipe) { - FIXME("no pipe found.\n"); - return E_POINTER; - } - if (GetCurrentProcessId() == req->reqh.mid.processid) { - ERR("In current process?\n"); - return E_FAIL; - } - req->hPipe = xpipe->hPipe; - req->state = REQSTATE_REQ_WAITING_FOR_REPLY; - reqtype = REQTYPE_REQUEST; - hres = write_pipe(req->hPipe,&reqtype,sizeof(reqtype)); - if (hres) return hres; - hres = write_pipe(req->hPipe,&(req->reqh),sizeof(req->reqh)); - if (hres) return hres; - hres = write_pipe(req->hPipe,req->Buffer,req->reqh.cbBuffer); - if (hres) return hres; - - /* This loop is about allowing re-entrancy. While waiting for the - * response to one RPC we may receive a request starting another. */ - while (!hres) { - hres = COM_RpcReceive(xpipe); - if (hres) break; - - for (i=0;istate==REQSTATE_REQ_GOT) && (xreq->hPipe==req->hPipe)) { - hres = COM_InvokeAndRpcSend(xreq); - if (hres) break; - } - } - if (req->state == REQSTATE_RESP_GOT) - return S_OK; - } - if (FAILED(hres)) - WARN("-- 0x%08lx\n", hres); - return hres; -} - -static HRESULT WINAPI -PipeBuf_SendReceive( - LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg,ULONG *status -) { - PipeBuf *This = (PipeBuf *)iface; - wine_rpc_request *req; - HRESULT hres; - - TRACE("()\n"); - - if (This->mid.processid == GetCurrentProcessId()) { - ERR("Need to call directly!\n"); - return E_FAIL; - } - - hres = RPC_GetRequest(&req); - if (hres) return hres; - req->reqh.iMethod = msg->iMethod; - req->reqh.cbBuffer = msg->cbBuffer; - memcpy(&(req->reqh.mid),&(This->mid),sizeof(This->mid)); - req->Buffer = msg->Buffer; - hres = RPC_QueueRequestAndWait(req); - if (hres) { - RPC_FreeRequest(req); - return hres; - } - msg->cbBuffer = req->resph.cbBuffer; - msg->Buffer = req->Buffer; - *status = req->resph.retval; - RPC_FreeRequest(req); - return S_OK; -} - - -static HRESULT WINAPI -PipeBuf_FreeBuffer(LPRPCCHANNELBUFFER iface,RPCOLEMESSAGE* msg) { - FIXME("(%p), stub!\n",msg); - return E_FAIL; -} - -static HRESULT WINAPI -PipeBuf_GetDestCtx( - LPRPCCHANNELBUFFER iface,DWORD* pdwDestContext,void** ppvDestContext -) { - FIXME("(%p,%p), stub!\n",pdwDestContext,ppvDestContext); - return E_FAIL; -} - -static HRESULT WINAPI -PipeBuf_IsConnected(LPRPCCHANNELBUFFER iface) { - FIXME("(), stub!\n"); - return S_OK; -} - -static IRpcChannelBufferVtbl pipebufvt = { - PipeBuf_QueryInterface, - PipeBuf_AddRef, - PipeBuf_Release, - PipeBuf_GetBuffer, - PipeBuf_SendReceive, - PipeBuf_FreeBuffer, - PipeBuf_GetDestCtx, - PipeBuf_IsConnected -}; - -HRESULT -PIPE_GetNewPipeBuf(wine_marshal_id *mid, IRpcChannelBuffer **pipebuf) { - wine_marshal_id ourid; - DWORD res; - HANDLE hPipe; - HRESULT hres; - PipeBuf *pbuf; - - hPipe = PIPE_FindByMID(mid); - if (hPipe == INVALID_HANDLE_VALUE) { - char pipefn[200]; - sprintf(pipefn,OLESTUBMGR"_%08lx",mid->processid); - hPipe = CreateFileA( - pipefn, - GENERIC_READ|GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - 0 - ); - if (hPipe == INVALID_HANDLE_VALUE) { - FIXME("Could not open named pipe %s, le is %lx\n",pipefn,GetLastError()); - return E_FAIL; - } - hres = PIPE_RegisterPipe(mid, hPipe, FALSE); - if (hres) return hres; - memset(&ourid,0,sizeof(ourid)); - ourid.processid = GetCurrentProcessId(); - if (!WriteFile(hPipe,&ourid,sizeof(ourid),&res,NULL)||(res!=sizeof(ourid))) { - ERR("Failed writing startup mid!\n"); - return E_FAIL; - } - } - pbuf = (PipeBuf*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PipeBuf)); - pbuf->lpVtbl = &pipebufvt; - pbuf->ref = 1; - memcpy(&(pbuf->mid),mid,sizeof(*mid)); - *pipebuf = (IRpcChannelBuffer*)pbuf; - return S_OK; -} - -static HRESULT -create_server(REFCLSID rclsid) { - static const WCHAR embedding[] = { ' ', '-','E','m','b','e','d','d','i','n','g',0 }; - HKEY key; - char buf[200]; - HRESULT hres = E_UNEXPECTED; - char xclsid[80]; - WCHAR exe[MAX_PATH+1]; - DWORD exelen = sizeof(exe); - WCHAR command[MAX_PATH+sizeof(embedding)/sizeof(WCHAR)]; - STARTUPINFOW sinfo; - PROCESS_INFORMATION pinfo; - - WINE_StringFromCLSID((LPCLSID)rclsid,xclsid); - - sprintf(buf,"CLSID\\%s\\LocalServer32",xclsid); - hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key); - - if (hres != ERROR_SUCCESS) { - WARN("CLSID %s not registered as LocalServer32\n", xclsid); - return REGDB_E_READREGDB; /* Probably */ - } - - memset(exe,0,sizeof(exe)); - hres= RegQueryValueExW(key, NULL, NULL, NULL, (LPBYTE)exe, &exelen); - RegCloseKey(key); - if (hres) { - WARN("No default value for LocalServer32 key\n"); - return REGDB_E_CLASSNOTREG; /* FIXME: check retval */ - } - - memset(&sinfo,0,sizeof(sinfo)); - sinfo.cb = sizeof(sinfo); - - /* EXE servers are started with the -Embedding switch. MSDN also claims /Embedding is used, - 9x does -Embedding, perhaps an 9x/NT difference? */ - - strcpyW(command, exe); - strcatW(command, embedding); - - TRACE("activating local server '%s' for %s\n", debugstr_w(command), xclsid); - - if (!CreateProcessW(exe, command, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) { - WARN("failed to run local server %s\n", debugstr_w(exe)); - return E_FAIL; - } - - return S_OK; -} -/* http://msdn.microsoft.com/library/en-us/dnmsj99/html/com0199.asp, Figure 4 */ -HRESULT create_marshalled_proxy(REFCLSID rclsid, REFIID iid, LPVOID *ppv) { - HRESULT hres; - HANDLE hPipe; - char pipefn[200]; - DWORD res,bufferlen; - char marshalbuffer[200]; - IStream *pStm; - LARGE_INTEGER seekto; - ULARGE_INTEGER newpos; - int tries = 0; -#define MAXTRIES 10000 - - TRACE("rclsid=%s, iid=%s\n", debugstr_guid(rclsid), debugstr_guid(iid)); - - strcpy(pipefn,PIPEPREF); - WINE_StringFromCLSID(rclsid,pipefn+strlen(PIPEPREF)); - - while (tries++=MAXTRIES) - return E_NOINTERFACE; - hres = CreateStreamOnHGlobal(0,TRUE,&pStm); - if (hres) return hres; - hres = IStream_Write(pStm,marshalbuffer,bufferlen,&res); - if (hres) goto out; - seekto.u.LowPart = 0;seekto.u.HighPart = 0; - hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos); - hres = CoUnmarshalInterface(pStm,&IID_IClassFactory,ppv); -out: - IStream_Release(pStm); - return hres; -} - - -static void WINAPI -PIPE_StartRequestThread(HANDLE xhPipe) { - wine_marshal_id remoteid; - HRESULT hres; - - hres = read_pipe(xhPipe,&remoteid,sizeof(remoteid)); - if (hres) { - ERR("Failed to read remote mid!\n"); - return; - } - PIPE_RegisterPipe(&remoteid,xhPipe, TRUE); -} - -static HRESULT -COM_RpcReceive(wine_pipe *xpipe) { - DWORD reqtype; - HRESULT hres = S_OK; - HANDLE xhPipe = xpipe->hPipe; - - /*FIXME("%lx %d reading reqtype\n",GetCurrentProcessId(),xhPipe);*/ - hres = read_pipe(xhPipe,&reqtype,sizeof(reqtype)); - if (hres) goto end; - EnterCriticalSection(&(xpipe->crit)); - /*FIXME("%lx got reqtype %ld\n",GetCurrentProcessId(),reqtype);*/ - - if (reqtype == REQTYPE_DISCONNECT) { /* only received by servers */ - wine_rpc_disconnect_header header; - IRpcStubBuffer *stub; - ULONG ret; - - hres = read_pipe(xhPipe, &header, sizeof(header)); - if (hres) { - ERR("could not read disconnect header\n"); - goto end; - } - - TRACE("read disconnect header\n"); - - hres = MARSHAL_Find_Stub_Buffer(&header.mid, &stub); - if (hres) { - ERR("could not locate stub to disconnect, mid.objectid=%p\n", (void*)header.mid.objectid); - goto end; - } - - - /* release reference added by MARSHAL_Find_Stub_Buffer call */ - IRpcStubBuffer_Release(stub); - /* release it for real */ - ret = IRpcStubBuffer_Release(stub); - /* FIXME: race */ - if (ret == 0) - MARSHAL_Invalidate_Stub_From_MID(&header.mid); - goto end; - } else if (reqtype == REQTYPE_REQUEST) { - wine_rpc_request *xreq; - RPC_GetRequest(&xreq); - xreq->hPipe = xhPipe; - hres = read_pipe(xhPipe,&(xreq->reqh),sizeof(xreq->reqh)); - if (hres) goto end; - xreq->resph.reqid = xreq->reqh.reqid; - xreq->Buffer = HeapAlloc(GetProcessHeap(),0, xreq->reqh.cbBuffer); - hres = read_pipe(xhPipe,xreq->Buffer,xreq->reqh.cbBuffer); - if (hres) goto end; - xreq->state = REQSTATE_REQ_GOT; - goto end; - } else if (reqtype == REQTYPE_RESPONSE) { - wine_rpc_response_header resph; - int i; - - hres = read_pipe(xhPipe,&resph,sizeof(resph)); - if (hres) goto end; - for (i=nrofreqs;i--;) { - wine_rpc_request *xreq = reqs[i]; - if (xreq->state != REQSTATE_REQ_WAITING_FOR_REPLY) - continue; - if (xreq->reqh.reqid == resph.reqid) { - memcpy(&(xreq->resph),&resph,sizeof(resph)); - - if (xreq->Buffer) - xreq->Buffer = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,xreq->Buffer,xreq->resph.cbBuffer); - else - xreq->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,xreq->resph.cbBuffer); - - hres = read_pipe(xhPipe,xreq->Buffer,xreq->resph.cbBuffer); - if (hres) goto end; - xreq->state = REQSTATE_RESP_GOT; - /*PulseEvent(hRpcChanged);*/ - goto end; - } - } - ERR("Did not find request for id %lx\n",resph.reqid); - hres = S_OK; - goto end; - } - ERR("Unknown reqtype %ld\n",reqtype); - hres = E_FAIL; -end: - LeaveCriticalSection(&(xpipe->crit)); - return hres; -} - -static DWORD WINAPI -_StubReaderThread(LPVOID param) { - wine_pipe *xpipe = (wine_pipe*)param; - HANDLE xhPipe = xpipe->hPipe; - HRESULT hres = S_OK; - - TRACE("STUB reader thread %lx\n",GetCurrentProcessId()); - while (!hres) { - int i; - hres = COM_RpcReceive(xpipe); - if (hres) break; - - for (i=nrofreqs;i--;) { - wine_rpc_request *xreq = reqs[i]; - if ((xreq->state == REQSTATE_REQ_GOT) && (xreq->hPipe == xhPipe)) { - hres = COM_InvokeAndRpcSend(xreq); - if (!hres) break; - } - } - } - FIXME("Failed with hres %lx\n",hres); - CloseHandle(xhPipe); - return 0; -} - -static DWORD WINAPI -_StubMgrThread(LPVOID param) { - char pipefn[200]; - HANDLE listenPipe; - - sprintf(pipefn,OLESTUBMGR"_%08lx",GetCurrentProcessId()); - TRACE("Stub Manager Thread starting on (%s)\n",pipefn); - - while (1) { - listenPipe = CreateNamedPipeA( - pipefn, - PIPE_ACCESS_DUPLEX, - PIPE_TYPE_BYTE|PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, - 4096, - 4096, - NMPWAIT_USE_DEFAULT_WAIT, - NULL - ); - if (listenPipe == INVALID_HANDLE_VALUE) { - FIXME("pipe creation failed for %s, le is %lx\n",pipefn,GetLastError()); - return 1; /* permanent failure, so quit stubmgr thread */ - } - if (!ConnectNamedPipe(listenPipe,NULL)) { - ERR("Failure during ConnectNamedPipe %lx!\n",GetLastError()); - CloseHandle(listenPipe); - continue; - } - PIPE_StartRequestThread(listenPipe); - } - return 0; -} - -void -STUBMGR_Start() { - static BOOL stubMgrRunning = FALSE; - DWORD tid; - - if (!stubMgrRunning) { - stubMgrRunning = TRUE; - CreateThread(NULL,0,_StubMgrThread,NULL,0,&tid); - Sleep(2000); /* actually we just try opening the pipe until it succeeds */ - } -} diff --git a/reactos/lib/ole32/stg_bigblockfile.c b/reactos/lib/ole32/stg_bigblockfile.c deleted file mode 100644 index 7532facccc6..00000000000 --- a/reactos/lib/ole32/stg_bigblockfile.c +++ /dev/null @@ -1,872 +0,0 @@ -/****************************************************************************** - * - * BigBlockFile - * - * This is the implementation of a file that consists of blocks of - * a predetermined size. - * This class is used in the Compound File implementation of the - * IStorage and IStream interfaces. It provides the functionality - * to read and write any blocks in the file as well as setting and - * obtaining the size of the file. - * The blocks are indexed sequentially from the start of the file - * starting with -1. - * - * TODO: - * - Support for a transacted mode - * - * Copyright 1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winuser.h" -#include "winerror.h" -#include "objbase.h" -#include "ole2.h" - -#include "storage32.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(storage); - -/*********************************************************** - * Data structures used internally by the BigBlockFile - * class. - */ - -/* We map in PAGE_SIZE-sized chunks. Must be a multiple of 4096. */ -#define PAGE_SIZE 131072 - -#define BLOCKS_PER_PAGE (PAGE_SIZE / BIG_BLOCK_SIZE) - -/* We keep a list of recently-discarded pages. This controls the - * size of that list. */ -#define MAX_VICTIM_PAGES 16 - -/* This structure provides one bit for each block in a page. - * Use BIGBLOCKFILE_{Test,Set,Clear}Bit to manipulate it. */ -typedef struct -{ - unsigned int bits[BLOCKS_PER_PAGE / (CHAR_BIT * sizeof(unsigned int))]; -} BlockBits; - -/*** - * This structure identifies the paged that are mapped - * from the file and their position in memory. It is - * also used to hold a reference count to those pages. - * - * page_index identifies which PAGE_SIZE chunk from the - * file this mapping represents. (The mappings are always - * PAGE_SIZE-aligned.) - */ -struct MappedPage -{ - MappedPage *next; - MappedPage *prev; - - DWORD page_index; - LPVOID lpBytes; - LONG refcnt; - - BlockBits readable_blocks; - BlockBits writable_blocks; -}; - -/*********************************************************** - * Prototypes for private methods - */ -static void* BIGBLOCKFILE_GetMappedView(LPBIGBLOCKFILE This, - DWORD page_index); -static void BIGBLOCKFILE_ReleaseMappedPage(LPBIGBLOCKFILE This, - MappedPage *page); -static void BIGBLOCKFILE_FreeAllMappedPages(LPBIGBLOCKFILE This); -static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This); -static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This); -static void* BIGBLOCKFILE_GetBigBlockPointer(LPBIGBLOCKFILE This, - ULONG index, - DWORD desired_access); -static MappedPage* BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This, - void* pBlock); -static MappedPage* BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This, - ULONG page_index); -static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags); -static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile); -static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt); - -/* Note that this evaluates a and b multiple times, so don't - * pass expressions with side effects. */ -#define ROUND_UP(a, b) ((((a) + (b) - 1)/(b))*(b)) - -/*********************************************************** - * Blockbits functions. - */ -static inline BOOL BIGBLOCKFILE_TestBit(const BlockBits *bb, - unsigned int index) -{ - unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int)); - unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int)); - - return bb->bits[array_index] & (1 << bit_index); -} - -static inline void BIGBLOCKFILE_SetBit(BlockBits *bb, unsigned int index) -{ - unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int)); - unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int)); - - bb->bits[array_index] |= (1 << bit_index); -} - -static inline void BIGBLOCKFILE_ClearBit(BlockBits *bb, unsigned int index) -{ - unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int)); - unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int)); - - bb->bits[array_index] &= ~(1 << bit_index); -} - -static inline void BIGBLOCKFILE_Zero(BlockBits *bb) -{ - memset(bb->bits, 0, sizeof(bb->bits)); -} - -/****************************************************************************** - * BIGBLOCKFILE_Construct - * - * Construct a big block file. Create the file mapping object. - * Create the read only mapped pages list, the writable mapped page list - * and the blocks in use list. - */ -BigBlockFile * BIGBLOCKFILE_Construct( - HANDLE hFile, - ILockBytes* pLkByt, - DWORD openFlags, - ULONG blocksize, - BOOL fileBased) -{ - LPBIGBLOCKFILE This; - - This = (LPBIGBLOCKFILE)HeapAlloc(GetProcessHeap(), 0, sizeof(BigBlockFile)); - - if (This == NULL) - return NULL; - - This->fileBased = fileBased; - - This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags); - - This->blocksize = blocksize; - - This->maplist = NULL; - This->victimhead = NULL; - This->victimtail = NULL; - This->num_victim_pages = 0; - - if (This->fileBased) - { - if (!BIGBLOCKFILE_FileInit(This, hFile)) - { - HeapFree(GetProcessHeap(), 0, This); - return NULL; - } - } - else - { - if (!BIGBLOCKFILE_MemInit(This, pLkByt)) - { - HeapFree(GetProcessHeap(), 0, This); - return NULL; - } - } - - return This; -} - -/****************************************************************************** - * BIGBLOCKFILE_FileInit - * - * Initialize a big block object supported by a file. - */ -static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile) -{ - This->pLkbyt = NULL; - This->hbytearray = 0; - This->pbytearray = NULL; - - This->hfile = hFile; - - if (This->hfile == INVALID_HANDLE_VALUE) - return FALSE; - - This->filesize.u.LowPart = GetFileSize(This->hfile, - &This->filesize.u.HighPart); - - if( This->filesize.u.LowPart || This->filesize.u.HighPart ) - { - /* create the file mapping object - */ - This->hfilemap = CreateFileMappingA(This->hfile, - NULL, - This->flProtect, - 0, 0, - NULL); - - if (!This->hfilemap) - { - CloseHandle(This->hfile); - return FALSE; - } - } - else - This->hfilemap = NULL; - - This->maplist = NULL; - - TRACE("file len %lu\n", This->filesize.u.LowPart); - - return TRUE; -} - -/****************************************************************************** - * BIGBLOCKFILE_MemInit - * - * Initialize a big block object supported by an ILockBytes on HGLOABL. - */ -static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt) -{ - This->hfile = 0; - This->hfilemap = 0; - - /* - * Retrieve the handle to the byte array from the LockByte object. - */ - if (GetHGlobalFromILockBytes(plkbyt, &(This->hbytearray)) != S_OK) - { - FIXME("May not be an ILockBytes on HGLOBAL\n"); - return FALSE; - } - - This->pLkbyt = plkbyt; - - /* - * Increment the reference count of the ILockByte object since - * we're keeping a reference to it. - */ - ILockBytes_AddRef(This->pLkbyt); - - This->filesize.u.LowPart = GlobalSize(This->hbytearray); - This->filesize.u.HighPart = 0; - - This->pbytearray = GlobalLock(This->hbytearray); - - TRACE("mem on %p len %lu\n", This->pbytearray, This->filesize.u.LowPart); - - return TRUE; -} - -/****************************************************************************** - * BIGBLOCKFILE_Destructor - * - * Destructor. Clean up, free memory. - */ -void BIGBLOCKFILE_Destructor( - LPBIGBLOCKFILE This) -{ - BIGBLOCKFILE_FreeAllMappedPages(This); - - if (This->fileBased) - { - CloseHandle(This->hfilemap); - CloseHandle(This->hfile); - } - else - { - GlobalUnlock(This->hbytearray); - ILockBytes_Release(This->pLkbyt); - } - - /* destroy this - */ - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** - * BIGBLOCKFILE_GetROBigBlock - * - * Returns the specified block in read only mode. - * Will return NULL if the block doesn't exists. - */ -void* BIGBLOCKFILE_GetROBigBlock( - LPBIGBLOCKFILE This, - ULONG index) -{ - /* - * block index starts at -1 - * translate to zero based index - */ - if (index == 0xffffffff) - index = 0; - else - index++; - - /* - * validate the block index - * - */ - if (This->blocksize * (index + 1) - > ROUND_UP(This->filesize.u.LowPart, This->blocksize)) - { - TRACE("out of range %lu vs %lu\n", This->blocksize * (index + 1), - This->filesize.u.LowPart); - return NULL; - } - - return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_READ); -} - -/****************************************************************************** - * BIGBLOCKFILE_GetBigBlock - * - * Returns the specified block. - * Will grow the file if necessary. - */ -void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index) -{ - /* - * block index starts at -1 - * translate to zero based index - */ - if (index == 0xffffffff) - index = 0; - else - index++; - - /* - * make sure that the block physically exists - */ - if ((This->blocksize * (index + 1)) > This->filesize.u.LowPart) - { - ULARGE_INTEGER newSize; - - newSize.u.HighPart = 0; - newSize.u.LowPart = This->blocksize * (index + 1); - - BIGBLOCKFILE_SetSize(This, newSize); - } - - return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_WRITE); -} - -/****************************************************************************** - * BIGBLOCKFILE_ReleaseBigBlock - * - * Releases the specified block. - */ -void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock) -{ - MappedPage *page; - - if (pBlock == NULL) - return; - - page = BIGBLOCKFILE_GetPageFromPointer(This, pBlock); - - if (page == NULL) - return; - - BIGBLOCKFILE_ReleaseMappedPage(This, page); -} - -/****************************************************************************** - * BIGBLOCKFILE_SetSize - * - * Sets the size of the file. - * - */ -void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize) -{ - if (This->filesize.u.LowPart == newSize.u.LowPart) - return; - - TRACE("from %lu to %lu\n", This->filesize.u.LowPart, newSize.u.LowPart); - /* - * unmap all views, must be done before call to SetEndFile - */ - BIGBLOCKFILE_UnmapAllMappedPages(This); - - if (This->fileBased) - { - char buf[10]; - - /* - * close file-mapping object, must be done before call to SetEndFile - */ - if( This->hfilemap ) - CloseHandle(This->hfilemap); - This->hfilemap = 0; - - /* - * BEGIN HACK - * This fixes a bug when saving through smbfs. - * smbmount a Windows shared directory, save a structured storage file - * to that dir: crash. - * - * The problem is that the SetFilePointer-SetEndOfFile combo below - * doesn't always succeed. The file is not grown. It seems like the - * operation is cached. By doing the WriteFile, the file is actually - * grown on disk. - * This hack is only needed when saving to smbfs. - */ - memset(buf, '0', 10); - SetFilePointer(This->hfile, newSize.u.LowPart, NULL, FILE_BEGIN); - WriteFile(This->hfile, buf, 10, NULL, NULL); - /* - * END HACK - */ - - /* - * set the new end of file - */ - SetFilePointer(This->hfile, newSize.u.LowPart, NULL, FILE_BEGIN); - SetEndOfFile(This->hfile); - - /* - * re-create the file mapping object - */ - This->hfilemap = CreateFileMappingA(This->hfile, - NULL, - This->flProtect, - 0, 0, - NULL); - } - else - { - GlobalUnlock(This->hbytearray); - - /* - * Resize the byte array object. - */ - ILockBytes_SetSize(This->pLkbyt, newSize); - - /* - * Re-acquire the handle, it may have changed. - */ - GetHGlobalFromILockBytes(This->pLkbyt, &This->hbytearray); - This->pbytearray = GlobalLock(This->hbytearray); - } - - This->filesize.u.LowPart = newSize.u.LowPart; - This->filesize.u.HighPart = newSize.u.HighPart; - - BIGBLOCKFILE_RemapAllMappedPages(This); -} - -/****************************************************************************** - * BIGBLOCKFILE_GetSize - * - * Returns the size of the file. - * - */ -ULARGE_INTEGER BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This) -{ - return This->filesize; -} - -/****************************************************************************** - * BIGBLOCKFILE_AccessCheck [PRIVATE] - * - * block_index is the index within the page. - */ -static BOOL BIGBLOCKFILE_AccessCheck(MappedPage *page, ULONG block_index, - DWORD desired_access) -{ - assert(block_index < BLOCKS_PER_PAGE); - - if (desired_access == FILE_MAP_READ) - { - if (BIGBLOCKFILE_TestBit(&page->writable_blocks, block_index)) - return FALSE; - - BIGBLOCKFILE_SetBit(&page->readable_blocks, block_index); - } - else - { - assert(desired_access == FILE_MAP_WRITE); - - if (BIGBLOCKFILE_TestBit(&page->readable_blocks, block_index)) - return FALSE; - - BIGBLOCKFILE_SetBit(&page->writable_blocks, block_index); - } - - return TRUE; -} - -/****************************************************************************** - * BIGBLOCKFILE_GetBigBlockPointer [PRIVATE] - * - * Returns a pointer to the specified block. - */ -static void* BIGBLOCKFILE_GetBigBlockPointer( - LPBIGBLOCKFILE This, - ULONG block_index, - DWORD desired_access) -{ - DWORD page_index = block_index / BLOCKS_PER_PAGE; - DWORD block_on_page = block_index % BLOCKS_PER_PAGE; - - MappedPage *page = BIGBLOCKFILE_GetMappedView(This, page_index); - if (!page || !page->lpBytes) return NULL; - - if (!BIGBLOCKFILE_AccessCheck(page, block_on_page, desired_access)) - { - BIGBLOCKFILE_ReleaseMappedPage(This, page); - return NULL; - } - - return (LPBYTE)page->lpBytes + (block_on_page * This->blocksize); -} - -/****************************************************************************** - * BIGBLOCKFILE_GetMappedPageFromPointer [PRIVATE] - * - * pBlock is a pointer to a block on a page. - * The page has to be on the in-use list. (As oppsed to the victim list.) - * - * Does not increment the usage count. - */ -static MappedPage *BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This, - void *pBlock) -{ - MappedPage *page; - - for (page = This->maplist; page != NULL; page = page->next) - { - if ((LPBYTE)pBlock >= (LPBYTE)page->lpBytes - && (LPBYTE)pBlock <= (LPBYTE)page->lpBytes + PAGE_SIZE) - break; - - } - - return page; -} - -/****************************************************************************** - * BIGBLOCKFILE_FindPageInList [PRIVATE] - * - */ -static MappedPage *BIGBLOCKFILE_FindPageInList(MappedPage *head, - ULONG page_index) -{ - for (; head != NULL; head = head->next) - { - if (head->page_index == page_index) - { - InterlockedIncrement(&head->refcnt); - break; - } - } - - return head; - -} - -static void BIGBLOCKFILE_UnlinkPage(MappedPage *page) -{ - if (page->next) page->next->prev = page->prev; - if (page->prev) page->prev->next = page->next; -} - -static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page) -{ - if (*head) (*head)->prev = page; - page->next = *head; - page->prev = NULL; - *head = page; -} - -/****************************************************************************** - * BIGBLOCKFILE_GetMappedView [PRIVATE] - * - * Gets the page requested if it is already mapped. - * If it's not already mapped, this method will map it - */ -static void * BIGBLOCKFILE_GetMappedView( - LPBIGBLOCKFILE This, - DWORD page_index) -{ - MappedPage *page; - - page = BIGBLOCKFILE_FindPageInList(This->maplist, page_index); - if (!page) - { - page = BIGBLOCKFILE_FindPageInList(This->victimhead, page_index); - if (page) - { - This->num_victim_pages--; - - BIGBLOCKFILE_Zero(&page->readable_blocks); - BIGBLOCKFILE_Zero(&page->writable_blocks); - } - } - - if (page) - { - /* If the page is not already at the head of the list, move - * it there. (Also moves pages from victim to main list.) */ - if (This->maplist != page) - { - if (This->victimhead == page) This->victimhead = page->next; - if (This->victimtail == page) This->victimtail = page->prev; - - BIGBLOCKFILE_UnlinkPage(page); - - BIGBLOCKFILE_LinkHeadPage(&This->maplist, page); - } - - return page; - } - - page = BIGBLOCKFILE_CreatePage(This, page_index); - if (!page) return NULL; - - BIGBLOCKFILE_LinkHeadPage(&This->maplist, page); - - return page; -} - -static BOOL BIGBLOCKFILE_MapPage(LPBIGBLOCKFILE This, MappedPage *page) -{ - DWORD lowoffset = PAGE_SIZE * page->page_index; - - if (This->fileBased) - { - DWORD numBytesToMap; - DWORD desired_access; - - if( !This->hfilemap ) - return FALSE; - - if (lowoffset + PAGE_SIZE > This->filesize.u.LowPart) - numBytesToMap = This->filesize.u.LowPart - lowoffset; - else - numBytesToMap = PAGE_SIZE; - - if (This->flProtect == PAGE_READONLY) - desired_access = FILE_MAP_READ; - else - desired_access = FILE_MAP_WRITE; - - page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0, - lowoffset, numBytesToMap); - } - else - { - page->lpBytes = (LPBYTE)This->pbytearray + lowoffset; - } - - TRACE("mapped page %lu to %p\n", page->page_index, page->lpBytes); - - return page->lpBytes != NULL; -} - -static MappedPage *BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This, - ULONG page_index) -{ - MappedPage *page; - - page = HeapAlloc(GetProcessHeap(), 0, sizeof(MappedPage)); - if (page == NULL) - return NULL; - - page->page_index = page_index; - page->refcnt = 1; - - page->next = NULL; - page->prev = NULL; - - BIGBLOCKFILE_MapPage(This, page); - - BIGBLOCKFILE_Zero(&page->readable_blocks); - BIGBLOCKFILE_Zero(&page->writable_blocks); - - return page; -} - -static void BIGBLOCKFILE_UnmapPage(LPBIGBLOCKFILE This, MappedPage *page) -{ - TRACE("%ld at %p\n", page->page_index, page->lpBytes); - if (page->refcnt > 0) - ERR("unmapping inuse page %p\n", page->lpBytes); - - if (This->fileBased && page->lpBytes) - UnmapViewOfFile(page->lpBytes); - - page->lpBytes = NULL; -} - -static void BIGBLOCKFILE_DeletePage(LPBIGBLOCKFILE This, MappedPage *page) -{ - BIGBLOCKFILE_UnmapPage(This, page); - - HeapFree(GetProcessHeap(), 0, page); -} - -/****************************************************************************** - * BIGBLOCKFILE_ReleaseMappedPage [PRIVATE] - * - * Decrements the reference count of the mapped page. - */ -static void BIGBLOCKFILE_ReleaseMappedPage( - LPBIGBLOCKFILE This, - MappedPage *page) -{ - assert(This != NULL); - assert(page != NULL); - - /* If the page is no longer refenced, move it to the victim list. - * If the victim list is too long, kick somebody off. */ - if (!InterlockedDecrement(&page->refcnt)) - { - if (This->maplist == page) This->maplist = page->next; - - BIGBLOCKFILE_UnlinkPage(page); - - if (MAX_VICTIM_PAGES > 0) - { - if (This->num_victim_pages >= MAX_VICTIM_PAGES) - { - MappedPage *victim = This->victimtail; - if (victim) - { - This->victimtail = victim->prev; - if (This->victimhead == victim) - This->victimhead = victim->next; - - BIGBLOCKFILE_UnlinkPage(victim); - BIGBLOCKFILE_DeletePage(This, victim); - } - } - else This->num_victim_pages++; - - BIGBLOCKFILE_LinkHeadPage(&This->victimhead, page); - if (This->victimtail == NULL) This->victimtail = page; - } - else - BIGBLOCKFILE_DeletePage(This, page); - } -} - -static void BIGBLOCKFILE_DeleteList(LPBIGBLOCKFILE This, MappedPage *list) -{ - while (list != NULL) - { - MappedPage *next = list->next; - - BIGBLOCKFILE_DeletePage(This, list); - - list = next; - } -} - -/****************************************************************************** - * BIGBLOCKFILE_FreeAllMappedPages [PRIVATE] - * - * Unmap all currently mapped pages. - * Empty mapped pages list. - */ -static void BIGBLOCKFILE_FreeAllMappedPages( - LPBIGBLOCKFILE This) -{ - BIGBLOCKFILE_DeleteList(This, This->maplist); - BIGBLOCKFILE_DeleteList(This, This->victimhead); - - This->maplist = NULL; - This->victimhead = NULL; - This->victimtail = NULL; - This->num_victim_pages = 0; -} - -static void BIGBLOCKFILE_UnmapList(LPBIGBLOCKFILE This, MappedPage *list) -{ - for (; list != NULL; list = list->next) - { - BIGBLOCKFILE_UnmapPage(This, list); - } -} - -static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This) -{ - BIGBLOCKFILE_UnmapList(This, This->maplist); - BIGBLOCKFILE_UnmapList(This, This->victimhead); -} - -static void BIGBLOCKFILE_RemapList(LPBIGBLOCKFILE This, MappedPage *list) -{ - while (list != NULL) - { - MappedPage *next = list->next; - - if (list->page_index * PAGE_SIZE > This->filesize.u.LowPart) - { - TRACE("discarding %lu\n", list->page_index); - - /* page is entirely outside of the file, delete it */ - BIGBLOCKFILE_UnlinkPage(list); - BIGBLOCKFILE_DeletePage(This, list); - } - else - { - /* otherwise, remap it */ - BIGBLOCKFILE_MapPage(This, list); - } - - list = next; - } -} - -static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This) -{ - BIGBLOCKFILE_RemapList(This, This->maplist); - BIGBLOCKFILE_RemapList(This, This->victimhead); -} - -/**************************************************************************** - * BIGBLOCKFILE_GetProtectMode - * - * This function will return a protection mode flag for a file-mapping object - * from the open flags of a file. - */ -static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags) -{ - if (openFlags & (STGM_WRITE | STGM_READWRITE)) - return PAGE_READWRITE; - else - return PAGE_READONLY; -} diff --git a/reactos/lib/ole32/stg_stream.c b/reactos/lib/ole32/stg_stream.c deleted file mode 100644 index 984b43be876..00000000000 --- a/reactos/lib/ole32/stg_stream.c +++ /dev/null @@ -1,895 +0,0 @@ -/* - * Compound Storage (32 bit version) - * Stream implementation - * - * This file contains the implementation of the stream interface - * for streams contained in a compound storage. - * - * Copyright 1999 Francis Beaudet - * Copyright 1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "winreg.h" -#include "winternl.h" -#include "wine/debug.h" - -#include "storage32.h" - -WINE_DEFAULT_DEBUG_CHANNEL(storage); - - -/* - * Virtual function table for the StgStreamImpl class. - */ -static IStreamVtbl StgStreamImpl_Vtbl = -{ - StgStreamImpl_QueryInterface, - StgStreamImpl_AddRef, - StgStreamImpl_Release, - StgStreamImpl_Read, - StgStreamImpl_Write, - StgStreamImpl_Seek, - StgStreamImpl_SetSize, - StgStreamImpl_CopyTo, - StgStreamImpl_Commit, - StgStreamImpl_Revert, - StgStreamImpl_LockRegion, - StgStreamImpl_UnlockRegion, - StgStreamImpl_Stat, - StgStreamImpl_Clone -}; - -/****************************************************************************** -** StgStreamImpl implementation -*/ - -/*** - * This is the constructor for the StgStreamImpl class. - * - * Params: - * parentStorage - Pointer to the storage that contains the stream to open - * ownerProperty - Index of the property that points to this stream. - */ -StgStreamImpl* StgStreamImpl_Construct( - StorageBaseImpl* parentStorage, - DWORD grfMode, - ULONG ownerProperty) -{ - StgStreamImpl* newStream; - - newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl)); - - if (newStream!=0) - { - /* - * Set-up the virtual function table and reference count. - */ - newStream->lpVtbl = &StgStreamImpl_Vtbl; - newStream->ref = 0; - - /* - * We want to nail-down the reference to the storage in case the - * stream out-lives the storage in the client application. - */ - newStream->parentStorage = parentStorage; - IStorage_AddRef((IStorage*)newStream->parentStorage); - - newStream->grfMode = grfMode; - newStream->ownerProperty = ownerProperty; - - /* - * Start the stream at the beginning. - */ - newStream->currentPosition.u.HighPart = 0; - newStream->currentPosition.u.LowPart = 0; - - /* - * Initialize the rest of the data. - */ - newStream->streamSize.u.HighPart = 0; - newStream->streamSize.u.LowPart = 0; - newStream->bigBlockChain = 0; - newStream->smallBlockChain = 0; - - /* - * Read the size from the property and determine if the blocks forming - * this stream are large or small. - */ - StgStreamImpl_OpenBlockChain(newStream); - } - - return newStream; -} - -/*** - * This is the destructor of the StgStreamImpl class. - * - * This method will clean-up all the resources used-up by the given StgStreamImpl - * class. The pointer passed-in to this function will be freed and will not - * be valid anymore. - */ -void StgStreamImpl_Destroy(StgStreamImpl* This) -{ - TRACE("(%p)\n", This); - - /* - * Release the reference we are holding on the parent storage. - */ - IStorage_Release((IStorage*)This->parentStorage); - This->parentStorage = 0; - - /* - * Make sure we clean-up the block chain stream objects that we were using. - */ - if (This->bigBlockChain != 0) - { - BlockChainStream_Destroy(This->bigBlockChain); - This->bigBlockChain = 0; - } - - if (This->smallBlockChain != 0) - { - SmallBlockChainStream_Destroy(This->smallBlockChain); - This->smallBlockChain = 0; - } - - /* - * Finally, free the memory used-up by the class. - */ - HeapFree(GetProcessHeap(), 0, This); -} - -/*** - * This implements the IUnknown method QueryInterface for this - * class - */ -HRESULT WINAPI StgStreamImpl_QueryInterface( - IStream* iface, - REFIID riid, /* [in] */ - void** ppvObject) /* [iid_is][out] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - /* - * Perform a sanity check on the parameters. - */ - if (ppvObject==0) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = (IStream*)This; - } - else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) - { - *ppvObject = (IStream*)This; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - StgStreamImpl_AddRef(iface); - - return S_OK; -} - -/*** - * This implements the IUnknown method AddRef for this - * class - */ -ULONG WINAPI StgStreamImpl_AddRef( - IStream* iface) -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - return InterlockedIncrement(&This->ref); -} - -/*** - * This implements the IUnknown method Release for this - * class - */ -ULONG WINAPI StgStreamImpl_Release( - IStream* iface) -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - ULONG ref; - - ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref==0) - { - StgStreamImpl_Destroy(This); - } - - return ref; -} - -/*** - * This method will open the block chain pointed by the property - * that describes the stream. - * If the stream's size is null, no chain is opened. - */ -void StgStreamImpl_OpenBlockChain( - StgStreamImpl* This) -{ - StgProperty curProperty; - BOOL readSucessful; - - /* - * Make sure no old object is left over. - */ - if (This->smallBlockChain != 0) - { - SmallBlockChainStream_Destroy(This->smallBlockChain); - This->smallBlockChain = 0; - } - - if (This->bigBlockChain != 0) - { - BlockChainStream_Destroy(This->bigBlockChain); - This->bigBlockChain = 0; - } - - /* - * Read the information from the property. - */ - readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage, - This->ownerProperty, - &curProperty); - - if (readSucessful) - { - This->streamSize = curProperty.size; - - /* - * This code supports only streams that are <32 bits in size. - */ - assert(This->streamSize.u.HighPart == 0); - - if(curProperty.startingBlock == BLOCK_END_OF_CHAIN) - { - assert( (This->streamSize.u.HighPart == 0) && (This->streamSize.u.LowPart == 0) ); - } - else - { - if ( (This->streamSize.u.HighPart == 0) && - (This->streamSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) ) - { - This->smallBlockChain = SmallBlockChainStream_Construct( - This->parentStorage->ancestorStorage, - This->ownerProperty); - } - else - { - This->bigBlockChain = BlockChainStream_Construct( - This->parentStorage->ancestorStorage, - NULL, - This->ownerProperty); - } - } - } -} - -/*** - * This method is part of the ISequentialStream interface. - * - * It reads a block of information from the stream at the current - * position. It then moves the current position at the end of the - * read block - * - * See the documentation of ISequentialStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Read( - IStream* iface, - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead) /* [out] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - ULONG bytesReadBuffer; - ULONG bytesToReadFromBuffer; - HRESULT res = S_FALSE; - - TRACE("(%p, %p, %ld, %p)\n", - iface, pv, cb, pcbRead); - - /* - * If the caller is not interested in the number of bytes read, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbRead==0) - pcbRead = &bytesReadBuffer; - - /* - * Using the known size of the stream, calculate the number of bytes - * to read from the block chain - */ - bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb); - - /* - * Depending on the type of chain that was opened when the stream was constructed, - * we delegate the work to the method that reads the block chains. - */ - if (This->smallBlockChain!=0) - { - SmallBlockChainStream_ReadAt(This->smallBlockChain, - This->currentPosition, - bytesToReadFromBuffer, - pv, - pcbRead); - - } - else if (This->bigBlockChain!=0) - { - BlockChainStream_ReadAt(This->bigBlockChain, - This->currentPosition, - bytesToReadFromBuffer, - pv, - pcbRead); - } - else - { - /* - * Small and big block chains are both NULL. This case will happen - * when a stream starts with BLOCK_END_OF_CHAIN and has size zero. - */ - - *pcbRead = 0; - res = S_OK; - goto end; - } - - /* - * We should always be able to read the proper amount of data from the - * chain. - */ - assert(bytesToReadFromBuffer == *pcbRead); - - /* - * Advance the pointer for the number of positions read. - */ - This->currentPosition.u.LowPart += *pcbRead; - - if(*pcbRead != cb) - { - WARN("read %ld instead of the required %ld bytes !\n", *pcbRead, cb); - /* - * this used to return S_FALSE, however MSDN docu says that an app should - * be prepared to handle error in case of stream end reached, as *some* - * implementations *might* return an error (IOW: most do *not*). - * As some program fails on returning S_FALSE, I better use S_OK here. - */ - res = S_OK; - } - else - res = S_OK; - -end: - TRACE("<-- %08lx\n", res); - return res; -} - -/*** - * This method is part of the ISequentialStream interface. - * - * It writes a block of information to the stream at the current - * position. It then moves the current position at the end of the - * written block. If the stream is too small to fit the block, - * the stream is grown to fit. - * - * See the documentation of ISequentialStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Write( - IStream* iface, - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten) /* [out] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - ULARGE_INTEGER newSize; - ULONG bytesWritten = 0; - - TRACE("(%p, %p, %ld, %p)\n", - iface, pv, cb, pcbWritten); - - /* - * Do we have permission to write to this stream? - */ - if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE))) { - return STG_E_ACCESSDENIED; - } - - /* - * If the caller is not interested in the number of bytes written, - * we use another buffer to avoid "if" statements in the code. - */ - if (pcbWritten == 0) - pcbWritten = &bytesWritten; - - /* - * Initialize the out parameter - */ - *pcbWritten = 0; - - if (cb == 0) - { - return S_OK; - } - else - { - newSize.u.HighPart = 0; - newSize.u.LowPart = This->currentPosition.u.LowPart + cb; - } - - /* - * Verify if we need to grow the stream - */ - if (newSize.u.LowPart > This->streamSize.u.LowPart) - { - /* grow stream */ - IStream_SetSize(iface, newSize); - } - - /* - * Depending on the type of chain that was opened when the stream was constructed, - * we delegate the work to the method that readwrites to the block chains. - */ - if (This->smallBlockChain!=0) - { - SmallBlockChainStream_WriteAt(This->smallBlockChain, - This->currentPosition, - cb, - pv, - pcbWritten); - - } - else if (This->bigBlockChain!=0) - { - BlockChainStream_WriteAt(This->bigBlockChain, - This->currentPosition, - cb, - pv, - pcbWritten); - } - else - assert(FALSE); - - /* - * Advance the position pointer for the number of positions written. - */ - This->currentPosition.u.LowPart += *pcbWritten; - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will move the current stream pointer according to the parameters - * given. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Seek( - IStream* iface, - LARGE_INTEGER dlibMove, /* [in] */ - DWORD dwOrigin, /* [in] */ - ULARGE_INTEGER* plibNewPosition) /* [out] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - ULARGE_INTEGER newPosition; - - TRACE("(%p, %ld, %ld, %p)\n", - iface, dlibMove.u.LowPart, dwOrigin, plibNewPosition); - - /* - * The caller is allowed to pass in NULL as the new position return value. - * If it happens, we assign it to a dynamic variable to avoid special cases - * in the code below. - */ - if (plibNewPosition == 0) - { - plibNewPosition = &newPosition; - } - - /* - * The file pointer is moved depending on the given "function" - * parameter. - */ - switch (dwOrigin) - { - case STREAM_SEEK_SET: - plibNewPosition->u.HighPart = 0; - plibNewPosition->u.LowPart = 0; - break; - case STREAM_SEEK_CUR: - *plibNewPosition = This->currentPosition; - break; - case STREAM_SEEK_END: - *plibNewPosition = This->streamSize; - break; - default: - return STG_E_INVALIDFUNCTION; - } - - plibNewPosition->QuadPart = RtlLargeIntegerAdd( plibNewPosition->QuadPart, dlibMove.QuadPart ); - - /* - * tell the caller what we calculated - */ - This->currentPosition = *plibNewPosition; - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will change the size of a stream. - * - * TODO: Switch from small blocks to big blocks and vice versa. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_SetSize( - IStream* iface, - ULARGE_INTEGER libNewSize) /* [in] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - StgProperty curProperty; - BOOL Success; - - TRACE("(%p, %ld)\n", iface, libNewSize.u.LowPart); - - /* - * As documented. - */ - if (libNewSize.u.HighPart != 0) - return STG_E_INVALIDFUNCTION; - - /* - * Do we have permission? - */ - if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE))) - return STG_E_ACCESSDENIED; - - if (This->streamSize.u.LowPart == libNewSize.u.LowPart) - return S_OK; - - /* - * This will happen if we're creating a stream - */ - if ((This->smallBlockChain == 0) && (This->bigBlockChain == 0)) - { - if (libNewSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) - { - This->smallBlockChain = SmallBlockChainStream_Construct( - This->parentStorage->ancestorStorage, - This->ownerProperty); - } - else - { - This->bigBlockChain = BlockChainStream_Construct( - This->parentStorage->ancestorStorage, - NULL, - This->ownerProperty); - } - } - - /* - * Read this stream's property to see if it's small blocks or big blocks - */ - Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage, - This->ownerProperty, - &curProperty); - /* - * Determine if we have to switch from small to big blocks or vice versa - */ - if ( (This->smallBlockChain!=0) && - (curProperty.size.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) ) - { - if (libNewSize.u.LowPart >= LIMIT_TO_USE_SMALL_BLOCK) - { - /* - * Transform the small block chain into a big block chain - */ - This->bigBlockChain = Storage32Impl_SmallBlocksToBigBlocks( - This->parentStorage->ancestorStorage, - &This->smallBlockChain); - } - } - - if (This->smallBlockChain!=0) - { - Success = SmallBlockChainStream_SetSize(This->smallBlockChain, libNewSize); - } - else - { - Success = BlockChainStream_SetSize(This->bigBlockChain, libNewSize); - } - - /* - * Write the new information about this stream to the property - */ - Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage, - This->ownerProperty, - &curProperty); - - curProperty.size.u.HighPart = libNewSize.u.HighPart; - curProperty.size.u.LowPart = libNewSize.u.LowPart; - - if (Success) - { - StorageImpl_WriteProperty(This->parentStorage->ancestorStorage, - This->ownerProperty, - &curProperty); - } - - This->streamSize = libNewSize; - - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * It will copy the 'cb' Bytes to 'pstm' IStream. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_CopyTo( - IStream* iface, - IStream* pstm, /* [unique][in] */ - ULARGE_INTEGER cb, /* [in] */ - ULARGE_INTEGER* pcbRead, /* [out] */ - ULARGE_INTEGER* pcbWritten) /* [out] */ -{ - HRESULT hr = S_OK; - BYTE tmpBuffer[128]; - ULONG bytesRead, bytesWritten, copySize; - ULARGE_INTEGER totalBytesRead; - ULARGE_INTEGER totalBytesWritten; - - TRACE("(%p, %p, %ld, %p, %p)\n", - iface, pstm, cb.u.LowPart, pcbRead, pcbWritten); - - /* - * Sanity check - */ - if ( pstm == 0 ) - return STG_E_INVALIDPOINTER; - - totalBytesRead.u.LowPart = totalBytesRead.u.HighPart = 0; - totalBytesWritten.u.LowPart = totalBytesWritten.u.HighPart = 0; - - /* - * use stack to store data temporarily - * there is surely a more performant way of doing it, for now this basic - * implementation will do the job - */ - while ( cb.u.LowPart > 0 ) - { - if ( cb.u.LowPart >= 128 ) - copySize = 128; - else - copySize = cb.u.LowPart; - - IStream_Read(iface, tmpBuffer, copySize, &bytesRead); - - totalBytesRead.u.LowPart += bytesRead; - - IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten); - - totalBytesWritten.u.LowPart += bytesWritten; - - /* - * Check that read & write operations were successful - */ - if (bytesRead != bytesWritten) - { - hr = STG_E_MEDIUMFULL; - break; - } - - if (bytesRead!=copySize) - cb.u.LowPart = 0; - else - cb.u.LowPart -= bytesRead; - } - - /* - * Update number of bytes read and written - */ - if (pcbRead) - { - pcbRead->u.LowPart = totalBytesRead.u.LowPart; - pcbRead->u.HighPart = totalBytesRead.u.HighPart; - } - - if (pcbWritten) - { - pcbWritten->u.LowPart = totalBytesWritten.u.LowPart; - pcbWritten->u.HighPart = totalBytesWritten.u.HighPart; - } - return hr; -} - -/*** - * This method is part of the IStream interface. - * - * For streams contained in structured storages, this method - * does nothing. This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Commit( - IStream* iface, - DWORD grfCommitFlags) /* [in] */ -{ - return S_OK; -} - -/*** - * This method is part of the IStream interface. - * - * For streams contained in structured storages, this method - * does nothing. This is what the documentation tells us. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Revert( - IStream* iface) -{ - return S_OK; -} - -HRESULT WINAPI StgStreamImpl_LockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - FIXME("not implemented!\n"); - return E_NOTIMPL; -} - -HRESULT WINAPI StgStreamImpl_UnlockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType) /* [in] */ -{ - FIXME("not implemented!\n"); - return E_NOTIMPL; -} - -/*** - * This method is part of the IStream interface. - * - * This method returns information about the current - * stream. - * - * See the documentation of IStream for more info. - */ -HRESULT WINAPI StgStreamImpl_Stat( - IStream* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - - StgProperty curProperty; - BOOL readSucessful; - - /* - * Read the information from the property. - */ - readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage, - This->ownerProperty, - &curProperty); - - if (readSucessful) - { - StorageUtl_CopyPropertyToSTATSTG(pstatstg, - &curProperty, - grfStatFlag); - - pstatstg->grfMode = This->grfMode; - - return S_OK; - } - - return E_FAIL; -} - -/*** - * This method is part of the IStream interface. - * - * This method returns a clone of the interface that allows for - * another seek pointer - * - * See the documentation of IStream for more info. - * - * I am not totally sure what I am doing here but I presume that this - * should be basically as simple as creating a new stream with the same - * parent etc and positioning its seek cursor. - */ -HRESULT WINAPI StgStreamImpl_Clone( - IStream* iface, - IStream** ppstm) /* [out] */ -{ - StgStreamImpl* const This=(StgStreamImpl*)iface; - HRESULT hres; - StgStreamImpl* new_stream; - LARGE_INTEGER seek_pos; - - /* - * Sanity check - */ - if ( ppstm == 0 ) - return STG_E_INVALIDPOINTER; - - new_stream = StgStreamImpl_Construct (This->parentStorage, This->grfMode, This->ownerProperty); - - if (!new_stream) - return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */ - - *ppstm = (IStream*) new_stream; - seek_pos.QuadPart = This->currentPosition.QuadPart; - - hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL); - - assert (SUCCEEDED(hres)); - - return S_OK; -} diff --git a/reactos/lib/ole32/storage.c b/reactos/lib/ole32/storage.c deleted file mode 100644 index 0e0b4858e00..00000000000 --- a/reactos/lib/ole32/storage.c +++ /dev/null @@ -1,2031 +0,0 @@ -/* Compound Storage - * - * Implemented using the documentation of the LAOLA project at - * - * (Thanks to Martin Schwartz ) - * - * Copyright 1998 Marcus Meissner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif - -#define NONAMELESSUNION -#define NONAMELESSSTRUCT -#include "windef.h" -#include "winbase.h" -#include "winreg.h" -#include "winternl.h" -#include "winerror.h" -#include "wine/winbase16.h" -#include "wownt32.h" -#include "wine/unicode.h" -#include "objbase.h" -#include "wine/debug.h" - -#include "ifs.h" - -WINE_DEFAULT_DEBUG_CHANNEL(ole); -WINE_DECLARE_DEBUG_CHANNEL(relay); - -struct storage_header { - BYTE magic[8]; /* 00: magic */ - BYTE unknown1[36]; /* 08: unknown */ - DWORD num_of_bbd_blocks;/* 2C: length of big datablocks */ - DWORD root_startblock;/* 30: root storage first big block */ - DWORD unknown2[2]; /* 34: unknown */ - DWORD sbd_startblock; /* 3C: small block depot first big block */ - DWORD unknown3[3]; /* 40: unknown */ - DWORD bbd_list[109]; /* 4C: big data block list (up to end of sector)*/ -}; -struct storage_pps_entry { - WCHAR pps_rawname[32];/* 00: \0 terminated widechar name */ - WORD pps_sizeofname; /* 40: namelength in bytes */ - BYTE pps_type; /* 42: flags, 1 storage/dir, 2 stream, 5 root */ - BYTE pps_unknown0; /* 43: unknown */ - DWORD pps_prev; /* 44: previous pps */ - DWORD pps_next; /* 48: next pps */ - DWORD pps_dir; /* 4C: directory pps */ - GUID pps_guid; /* 50: class ID */ - DWORD pps_unknown1; /* 60: unknown */ - FILETIME pps_ft1; /* 64: filetime1 */ - FILETIME pps_ft2; /* 70: filetime2 */ - DWORD pps_sb; /* 74: data startblock */ - DWORD pps_size; /* 78: datalength. (<0x1000)?small:big blocks*/ - DWORD pps_unknown2; /* 7C: unknown */ -}; - -#define STORAGE_CHAINENTRY_FAT 0xfffffffd -#define STORAGE_CHAINENTRY_ENDOFCHAIN 0xfffffffe -#define STORAGE_CHAINENTRY_FREE 0xffffffff - - -static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1}; - -#define BIGSIZE 512 -#define SMALLSIZE 64 - -#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))); -static IStorage16Vtbl stvt16; -static IStorage16Vtbl *segstvt16 = NULL; -static IStream16Vtbl strvt16; -static IStream16Vtbl *segstrvt16 = NULL; - -/*ULONG WINAPI IStorage16_AddRef(LPSTORAGE16 this);*/ -static void _create_istorage16(LPSTORAGE16 *stg); -static void _create_istream16(LPSTREAM16 *str); - -#define IMPLEMENTED 1 - -/* The following is taken from the CorVu implementation of docfiles, and - * documents things about the file format that are not implemented here, and - * not documented by the LAOLA project. The CorVu implementation was posted - * to wine-devel in February 2004, and released under the LGPL at the same - * time. Because that implementation is in C++, it's not directly usable in - * Wine, but does have documentation value. - * - * - * #define DF_EXT_VTOC -4 - * #define DF_VTOC_VTOC -3 - * #define DF_VTOC_EOF -2 - * #define DF_VTOC_FREE -1 - * #define DF_NAMELEN 0x20 // Maximum entry name length - 31 characters plus - * // a NUL terminator - * - * #define DF_FT_STORAGE 1 - * #define DF_FT_STREAM 2 - * #define DF_FT_LOCKBYTES 3 // Not used -- How the bloody hell did I manage - * #define DF_FT_PROPERTY 4 // Not Used -- to figure these two out? - * #define DF_FT_ROOT 5 - * - * #define DF_BLOCK_SIZE 0x200 - * #define DF_VTOC_SIZE 0x80 - * #define DF_DE_PER_BLOCK 4 - * #define DF_STREAM_BLOCK_SIZE 0x40 - * - * A DocFile is divided into blocks of 512 bytes. - * The first block contains the header. - * - * The file header contains The first 109 entries in the VTOC of VTOCs. - * - * Each block pointed to by a VTOC of VTOCs contains a VTOC, which - * includes block chains - just like FAT. This is a somewhat poor - * design for the following reasons: - * - * 1. FAT was a poor file system design to begin with, and - * has long been known to be horrendously inefficient - * for day to day operations. - * - * 2. The problem is compounded here, since the file - * level streams are generally *not* read sequentially. - * This means that a significant percentage of reads - * require seeking from the start of the chain. - * - * Data chains also contain an internal VTOC. The block size for - * the standard VTOC is 512. The block size for the internal VTOC - * is 64. - * - * Now, the 109 blocks in the VTOC of VTOCs allows for files of - * up to around 7MB. So what do you think happens if that's - * exceeded? Well, there's an entry in the header block which - * points to the first block used as additional storage for - * the VTOC of VTOCs. - * - * Now we can get up to around 15MB. Now, guess how the file - * format adds in another block to the VTOC of VTOCs. Come on, - * it's no big surprise. That's right - the last entry in each - * block extending the VTOC of VTOCs is, you guessed it, the - * block number of the next block containing an extension to - * the VTOC of VTOCs. The VTOC of VTOCs is chained!!!! - * - * So, to review: - * - * 1. If you are using a FAT file system, the location of - * your file's blocks is stored in chains. - * - * 2. At the abstract level, the file contains a VTOC of VTOCs, - * which is stored in the most inefficient possible format for - * random access - a chain (AKA list). - * - * 3. The VTOC of VTOCs contains descriptions of three file level - * streams: - * - * a. The Directory stream - * b. The Data stream - * c. The Data VTOC stream - * - * These are, of course, represented as chains. - * - * 4. The Data VTOC contains data describing the chains of blocks - * within the Data stream. - * - * That's right - we have a total of four levels of block chains! - * - * Now, is that complicated enough for you? No? OK, there's another - * complication. If an individual stream (ie. an IStream) reaches - * 4096 bytes in size, it gets moved from the Data Stream to - * a new file level stream. Now, if the stream then gets truncated - * back to less than 4096 bytes, it returns to the data stream. - * - * The effect of using this format can be seen very easily. Pick - * an arbitrary application with a grid data representation that - * can export to both Lotus 123 and Excel 5 or higher. Export - * a large file to Lotus 123 and time it. Export the same thing - * to Excel 5 and time that. The difference is the inefficiency - * of the Microsoft DocFile format. - * - * - * #define TOTAL_SIMPLE_VTOCS 109 - * - * struct DocFile_Header - * { - * df_byte iMagic1; // 0xd0 - * df_byte iMagic2; // 0xcf - * df_byte iMagic3; // 0x11 - * df_byte iMagic4; // 0xe0 - Spells D0CF11E0, or DocFile - * df_byte iMagic5; // 161 (igi upside down) - * df_byte iMagic6; // 177 (lli upside down - see below - * df_byte iMagic7; // 26 (gz upside down) - * df_byte iMagic8; // 225 (szz upside down) - see below - * df_int4 aiUnknown1[4]; - * df_int4 iVersion; // DocFile Version - 0x03003E - * df_int4 aiUnknown2[4]; - * df_int4 nVTOCs; // Number of VTOCs - * df_int4 iFirstDirBlock; // First Directory Block - * df_int4 aiUnknown3[2]; - * df_int4 iFirstDataVTOC; // First data VTOC block - * df_int4 iHasData; // 1 if there is data in the file - yes, this is important - * df_int4 iExtendedVTOC; // Extended VTOC location - * df_int4 iExtendedVTOCSize; // Size of extended VTOC (+1?) - * df_int4 aiVTOCofVTOCs[TOTAL_SIMPLE_VTOCS]; - * }; - * - * struct DocFile_VTOC - * { - * df_int4 aiBlocks[DF_VTOC_SIZE]; - * }; - * - * - * The meaning of the magic numbers - * - * 0xd0cf11e0 is DocFile with a zero on the end (sort of) - * - * If you key 177161 into a calculator, then turn the calculator - * upside down, you get igilli, which may be a reference to - * somebody's name, or to the Hebrew word for "angel". - * - * If you key 26225 into a calculator, then turn it upside down, you - * get szzgz. Microsoft has a tradition of creating nonsense words - * using the letters s, g, z and y. We think szzgz may be one of the - * Microsoft placeholder variables, along the lines of foo, bar and baz. - * Alternatively, it could be 22526, which would be gzszz. - * - * - * struct DocFile_DirEnt - * { - * df_char achEntryName[DF_NAMELEN]; // Entry Name - * df_int2 iNameLen; // Name length in bytes, including NUL terminator - * df_byte iFileType; // Entry type - * df_byte iColour; // 1 = Black, 0 = Red - * df_int4 iLeftSibling; // Next Left Sibling Entry - See below - * df_int4 iRightSibling; // Next Right Sibling Entry - * df_int4 iFirstChild; // First Child Entry - * df_byte achClassID[16]; // Class ID - * df_int4 iStateBits; // [GS]etStateBits value - * df_int4 iCreatedLow; // Low DWORD of creation time - * df_int4 iCreatedHigh; // High DWORD of creation time - * df_int4 iModifiedLow; // Low DWORD of modification time - * df_int4 iModifiedHigh; // High DWORD of modification time - * df_int4 iVTOCPosition; // VTOC Position - * df_int4 iFileSize; // Size of the stream - * df_int4 iZero; // We think this is part of the 64 bit stream size - must be 0 - * }; - * - * Siblings - * ======== - * - * Siblings are stored in an obscure but incredibly elegant - * data structure called a red-black tree. This is generally - * defined as a 2-3-4 tree stored in a binary tree. - * - * A red-black tree can always be balanced very easily. The rules - * for a red-black tree are as follows: - * - * 1. The root node is always black. - * 2. The parent of a red node is always black. - * - * There is a Java demo of red-black trees at: - * - * http://langevin.usc.edu/BST/RedBlackTree-Example.html - * - * This demo is an excellent tool for learning how red-black - * trees work, without having to go through the process of - * learning how they were derived. - * - * Within the tree, elements are ordered by the length of the - * name and within that, ASCII order by name. This causes the - * apparently bizarre reordering you see when you use dfview. - * - * This is a somewhat bizarre choice. It suggests that the - * designer of the DocFile format was trying to optimise - * searching through the directory entries. However searching - * through directory entries is a relatively rare operation. - * Reading and seeking within a stream are much more common - * operations, especially within the file level streams, yet - * these use the horrendously inefficient FAT chains. - * - * This suggests that the designer was probably somebody - * fresh out of university, who had some basic knowledge of - * basic data structures, but little knowledge of anything - * more practical. It is bizarre to attempt to optimise - * directory searches while not using a more efficient file - * block locating system than FAT (seedling/sapling/tree - * would result in a massive improvement - in fact we have - * an alternative to DocFiles that we use internally that - * uses seedling/sapling/tree and *is* far more efficient). - * - * It is worth noting that the MS implementation of red-black - * trees is incorrect (I can tell you're surprised) and - * actually causes more operations to occur than are really - * needed. Fortunately the fact that our implementation is - * correct will not cause any problems - the MS implementation - * still appears to cause the tree to satisfy the rules, albeit - * a sequence of the same insertions in the different - * implementations may result in a different, and possibly - * deeper (but never shallower) tree. - */ - - -/****************************************************************************** - * STORAGE_get_big_block [Internal] - * - * Reading OLE compound storage - */ -static BOOL -STORAGE_get_big_block(HANDLE hf,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 (!ReadFile( hf, block, BIGSIZE, &result, NULL ) || result != BIGSIZE) - { - WARN("(block size %d): read didn't read (%ld)\n",n,GetLastError()); - return FALSE; - } - return TRUE; -} - -/****************************************************************************** - * STORAGE_put_big_block [INTERNAL] - */ -static BOOL -STORAGE_put_big_block(HANDLE hf,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 (!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) { - INT bbs[BIGSIZE/sizeof(INT)]; - struct storage_header sth; - - READ_HEADER; - - assert(blocknr>>7>7]==0xffffffff) - return -5; - if (!STORAGE_get_big_block(hf,sth.bbd_list[blocknr>>7],(LPBYTE)bbs)) - return -5; - assert(bbs[blocknr&0x7f]!=STORAGE_CHAINENTRY_FREE); - return bbs[blocknr&0x7f]; -} - -/****************************************************************************** - * STORAGE_get_nth_next_big_blocknr [INTERNAL] - */ -static int -STORAGE_get_nth_next_big_blocknr(HANDLE hf,int blocknr,int nr) { - INT bbs[BIGSIZE/sizeof(INT)]; - int lastblock = -1; - struct storage_header sth; - - READ_HEADER; - - assert(blocknr>=0); - while (nr--) { - assert((blocknr>>7)>7]!=0xffffffff); - - /* simple caching... */ - if (lastblock!=sth.bbd_list[blocknr>>7]) { - BOOL ret = STORAGE_get_big_block(hf,sth.bbd_list[blocknr>>7],(LPBYTE)bbs); - assert(ret); - lastblock = sth.bbd_list[blocknr>>7]; - } - blocknr = bbs[blocknr&0x7f]; - } - return blocknr; -} - -/****************************************************************************** - * STORAGE_get_root_pps_entry [Internal] - */ -static BOOL -STORAGE_get_root_pps_entry(HANDLE hf,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; - blocknr = sth.root_startblock; - while (blocknr>=0) { - BOOL ret = STORAGE_get_big_block(hf,blocknr,block); - assert(ret); - for (i=0;i<4;i++) { - if (!stde[i].pps_sizeofname) - continue; - if (stde[i].pps_type==5) { - *pstde=stde[i]; - return TRUE; - } - } - blocknr=STORAGE_get_next_big_blocknr(hf,blocknr); - } - return FALSE; -} - -/****************************************************************************** - * STORAGE_get_small_block [INTERNAL] - */ -static BOOL -STORAGE_get_small_block(HANDLE hf,int blocknr,BYTE *sblock) { - BYTE block[BIGSIZE]; - int bigblocknr; - struct storage_pps_entry root; - BOOL ret; - - assert(blocknr>=0); - ret = STORAGE_get_root_pps_entry(hf,&root); - assert(ret); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); - assert(ret); - - memcpy(sblock,((LPBYTE)block)+SMALLSIZE*(blocknr&(SMALLBLOCKS_PER_BIGBLOCK-1)),SMALLSIZE); - return TRUE; -} - -/****************************************************************************** - * STORAGE_put_small_block [INTERNAL] - */ -static BOOL -STORAGE_put_small_block(HANDLE hf,int blocknr,BYTE *sblock) { - BYTE block[BIGSIZE]; - int bigblocknr; - struct storage_pps_entry root; - BOOL ret; - - assert(blocknr>=0); - - ret = STORAGE_get_root_pps_entry(hf,&root); - assert(ret); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,root.pps_sb,blocknr/SMALLBLOCKS_PER_BIGBLOCK); - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); - assert(ret); - - memcpy(((LPBYTE)block)+SMALLSIZE*(blocknr&(SMALLBLOCKS_PER_BIGBLOCK-1)),sblock,SMALLSIZE); - ret = STORAGE_put_big_block(hf,bigblocknr,block); - assert(ret); - return TRUE; -} - -/****************************************************************************** - * STORAGE_get_next_small_blocknr [INTERNAL] - */ -static int -STORAGE_get_next_small_blocknr(HANDLE hf,int blocknr) { - BYTE block[BIGSIZE]; - LPINT sbd = (LPINT)block; - int bigblocknr; - struct storage_header sth; - BOOL ret; - - READ_HEADER; - assert(blocknr>=0); - bigblocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.sbd_startblock,blocknr/128); - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); - assert(ret); - assert(sbd[blocknr & 127]!=STORAGE_CHAINENTRY_FREE); - return sbd[blocknr & (128-1)]; -} - -/****************************************************************************** - * STORAGE_get_nth_next_small_blocknr [INTERNAL] - */ -static int -STORAGE_get_nth_next_small_blocknr(HANDLE hf,int blocknr,int nr) { - int lastblocknr=-1; - BYTE block[BIGSIZE]; - LPINT sbd = (LPINT)block; - struct storage_header sth; - BOOL ret; - - READ_HEADER; - 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); - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); - assert(ret); - lastblocknr = blocknr; - } - assert(lastblocknr>=0); - lastblocknr=blocknr; - blocknr=sbd[blocknr & (128-1)]; - assert(blocknr!=STORAGE_CHAINENTRY_FREE); - } - return blocknr; -} - -/****************************************************************************** - * STORAGE_get_pps_entry [INTERNAL] - */ -static int -STORAGE_get_pps_entry(HANDLE hf,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; - /* we have 4 pps entries per big block */ - blocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.root_startblock,n/4); - assert(blocknr>=0); - ret = STORAGE_get_big_block(hf,blocknr,block); - assert(ret); - - *pstde=*stde; - return 1; -} - -/****************************************************************************** - * STORAGE_put_pps_entry [Internal] - */ -static int -STORAGE_put_pps_entry(HANDLE hf,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; - - /* we have 4 pps entries per big block */ - blocknr = STORAGE_get_nth_next_big_blocknr(hf,sth.root_startblock,n/4); - assert(blocknr>=0); - ret = STORAGE_get_big_block(hf,blocknr,block); - assert(ret); - *stde=*pstde; - ret = STORAGE_put_big_block(hf,blocknr,block); - assert(ret); - return 1; -} - -/****************************************************************************** - * STORAGE_look_for_named_pps [Internal] - */ -static int -STORAGE_look_for_named_pps(HANDLE hf,int n,LPOLESTR name) { - struct storage_pps_entry stde; - int ret; - - if (n==-1) - return -1; - if (1!=STORAGE_get_pps_entry(hf,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); - if (ret!=-1) - return ret; - } - if (stde.pps_next != -1) { - ret=STORAGE_look_for_named_pps(hf,stde.pps_next,name); - if (ret!=-1) - return ret; - } - return -1; -} - -/****************************************************************************** - * STORAGE_dump_pps_entry [Internal] - * - * FIXME - * Function is unused - */ -void -STORAGE_dump_pps_entry(struct storage_pps_entry *stde) { - char name[33]; - - WideCharToMultiByte( CP_ACP, 0, stde->pps_rawname, -1, name, sizeof(name), NULL, NULL); - if (!stde->pps_sizeofname) - return; - DPRINTF("name: %s\n",name); - DPRINTF("type: %d\n",stde->pps_type); - DPRINTF("prev pps: %ld\n",stde->pps_prev); - DPRINTF("next pps: %ld\n",stde->pps_next); - DPRINTF("dir pps: %ld\n",stde->pps_dir); - DPRINTF("guid: %s\n",debugstr_guid(&(stde->pps_guid))); - if (stde->pps_type !=2) { - time_t t; - DWORD dw; - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&(stde->pps_ft1),&dw); - t = dw; - DPRINTF("ts1: %s\n",ctime(&t)); - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&(stde->pps_ft2),&dw); - t = dw; - DPRINTF("ts2: %s\n",ctime(&t)); - } - DPRINTF("startblock: %ld\n",stde->pps_sb); - DPRINTF("size: %ld\n",stde->pps_size); -} - -/****************************************************************************** - * STORAGE_init_storage [INTERNAL] - */ -static BOOL -STORAGE_init_storage(HANDLE hf) { - BYTE block[BIGSIZE]; - LPDWORD bbs; - struct storage_header *sth; - struct storage_pps_entry *stde; - DWORD result; - - SetFilePointer( hf, 0, NULL, SEEK_SET ); - /* block -1 is the storage header */ - sth = (struct storage_header*)block; - memcpy(sth->magic,STORAGE_magic,8); - memset(sth->unknown1,0,sizeof(sth->unknown1)); - memset(sth->unknown2,0,sizeof(sth->unknown2)); - memset(sth->unknown3,0,sizeof(sth->unknown3)); - sth->num_of_bbd_blocks = 1; - sth->root_startblock = 1; - 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; - /* 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; - /* block 1 is the root directory entry */ - memset(block,0x00,sizeof(block)); - stde = (struct storage_pps_entry*)block; - MultiByteToWideChar( CP_ACP, 0, "RootEntry", -1, stde->pps_rawname, - sizeof(stde->pps_rawname)/sizeof(WCHAR)); - stde->pps_sizeofname = (strlenW(stde->pps_rawname)+1) * sizeof(WCHAR); - stde->pps_type = 5; - stde->pps_dir = -1; - stde->pps_next = -1; - stde->pps_prev = -1; - stde->pps_sb = 0xffffffff; - stde->pps_size = 0; - return (WriteFile( hf, block, BIGSIZE, &result, NULL ) && result == BIGSIZE); -} - -/****************************************************************************** - * STORAGE_set_big_chain [Internal] - */ -static BOOL -STORAGE_set_big_chain(HANDLE hf,int blocknr,INT type) { - BYTE block[BIGSIZE]; - LPINT bbd = (LPINT)block; - int nextblocknr,bigblocknr; - struct storage_header sth; - BOOL ret; - - READ_HEADER; - assert(blocknr!=type); - while (blocknr>=0) { - bigblocknr = sth.bbd_list[blocknr/128]; - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,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); - assert(ret); - type = STORAGE_CHAINENTRY_FREE; - blocknr = nextblocknr; - } - return TRUE; -} - -/****************************************************************************** - * STORAGE_set_small_chain [Internal] - */ -static BOOL -STORAGE_set_small_chain(HANDLE hf,int blocknr,INT type) { - BYTE block[BIGSIZE]; - LPINT sbd = (LPINT)block; - int lastblocknr,nextsmallblocknr,bigblocknr; - struct storage_header sth; - BOOL ret; - - READ_HEADER; - - 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); - assert(bigblocknr>=0); - ret = STORAGE_get_big_block(hf,bigblocknr,block); - assert(ret); - } - lastblocknr = blocknr; - nextsmallblocknr = sbd[blocknr&(128-1)]; - sbd[blocknr&(128-1)] = type; - ret = STORAGE_put_big_block(hf,bigblocknr,block); - assert(ret); - if (type>=0) - return TRUE; - type = STORAGE_CHAINENTRY_FREE; - blocknr = nextsmallblocknr; - } - return TRUE; -} - -/****************************************************************************** - * STORAGE_get_free_big_blocknr [Internal] - */ -static int -STORAGE_get_free_big_blocknr(HANDLE hf) { - BYTE block[BIGSIZE]; - LPINT sbd = (LPINT)block; - int lastbigblocknr,i,bigblocknr; - unsigned int curblock; - struct storage_header sth; - BOOL ret; - - READ_HEADER; - curblock = 0; - lastbigblocknr = -1; - bigblocknr = sth.bbd_list[curblock]; - while (curblock=0); - ret = STORAGE_get_big_block(hf,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); - assert(ret); - memset(block,0x42,sizeof(block)); - ret = STORAGE_put_big_block(hf,i+curblock*128,block); - assert(ret); - return i+curblock*128; - } - lastbigblocknr = bigblocknr; - bigblocknr = sth.bbd_list[++curblock]; - } - bigblocknr = curblock*128; - /* since we have marked all blocks from 0 up to curblock*128-1 - * the next free one is curblock*128, where we happily put our - * next large block depot. - */ - 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); - 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); - 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); - assert(ret); - - /* Set the end of the chain for the bigblockdepots */ - ret = STORAGE_set_big_chain(hf,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); - assert(ret); - return bigblocknr+1; -} - - -/****************************************************************************** - * STORAGE_get_free_small_blocknr [Internal] - */ -static int -STORAGE_get_free_small_blocknr(HANDLE hf) { - BYTE block[BIGSIZE]; - LPINT sbd = (LPINT)block; - int lastbigblocknr,newblocknr,i,curblock,bigblocknr; - struct storage_pps_entry root; - struct storage_header sth; - - READ_HEADER; - bigblocknr = sth.sbd_startblock; - curblock = 0; - lastbigblocknr = -1; - newblocknr = -1; - while (bigblocknr>=0) { - if (!STORAGE_get_big_block(hf,bigblocknr,block)) - return -1; - for (i=0;i<128;i++) - if (sbd[i]==STORAGE_CHAINENTRY_FREE) { - sbd[i]=STORAGE_CHAINENTRY_ENDOFCHAIN; - newblocknr = i+curblock*128; - break; - } - if (i!=128) - break; - lastbigblocknr = bigblocknr; - bigblocknr = STORAGE_get_next_big_blocknr(hf,bigblocknr); - curblock++; - } - if (newblocknr==-1) { - bigblocknr = STORAGE_get_free_big_blocknr(hf); - if (bigblocknr<0) - return -1; - READ_HEADER; - memset(block,0xff,sizeof(block)); - sbd[0]=STORAGE_CHAINENTRY_ENDOFCHAIN; - if (!STORAGE_put_big_block(hf,bigblocknr,block)) - return -1; - if (lastbigblocknr==-1) { - sth.sbd_startblock = bigblocknr; - if (!STORAGE_put_big_block(hf,-1,(LPBYTE)&sth)) /* need to write it */ - return -1; - } else { - if (!STORAGE_set_big_chain(hf,lastbigblocknr,bigblocknr)) - return -1; - } - if (!STORAGE_set_big_chain(hf,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)) - 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); - while (root.pps_size < (newblocknr*SMALLSIZE+SMALLSIZE-1)) { - /* we need to allocate more stuff */ - bigblocknr = STORAGE_get_free_big_blocknr(hf); - if (bigblocknr<0) - return -1; - READ_HEADER; - if (root.pps_sb==-1) { - root.pps_sb = bigblocknr; - root.pps_size += BIGSIZE; - } else { - if (!STORAGE_set_big_chain(hf,lastbigblocknr,bigblocknr)) - return -1; - root.pps_size += BIGSIZE; - } - lastbigblocknr = bigblocknr; - } - if (!STORAGE_set_big_chain(hf,lastbigblocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - return -1; - if (!STORAGE_put_pps_entry(hf,0,&root)) - return -1; - return newblocknr; -} - -/****************************************************************************** - * STORAGE_get_free_pps_entry [Internal] - */ -static int -STORAGE_get_free_pps_entry(HANDLE hf) { - 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; - blocknr = sth.root_startblock; - assert(blocknr>=0); - curblock=0; - while (blocknr>=0) { - if (!STORAGE_get_big_block(hf,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); - curblock++; - } - assert(blocknr==STORAGE_CHAINENTRY_ENDOFCHAIN); - blocknr = STORAGE_get_free_big_blocknr(hf); - /* sth invalidated */ - if (blocknr<0) - return -1; - - if (!STORAGE_set_big_chain(hf,lastblocknr,blocknr)) - return -1; - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - return -1; - memset(block,0,sizeof(block)); - STORAGE_put_big_block(hf,blocknr,block); - return curblock*4; -} - -/* --- IStream16 implementation */ - -typedef struct -{ - /* IUnknown fields */ - IStream16Vtbl *lpVtbl; - DWORD ref; - /* IStream16 fields */ - SEGPTR thisptr; /* pointer to this struct as segmented */ - struct storage_pps_entry stde; - int ppsent; - HANDLE hf; - ULARGE_INTEGER offset; -} IStream16Impl; - -/****************************************************************************** - * IStream16_QueryInterface [STORAGE.518] - */ -HRESULT WINAPI IStream16_fnQueryInterface( - IStream16* iface,REFIID refiid,LPVOID *obj -) { - IStream16Impl *This = (IStream16Impl *)iface; - TRACE_(relay)("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj); - if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) { - *obj = This; - return 0; - } - return OLE_E_ENUM_NOMORE; - -} - -/****************************************************************************** - * IStream16_AddRef [STORAGE.519] - */ -ULONG WINAPI IStream16_fnAddRef(IStream16* iface) { - IStream16Impl *This = (IStream16Impl *)iface; - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * IStream16_Release [STORAGE.520] - */ -ULONG WINAPI IStream16_fnRelease(IStream16* iface) { - IStream16Impl *This = (IStream16Impl *)iface; - ULONG ref; - FlushFileBuffers(This->hf); - ref = InterlockedDecrement(&This->ref); - if (!ref) { - CloseHandle(This->hf); - UnMapLS( This->thisptr ); - HeapFree( GetProcessHeap(), 0, This ); - } - return ref; -} - -/****************************************************************************** - * IStream16_Seek [STORAGE.523] - * - * FIXME - * Does not handle 64 bits - */ -HRESULT WINAPI IStream16_fnSeek( - IStream16* iface,LARGE_INTEGER offset,DWORD whence,ULARGE_INTEGER *newpos -) { - IStream16Impl *This = (IStream16Impl *)iface; - TRACE_(relay)("(%p)->([%ld.%ld],%ld,%p)\n",This,offset.u.HighPart,offset.u.LowPart,whence,newpos); - - switch (whence) { - /* unix SEEK_xx should be the same as win95 ones */ - case SEEK_SET: - /* offset must be ==0 (<0 is invalid, and >0 cannot be handled - * right now. - */ - assert(offset.u.HighPart==0); - This->offset.u.HighPart = offset.u.HighPart; - This->offset.u.LowPart = offset.u.LowPart; - break; - case SEEK_CUR: - if (offset.u.HighPart < 0) { - /* FIXME: is this negation correct ? */ - offset.u.HighPart = -offset.u.HighPart; - offset.u.LowPart = (0xffffffff ^ offset.u.LowPart)+1; - - assert(offset.u.HighPart==0); - assert(This->offset.u.LowPart >= offset.u.LowPart); - This->offset.u.LowPart -= offset.u.LowPart; - } else { - assert(offset.u.HighPart==0); - This->offset.u.LowPart+= offset.u.LowPart; - } - break; - case SEEK_END: - assert(offset.u.HighPart==0); - This->offset.u.LowPart = This->stde.pps_size-offset.u.LowPart; - break; - } - if (This->offset.u.LowPart>This->stde.pps_size) - This->offset.u.LowPart=This->stde.pps_size; - if (newpos) *newpos = This->offset; - return S_OK; -} - -/****************************************************************************** - * IStream16_Read [STORAGE.521] - */ -HRESULT WINAPI IStream16_fnRead( - IStream16* iface,void *pv,ULONG cb,ULONG *pcbRead -) { - IStream16Impl *This = (IStream16Impl *)iface; - BYTE block[BIGSIZE]; - ULONG *bytesread=pcbRead,xxread; - int blocknr; - LPBYTE pbv = pv; - - TRACE_(relay)("(%p)->(%p,%ld,%p)\n",This,pv,cb,pcbRead); - if (!pcbRead) bytesread=&xxread; - *bytesread = 0; - - if (cb>This->stde.pps_size-This->offset.u.LowPart) - 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); - while (cb) { - unsigned int cc; - - if (!STORAGE_get_small_block(This->hf,blocknr,block)) { - WARN("small block read failed!!!\n"); - return E_FAIL; - } - cc = cb; - if (cc>SMALLSIZE-(This->offset.u.LowPart&(SMALLSIZE-1))) - cc=SMALLSIZE-(This->offset.u.LowPart&(SMALLSIZE-1)); - memcpy(pbv,block+(This->offset.u.LowPart&(SMALLSIZE-1)),cc); - This->offset.u.LowPart+=cc; - pbv+=cc; - *bytesread+=cc; - cb-=cc; - blocknr = STORAGE_get_next_small_blocknr(This->hf,blocknr); - } - } else { - /* use big block reader */ - blocknr = STORAGE_get_nth_next_big_blocknr(This->hf,This->stde.pps_sb,This->offset.u.LowPart/BIGSIZE); - while (cb) { - unsigned int cc; - - if (!STORAGE_get_big_block(This->hf,blocknr,block)) { - WARN("big block read failed!!!\n"); - return E_FAIL; - } - cc = cb; - if (cc>BIGSIZE-(This->offset.u.LowPart&(BIGSIZE-1))) - cc=BIGSIZE-(This->offset.u.LowPart&(BIGSIZE-1)); - memcpy(pbv,block+(This->offset.u.LowPart&(BIGSIZE-1)),cc); - This->offset.u.LowPart+=cc; - pbv+=cc; - *bytesread+=cc; - cb-=cc; - blocknr=STORAGE_get_next_big_blocknr(This->hf,blocknr); - } - } - return S_OK; -} - -/****************************************************************************** - * IStream16_Write [STORAGE.522] - */ -HRESULT WINAPI IStream16_fnWrite( - IStream16* iface,const void *pv,ULONG cb,ULONG *pcbWrite -) { - IStream16Impl *This = (IStream16Impl *)iface; - 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; - *byteswritten = 0; - - TRACE_(relay)("(%p)->(%p,%ld,%p)\n",This,pv,cb,pcbWrite); - /* do we need to junk some blocks? */ - newsize = This->offset.u.LowPart+cb; - oldsize = This->stde.pps_size; - if (newsize < oldsize) { - if (oldsize < 0x1000) { - /* only small blocks */ - blocknr=STORAGE_get_nth_next_small_blocknr(hf,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)) - return E_FAIL; - } else { - if (newsize >= 0x1000) { - blocknr=STORAGE_get_nth_next_big_blocknr(hf,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)) - return E_FAIL; - } else { - /* Migrate large blocks to small blocks - * (we just migrate newsize bytes) - */ - LPBYTE curdata,data = HeapAlloc(GetProcessHeap(),0,newsize+BIGSIZE); - HRESULT r = E_FAIL; - - cc = newsize; - blocknr = This->stde.pps_sb; - curdata = data; - while (cc>0) { - if (!STORAGE_get_big_block(hf,blocknr,curdata)) { - HeapFree(GetProcessHeap(),0,data); - return E_FAIL; - } - curdata += BIGSIZE; - cc -= BIGSIZE; - blocknr = STORAGE_get_next_big_blocknr(hf,blocknr); - } - /* frees complete chain for this stream */ - if (!STORAGE_set_big_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) - goto err; - curdata = data; - blocknr = This->stde.pps_sb = STORAGE_get_free_small_blocknr(hf); - if (blocknr<0) - goto err; - cc = newsize; - while (cc>0) { - if (!STORAGE_put_small_block(hf,blocknr,curdata)) - goto err; - cc -= SMALLSIZE; - if (cc<=0) { - if (!STORAGE_set_small_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - goto err; - break; - } else { - int newblocknr = STORAGE_get_free_small_blocknr(hf); - if (newblocknr<0) - goto err; - if (!STORAGE_set_small_chain(hf,blocknr,newblocknr)) - goto err; - blocknr = newblocknr; - } - curdata += SMALLSIZE; - } - r = S_OK; - err: - HeapFree(GetProcessHeap(),0,data); - if(r != S_OK) - return r; - } - } - This->stde.pps_size = newsize; - } - - 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); - assert(blocknr>=0); - lastblocknr = blocknr; - for (i=oldsize/BIGSIZE;istde.pps_sb = blocknr = STORAGE_get_free_small_blocknr(hf); - else - blocknr = STORAGE_get_nth_next_small_blocknr(hf,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;istde.pps_sb = blocknr; - } else { - /* Migrate small blocks to big blocks */ - LPBYTE curdata,data = HeapAlloc(GetProcessHeap(),0,oldsize+BIGSIZE); - HRESULT r = E_FAIL; - - cc = oldsize; - blocknr = This->stde.pps_sb; - curdata = data; - /* slurp in */ - while (cc>0) { - if (!STORAGE_get_small_block(hf,blocknr,curdata)) - goto err2; - curdata += SMALLSIZE; - cc -= SMALLSIZE; - blocknr = STORAGE_get_next_small_blocknr(hf,blocknr); - } - /* free small block chain */ - if (!STORAGE_set_small_chain(hf,This->stde.pps_sb,STORAGE_CHAINENTRY_FREE)) - goto err2; - curdata = data; - blocknr = This->stde.pps_sb = STORAGE_get_free_big_blocknr(hf); - 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)) - goto err2; - cc -= BIGSIZE; - if (cc<=0) { - if (!STORAGE_set_big_chain(hf,blocknr,STORAGE_CHAINENTRY_ENDOFCHAIN)) - goto err2; - break; - } else { - int newblocknr = STORAGE_get_free_big_blocknr(hf); - if (newblocknr<0) - goto err2; - if (!STORAGE_set_big_chain(hf,blocknr,newblocknr)) - goto err2; - blocknr = newblocknr; - } - curdata += BIGSIZE; - } - r = S_OK; - err2: - HeapFree(GetProcessHeap(),0,data); - if(r != S_OK) - return r; - } - /* generate big blocks to fit the new data */ - lastblocknr = blocknr; - for (i=oldsize/BIGSIZE;istde.pps_size = newsize; - } - - /* 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))) - 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); - assert(blocknr>=0); - while (cb>0) { - /* we ensured that it is allocated above */ - assert(blocknr>=0); - /* 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)) - return E_FAIL; - - cc = SMALLSIZE-(This->offset.u.LowPart&(SMALLSIZE-1)); - if (cc>cb) - cc=cb; - memcpy( ((LPBYTE)block)+(This->offset.u.LowPart&(SMALLSIZE-1)), - pbv+curoffset, - cc - ); - if (!STORAGE_put_small_block(hf,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); - } - } else { - blocknr = STORAGE_get_nth_next_big_blocknr(hf,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 */ - assert(blocknr>=0); - /* 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)) - return E_FAIL; - - cc = BIGSIZE-(This->offset.u.LowPart&(BIGSIZE-1)); - if (cc>cb) - cc=cb; - memcpy( ((LPBYTE)block)+(This->offset.u.LowPart&(BIGSIZE-1)), - pbv+curoffset, - cc - ); - if (!STORAGE_put_big_block(hf,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); - } - } - return S_OK; -} - -/****************************************************************************** - * _create_istream16 [Internal] - */ -static void _create_istream16(LPSTREAM16 *str) { - IStream16Impl* lpst; - - if (!strvt16.QueryInterface) { - HMODULE16 wp = GetModuleHandle16("STORAGE"); - if (wp>=32) { - /* FIXME: what is This GetProcAddress16. Should the name be IStream16_QueryInterface of IStream16_fnQueryInterface */ -#define VTENT(xfn) strvt16.xfn = (void*)GetProcAddress16(wp,"IStream16_"#xfn);assert(strvt16.xfn) - VTENT(QueryInterface); - VTENT(AddRef); - VTENT(Release); - VTENT(Read); - VTENT(Write); - VTENT(Seek); - VTENT(SetSize); - VTENT(CopyTo); - VTENT(Commit); - VTENT(Revert); - VTENT(LockRegion); - VTENT(UnlockRegion); - VTENT(Stat); - VTENT(Clone); -#undef VTENT - segstrvt16 = (IStream16Vtbl*)MapLS( &strvt16 ); - } else { -#define VTENT(xfn) strvt16.xfn = IStream16_fn##xfn; - VTENT(QueryInterface); - VTENT(AddRef); - VTENT(Release); - VTENT(Read); - VTENT(Write); - VTENT(Seek); - /* - VTENT(CopyTo); - VTENT(Commit); - VTENT(SetSize); - VTENT(Revert); - VTENT(LockRegion); - VTENT(UnlockRegion); - VTENT(Stat); - VTENT(Clone); - */ -#undef VTENT - segstrvt16 = &strvt16; - } - } - lpst = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpst) ); - lpst->lpVtbl = segstrvt16; - lpst->ref = 1; - lpst->thisptr = MapLS( lpst ); - *str = (void*)lpst->thisptr; -} - - -/* --- IStream32 implementation */ - -typedef struct -{ - /* IUnknown fields */ - IStreamVtbl *lpVtbl; - DWORD ref; - /* IStream32 fields */ - struct storage_pps_entry stde; - int ppsent; - HANDLE hf; - ULARGE_INTEGER offset; -} IStream32Impl; - -/***************************************************************************** - * IStream32_QueryInterface [VTABLE] - */ -HRESULT WINAPI IStream_fnQueryInterface( - IStream* iface,REFIID refiid,LPVOID *obj -) { - IStream32Impl *This = (IStream32Impl *)iface; - - TRACE_(relay)("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj); - if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) { - *obj = This; - return 0; - } - return OLE_E_ENUM_NOMORE; - -} - -/****************************************************************************** - * IStream32_AddRef [VTABLE] - */ -ULONG WINAPI IStream_fnAddRef(IStream* iface) { - IStream32Impl *This = (IStream32Impl *)iface; - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * IStream32_Release [VTABLE] - */ -ULONG WINAPI IStream_fnRelease(IStream* iface) { - IStream32Impl *This = (IStream32Impl *)iface; - ULONG ref; - FlushFileBuffers(This->hf); - ref = InterlockedDecrement(&This->ref); - if (!ref) { - CloseHandle(This->hf); - HeapFree( GetProcessHeap(), 0, This ); - } - return ref; -} - -/* --- IStorage16 implementation */ - -typedef struct -{ - /* IUnknown fields */ - IStorage16Vtbl *lpVtbl; - DWORD 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] - */ -HRESULT WINAPI IStorage16_fnQueryInterface( - IStorage16* iface,REFIID refiid,LPVOID *obj -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - - TRACE_(relay)("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj); - - if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) { - *obj = This; - return 0; - } - return OLE_E_ENUM_NOMORE; -} - -/****************************************************************************** - * IStorage16_AddRef [STORAGE.501] - */ -ULONG WINAPI IStorage16_fnAddRef(IStorage16* iface) { - IStorage16Impl *This = (IStorage16Impl *)iface; - return InterlockedIncrement(&This->ref); -} - -/****************************************************************************** - * IStorage16_Release [STORAGE.502] - */ -ULONG WINAPI IStorage16_fnRelease(IStorage16* iface) { - IStorage16Impl *This = (IStorage16Impl *)iface; - ULONG ref; - ref = InterlockedDecrement(&This->ref); - if (!ref) - { - UnMapLS( This->thisptr ); - HeapFree( GetProcessHeap(), 0, This ); - } - return ref; -} - -/****************************************************************************** - * IStorage16_Stat [STORAGE.517] - */ -HRESULT WINAPI IStorage16_fnStat( - LPSTORAGE16 iface,STATSTG16 *pstatstg, DWORD grfStatFlag -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - DWORD len = WideCharToMultiByte( CP_ACP, 0, This->stde.pps_rawname, -1, NULL, 0, NULL, NULL ); - LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, len ); - - TRACE("(%p)->(%p,0x%08lx)\n", - This,pstatstg,grfStatFlag - ); - WideCharToMultiByte( CP_ACP, 0, This->stde.pps_rawname, -1, nameA, len, NULL, NULL ); - pstatstg->pwcsName=(LPOLESTR16)MapLS( nameA ); - pstatstg->type = This->stde.pps_type; - pstatstg->cbSize.u.LowPart = This->stde.pps_size; - pstatstg->mtime = This->stde.pps_ft1; /* FIXME */ /* why? */ - pstatstg->atime = This->stde.pps_ft2; /* FIXME */ - pstatstg->ctime = This->stde.pps_ft2; /* FIXME */ - pstatstg->grfMode = 0; /* FIXME */ - pstatstg->grfLocksSupported = 0; /* FIXME */ - pstatstg->clsid = This->stde.pps_guid; - pstatstg->grfStateBits = 0; /* FIXME */ - pstatstg->reserved = 0; - return S_OK; -} - -/****************************************************************************** - * IStorage16_Commit [STORAGE.509] - */ -HRESULT WINAPI IStorage16_fnCommit( - LPSTORAGE16 iface,DWORD commitflags -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - FIXME("(%p)->(0x%08lx),STUB!\n", - This,commitflags - ); - return S_OK; -} - -/****************************************************************************** - * IStorage16_CopyTo [STORAGE.507] - */ -HRESULT WINAPI IStorage16_fnCopyTo(LPSTORAGE16 iface,DWORD ciidExclude,const IID *rgiidExclude,SNB16 SNB16Exclude,IStorage16 *pstgDest) { - IStorage16Impl *This = (IStorage16Impl *)iface; - FIXME("IStorage16(%p)->(0x%08lx,%s,%p,%p),stub!\n", - This,ciidExclude,debugstr_guid(rgiidExclude),SNB16Exclude,pstgDest - ); - return S_OK; -} - - -/****************************************************************************** - * IStorage16_CreateStorage [STORAGE.505] - */ -HRESULT WINAPI IStorage16_fnCreateStorage( - LPSTORAGE16 iface,LPCOLESTR16 pwcsName,DWORD grfMode,DWORD dwStgFormat,DWORD reserved2, IStorage16 **ppstg -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - IStorage16Impl* lpstg; - int ppsent,x; - struct storage_pps_entry stde; - struct storage_header sth; - HANDLE hf=This->hf; - BOOL ret; - int nPPSEntries; - - READ_HEADER; - - TRACE("(%p)->(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n", - This,pwcsName,grfMode,dwStgFormat,reserved2,ppstg - ); - if (grfMode & STGM_TRANSACTED) - FIXME("We do not support transacted Compound Storage. Using direct mode.\n"); - _create_istorage16(ppstg); - lpstg = MapSL((SEGPTR)*ppstg); - lpstg->hf = This->hf; - - ppsent=STORAGE_get_free_pps_entry(lpstg->hf); - if (ppsent<0) - return E_FAIL; - stde=This->stde; - if (stde.pps_dir==-1) { - stde.pps_dir = ppsent; - x = This->ppsent; - } else { - FIXME(" use prev chain too ?\n"); - x=stde.pps_dir; - if (1!=STORAGE_get_pps_entry(lpstg->hf,x,&stde)) - return E_FAIL; - while (stde.pps_next!=-1) { - x=stde.pps_next; - if (1!=STORAGE_get_pps_entry(lpstg->hf,x,&stde)) - return E_FAIL; - } - stde.pps_next = ppsent; - } - ret = STORAGE_put_pps_entry(lpstg->hf,x,&stde); - assert(ret); - nPPSEntries = STORAGE_get_pps_entry(lpstg->hf,ppsent,&(lpstg->stde)); - assert(nPPSEntries == 1); - MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, lpstg->stde.pps_rawname, - sizeof(lpstg->stde.pps_rawname)/sizeof(WCHAR)); - lpstg->stde.pps_sizeofname = (strlenW(lpstg->stde.pps_rawname)+1)*sizeof(WCHAR); - lpstg->stde.pps_next = -1; - lpstg->stde.pps_prev = -1; - lpstg->stde.pps_dir = -1; - lpstg->stde.pps_sb = -1; - lpstg->stde.pps_size = 0; - lpstg->stde.pps_type = 1; - lpstg->ppsent = ppsent; - /* FIXME: timestamps? */ - if (!STORAGE_put_pps_entry(lpstg->hf,ppsent,&(lpstg->stde))) - return E_FAIL; - return S_OK; -} - -/****************************************************************************** - * IStorage16_CreateStream [STORAGE.503] - */ -HRESULT WINAPI IStorage16_fnCreateStream( - LPSTORAGE16 iface,LPCOLESTR16 pwcsName,DWORD grfMode,DWORD reserved1,DWORD reserved2, IStream16 **ppstm -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - IStream16Impl* lpstr; - int ppsent,x; - struct storage_pps_entry stde; - BOOL ret; - int nPPSEntries; - - TRACE("(%p)->(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n", - This,pwcsName,grfMode,reserved1,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 ); - lpstr->offset.u.LowPart = 0; - lpstr->offset.u.HighPart = 0; - - ppsent=STORAGE_get_free_pps_entry(lpstr->hf); - if (ppsent<0) - return E_FAIL; - stde=This->stde; - if (stde.pps_next==-1) - x=This->ppsent; - else - while (stde.pps_next!=-1) { - x=stde.pps_next; - if (1!=STORAGE_get_pps_entry(lpstr->hf,x,&stde)) - return E_FAIL; - } - stde.pps_next = ppsent; - ret = STORAGE_put_pps_entry(lpstr->hf,x,&stde); - assert(ret); - nPPSEntries = STORAGE_get_pps_entry(lpstr->hf,ppsent,&(lpstr->stde)); - assert(nPPSEntries == 1); - MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, lpstr->stde.pps_rawname, - sizeof(lpstr->stde.pps_rawname)/sizeof(WCHAR)); - lpstr->stde.pps_sizeofname = (strlenW(lpstr->stde.pps_rawname)+1) * sizeof(WCHAR); - lpstr->stde.pps_next = -1; - lpstr->stde.pps_prev = -1; - lpstr->stde.pps_dir = -1; - lpstr->stde.pps_sb = -1; - 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))) - return E_FAIL; - return S_OK; -} - -/****************************************************************************** - * IStorage16_OpenStorage [STORAGE.506] - */ -HRESULT WINAPI IStorage16_fnOpenStorage( - LPSTORAGE16 iface,LPCOLESTR16 pwcsName, IStorage16 *pstgPrio, DWORD grfMode, SNB16 snbExclude, DWORD reserved, IStorage16 **ppstg -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - IStream16Impl* lpstg; - WCHAR name[33]; - int newpps; - - TRACE_(relay)("(%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 ); - MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, name, sizeof(name)/sizeof(WCHAR)); - newpps = STORAGE_look_for_named_pps(lpstg->hf,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))) { - IStream16_fnRelease((IStream16*)lpstg); - return E_FAIL; - } - lpstg->ppsent = newpps; - return S_OK; -} - -/****************************************************************************** - * IStorage16_OpenStream [STORAGE.504] - */ -HRESULT WINAPI IStorage16_fnOpenStream( - LPSTORAGE16 iface,LPCOLESTR16 pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream16 **ppstm -) { - IStorage16Impl *This = (IStorage16Impl *)iface; - IStream16Impl* lpstr; - WCHAR name[33]; - int newpps; - - TRACE_(relay)("(%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 ); - MultiByteToWideChar( CP_ACP, 0, pwcsName, -1, name, sizeof(name)/sizeof(WCHAR)); - newpps = STORAGE_look_for_named_pps(lpstr->hf,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))) { - IStream16_fnRelease((IStream16*)lpstr); - return E_FAIL; - } - lpstr->offset.u.LowPart = 0; - lpstr->offset.u.HighPart = 0; - lpstr->ppsent = newpps; - return S_OK; -} - -/****************************************************************************** - * _create_istorage16 [INTERNAL] - */ -static void _create_istorage16(LPSTORAGE16 *stg) { - IStorage16Impl* lpst; - - if (!stvt16.QueryInterface) { - HMODULE16 wp = GetModuleHandle16("STORAGE"); - if (wp>=32) { -#define VTENT(xfn) stvt16.xfn = (void*)GetProcAddress16(wp,"IStorage16_"#xfn); - VTENT(QueryInterface) - VTENT(AddRef) - VTENT(Release) - VTENT(CreateStream) - VTENT(OpenStream) - VTENT(CreateStorage) - VTENT(OpenStorage) - VTENT(CopyTo) - VTENT(MoveElementTo) - VTENT(Commit) - VTENT(Revert) - VTENT(EnumElements) - VTENT(DestroyElement) - VTENT(RenameElement) - VTENT(SetElementTimes) - VTENT(SetClass) - VTENT(SetStateBits) - VTENT(Stat) -#undef VTENT - segstvt16 = (IStorage16Vtbl*)MapLS( &stvt16 ); - } else { -#define VTENT(xfn) stvt16.xfn = IStorage16_fn##xfn; - VTENT(QueryInterface) - VTENT(AddRef) - VTENT(Release) - VTENT(CreateStream) - VTENT(OpenStream) - VTENT(CreateStorage) - VTENT(OpenStorage) - VTENT(CopyTo) - VTENT(Commit) - /* not (yet) implemented ... - VTENT(MoveElementTo) - VTENT(Revert) - VTENT(EnumElements) - VTENT(DestroyElement) - VTENT(RenameElement) - VTENT(SetElementTimes) - VTENT(SetClass) - VTENT(SetStateBits) - VTENT(Stat) - */ -#undef VTENT - segstvt16 = &stvt16; - } - } - lpst = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpst) ); - lpst->lpVtbl = segstvt16; - lpst->ref = 1; - lpst->thisptr = MapLS(lpst); - *stg = (void*)lpst->thisptr; -} - -/****************************************************************************** - * Storage API functions - */ - -/****************************************************************************** - * StgCreateDocFileA [STORAGE.1] - */ -HRESULT WINAPI StgCreateDocFile16( - LPCOLESTR16 pwcsName,DWORD grfMode,DWORD reserved,IStorage16 **ppstgOpen -) { - HANDLE hf; - int i,ret; - IStorage16Impl* lpstg; - struct storage_pps_entry stde; - - TRACE("(%s,0x%08lx,0x%08lx,%p)\n", - pwcsName,grfMode,reserved,ppstgOpen - ); - _create_istorage16(ppstgOpen); - hf = CreateFileA(pwcsName,GENERIC_READ|GENERIC_WRITE,0,NULL,CREATE_NEW,0,0); - if (hf==INVALID_HANDLE_VALUE) { - WARN("couldn't open file for storage:%ld\n",GetLastError()); - return E_FAIL; - } - lpstg = MapSL((SEGPTR)*ppstgOpen); - lpstg->hf = hf; - /* FIXME: check for existence before overwriting? */ - if (!STORAGE_init_storage(hf)) { - CloseHandle(hf); - return E_FAIL; - } - i=0;ret=0; - while (!ret) { /* neither 1 nor <0 */ - ret=STORAGE_get_pps_entry(hf,i,&stde); - if ((ret==1) && (stde.pps_type==5)) { - lpstg->stde = stde; - lpstg->ppsent = i; - break; - } - i++; - } - if (ret!=1) { - IStorage16_fnRelease((IStorage16*)lpstg); /* will remove it */ - return E_FAIL; - } - - return S_OK; -} - -/****************************************************************************** - * StgIsStorageFile [STORAGE.5] - */ -HRESULT WINAPI StgIsStorageFile16(LPCOLESTR16 fn) { - UNICODE_STRING strW; - HRESULT ret; - - RtlCreateUnicodeStringFromAsciiz(&strW, fn); - ret = StgIsStorageFile( strW.Buffer ); - RtlFreeUnicodeString( &strW ); - - return ret; -} - -/****************************************************************************** - * StgOpenStorage [STORAGE.3] - */ -HRESULT WINAPI StgOpenStorage16( - LPCOLESTR16 pwcsName,IStorage16 *pstgPriority,DWORD grfMode, - SNB16 snbExclude,DWORD reserved, IStorage16 **ppstgOpen -) { - HANDLE hf; - int ret,i; - IStorage16Impl* lpstg; - struct storage_pps_entry stde; - - TRACE("(%s,%p,0x%08lx,%p,%ld,%p)\n", - pwcsName,pstgPriority,grfMode,snbExclude,reserved,ppstgOpen - ); - _create_istorage16(ppstgOpen); - hf = CreateFileA(pwcsName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); - if (hf==INVALID_HANDLE_VALUE) { - WARN("Couldn't open file for storage\n"); - return E_FAIL; - } - lpstg = MapSL((SEGPTR)*ppstgOpen); - lpstg->hf = hf; - - i=0;ret=0; - while (!ret) { /* neither 1 nor <0 */ - ret=STORAGE_get_pps_entry(hf,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; - -} - -/****************************************************************************** - * StgIsStorageILockBytes [STORAGE.6] - * - * Determines if the ILockBytes contains a storage object. - */ -HRESULT WINAPI StgIsStorageILockBytes16(SEGPTR plkbyt) -{ - DWORD args[6]; - HRESULT hres; - HANDLE16 hsig; - - args[0] = (DWORD)plkbyt; /* iface */ - args[1] = args[2] = 0; /* ULARGE_INTEGER offset */ - args[3] = (DWORD)K32WOWGlobalAllocLock16( 0, 8, &hsig ); /* sig */ - args[4] = 8; - args[5] = 0; - - if (!K32WOWCallback16Ex( - (DWORD)((ILockBytes16Vtbl*)MapSL( - (SEGPTR)((LPLOCKBYTES16)MapSL(plkbyt))->lpVtbl) - )->ReadAt, - WCB16_PASCAL, - 6*sizeof(DWORD), - (LPVOID)args, - (LPDWORD)&hres - )) { - ERR("CallTo16 ILockBytes16::ReadAt() failed, hres %lx\n",hres); - return hres; - } - if (memcmp(MapSL(args[3]), STORAGE_magic, sizeof(STORAGE_magic)) == 0) { - K32WOWGlobalUnlockFree16(args[3]); - return S_OK; - } - K32WOWGlobalUnlockFree16(args[3]); - return S_FALSE; -} - -/****************************************************************************** - * StgOpenStorageOnILockBytes [STORAGE.4] - */ -HRESULT WINAPI StgOpenStorageOnILockBytes16( - ILockBytes16 *plkbyt, - IStorage16 *pstgPriority, - DWORD grfMode, - SNB16 snbExclude, - DWORD reserved, - IStorage16 **ppstgOpen) -{ - IStorage16Impl* lpstg; - - if ((plkbyt == 0) || (ppstgOpen == 0)) - return STG_E_INVALIDPOINTER; - - *ppstgOpen = 0; - - _create_istorage16(ppstgOpen); - lpstg = MapSL((SEGPTR)*ppstgOpen); - - /* just teach it to use HANDLE instead of ilockbytes :/ */ - - return S_OK; -} diff --git a/reactos/lib/ole32/storage.spec b/reactos/lib/ole32/storage.spec deleted file mode 100644 index f9cf3cc5a31..00000000000 --- a/reactos/lib/ole32/storage.spec +++ /dev/null @@ -1,59 +0,0 @@ -# Compound Storage DLL. -# (FIXME: some methods are commented out. Commenting them in _WILL_ -# result in dataloss. Do it at your own risk.) - -1 pascal StgCreateDocFileA(str long long ptr) StgCreateDocFile16 -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 -5 pascal StgIsStorageFile(str) StgIsStorageFile16 -6 pascal StgIsStorageILockBytes(segptr) StgIsStorageILockBytes16 -7 stub StgSetTimes -#8 WEP -#9 ___EXPORTEDSTUB -103 stub DllGetClassObject - -# Storage Interface functions. Starting at 500 -# these are not exported in the real storage.dll, we use them -# as 16->32 relays. They use the cdecl calling convention. - -# IStorage -500 cdecl IStorage16_QueryInterface(ptr ptr ptr) IStorage16_fnQueryInterface -501 cdecl IStorage16_AddRef(ptr) IStorage16_fnAddRef -502 cdecl IStorage16_Release(ptr) IStorage16_fnRelease -#503 cdecl IStorage16_CreateStream(ptr str long long long ptr) IStorage16_fnCreateStream -503 stub IStorage16_CreateStream - -504 cdecl IStorage16_OpenStream(ptr str ptr long long ptr) IStorage16_fnOpenStream -#505 cdecl IStorage16_CreateStorage(ptr str long long long ptr) IStorage16_fnCreateStorage -505 stub IStorage16_CreateStorage -506 cdecl IStorage16_OpenStorage(ptr str ptr long ptr long ptr) IStorage16_fnOpenStorage -507 cdecl IStorage16_CopyTo(ptr long ptr ptr ptr) IStorage16_fnCopyTo -508 stub IStorage16_MoveElementTo -509 cdecl IStorage16_Commit(ptr long) IStorage16_fnCommit -510 stub IStorage16_Revert -511 stub IStorage16_EnumElements -512 stub IStorage16_DestroyElement -513 stub IStorage16_RenameElement -514 stub IStorage16_SetElementTimes -515 stub IStorage16_SetClass -516 stub IStorage16_SetStateBits -517 cdecl IStorage16_Stat(ptr ptr long) IStorage16_fnStat - -# IStream -518 cdecl IStream16_QueryInterface(ptr ptr ptr) IStream16_fnQueryInterface -519 cdecl IStream16_AddRef(ptr) IStream16_fnAddRef -520 cdecl IStream16_Release(ptr) IStream16_fnRelease -521 cdecl IStream16_Read(ptr ptr long ptr) IStream16_fnRead -#522 cdecl IStream16_Write(ptr ptr long ptr) IStream16_fnWrite -522 stub IStream16_Write -523 cdecl IStream16_Seek(ptr long long long ptr) IStream16_fnSeek -524 stub IStream16_SetSize -525 stub IStream16_CopyTo -526 stub IStream16_Commit -527 stub IStream16_Revert -528 stub IStream16_LockRegion -529 stub IStream16_UnlockRegion -530 stub IStream16_Stat -531 stub IStream16_Clone diff --git a/reactos/lib/ole32/storage32.c b/reactos/lib/ole32/storage32.c deleted file mode 100644 index 6dcdeda8246..00000000000 --- a/reactos/lib/ole32/storage32.c +++ /dev/null @@ -1,7491 +0,0 @@ -/* - * Compound Storage (32 bit version) - * Storage implementation - * - * This file contains the compound file implementation - * of the storage interface. - * - * Copyright 1999 Francis Beaudet - * Copyright 1999 Sylvain St-Germain - * Copyright 1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT - -#include "windef.h" -#include "winbase.h" -#include "winnls.h" -#include "winuser.h" -#include "wine/unicode.h" -#include "wine/debug.h" - -#include "storage32.h" -#include "ole2.h" /* For Write/ReadClassStm */ - -#include "winreg.h" -#include "wine/wingdi16.h" - -WINE_DEFAULT_DEBUG_CHANNEL(storage); - -#define FILE_BEGIN 0 - - -/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ -#define OLESTREAM_ID 0x501 -#define OLESTREAM_MAX_STR_LEN 255 - -static const char rootPropertyName[] = "Root Entry"; - - -/* OLESTREAM memory structure to use for Get and Put Routines */ -/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ -typedef struct -{ - DWORD dwOleID; - DWORD dwTypeID; - DWORD dwOleTypeNameLength; - CHAR strOleTypeName[OLESTREAM_MAX_STR_LEN]; - CHAR *pstrOleObjFileName; - DWORD dwOleObjFileNameLength; - DWORD dwMetaFileWidth; - DWORD dwMetaFileHeight; - CHAR strUnknown[8]; /* don't know what is this 8 byts information in OLE stream. */ - DWORD dwDataLength; - BYTE *pData; -}OLECONVERT_OLESTREAM_DATA; - -/* CompObj Stream structure */ -/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ -typedef struct -{ - BYTE byUnknown1[12]; - CLSID clsid; - DWORD dwCLSIDNameLength; - CHAR strCLSIDName[OLESTREAM_MAX_STR_LEN]; - DWORD dwOleTypeNameLength; - CHAR strOleTypeName[OLESTREAM_MAX_STR_LEN]; - DWORD dwProgIDNameLength; - CHAR strProgIDName[OLESTREAM_MAX_STR_LEN]; - BYTE byUnknown2[16]; -}OLECONVERT_ISTORAGE_COMPOBJ; - - -/* Ole Presention Stream structure */ -/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ -typedef struct -{ - BYTE byUnknown1[28]; - DWORD dwExtentX; - DWORD dwExtentY; - DWORD dwSize; - BYTE *pData; -}OLECONVERT_ISTORAGE_OLEPRES; - - - -/*********************************************************************** - * Forward declaration of internal functions used by the method DestroyElement - */ -static HRESULT deleteStorageProperty( - StorageImpl *parentStorage, - ULONG foundPropertyIndexToDelete, - StgProperty propertyToDelete); - -static HRESULT deleteStreamProperty( - StorageImpl *parentStorage, - ULONG foundPropertyIndexToDelete, - StgProperty propertyToDelete); - -static HRESULT findPlaceholder( - StorageImpl *storage, - ULONG propertyIndexToStore, - ULONG storagePropertyIndex, - INT typeOfRelation); - -static HRESULT adjustPropertyChain( - StorageImpl *This, - StgProperty propertyToDelete, - StgProperty parentProperty, - ULONG parentPropertyId, - INT typeOfRelation); - -/*********************************************************************** - * Declaration of the functions used to manipulate StgProperty - */ - -static ULONG getFreeProperty( - StorageImpl *storage); - -static void updatePropertyChain( - StorageImpl *storage, - ULONG newPropertyIndex, - StgProperty newProperty); - -static LONG propertyNameCmp( - const OLECHAR *newProperty, - const OLECHAR *currentProperty); - - -/*********************************************************************** - * Declaration of miscellaneous functions... - */ -static HRESULT validateSTGM(DWORD stgmValue); - -static DWORD GetShareModeFromSTGM(DWORD stgm); -static DWORD GetAccessModeFromSTGM(DWORD stgm); -static DWORD GetCreationModeFromSTGM(DWORD stgm); - -/* - * Virtual function table for the IStorage32Impl class. - */ -static IStorageVtbl Storage32Impl_Vtbl = -{ - StorageBaseImpl_QueryInterface, - StorageBaseImpl_AddRef, - StorageBaseImpl_Release, - StorageBaseImpl_CreateStream, - StorageBaseImpl_OpenStream, - StorageImpl_CreateStorage, - StorageBaseImpl_OpenStorage, - StorageImpl_CopyTo, - StorageImpl_MoveElementTo, - StorageImpl_Commit, - StorageImpl_Revert, - StorageBaseImpl_EnumElements, - StorageImpl_DestroyElement, - StorageBaseImpl_RenameElement, - StorageImpl_SetElementTimes, - StorageBaseImpl_SetClass, - StorageImpl_SetStateBits, - StorageImpl_Stat -}; - -/* - * Virtual function table for the Storage32InternalImpl class. - */ -static IStorageVtbl Storage32InternalImpl_Vtbl = - { - StorageBaseImpl_QueryInterface, - StorageBaseImpl_AddRef, - StorageBaseImpl_Release, - StorageBaseImpl_CreateStream, - StorageBaseImpl_OpenStream, - StorageImpl_CreateStorage, - StorageBaseImpl_OpenStorage, - StorageImpl_CopyTo, - StorageImpl_MoveElementTo, - StorageInternalImpl_Commit, - StorageInternalImpl_Revert, - StorageBaseImpl_EnumElements, - StorageImpl_DestroyElement, - StorageBaseImpl_RenameElement, - StorageImpl_SetElementTimes, - StorageBaseImpl_SetClass, - StorageImpl_SetStateBits, - StorageBaseImpl_Stat -}; - -/* - * Virtual function table for the IEnumSTATSTGImpl class. - */ -static IEnumSTATSTGVtbl IEnumSTATSTGImpl_Vtbl = -{ - IEnumSTATSTGImpl_QueryInterface, - IEnumSTATSTGImpl_AddRef, - IEnumSTATSTGImpl_Release, - IEnumSTATSTGImpl_Next, - IEnumSTATSTGImpl_Skip, - IEnumSTATSTGImpl_Reset, - IEnumSTATSTGImpl_Clone -}; - - - - - -/************************************************************************ -** Storage32BaseImpl implementatiion -*/ - -/************************************************************************ - * Storage32BaseImpl_QueryInterface (IUnknown) - * - * This method implements the common QueryInterface for all IStorage32 - * implementations contained in this file. - * - * See Windows documentation for more details on IUnknown methods. - */ -HRESULT WINAPI StorageBaseImpl_QueryInterface( - IStorage* iface, - REFIID riid, - void** ppvObject) -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (ppvObject==0) ) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = (IStorage*)This; - } - else if (memcmp(&IID_IStorage, riid, sizeof(IID_IStorage)) == 0) - { - *ppvObject = (IStorage*)This; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - StorageBaseImpl_AddRef(iface); - - return S_OK; -} - -/************************************************************************ - * Storage32BaseImpl_AddRef (IUnknown) - * - * This method implements the common AddRef for all IStorage32 - * implementations contained in this file. - * - * See Windows documentation for more details on IUnknown methods. - */ -ULONG WINAPI StorageBaseImpl_AddRef( - IStorage* iface) -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - return InterlockedIncrement(&This->ref); -} - -/************************************************************************ - * Storage32BaseImpl_Release (IUnknown) - * - * This method implements the common Release for all IStorage32 - * implementations contained in this file. - * - * See Windows documentation for more details on IUnknown methods. - */ -ULONG WINAPI StorageBaseImpl_Release( - IStorage* iface) -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - /* - * Decrease the reference count on this object. - */ - ULONG ref = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (ref == 0) - { - /* - * Since we are using a system of base-classes, we want to call the - * destructor of the appropriate derived class. To do this, we are - * using virtual functions to implement the destructor. - */ - This->v_destructor(This); - } - - return ref; -} - -/************************************************************************ - * Storage32BaseImpl_OpenStream (IStorage) - * - * This method will open the specified stream object from the current storage. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_OpenStream( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - void* reserved1, /* [unique][in] */ - DWORD grfMode, /* [in] */ - DWORD reserved2, /* [in] */ - IStream** ppstm) /* [out] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - IEnumSTATSTGImpl* propertyEnumeration; - StgStreamImpl* newStream; - StgProperty currentProperty; - ULONG foundPropertyIndex; - HRESULT res = STG_E_UNKNOWN; - - TRACE("(%p, %s, %p, %lx, %ld, %p)\n", - iface, debugstr_w(pwcsName), reserved1, grfMode, reserved2, ppstm); - - /* - * Perform a sanity check on the parameters. - */ - if ( (pwcsName==NULL) || (ppstm==0) ) - { - res = E_INVALIDARG; - goto end; - } - - /* - * Initialize the out parameter - */ - *ppstm = NULL; - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - { - res = STG_E_INVALIDFLAG; - goto end; - } - - /* - * As documented. - */ - if ( !(grfMode & STGM_SHARE_EXCLUSIVE) || - (grfMode & STGM_DELETEONRELEASE) || - (grfMode & STGM_TRANSACTED) ) - { - res = STG_E_INVALIDFUNCTION; - goto end; - } - - /* - * Create a property enumeration to search the properties - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct( - This->ancestorStorage, - This->rootPropertySetIndex); - - /* - * Search the enumeration for the property with the given name - */ - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty( - propertyEnumeration, - pwcsName, - ¤tProperty); - - /* - * Delete the property enumeration since we don't need it anymore - */ - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - /* - * If it was found, construct the stream object and return a pointer to it. - */ - if ( (foundPropertyIndex!=PROPERTY_NULL) && - (currentProperty.propertyType==PROPTYPE_STREAM) ) - { - newStream = StgStreamImpl_Construct(This, grfMode, foundPropertyIndex); - - if (newStream!=0) - { - newStream->grfMode = grfMode; - *ppstm = (IStream*)newStream; - - /* - * Since we are returning a pointer to the interface, we have to - * nail down the reference. - */ - StgStreamImpl_AddRef(*ppstm); - - res = S_OK; - goto end; - } - - res = E_OUTOFMEMORY; - goto end; - } - - res = STG_E_FILENOTFOUND; - -end: - if (res == S_OK) - TRACE("<-- IStream %p\n", *ppstm); - TRACE("<-- %08lx\n", res); - return res; -} - -/************************************************************************ - * Storage32BaseImpl_OpenStorage (IStorage) - * - * This method will open a new storage object from the current storage. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_OpenStorage( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][unique][in] */ - IStorage* pstgPriority, /* [unique][in] */ - DWORD grfMode, /* [in] */ - SNB snbExclude, /* [unique][in] */ - DWORD reserved, /* [in] */ - IStorage** ppstg) /* [out] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - StorageInternalImpl* newStorage; - IEnumSTATSTGImpl* propertyEnumeration; - StgProperty currentProperty; - ULONG foundPropertyIndex; - HRESULT res = STG_E_UNKNOWN; - - TRACE("(%p, %s, %p, %lx, %p, %ld, %p)\n", - iface, debugstr_w(pwcsName), pstgPriority, - grfMode, snbExclude, reserved, ppstg); - - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (pwcsName==NULL) || (ppstg==0) ) - { - res = E_INVALIDARG; - goto end; - } - - /* as documented */ - if (snbExclude != NULL) - { - res = STG_E_INVALIDPARAMETER; - goto end; - } - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - { - res = STG_E_INVALIDFLAG; - goto end; - } - - /* - * As documented. - */ - if ( !(grfMode & STGM_SHARE_EXCLUSIVE) || - (grfMode & STGM_DELETEONRELEASE) || - (grfMode & STGM_PRIORITY) ) - { - res = STG_E_INVALIDFUNCTION; - goto end; - } - - /* - * Initialize the out parameter - */ - *ppstg = NULL; - - /* - * Create a property enumeration to search the properties - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct( - This->ancestorStorage, - This->rootPropertySetIndex); - - /* - * Search the enumeration for the property with the given name - */ - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty( - propertyEnumeration, - pwcsName, - ¤tProperty); - - /* - * Delete the property enumeration since we don't need it anymore - */ - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - /* - * If it was found, construct the stream object and return a pointer to it. - */ - if ( (foundPropertyIndex!=PROPERTY_NULL) && - (currentProperty.propertyType==PROPTYPE_STORAGE) ) - { - /* - * Construct a new Storage object - */ - newStorage = StorageInternalImpl_Construct( - This->ancestorStorage, - foundPropertyIndex); - - if (newStorage != 0) - { - *ppstg = (IStorage*)newStorage; - - /* - * Since we are returning a pointer to the interface, - * we have to nail down the reference. - */ - StorageBaseImpl_AddRef(*ppstg); - - res = S_OK; - goto end; - } - - res = STG_E_INSUFFICIENTMEMORY; - goto end; - } - - res = STG_E_FILENOTFOUND; - -end: - TRACE("<-- %08lx\n", res); - return res; -} - -/************************************************************************ - * Storage32BaseImpl_EnumElements (IStorage) - * - * This method will create an enumerator object that can be used to - * retrieve informatino about all the properties in the storage object. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_EnumElements( - IStorage* iface, - DWORD reserved1, /* [in] */ - void* reserved2, /* [size_is][unique][in] */ - DWORD reserved3, /* [in] */ - IEnumSTATSTG** ppenum) /* [out] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - IEnumSTATSTGImpl* newEnum; - - TRACE("(%p, %ld, %p, %ld, %p)\n", - iface, reserved1, reserved2, reserved3, ppenum); - - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (ppenum==0)) - return E_INVALIDARG; - - /* - * Construct the enumerator. - */ - newEnum = IEnumSTATSTGImpl_Construct( - This->ancestorStorage, - This->rootPropertySetIndex); - - if (newEnum!=0) - { - *ppenum = (IEnumSTATSTG*)newEnum; - - /* - * Don't forget to nail down a reference to the new object before - * returning it. - */ - IEnumSTATSTGImpl_AddRef(*ppenum); - - return S_OK; - } - - return E_OUTOFMEMORY; -} - -/************************************************************************ - * Storage32BaseImpl_Stat (IStorage) - * - * This method will retrieve information about this storage object. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_Stat( - IStorage* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - StgProperty curProperty; - BOOL readSuccessful; - HRESULT res = STG_E_UNKNOWN; - - TRACE("(%p, %p, %lx)\n", - iface, pstatstg, grfStatFlag); - - /* - * Perform a sanity check on the parameters. - */ - if ( (This==0) || (pstatstg==0)) - { - res = E_INVALIDARG; - goto end; - } - - /* - * Read the information from the property. - */ - readSuccessful = StorageImpl_ReadProperty( - This->ancestorStorage, - This->rootPropertySetIndex, - &curProperty); - - if (readSuccessful) - { - StorageUtl_CopyPropertyToSTATSTG( - pstatstg, - &curProperty, - grfStatFlag); - - res = S_OK; - goto end; - } - - res = E_FAIL; - -end: - if (res == S_OK) - { - TRACE("<-- STATSTG: pwcsName: %s, type: %ld, cbSize.Low/High: %ld/%ld, grfMode: %08lx, grfLocksSupported: %ld, grfStateBits: %08lx\n", debugstr_w(pstatstg->pwcsName), pstatstg->type, pstatstg->cbSize.u.LowPart, pstatstg->cbSize.u.HighPart, pstatstg->grfMode, pstatstg->grfLocksSupported, pstatstg->grfStateBits); - } - TRACE("<-- %08lx\n", res); - return res; -} - -/************************************************************************ - * Storage32BaseImpl_RenameElement (IStorage) - * - * This method will rename the specified element. - * - * See Windows documentation for more details on IStorage methods. - * - * Implementation notes: The method used to rename consists of creating a clone - * of the deleted StgProperty object setting it with the new name and to - * perform a DestroyElement of the old StgProperty. - */ -HRESULT WINAPI StorageBaseImpl_RenameElement( - IStorage* iface, - const OLECHAR* pwcsOldName, /* [in] */ - const OLECHAR* pwcsNewName) /* [in] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - IEnumSTATSTGImpl* propertyEnumeration; - StgProperty currentProperty; - ULONG foundPropertyIndex; - - TRACE("(%p, %s, %s)\n", - iface, debugstr_w(pwcsOldName), debugstr_w(pwcsNewName)); - - /* - * Create a property enumeration to search the properties - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct(This->ancestorStorage, - This->rootPropertySetIndex); - - /* - * Search the enumeration for the new property name - */ - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty(propertyEnumeration, - pwcsNewName, - ¤tProperty); - - if (foundPropertyIndex != PROPERTY_NULL) - { - /* - * There is already a property with the new name - */ - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - return STG_E_FILEALREADYEXISTS; - } - - IEnumSTATSTGImpl_Reset((IEnumSTATSTG*)propertyEnumeration); - - /* - * Search the enumeration for the old property name - */ - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty(propertyEnumeration, - pwcsOldName, - ¤tProperty); - - /* - * Delete the property enumeration since we don't need it anymore - */ - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - if (foundPropertyIndex != PROPERTY_NULL) - { - StgProperty renamedProperty; - ULONG renamedPropertyIndex; - - /* - * Setup a new property for the renamed property - */ - renamedProperty.sizeOfNameString = - ( lstrlenW(pwcsNewName)+1 ) * sizeof(WCHAR); - - if (renamedProperty.sizeOfNameString > PROPERTY_NAME_BUFFER_LEN) - return STG_E_INVALIDNAME; - - strcpyW(renamedProperty.name, pwcsNewName); - - renamedProperty.propertyType = currentProperty.propertyType; - renamedProperty.startingBlock = currentProperty.startingBlock; - renamedProperty.size.u.LowPart = currentProperty.size.u.LowPart; - renamedProperty.size.u.HighPart = currentProperty.size.u.HighPart; - - renamedProperty.previousProperty = PROPERTY_NULL; - renamedProperty.nextProperty = PROPERTY_NULL; - - /* - * Bring the dirProperty link in case it is a storage and in which - * case the renamed storage elements don't require to be reorganized. - */ - renamedProperty.dirProperty = currentProperty.dirProperty; - - /* call CoFileTime to get the current time - renamedProperty.timeStampS1 - renamedProperty.timeStampD1 - renamedProperty.timeStampS2 - renamedProperty.timeStampD2 - renamedProperty.propertyUniqueID - */ - - /* - * Obtain a free property in the property chain - */ - renamedPropertyIndex = getFreeProperty(This->ancestorStorage); - - /* - * Save the new property into the new property spot - */ - StorageImpl_WriteProperty( - This->ancestorStorage, - renamedPropertyIndex, - &renamedProperty); - - /* - * Find a spot in the property chain for our newly created property. - */ - updatePropertyChain( - (StorageImpl*)This, - renamedPropertyIndex, - renamedProperty); - - /* - * At this point the renamed property has been inserted in the tree, - * now, before to Destroy the old property we must zeroed it's dirProperty - * otherwise the DestroyProperty below will zap it all and we do not want - * this to happen. - * Also, we fake that the old property is a storage so the DestroyProperty - * will not do a SetSize(0) on the stream data. - * - * This means that we need to tweek the StgProperty if it is a stream or a - * non empty storage. - */ - StorageImpl_ReadProperty(This->ancestorStorage, - foundPropertyIndex, - ¤tProperty); - - currentProperty.dirProperty = PROPERTY_NULL; - currentProperty.propertyType = PROPTYPE_STORAGE; - StorageImpl_WriteProperty( - This->ancestorStorage, - foundPropertyIndex, - ¤tProperty); - - /* - * Invoke Destroy to get rid of the ole property and automatically redo - * the linking of it's previous and next members... - */ - StorageImpl_DestroyElement((IStorage*)This->ancestorStorage, pwcsOldName); - - } - else - { - /* - * There is no property with the old name - */ - return STG_E_FILENOTFOUND; - } - - return S_OK; -} - -/************************************************************************ - * Storage32BaseImpl_CreateStream (IStorage) - * - * This method will create a stream object within this storage - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_CreateStream( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - DWORD grfMode, /* [in] */ - DWORD reserved1, /* [in] */ - DWORD reserved2, /* [in] */ - IStream** ppstm) /* [out] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - IEnumSTATSTGImpl* propertyEnumeration; - StgStreamImpl* newStream; - StgProperty currentProperty, newStreamProperty; - ULONG foundPropertyIndex, newPropertyIndex; - - TRACE("(%p, %s, %lx, %ld, %ld, %p)\n", - iface, debugstr_w(pwcsName), grfMode, - reserved1, reserved2, ppstm); - - /* - * Validate parameters - */ - if (ppstm == 0) - return STG_E_INVALIDPOINTER; - - if (pwcsName == 0) - return STG_E_INVALIDNAME; - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - return STG_E_INVALIDFLAG; - - /* - * As documented. - */ - if ( !(grfMode & STGM_SHARE_EXCLUSIVE) || - (grfMode & STGM_DELETEONRELEASE) || - (grfMode & STGM_TRANSACTED) ) - return STG_E_INVALIDFUNCTION; - - /* - * Initialize the out parameter - */ - *ppstm = 0; - - /* - * Create a property enumeration to search the properties - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct(This->ancestorStorage, - This->rootPropertySetIndex); - - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty(propertyEnumeration, - pwcsName, - ¤tProperty); - - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - if (foundPropertyIndex != PROPERTY_NULL) - { - /* - * An element with this name already exists - */ - if (grfMode & STGM_CREATE) - { - IStorage_DestroyElement(iface, pwcsName); - } - else - return STG_E_FILEALREADYEXISTS; - } - - /* - * memset the empty property - */ - memset(&newStreamProperty, 0, sizeof(StgProperty)); - - newStreamProperty.sizeOfNameString = - ( lstrlenW(pwcsName)+1 ) * sizeof(WCHAR); - - if (newStreamProperty.sizeOfNameString > PROPERTY_NAME_BUFFER_LEN) - return STG_E_INVALIDNAME; - - strcpyW(newStreamProperty.name, pwcsName); - - newStreamProperty.propertyType = PROPTYPE_STREAM; - newStreamProperty.startingBlock = BLOCK_END_OF_CHAIN; - newStreamProperty.size.u.LowPart = 0; - newStreamProperty.size.u.HighPart = 0; - - newStreamProperty.previousProperty = PROPERTY_NULL; - newStreamProperty.nextProperty = PROPERTY_NULL; - newStreamProperty.dirProperty = PROPERTY_NULL; - - /* call CoFileTime to get the current time - newStreamProperty.timeStampS1 - newStreamProperty.timeStampD1 - newStreamProperty.timeStampS2 - newStreamProperty.timeStampD2 - */ - - /* newStreamProperty.propertyUniqueID */ - - /* - * Get a free property or create a new one - */ - newPropertyIndex = getFreeProperty(This->ancestorStorage); - - /* - * Save the new property into the new property spot - */ - StorageImpl_WriteProperty( - This->ancestorStorage, - newPropertyIndex, - &newStreamProperty); - - /* - * Find a spot in the property chain for our newly created property. - */ - updatePropertyChain( - (StorageImpl*)This, - newPropertyIndex, - newStreamProperty); - - /* - * Open the stream to return it. - */ - newStream = StgStreamImpl_Construct(This, grfMode, newPropertyIndex); - - if (newStream != 0) - { - *ppstm = (IStream*)newStream; - - /* - * Since we are returning a pointer to the interface, we have to nail down - * the reference. - */ - StgStreamImpl_AddRef(*ppstm); - } - else - { - return STG_E_INSUFFICIENTMEMORY; - } - - return S_OK; -} - -/************************************************************************ - * Storage32BaseImpl_SetClass (IStorage) - * - * This method will write the specified CLSID in the property of this - * storage. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageBaseImpl_SetClass( - IStorage* iface, - REFCLSID clsid) /* [in] */ -{ - StorageBaseImpl *This = (StorageBaseImpl *)iface; - HRESULT hRes = E_FAIL; - StgProperty curProperty; - BOOL success; - - TRACE("(%p, %p)\n", iface, clsid); - - success = StorageImpl_ReadProperty(This->ancestorStorage, - This->rootPropertySetIndex, - &curProperty); - if (success) - { - curProperty.propertyUniqueID = *clsid; - - success = StorageImpl_WriteProperty(This->ancestorStorage, - This->rootPropertySetIndex, - &curProperty); - if (success) - hRes = S_OK; - } - - return hRes; -} - -/************************************************************************ -** Storage32Impl implementation -*/ - -/************************************************************************ - * Storage32Impl_CreateStorage (IStorage) - * - * This method will create the storage object within the provided storage. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageImpl_CreateStorage( - IStorage* iface, - const OLECHAR *pwcsName, /* [string][in] */ - DWORD grfMode, /* [in] */ - DWORD reserved1, /* [in] */ - DWORD reserved2, /* [in] */ - IStorage **ppstg) /* [out] */ -{ - StorageImpl* const This=(StorageImpl*)iface; - - IEnumSTATSTGImpl *propertyEnumeration; - StgProperty currentProperty; - StgProperty newProperty; - ULONG foundPropertyIndex; - ULONG newPropertyIndex; - HRESULT hr; - - TRACE("(%p, %s, %lx, %ld, %ld, %p)\n", - iface, debugstr_w(pwcsName), grfMode, - reserved1, reserved2, ppstg); - - /* - * Validate parameters - */ - if (ppstg == 0) - return STG_E_INVALIDPOINTER; - - if (pwcsName == 0) - return STG_E_INVALIDNAME; - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) ) || - (grfMode & STGM_DELETEONRELEASE) ) - return STG_E_INVALIDFLAG; - - /* - * Initialize the out parameter - */ - *ppstg = 0; - - /* - * Create a property enumeration and search the properties - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct( This->ancestorStorage, - This->rootPropertySetIndex); - - foundPropertyIndex = IEnumSTATSTGImpl_FindProperty(propertyEnumeration, - pwcsName, - ¤tProperty); - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - if (foundPropertyIndex != PROPERTY_NULL) - { - /* - * An element with this name already exists - */ - if (grfMode & STGM_CREATE) - IStorage_DestroyElement(iface, pwcsName); - else - return STG_E_FILEALREADYEXISTS; - } - - /* - * memset the empty property - */ - memset(&newProperty, 0, sizeof(StgProperty)); - - newProperty.sizeOfNameString = (lstrlenW(pwcsName)+1)*sizeof(WCHAR); - - if (newProperty.sizeOfNameString > PROPERTY_NAME_BUFFER_LEN) - return STG_E_INVALIDNAME; - - strcpyW(newProperty.name, pwcsName); - - newProperty.propertyType = PROPTYPE_STORAGE; - newProperty.startingBlock = BLOCK_END_OF_CHAIN; - newProperty.size.u.LowPart = 0; - newProperty.size.u.HighPart = 0; - - newProperty.previousProperty = PROPERTY_NULL; - newProperty.nextProperty = PROPERTY_NULL; - newProperty.dirProperty = PROPERTY_NULL; - - /* call CoFileTime to get the current time - newProperty.timeStampS1 - newProperty.timeStampD1 - newProperty.timeStampS2 - newProperty.timeStampD2 - */ - - /* newStorageProperty.propertyUniqueID */ - - /* - * Obtain a free property in the property chain - */ - newPropertyIndex = getFreeProperty(This->ancestorStorage); - - /* - * Save the new property into the new property spot - */ - StorageImpl_WriteProperty( - This->ancestorStorage, - newPropertyIndex, - &newProperty); - - /* - * Find a spot in the property chain for our newly created property. - */ - updatePropertyChain( - This, - newPropertyIndex, - newProperty); - - /* - * Open it to get a pointer to return. - */ - hr = IStorage_OpenStorage( - iface, - (const OLECHAR*)pwcsName, - 0, - grfMode, - 0, - 0, - ppstg); - - if( (hr != S_OK) || (*ppstg == NULL)) - { - return hr; - } - - - return S_OK; -} - - -/*************************************************************************** - * - * Internal Method - * - * Get a free property or create a new one. - */ -static ULONG getFreeProperty( - StorageImpl *storage) -{ - ULONG currentPropertyIndex = 0; - ULONG newPropertyIndex = PROPERTY_NULL; - BOOL readSuccessful = TRUE; - StgProperty currentProperty; - - do - { - /* - * Start by reading the root property - */ - readSuccessful = StorageImpl_ReadProperty(storage->ancestorStorage, - currentPropertyIndex, - ¤tProperty); - if (readSuccessful) - { - if (currentProperty.sizeOfNameString == 0) - { - /* - * The property existis and is available, we found it. - */ - newPropertyIndex = currentPropertyIndex; - } - } - else - { - /* - * We exhausted the property list, we will create more space below - */ - newPropertyIndex = currentPropertyIndex; - } - currentPropertyIndex++; - - } while (newPropertyIndex == PROPERTY_NULL); - - /* - * grow the property chain - */ - if (! readSuccessful) - { - StgProperty emptyProperty; - ULARGE_INTEGER newSize; - ULONG propertyIndex; - ULONG lastProperty = 0; - ULONG blockCount = 0; - - /* - * obtain the new count of property blocks - */ - blockCount = BlockChainStream_GetCount( - storage->ancestorStorage->rootBlockChain)+1; - - /* - * initialize the size used by the property stream - */ - newSize.u.HighPart = 0; - newSize.u.LowPart = storage->bigBlockSize * blockCount; - - /* - * add a property block to the property chain - */ - BlockChainStream_SetSize(storage->ancestorStorage->rootBlockChain, newSize); - - /* - * memset the empty property in order to initialize the unused newly - * created property - */ - memset(&emptyProperty, 0, sizeof(StgProperty)); - - /* - * initialize them - */ - lastProperty = storage->bigBlockSize / PROPSET_BLOCK_SIZE * blockCount; - - for( - propertyIndex = newPropertyIndex; - propertyIndex < lastProperty; - propertyIndex++) - { - StorageImpl_WriteProperty( - storage->ancestorStorage, - propertyIndex, - &emptyProperty); - } - } - - return newPropertyIndex; -} - -/**************************************************************************** - * - * Internal Method - * - * Case insensitive comparaison of StgProperty.name by first considering - * their size. - * - * Returns <0 when newPrpoerty < currentProperty - * >0 when newPrpoerty > currentProperty - * 0 when newPrpoerty == currentProperty - */ -static LONG propertyNameCmp( - const OLECHAR *newProperty, - const OLECHAR *currentProperty) -{ - LONG diff = lstrlenW(newProperty) - lstrlenW(currentProperty); - - if (diff == 0) - { - /* - * We compare the string themselves only when they are of the same length - */ - diff = lstrcmpiW( newProperty, currentProperty); - } - - return diff; -} - -/**************************************************************************** - * - * Internal Method - * - * Properly link this new element in the property chain. - */ -static void updatePropertyChain( - StorageImpl *storage, - ULONG newPropertyIndex, - StgProperty newProperty) -{ - StgProperty currentProperty; - - /* - * Read the root property - */ - StorageImpl_ReadProperty(storage->ancestorStorage, - storage->rootPropertySetIndex, - ¤tProperty); - - if (currentProperty.dirProperty != PROPERTY_NULL) - { - /* - * The root storage contains some element, therefore, start the research - * for the appropriate location. - */ - BOOL found = 0; - ULONG current, next, previous, currentPropertyId; - - /* - * Keep the StgProperty sequence number of the storage first property - */ - currentPropertyId = currentProperty.dirProperty; - - /* - * Read - */ - StorageImpl_ReadProperty(storage->ancestorStorage, - currentProperty.dirProperty, - ¤tProperty); - - previous = currentProperty.previousProperty; - next = currentProperty.nextProperty; - current = currentPropertyId; - - while (found == 0) - { - LONG diff = propertyNameCmp( newProperty.name, currentProperty.name); - - if (diff < 0) - { - if (previous != PROPERTY_NULL) - { - StorageImpl_ReadProperty(storage->ancestorStorage, - previous, - ¤tProperty); - current = previous; - } - else - { - currentProperty.previousProperty = newPropertyIndex; - StorageImpl_WriteProperty(storage->ancestorStorage, - current, - ¤tProperty); - found = 1; - } - } - else if (diff > 0) - { - if (next != PROPERTY_NULL) - { - StorageImpl_ReadProperty(storage->ancestorStorage, - next, - ¤tProperty); - current = next; - } - else - { - currentProperty.nextProperty = newPropertyIndex; - StorageImpl_WriteProperty(storage->ancestorStorage, - current, - ¤tProperty); - found = 1; - } - } - else - { - /* - * Trying to insert an item with the same name in the - * subtree structure. - */ - assert(FALSE); - } - - previous = currentProperty.previousProperty; - next = currentProperty.nextProperty; - } - } - else - { - /* - * The root storage is empty, link the new property to it's dir property - */ - currentProperty.dirProperty = newPropertyIndex; - StorageImpl_WriteProperty(storage->ancestorStorage, - storage->rootPropertySetIndex, - ¤tProperty); - } -} - - -/************************************************************************* - * CopyTo (IStorage) - */ -HRESULT WINAPI StorageImpl_CopyTo( - IStorage* iface, - DWORD ciidExclude, /* [in] */ - const IID* rgiidExclude, /* [size_is][unique][in] */ - SNB snbExclude, /* [unique][in] */ - IStorage* pstgDest) /* [unique][in] */ -{ - IEnumSTATSTG *elements = 0; - STATSTG curElement, strStat; - HRESULT hr; - IStorage *pstgTmp, *pstgChild; - IStream *pstrTmp, *pstrChild; - - if ((ciidExclude != 0) || (rgiidExclude != NULL) || (snbExclude != NULL)) - FIXME("Exclude option not implemented\n"); - - TRACE("(%p, %ld, %p, %p, %p)\n", - iface, ciidExclude, rgiidExclude, - snbExclude, pstgDest); - - /* - * Perform a sanity check - */ - if ( pstgDest == 0 ) - return STG_E_INVALIDPOINTER; - - /* - * Enumerate the elements - */ - hr = IStorage_EnumElements( iface, 0, 0, 0, &elements ); - - if ( hr != S_OK ) - return hr; - - /* - * set the class ID - */ - IStorage_Stat( iface, &curElement, STATFLAG_NONAME); - IStorage_SetClass( pstgDest, &curElement.clsid ); - - do - { - /* - * Obtain the next element - */ - hr = IEnumSTATSTG_Next( elements, 1, &curElement, NULL ); - - if ( hr == S_FALSE ) - { - hr = S_OK; /* done, every element has been copied */ - break; - } - - if (curElement.type == STGTY_STORAGE) - { - /* - * open child source storage - */ - hr = IStorage_OpenStorage( iface, curElement.pwcsName, NULL, - STGM_READ|STGM_SHARE_EXCLUSIVE, - NULL, 0, &pstgChild ); - - if (hr != S_OK) - break; - - /* - * Check if destination storage is not a child of the source - * storage, which will cause an infinite loop - */ - if (pstgChild == pstgDest) - { - IEnumSTATSTG_Release(elements); - - return STG_E_ACCESSDENIED; - } - - /* - * create a new storage in destination storage - */ - hr = IStorage_CreateStorage( pstgDest, curElement.pwcsName, - STGM_FAILIFTHERE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, - 0, 0, - &pstgTmp ); - /* - * if it already exist, don't create a new one use this one - */ - if (hr == STG_E_FILEALREADYEXISTS) - { - hr = IStorage_OpenStorage( pstgDest, curElement.pwcsName, NULL, - STGM_WRITE|STGM_SHARE_EXCLUSIVE, - NULL, 0, &pstgTmp ); - } - - if (hr != S_OK) - break; - - - /* - * do the copy recursively - */ - hr = IStorage_CopyTo( pstgChild, ciidExclude, rgiidExclude, - snbExclude, pstgTmp ); - - IStorage_Release( pstgTmp ); - IStorage_Release( pstgChild ); - } - else if (curElement.type == STGTY_STREAM) - { - /* - * create a new stream in destination storage. If the stream already - * exist, it will be deleted and a new one will be created. - */ - hr = IStorage_CreateStream( pstgDest, curElement.pwcsName, - STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE, - 0, 0, &pstrTmp ); - - if (hr != S_OK) - break; - - /* - * open child stream storage - */ - hr = IStorage_OpenStream( iface, curElement.pwcsName, NULL, - STGM_READ|STGM_SHARE_EXCLUSIVE, - 0, &pstrChild ); - - if (hr != S_OK) - break; - - /* - * Get the size of the source stream - */ - IStream_Stat( pstrChild, &strStat, STATFLAG_NONAME ); - - /* - * Set the size of the destination stream. - */ - IStream_SetSize(pstrTmp, strStat.cbSize); - - /* - * do the copy - */ - hr = IStream_CopyTo( pstrChild, pstrTmp, strStat.cbSize, - NULL, NULL ); - - IStream_Release( pstrTmp ); - IStream_Release( pstrChild ); - } - else - { - WARN("unknown element type: %ld\n", curElement.type); - } - - } while (hr == S_OK); - - /* - * Clean-up - */ - IEnumSTATSTG_Release(elements); - - return hr; -} - -/************************************************************************* - * MoveElementTo (IStorage) - */ -HRESULT WINAPI StorageImpl_MoveElementTo( - IStorage* iface, - const OLECHAR *pwcsName, /* [string][in] */ - IStorage *pstgDest, /* [unique][in] */ - const OLECHAR *pwcsNewName,/* [string][in] */ - DWORD grfFlags) /* [in] */ -{ - FIXME("not implemented!\n"); - return E_NOTIMPL; -} - -/************************************************************************* - * Commit (IStorage) - */ -HRESULT WINAPI StorageImpl_Commit( - IStorage* iface, - DWORD grfCommitFlags)/* [in] */ -{ - FIXME("(%ld): stub!\n", grfCommitFlags); - return S_OK; -} - -/************************************************************************* - * Revert (IStorage) - */ -HRESULT WINAPI StorageImpl_Revert( - IStorage* iface) -{ - FIXME("not implemented!\n"); - return E_NOTIMPL; -} - -/************************************************************************* - * DestroyElement (IStorage) - * - * Stategy: This implementation is build this way for simplicity not for speed. - * I always delete the top most element of the enumeration and adjust - * the deleted element pointer all the time. This takes longer to - * do but allow to reinvoke DestroyElement whenever we encounter a - * storage object. The optimisation reside in the usage of another - * enumeration stategy that would give all the leaves of a storage - * first. (postfix order) - */ -HRESULT WINAPI StorageImpl_DestroyElement( - IStorage* iface, - const OLECHAR *pwcsName)/* [string][in] */ -{ - StorageImpl* const This=(StorageImpl*)iface; - - IEnumSTATSTGImpl* propertyEnumeration; - HRESULT hr = S_OK; - BOOL res; - StgProperty propertyToDelete; - StgProperty parentProperty; - ULONG foundPropertyIndexToDelete; - ULONG typeOfRelation; - ULONG parentPropertyId; - - TRACE("(%p, %s)\n", - iface, debugstr_w(pwcsName)); - - /* - * Perform a sanity check on the parameters. - */ - if (pwcsName==NULL) - return STG_E_INVALIDPOINTER; - - /* - * Create a property enumeration to search the property with the given name - */ - propertyEnumeration = IEnumSTATSTGImpl_Construct( - This->ancestorStorage, - This->rootPropertySetIndex); - - foundPropertyIndexToDelete = IEnumSTATSTGImpl_FindProperty( - propertyEnumeration, - pwcsName, - &propertyToDelete); - - IEnumSTATSTGImpl_Destroy(propertyEnumeration); - - if ( foundPropertyIndexToDelete == PROPERTY_NULL ) - { - return STG_E_FILENOTFOUND; - } - - /* - * Find the parent property of the property to delete (the one that - * link to it). If This->dirProperty == foundPropertyIndexToDelete, - * the parent is This. Otherwise, the parent is one of it's sibling... - */ - - /* - * First, read This's StgProperty.. - */ - res = StorageImpl_ReadProperty( - This->ancestorStorage, - This->rootPropertySetIndex, - &parentProperty); - - assert(res==TRUE); - - /* - * Second, check to see if by any chance the actual storage (This) is not - * the parent of the property to delete... We never know... - */ - if ( parentProperty.dirProperty == foundPropertyIndexToDelete ) - { - /* - * Set data as it would have been done in the else part... - */ - typeOfRelation = PROPERTY_RELATION_DIR; - parentPropertyId = This->rootPropertySetIndex; - } - else - { - /* - * Create a property enumeration to search the parent properties, and - * delete it once done. - */ - IEnumSTATSTGImpl* propertyEnumeration2; - - propertyEnumeration2 = IEnumSTATSTGImpl_Construct( - This->ancestorStorage, - This->rootPropertySetIndex); - - typeOfRelation = IEnumSTATSTGImpl_FindParentProperty( - propertyEnumeration2, - foundPropertyIndexToDelete, - &parentProperty, - &parentPropertyId); - - IEnumSTATSTGImpl_Destroy(propertyEnumeration2); - } - - if ( propertyToDelete.propertyType == PROPTYPE_STORAGE ) - { - hr = deleteStorageProperty( - This, - foundPropertyIndexToDelete, - propertyToDelete); - } - else if ( propertyToDelete.propertyType == PROPTYPE_STREAM ) - { - hr = deleteStreamProperty( - This, - foundPropertyIndexToDelete, - propertyToDelete); - } - - if (hr!=S_OK) - return hr; - - /* - * Adjust the property chain - */ - hr = adjustPropertyChain( - This, - propertyToDelete, - parentProperty, - parentPropertyId, - typeOfRelation); - - return hr; -} - - -/************************************************************************ - * StorageImpl_Stat (IStorage) - * - * This method will retrieve information about this storage object. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT WINAPI StorageImpl_Stat( IStorage* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag) /* [in] */ -{ - StorageImpl* const This = (StorageImpl*)iface; - HRESULT result = StorageBaseImpl_Stat( iface, pstatstg, grfStatFlag ); - - if ( !FAILED(result) && ((grfStatFlag & STATFLAG_NONAME) == 0) && This->pwcsName ) - { - CoTaskMemFree(pstatstg->pwcsName); - pstatstg->pwcsName = CoTaskMemAlloc((lstrlenW(This->pwcsName)+1)*sizeof(WCHAR)); - strcpyW(pstatstg->pwcsName, This->pwcsName); - } - - return result; -} - - - -/********************************************************************* - * - * Internal Method - * - * Perform the deletion of a complete storage node - * - */ -static HRESULT deleteStorageProperty( - StorageImpl *parentStorage, - ULONG indexOfPropertyToDelete, - StgProperty propertyToDelete) -{ - IEnumSTATSTG *elements = 0; - IStorage *childStorage = 0; - STATSTG currentElement; - HRESULT hr; - HRESULT destroyHr = S_OK; - - /* - * Open the storage and enumerate it - */ - hr = StorageBaseImpl_OpenStorage( - (IStorage*)parentStorage, - propertyToDelete.name, - 0, - STGM_SHARE_EXCLUSIVE, - 0, - 0, - &childStorage); - - if (hr != S_OK) - { - return hr; - } - - /* - * Enumerate the elements - */ - IStorage_EnumElements( childStorage, 0, 0, 0, &elements); - - do - { - /* - * Obtain the next element - */ - hr = IEnumSTATSTG_Next(elements, 1, ¤tElement, NULL); - if (hr==S_OK) - { - destroyHr = StorageImpl_DestroyElement( - (IStorage*)childStorage, - (OLECHAR*)currentElement.pwcsName); - - CoTaskMemFree(currentElement.pwcsName); - } - - /* - * We need to Reset the enumeration every time because we delete elements - * and the enumeration could be invalid - */ - IEnumSTATSTG_Reset(elements); - - } while ((hr == S_OK) && (destroyHr == S_OK)); - - /* - * Invalidate the property by zeroing it's name member. - */ - propertyToDelete.sizeOfNameString = 0; - - StorageImpl_WriteProperty(parentStorage->ancestorStorage, - indexOfPropertyToDelete, - &propertyToDelete); - - IStorage_Release(childStorage); - IEnumSTATSTG_Release(elements); - - return destroyHr; -} - -/********************************************************************* - * - * Internal Method - * - * Perform the deletion of a stream node - * - */ -static HRESULT deleteStreamProperty( - StorageImpl *parentStorage, - ULONG indexOfPropertyToDelete, - StgProperty propertyToDelete) -{ - IStream *pis; - HRESULT hr; - ULARGE_INTEGER size; - - size.u.HighPart = 0; - size.u.LowPart = 0; - - hr = StorageBaseImpl_OpenStream( - (IStorage*)parentStorage, - (OLECHAR*)propertyToDelete.name, - NULL, - STGM_WRITE | STGM_SHARE_EXCLUSIVE, - 0, - &pis); - - if (hr!=S_OK) - { - return(hr); - } - - /* - * Zap the stream - */ - hr = IStream_SetSize(pis, size); - - if(hr != S_OK) - { - return hr; - } - - /* - * Release the stream object. - */ - IStream_Release(pis); - - /* - * Invalidate the property by zeroing it's name member. - */ - propertyToDelete.sizeOfNameString = 0; - - /* - * Here we should re-read the property so we get the updated pointer - * but since we are here to zap it, I don't do it... - */ - StorageImpl_WriteProperty( - parentStorage->ancestorStorage, - indexOfPropertyToDelete, - &propertyToDelete); - - return S_OK; -} - -/********************************************************************* - * - * Internal Method - * - * Finds a placeholder for the StgProperty within the Storage - * - */ -static HRESULT findPlaceholder( - StorageImpl *storage, - ULONG propertyIndexToStore, - ULONG storePropertyIndex, - INT typeOfRelation) -{ - StgProperty storeProperty; - HRESULT hr = S_OK; - BOOL res = TRUE; - - /* - * Read the storage property - */ - res = StorageImpl_ReadProperty( - storage->ancestorStorage, - storePropertyIndex, - &storeProperty); - - if(! res) - { - return E_FAIL; - } - - if (typeOfRelation == PROPERTY_RELATION_PREVIOUS) - { - if (storeProperty.previousProperty != PROPERTY_NULL) - { - return findPlaceholder( - storage, - propertyIndexToStore, - storeProperty.previousProperty, - typeOfRelation); - } - else - { - storeProperty.previousProperty = propertyIndexToStore; - } - } - else if (typeOfRelation == PROPERTY_RELATION_NEXT) - { - if (storeProperty.nextProperty != PROPERTY_NULL) - { - return findPlaceholder( - storage, - propertyIndexToStore, - storeProperty.nextProperty, - typeOfRelation); - } - else - { - storeProperty.nextProperty = propertyIndexToStore; - } - } - else if (typeOfRelation == PROPERTY_RELATION_DIR) - { - if (storeProperty.dirProperty != PROPERTY_NULL) - { - return findPlaceholder( - storage, - propertyIndexToStore, - storeProperty.dirProperty, - typeOfRelation); - } - else - { - storeProperty.dirProperty = propertyIndexToStore; - } - } - - hr = StorageImpl_WriteProperty( - storage->ancestorStorage, - storePropertyIndex, - &storeProperty); - - if(! hr) - { - return E_FAIL; - } - - return S_OK; -} - -/************************************************************************* - * - * Internal Method - * - * This method takes the previous and the next property link of a property - * to be deleted and find them a place in the Storage. - */ -static HRESULT adjustPropertyChain( - StorageImpl *This, - StgProperty propertyToDelete, - StgProperty parentProperty, - ULONG parentPropertyId, - INT typeOfRelation) -{ - ULONG newLinkProperty = PROPERTY_NULL; - BOOL needToFindAPlaceholder = FALSE; - ULONG storeNode = PROPERTY_NULL; - ULONG toStoreNode = PROPERTY_NULL; - INT relationType = 0; - HRESULT hr = S_OK; - BOOL res = TRUE; - - if (typeOfRelation == PROPERTY_RELATION_PREVIOUS) - { - if (propertyToDelete.previousProperty != PROPERTY_NULL) - { - /* - * Set the parent previous to the property to delete previous - */ - newLinkProperty = propertyToDelete.previousProperty; - - if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * We also need to find a storage for the other link, setup variables - * to do this at the end... - */ - needToFindAPlaceholder = TRUE; - storeNode = propertyToDelete.previousProperty; - toStoreNode = propertyToDelete.nextProperty; - relationType = PROPERTY_RELATION_NEXT; - } - } - else if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * Set the parent previous to the property to delete next - */ - newLinkProperty = propertyToDelete.nextProperty; - } - - /* - * Link it for real... - */ - parentProperty.previousProperty = newLinkProperty; - - } - else if (typeOfRelation == PROPERTY_RELATION_NEXT) - { - if (propertyToDelete.previousProperty != PROPERTY_NULL) - { - /* - * Set the parent next to the property to delete next previous - */ - newLinkProperty = propertyToDelete.previousProperty; - - if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * We also need to find a storage for the other link, setup variables - * to do this at the end... - */ - needToFindAPlaceholder = TRUE; - storeNode = propertyToDelete.previousProperty; - toStoreNode = propertyToDelete.nextProperty; - relationType = PROPERTY_RELATION_NEXT; - } - } - else if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * Set the parent next to the property to delete next - */ - newLinkProperty = propertyToDelete.nextProperty; - } - - /* - * Link it for real... - */ - parentProperty.nextProperty = newLinkProperty; - } - else /* (typeOfRelation == PROPERTY_RELATION_DIR) */ - { - if (propertyToDelete.previousProperty != PROPERTY_NULL) - { - /* - * Set the parent dir to the property to delete previous - */ - newLinkProperty = propertyToDelete.previousProperty; - - if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * We also need to find a storage for the other link, setup variables - * to do this at the end... - */ - needToFindAPlaceholder = TRUE; - storeNode = propertyToDelete.previousProperty; - toStoreNode = propertyToDelete.nextProperty; - relationType = PROPERTY_RELATION_NEXT; - } - } - else if (propertyToDelete.nextProperty != PROPERTY_NULL) - { - /* - * Set the parent dir to the property to delete next - */ - newLinkProperty = propertyToDelete.nextProperty; - } - - /* - * Link it for real... - */ - parentProperty.dirProperty = newLinkProperty; - } - - /* - * Write back the parent property - */ - res = StorageImpl_WriteProperty( - This->ancestorStorage, - parentPropertyId, - &parentProperty); - if(! res) - { - return E_FAIL; - } - - /* - * If a placeholder is required for the other link, then, find one and - * get out of here... - */ - if (needToFindAPlaceholder) - { - hr = findPlaceholder( - This, - toStoreNode, - storeNode, - relationType); - } - - return hr; -} - - -/****************************************************************************** - * SetElementTimes (IStorage) - */ -HRESULT WINAPI StorageImpl_SetElementTimes( - IStorage* iface, - const OLECHAR *pwcsName,/* [string][in] */ - const FILETIME *pctime, /* [in] */ - const FILETIME *patime, /* [in] */ - const FILETIME *pmtime) /* [in] */ -{ - FIXME("(%s,...), stub!\n",debugstr_w(pwcsName)); - return S_OK; -} - -/****************************************************************************** - * SetStateBits (IStorage) - */ -HRESULT WINAPI StorageImpl_SetStateBits( - IStorage* iface, - DWORD grfStateBits,/* [in] */ - DWORD grfMask) /* [in] */ -{ - FIXME("not implemented!\n"); - return E_NOTIMPL; -} - -HRESULT StorageImpl_Construct( - StorageImpl* This, - HANDLE hFile, - LPCOLESTR pwcsName, - ILockBytes* pLkbyt, - DWORD openFlags, - BOOL fileBased, - BOOL fileCreate) -{ - HRESULT hr = S_OK; - StgProperty currentProperty; - BOOL readSuccessful; - ULONG currentPropertyIndex; - - if ( FAILED( validateSTGM(openFlags) )) - return STG_E_INVALIDFLAG; - - memset(This, 0, sizeof(StorageImpl)); - - /* - * Initialize the virtual function table. - */ - This->lpVtbl = &Storage32Impl_Vtbl; - This->v_destructor = &StorageImpl_Destroy; - - /* - * This is the top-level storage so initialize the ancestor pointer - * to this. - */ - This->ancestorStorage = This; - - /* - * Initialize the physical support of the storage. - */ - This->hFile = hFile; - - /* - * Store copy of file path. - */ - if(pwcsName) { - This->pwcsName = HeapAlloc(GetProcessHeap(), 0, - (lstrlenW(pwcsName)+1)*sizeof(WCHAR)); - if (!This->pwcsName) - return STG_E_INSUFFICIENTMEMORY; - strcpyW(This->pwcsName, pwcsName); - } - - /* - * Initialize the big block cache. - */ - This->bigBlockSize = DEF_BIG_BLOCK_SIZE; - This->smallBlockSize = DEF_SMALL_BLOCK_SIZE; - This->bigBlockFile = BIGBLOCKFILE_Construct(hFile, - pLkbyt, - openFlags, - This->bigBlockSize, - fileBased); - - if (This->bigBlockFile == 0) - return E_FAIL; - - if (fileCreate) - { - ULARGE_INTEGER size; - BYTE* bigBlockBuffer; - - /* - * Initialize all header variables: - * - The big block depot consists of one block and it is at block 0 - * - The properties start at block 1 - * - There is no small block depot - */ - memset( This->bigBlockDepotStart, - BLOCK_UNUSED, - sizeof(This->bigBlockDepotStart)); - - This->bigBlockDepotCount = 1; - This->bigBlockDepotStart[0] = 0; - This->rootStartBlock = 1; - This->smallBlockDepotStart = BLOCK_END_OF_CHAIN; - This->bigBlockSizeBits = DEF_BIG_BLOCK_SIZE_BITS; - This->smallBlockSizeBits = DEF_SMALL_BLOCK_SIZE_BITS; - This->extBigBlockDepotStart = BLOCK_END_OF_CHAIN; - This->extBigBlockDepotCount = 0; - - StorageImpl_SaveFileHeader(This); - - /* - * Add one block for the big block depot and one block for the properties - */ - size.u.HighPart = 0; - size.u.LowPart = This->bigBlockSize * 3; - BIGBLOCKFILE_SetSize(This->bigBlockFile, size); - - /* - * Initialize the big block depot - */ - bigBlockBuffer = StorageImpl_GetBigBlock(This, 0); - memset(bigBlockBuffer, BLOCK_UNUSED, This->bigBlockSize); - StorageUtl_WriteDWord(bigBlockBuffer, 0, BLOCK_SPECIAL); - StorageUtl_WriteDWord(bigBlockBuffer, sizeof(ULONG), BLOCK_END_OF_CHAIN); - StorageImpl_ReleaseBigBlock(This, bigBlockBuffer); - } - else - { - /* - * Load the header for the file. - */ - hr = StorageImpl_LoadFileHeader(This); - - if (FAILED(hr)) - { - BIGBLOCKFILE_Destructor(This->bigBlockFile); - - return hr; - } - } - - /* - * There is no block depot cached yet. - */ - This->indexBlockDepotCached = 0xFFFFFFFF; - - /* - * Start searching for free blocks with block 0. - */ - This->prevFreeBlock = 0; - - /* - * Create the block chain abstractions. - */ - if(!(This->rootBlockChain = - BlockChainStream_Construct(This, &This->rootStartBlock, PROPERTY_NULL))) - return STG_E_READFAULT; - - if(!(This->smallBlockDepotChain = - BlockChainStream_Construct(This, &This->smallBlockDepotStart, - PROPERTY_NULL))) - return STG_E_READFAULT; - - /* - * Write the root property - */ - if (fileCreate) - { - StgProperty rootProp; - /* - * Initialize the property chain - */ - memset(&rootProp, 0, sizeof(rootProp)); - MultiByteToWideChar( CP_ACP, 0, rootPropertyName, -1, rootProp.name, - sizeof(rootProp.name)/sizeof(WCHAR) ); - rootProp.sizeOfNameString = (strlenW(rootProp.name)+1) * sizeof(WCHAR); - rootProp.propertyType = PROPTYPE_ROOT; - rootProp.previousProperty = PROPERTY_NULL; - rootProp.nextProperty = PROPERTY_NULL; - rootProp.dirProperty = PROPERTY_NULL; - rootProp.startingBlock = BLOCK_END_OF_CHAIN; - rootProp.size.u.HighPart = 0; - rootProp.size.u.LowPart = 0; - - StorageImpl_WriteProperty(This, 0, &rootProp); - } - - /* - * Find the ID of the root in the property sets. - */ - currentPropertyIndex = 0; - - do - { - readSuccessful = StorageImpl_ReadProperty( - This, - currentPropertyIndex, - ¤tProperty); - - if (readSuccessful) - { - if ( (currentProperty.sizeOfNameString != 0 ) && - (currentProperty.propertyType == PROPTYPE_ROOT) ) - { - This->rootPropertySetIndex = currentPropertyIndex; - } - } - - currentPropertyIndex++; - - } while (readSuccessful && (This->rootPropertySetIndex == PROPERTY_NULL) ); - - if (!readSuccessful) - { - /* TODO CLEANUP */ - return STG_E_READFAULT; - } - - /* - * Create the block chain abstraction for the small block root chain. - */ - if(!(This->smallBlockRootChain = - BlockChainStream_Construct(This, NULL, This->rootPropertySetIndex))) - return STG_E_READFAULT; - - return hr; -} - -void StorageImpl_Destroy( - StorageImpl* This) -{ - TRACE("(%p)\n", This); - - if(This->pwcsName) - HeapFree(GetProcessHeap(), 0, This->pwcsName); - - BlockChainStream_Destroy(This->smallBlockRootChain); - BlockChainStream_Destroy(This->rootBlockChain); - BlockChainStream_Destroy(This->smallBlockDepotChain); - - BIGBLOCKFILE_Destructor(This->bigBlockFile); - return; -} - -/****************************************************************************** - * Storage32Impl_GetNextFreeBigBlock - * - * Returns the index of the next free big block. - * If the big block depot is filled, this method will enlarge it. - * - */ -ULONG StorageImpl_GetNextFreeBigBlock( - StorageImpl* This) -{ - ULONG depotBlockIndexPos; - void *depotBuffer; - ULONG depotBlockOffset; - ULONG blocksPerDepot = This->bigBlockSize / sizeof(ULONG); - ULONG nextBlockIndex = BLOCK_SPECIAL; - int depotIndex = 0; - ULONG freeBlock = BLOCK_UNUSED; - - depotIndex = This->prevFreeBlock / blocksPerDepot; - depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG); - - /* - * Scan the entire big block depot until we find a block marked free - */ - while (nextBlockIndex != BLOCK_UNUSED) - { - if (depotIndex < COUNT_BBDEPOTINHEADER) - { - depotBlockIndexPos = This->bigBlockDepotStart[depotIndex]; - - /* - * Grow the primary depot. - */ - if (depotBlockIndexPos == BLOCK_UNUSED) - { - depotBlockIndexPos = depotIndex*blocksPerDepot; - - /* - * Add a block depot. - */ - Storage32Impl_AddBlockDepot(This, depotBlockIndexPos); - This->bigBlockDepotCount++; - This->bigBlockDepotStart[depotIndex] = depotBlockIndexPos; - - /* - * Flag it as a block depot. - */ - StorageImpl_SetNextBlockInChain(This, - depotBlockIndexPos, - BLOCK_SPECIAL); - - /* Save new header information. - */ - StorageImpl_SaveFileHeader(This); - } - } - else - { - depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotIndex); - - if (depotBlockIndexPos == BLOCK_UNUSED) - { - /* - * Grow the extended depot. - */ - ULONG extIndex = BLOCK_UNUSED; - ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER; - ULONG extBlockOffset = numExtBlocks % (blocksPerDepot - 1); - - if (extBlockOffset == 0) - { - /* We need an extended block. - */ - extIndex = Storage32Impl_AddExtBlockDepot(This); - This->extBigBlockDepotCount++; - depotBlockIndexPos = extIndex + 1; - } - else - depotBlockIndexPos = depotIndex * blocksPerDepot; - - /* - * Add a block depot and mark it in the extended block. - */ - Storage32Impl_AddBlockDepot(This, depotBlockIndexPos); - This->bigBlockDepotCount++; - Storage32Impl_SetExtDepotBlock(This, depotIndex, depotBlockIndexPos); - - /* Flag the block depot. - */ - StorageImpl_SetNextBlockInChain(This, - depotBlockIndexPos, - BLOCK_SPECIAL); - - /* If necessary, flag the extended depot block. - */ - if (extIndex != BLOCK_UNUSED) - StorageImpl_SetNextBlockInChain(This, extIndex, BLOCK_EXTBBDEPOT); - - /* Save header information. - */ - StorageImpl_SaveFileHeader(This); - } - } - - depotBuffer = StorageImpl_GetROBigBlock(This, depotBlockIndexPos); - - if (depotBuffer != 0) - { - while ( ( (depotBlockOffset/sizeof(ULONG) ) < blocksPerDepot) && - ( nextBlockIndex != BLOCK_UNUSED)) - { - StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex); - - if (nextBlockIndex == BLOCK_UNUSED) - { - freeBlock = (depotIndex * blocksPerDepot) + - (depotBlockOffset/sizeof(ULONG)); - } - - depotBlockOffset += sizeof(ULONG); - } - - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - - depotIndex++; - depotBlockOffset = 0; - } - - This->prevFreeBlock = freeBlock; - - return freeBlock; -} - -/****************************************************************************** - * Storage32Impl_AddBlockDepot - * - * This will create a depot block, essentially it is a block initialized - * to BLOCK_UNUSEDs. - */ -void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex) -{ - BYTE* blockBuffer; - - blockBuffer = StorageImpl_GetBigBlock(This, blockIndex); - - /* - * Initialize blocks as free - */ - memset(blockBuffer, BLOCK_UNUSED, This->bigBlockSize); - - StorageImpl_ReleaseBigBlock(This, blockBuffer); -} - -/****************************************************************************** - * Storage32Impl_GetExtDepotBlock - * - * Returns the index of the block that corresponds to the specified depot - * index. This method is only for depot indexes equal or greater than - * COUNT_BBDEPOTINHEADER. - */ -ULONG Storage32Impl_GetExtDepotBlock(StorageImpl* This, ULONG depotIndex) -{ - ULONG depotBlocksPerExtBlock = (This->bigBlockSize / sizeof(ULONG)) - 1; - ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER; - ULONG extBlockCount = numExtBlocks / depotBlocksPerExtBlock; - ULONG extBlockOffset = numExtBlocks % depotBlocksPerExtBlock; - ULONG blockIndex = BLOCK_UNUSED; - ULONG extBlockIndex = This->extBigBlockDepotStart; - - assert(depotIndex >= COUNT_BBDEPOTINHEADER); - - if (This->extBigBlockDepotStart == BLOCK_END_OF_CHAIN) - return BLOCK_UNUSED; - - while (extBlockCount > 0) - { - extBlockIndex = Storage32Impl_GetNextExtendedBlock(This, extBlockIndex); - extBlockCount--; - } - - if (extBlockIndex != BLOCK_UNUSED) - { - BYTE* depotBuffer; - - depotBuffer = StorageImpl_GetROBigBlock(This, extBlockIndex); - - if (depotBuffer != 0) - { - StorageUtl_ReadDWord(depotBuffer, - extBlockOffset * sizeof(ULONG), - &blockIndex); - - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - } - - return blockIndex; -} - -/****************************************************************************** - * Storage32Impl_SetExtDepotBlock - * - * Associates the specified block index to the specified depot index. - * This method is only for depot indexes equal or greater than - * COUNT_BBDEPOTINHEADER. - */ -void Storage32Impl_SetExtDepotBlock(StorageImpl* This, - ULONG depotIndex, - ULONG blockIndex) -{ - ULONG depotBlocksPerExtBlock = (This->bigBlockSize / sizeof(ULONG)) - 1; - ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER; - ULONG extBlockCount = numExtBlocks / depotBlocksPerExtBlock; - ULONG extBlockOffset = numExtBlocks % depotBlocksPerExtBlock; - ULONG extBlockIndex = This->extBigBlockDepotStart; - - assert(depotIndex >= COUNT_BBDEPOTINHEADER); - - while (extBlockCount > 0) - { - extBlockIndex = Storage32Impl_GetNextExtendedBlock(This, extBlockIndex); - extBlockCount--; - } - - if (extBlockIndex != BLOCK_UNUSED) - { - BYTE* depotBuffer; - - depotBuffer = StorageImpl_GetBigBlock(This, extBlockIndex); - - if (depotBuffer != 0) - { - StorageUtl_WriteDWord(depotBuffer, - extBlockOffset * sizeof(ULONG), - blockIndex); - - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - } -} - -/****************************************************************************** - * Storage32Impl_AddExtBlockDepot - * - * Creates an extended depot block. - */ -ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This) -{ - ULONG numExtBlocks = This->extBigBlockDepotCount; - ULONG nextExtBlock = This->extBigBlockDepotStart; - BYTE* depotBuffer = NULL; - ULONG index = BLOCK_UNUSED; - ULONG nextBlockOffset = This->bigBlockSize - sizeof(ULONG); - ULONG blocksPerDepotBlock = This->bigBlockSize / sizeof(ULONG); - ULONG depotBlocksPerExtBlock = blocksPerDepotBlock - 1; - - index = (COUNT_BBDEPOTINHEADER + (numExtBlocks * depotBlocksPerExtBlock)) * - blocksPerDepotBlock; - - if ((numExtBlocks == 0) && (nextExtBlock == BLOCK_END_OF_CHAIN)) - { - /* - * The first extended block. - */ - This->extBigBlockDepotStart = index; - } - else - { - unsigned int i; - /* - * Follow the chain to the last one. - */ - for (i = 0; i < (numExtBlocks - 1); i++) - { - nextExtBlock = Storage32Impl_GetNextExtendedBlock(This, nextExtBlock); - } - - /* - * Add the new extended block to the chain. - */ - depotBuffer = StorageImpl_GetBigBlock(This, nextExtBlock); - StorageUtl_WriteDWord(depotBuffer, nextBlockOffset, index); - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - - /* - * Initialize this block. - */ - depotBuffer = StorageImpl_GetBigBlock(This, index); - memset(depotBuffer, BLOCK_UNUSED, This->bigBlockSize); - StorageImpl_ReleaseBigBlock(This, depotBuffer); - - return index; -} - -/****************************************************************************** - * Storage32Impl_FreeBigBlock - * - * This method will flag the specified block as free in the big block depot. - */ -void StorageImpl_FreeBigBlock( - StorageImpl* This, - ULONG blockIndex) -{ - StorageImpl_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED); - - if (blockIndex < This->prevFreeBlock) - This->prevFreeBlock = blockIndex; -} - -/************************************************************************ - * Storage32Impl_GetNextBlockInChain - * - * This method will retrieve the block index of the next big block in - * in the chain. - * - * Params: This - Pointer to the Storage object. - * blockIndex - Index of the block to retrieve the chain - * for. - * nextBlockIndex - receives the return value. - * - * Returns: This method returns the index of the next block in the chain. - * It will return the constants: - * BLOCK_SPECIAL - If the block given was not part of a - * chain. - * BLOCK_END_OF_CHAIN - If the block given was the last in - * a chain. - * BLOCK_UNUSED - If the block given was not past of a chain - * and is available. - * BLOCK_EXTBBDEPOT - This block is part of the extended - * big block depot. - * - * See Windows documentation for more details on IStorage methods. - */ -HRESULT StorageImpl_GetNextBlockInChain( - StorageImpl* This, - ULONG blockIndex, - ULONG* nextBlockIndex) -{ - ULONG offsetInDepot = blockIndex * sizeof (ULONG); - ULONG depotBlockCount = offsetInDepot / This->bigBlockSize; - ULONG depotBlockOffset = offsetInDepot % This->bigBlockSize; - void* depotBuffer; - ULONG depotBlockIndexPos; - int index; - - *nextBlockIndex = BLOCK_SPECIAL; - - if(depotBlockCount >= This->bigBlockDepotCount) - { - WARN("depotBlockCount %ld, bigBlockDepotCount %ld\n", depotBlockCount, - This->bigBlockDepotCount); - return STG_E_READFAULT; - } - - /* - * Cache the currently accessed depot block. - */ - if (depotBlockCount != This->indexBlockDepotCached) - { - This->indexBlockDepotCached = depotBlockCount; - - if (depotBlockCount < COUNT_BBDEPOTINHEADER) - { - depotBlockIndexPos = This->bigBlockDepotStart[depotBlockCount]; - } - else - { - /* - * We have to look in the extended depot. - */ - depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotBlockCount); - } - - depotBuffer = StorageImpl_GetROBigBlock(This, depotBlockIndexPos); - - if (!depotBuffer) - return STG_E_READFAULT; - - for (index = 0; index < NUM_BLOCKS_PER_DEPOT_BLOCK; index++) - { - StorageUtl_ReadDWord(depotBuffer, index*sizeof(ULONG), nextBlockIndex); - This->blockDepotCached[index] = *nextBlockIndex; - } - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - - *nextBlockIndex = This->blockDepotCached[depotBlockOffset/sizeof(ULONG)]; - - return S_OK; -} - -/****************************************************************************** - * Storage32Impl_GetNextExtendedBlock - * - * Given an extended block this method will return the next extended block. - * - * NOTES: - * The last ULONG of an extended block is the block index of the next - * extended block. Extended blocks are marked as BLOCK_EXTBBDEPOT in the - * depot. - * - * Return values: - * - The index of the next extended block - * - BLOCK_UNUSED: there is no next extended block. - * - Any other return values denotes failure. - */ -ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex) -{ - ULONG nextBlockIndex = BLOCK_SPECIAL; - ULONG depotBlockOffset = This->bigBlockSize - sizeof(ULONG); - void* depotBuffer; - - depotBuffer = StorageImpl_GetROBigBlock(This, blockIndex); - - if (depotBuffer!=0) - { - StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex); - - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - - return nextBlockIndex; -} - -/****************************************************************************** - * Storage32Impl_SetNextBlockInChain - * - * This method will write the index of the specified block's next block - * in the big block depot. - * - * For example: to create the chain 3 -> 1 -> 7 -> End of Chain - * do the following - * - * Storage32Impl_SetNextBlockInChain(This, 3, 1); - * Storage32Impl_SetNextBlockInChain(This, 1, 7); - * Storage32Impl_SetNextBlockInChain(This, 7, BLOCK_END_OF_CHAIN); - * - */ -void StorageImpl_SetNextBlockInChain( - StorageImpl* This, - ULONG blockIndex, - ULONG nextBlock) -{ - ULONG offsetInDepot = blockIndex * sizeof (ULONG); - ULONG depotBlockCount = offsetInDepot / This->bigBlockSize; - ULONG depotBlockOffset = offsetInDepot % This->bigBlockSize; - ULONG depotBlockIndexPos; - void* depotBuffer; - - assert(depotBlockCount < This->bigBlockDepotCount); - assert(blockIndex != nextBlock); - - if (depotBlockCount < COUNT_BBDEPOTINHEADER) - { - depotBlockIndexPos = This->bigBlockDepotStart[depotBlockCount]; - } - else - { - /* - * We have to look in the extended depot. - */ - depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotBlockCount); - } - - depotBuffer = StorageImpl_GetBigBlock(This, depotBlockIndexPos); - - if (depotBuffer!=0) - { - StorageUtl_WriteDWord(depotBuffer, depotBlockOffset, nextBlock); - StorageImpl_ReleaseBigBlock(This, depotBuffer); - } - - /* - * Update the cached block depot, if necessary. - */ - if (depotBlockCount == This->indexBlockDepotCached) - { - This->blockDepotCached[depotBlockOffset/sizeof(ULONG)] = nextBlock; - } -} - -/****************************************************************************** - * Storage32Impl_LoadFileHeader - * - * This method will read in the file header, i.e. big block index -1. - */ -HRESULT StorageImpl_LoadFileHeader( - StorageImpl* This) -{ - HRESULT hr = STG_E_FILENOTFOUND; - void* headerBigBlock = NULL; - int index; - - /* - * Get a pointer to the big block of data containing the header. - */ - headerBigBlock = StorageImpl_GetROBigBlock(This, -1); - - /* - * Extract the information from the header. - */ - if (headerBigBlock!=0) - { - /* - * Check for the "magic number" signature and return an error if it is not - * found. - */ - if (memcmp(headerBigBlock, STORAGE_oldmagic, sizeof(STORAGE_oldmagic))==0) - { - StorageImpl_ReleaseBigBlock(This, headerBigBlock); - return STG_E_OLDFORMAT; - } - - if (memcmp(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic))!=0) - { - StorageImpl_ReleaseBigBlock(This, headerBigBlock); - return STG_E_INVALIDHEADER; - } - - StorageUtl_ReadWord( - headerBigBlock, - OFFSET_BIGBLOCKSIZEBITS, - &This->bigBlockSizeBits); - - StorageUtl_ReadWord( - headerBigBlock, - OFFSET_SMALLBLOCKSIZEBITS, - &This->smallBlockSizeBits); - - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_BBDEPOTCOUNT, - &This->bigBlockDepotCount); - - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_ROOTSTARTBLOCK, - &This->rootStartBlock); - - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_SBDEPOTSTART, - &This->smallBlockDepotStart); - - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_EXTBBDEPOTSTART, - &This->extBigBlockDepotStart); - - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_EXTBBDEPOTCOUNT, - &This->extBigBlockDepotCount); - - for (index = 0; index < COUNT_BBDEPOTINHEADER; index ++) - { - StorageUtl_ReadDWord( - headerBigBlock, - OFFSET_BBDEPOTSTART + (sizeof(ULONG)*index), - &(This->bigBlockDepotStart[index])); - } - - /* - * Make the bitwise arithmetic to get the size of the blocks in bytes. - */ - if ((1 << 2) == 4) - { - This->bigBlockSize = 0x000000001 << (DWORD)This->bigBlockSizeBits; - This->smallBlockSize = 0x000000001 << (DWORD)This->smallBlockSizeBits; - } - else - { - This->bigBlockSize = 0x000000001 >> (DWORD)This->bigBlockSizeBits; - This->smallBlockSize = 0x000000001 >> (DWORD)This->smallBlockSizeBits; - } - - /* - * Right now, the code is making some assumptions about the size of the - * blocks, just make sure they are what we're expecting. - */ - if (This->bigBlockSize != DEF_BIG_BLOCK_SIZE || - This->smallBlockSize != DEF_SMALL_BLOCK_SIZE) - { - WARN("Broken OLE storage file\n"); - hr = STG_E_INVALIDHEADER; - } - else - hr = S_OK; - - /* - * Release the block. - */ - StorageImpl_ReleaseBigBlock(This, headerBigBlock); - } - - return hr; -} - -/****************************************************************************** - * Storage32Impl_SaveFileHeader - * - * This method will save to the file the header, i.e. big block -1. - */ -void StorageImpl_SaveFileHeader( - StorageImpl* This) -{ - BYTE headerBigBlock[BIG_BLOCK_SIZE]; - int index; - BOOL success; - - /* - * Get a pointer to the big block of data containing the header. - */ - success = StorageImpl_ReadBigBlock(This, -1, headerBigBlock); - - /* - * If the block read failed, the file is probably new. - */ - if (!success) - { - /* - * Initialize for all unknown fields. - */ - memset(headerBigBlock, 0, BIG_BLOCK_SIZE); - - /* - * Initialize the magic number. - */ - memcpy(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic)); - - /* - * And a bunch of things we don't know what they mean - */ - StorageUtl_WriteWord(headerBigBlock, 0x18, 0x3b); - StorageUtl_WriteWord(headerBigBlock, 0x1a, 0x3); - StorageUtl_WriteWord(headerBigBlock, 0x1c, (WORD)-2); - StorageUtl_WriteDWord(headerBigBlock, 0x38, (DWORD)0x1000); - } - - /* - * Write the information to the header. - */ - StorageUtl_WriteWord( - headerBigBlock, - OFFSET_BIGBLOCKSIZEBITS, - This->bigBlockSizeBits); - - StorageUtl_WriteWord( - headerBigBlock, - OFFSET_SMALLBLOCKSIZEBITS, - This->smallBlockSizeBits); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_BBDEPOTCOUNT, - This->bigBlockDepotCount); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_ROOTSTARTBLOCK, - This->rootStartBlock); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_SBDEPOTSTART, - This->smallBlockDepotStart); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_SBDEPOTCOUNT, - This->smallBlockDepotChain ? - BlockChainStream_GetCount(This->smallBlockDepotChain) : 0); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_EXTBBDEPOTSTART, - This->extBigBlockDepotStart); - - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_EXTBBDEPOTCOUNT, - This->extBigBlockDepotCount); - - for (index = 0; index < COUNT_BBDEPOTINHEADER; index ++) - { - StorageUtl_WriteDWord( - headerBigBlock, - OFFSET_BBDEPOTSTART + (sizeof(ULONG)*index), - (This->bigBlockDepotStart[index])); - } - - /* - * Write the big block back to the file. - */ - StorageImpl_WriteBigBlock(This, -1, headerBigBlock); -} - -/****************************************************************************** - * Storage32Impl_ReadProperty - * - * This method will read the specified property from the property chain. - */ -BOOL StorageImpl_ReadProperty( - StorageImpl* This, - ULONG index, - StgProperty* buffer) -{ - BYTE currentProperty[PROPSET_BLOCK_SIZE]; - ULARGE_INTEGER offsetInPropSet; - BOOL readSuccessful; - ULONG bytesRead; - - offsetInPropSet.u.HighPart = 0; - offsetInPropSet.u.LowPart = index * PROPSET_BLOCK_SIZE; - - readSuccessful = BlockChainStream_ReadAt( - This->rootBlockChain, - offsetInPropSet, - PROPSET_BLOCK_SIZE, - currentProperty, - &bytesRead); - - if (readSuccessful) - { - /* replace the name of root entry (often "Root Entry") by the file name */ - WCHAR *propName = (index == This->rootPropertySetIndex) ? - This->filename : (WCHAR *)currentProperty+OFFSET_PS_NAME; - - memset(buffer->name, 0, sizeof(buffer->name)); - memcpy( - buffer->name, - propName, - PROPERTY_NAME_BUFFER_LEN ); - TRACE("storage name: %s\n", debugstr_w(buffer->name)); - - memcpy(&buffer->propertyType, currentProperty + OFFSET_PS_PROPERTYTYPE, 1); - - StorageUtl_ReadWord( - currentProperty, - OFFSET_PS_NAMELENGTH, - &buffer->sizeOfNameString); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_PREVIOUSPROP, - &buffer->previousProperty); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_NEXTPROP, - &buffer->nextProperty); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_DIRPROP, - &buffer->dirProperty); - - StorageUtl_ReadGUID( - currentProperty, - OFFSET_PS_GUID, - &buffer->propertyUniqueID); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_TSS1, - &buffer->timeStampS1); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_TSD1, - &buffer->timeStampD1); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_TSS2, - &buffer->timeStampS2); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_TSD2, - &buffer->timeStampD2); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_STARTBLOCK, - &buffer->startingBlock); - - StorageUtl_ReadDWord( - currentProperty, - OFFSET_PS_SIZE, - &buffer->size.u.LowPart); - - buffer->size.u.HighPart = 0; - } - - return readSuccessful; -} - -/********************************************************************* - * Write the specified property into the property chain - */ -BOOL StorageImpl_WriteProperty( - StorageImpl* This, - ULONG index, - StgProperty* buffer) -{ - BYTE currentProperty[PROPSET_BLOCK_SIZE]; - ULARGE_INTEGER offsetInPropSet; - BOOL writeSuccessful; - ULONG bytesWritten; - - offsetInPropSet.u.HighPart = 0; - offsetInPropSet.u.LowPart = index * PROPSET_BLOCK_SIZE; - - memset(currentProperty, 0, PROPSET_BLOCK_SIZE); - - memcpy( - currentProperty + OFFSET_PS_NAME, - buffer->name, - PROPERTY_NAME_BUFFER_LEN ); - - memcpy(currentProperty + OFFSET_PS_PROPERTYTYPE, &buffer->propertyType, 1); - - StorageUtl_WriteWord( - currentProperty, - OFFSET_PS_NAMELENGTH, - buffer->sizeOfNameString); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_PREVIOUSPROP, - buffer->previousProperty); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_NEXTPROP, - buffer->nextProperty); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_DIRPROP, - buffer->dirProperty); - - StorageUtl_WriteGUID( - currentProperty, - OFFSET_PS_GUID, - &buffer->propertyUniqueID); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_TSS1, - buffer->timeStampS1); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_TSD1, - buffer->timeStampD1); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_TSS2, - buffer->timeStampS2); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_TSD2, - buffer->timeStampD2); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_STARTBLOCK, - buffer->startingBlock); - - StorageUtl_WriteDWord( - currentProperty, - OFFSET_PS_SIZE, - buffer->size.u.LowPart); - - writeSuccessful = BlockChainStream_WriteAt(This->rootBlockChain, - offsetInPropSet, - PROPSET_BLOCK_SIZE, - currentProperty, - &bytesWritten); - return writeSuccessful; -} - -BOOL StorageImpl_ReadBigBlock( - StorageImpl* This, - ULONG blockIndex, - void* buffer) -{ - void* bigBlockBuffer; - - bigBlockBuffer = StorageImpl_GetROBigBlock(This, blockIndex); - - if (bigBlockBuffer!=0) - { - memcpy(buffer, bigBlockBuffer, This->bigBlockSize); - - StorageImpl_ReleaseBigBlock(This, bigBlockBuffer); - - return TRUE; - } - - return FALSE; -} - -BOOL StorageImpl_WriteBigBlock( - StorageImpl* This, - ULONG blockIndex, - void* buffer) -{ - void* bigBlockBuffer; - - bigBlockBuffer = StorageImpl_GetBigBlock(This, blockIndex); - - if (bigBlockBuffer!=0) - { - memcpy(bigBlockBuffer, buffer, This->bigBlockSize); - - StorageImpl_ReleaseBigBlock(This, bigBlockBuffer); - - return TRUE; - } - - return FALSE; -} - -void* StorageImpl_GetROBigBlock( - StorageImpl* This, - ULONG blockIndex) -{ - return BIGBLOCKFILE_GetROBigBlock(This->bigBlockFile, blockIndex); -} - -void* StorageImpl_GetBigBlock( - StorageImpl* This, - ULONG blockIndex) -{ - return BIGBLOCKFILE_GetBigBlock(This->bigBlockFile, blockIndex); -} - -void StorageImpl_ReleaseBigBlock( - StorageImpl* This, - void* pBigBlock) -{ - BIGBLOCKFILE_ReleaseBigBlock(This->bigBlockFile, pBigBlock); -} - -/****************************************************************************** - * Storage32Impl_SmallBlocksToBigBlocks - * - * This method will convert a small block chain to a big block chain. - * The small block chain will be destroyed. - */ -BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks( - StorageImpl* This, - SmallBlockChainStream** ppsbChain) -{ - ULONG bbHeadOfChain = BLOCK_END_OF_CHAIN; - ULARGE_INTEGER size, offset; - ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten; - ULONG propertyIndex; - BOOL successRead, successWrite; - StgProperty chainProperty; - BYTE *buffer; - BlockChainStream *bbTempChain = NULL; - BlockChainStream *bigBlockChain = NULL; - - /* - * Create a temporary big block chain that doesn't have - * an associated property. This temporary chain will be - * used to copy data from small blocks to big blocks. - */ - bbTempChain = BlockChainStream_Construct(This, - &bbHeadOfChain, - PROPERTY_NULL); - if(!bbTempChain) return NULL; - /* - * Grow the big block chain. - */ - size = SmallBlockChainStream_GetSize(*ppsbChain); - BlockChainStream_SetSize(bbTempChain, size); - - /* - * Copy the contents of the small block chain to the big block chain - * by small block size increments. - */ - offset.u.LowPart = 0; - offset.u.HighPart = 0; - cbTotalRead = 0; - cbTotalWritten = 0; - - buffer = (BYTE *) HeapAlloc(GetProcessHeap(),0,DEF_SMALL_BLOCK_SIZE); - do - { - successRead = SmallBlockChainStream_ReadAt(*ppsbChain, - offset, - DEF_SMALL_BLOCK_SIZE, - buffer, - &cbRead); - cbTotalRead += cbRead; - - successWrite = BlockChainStream_WriteAt(bbTempChain, - offset, - cbRead, - buffer, - &cbWritten); - cbTotalWritten += cbWritten; - - offset.u.LowPart += This->smallBlockSize; - - } while (successRead && successWrite); - HeapFree(GetProcessHeap(),0,buffer); - - assert(cbTotalRead == cbTotalWritten); - - /* - * Destroy the small block chain. - */ - propertyIndex = (*ppsbChain)->ownerPropertyIndex; - size.u.HighPart = 0; - size.u.LowPart = 0; - SmallBlockChainStream_SetSize(*ppsbChain, size); - SmallBlockChainStream_Destroy(*ppsbChain); - *ppsbChain = 0; - - /* - * Change the property information. This chain is now a big block chain - * and it doesn't reside in the small blocks chain anymore. - */ - StorageImpl_ReadProperty(This, propertyIndex, &chainProperty); - - chainProperty.startingBlock = bbHeadOfChain; - - StorageImpl_WriteProperty(This, propertyIndex, &chainProperty); - - /* - * Destroy the temporary propertyless big block chain. - * Create a new big block chain associated with this property. - */ - BlockChainStream_Destroy(bbTempChain); - bigBlockChain = BlockChainStream_Construct(This, - NULL, - propertyIndex); - - return bigBlockChain; -} - -/****************************************************************************** -** Storage32InternalImpl implementation -*/ - -StorageInternalImpl* StorageInternalImpl_Construct( - StorageImpl* ancestorStorage, - ULONG rootPropertyIndex) -{ - StorageInternalImpl* newStorage; - - /* - * Allocate space for the new storage object - */ - newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageInternalImpl)); - - if (newStorage!=0) - { - memset(newStorage, 0, sizeof(StorageInternalImpl)); - - /* - * Initialize the virtual function table. - */ - newStorage->lpVtbl = &Storage32InternalImpl_Vtbl; - newStorage->v_destructor = &StorageInternalImpl_Destroy; - - /* - * Keep the ancestor storage pointer and nail a reference to it. - */ - newStorage->ancestorStorage = ancestorStorage; - StorageBaseImpl_AddRef((IStorage*)(newStorage->ancestorStorage)); - - /* - * Keep the index of the root property set for this storage, - */ - newStorage->rootPropertySetIndex = rootPropertyIndex; - - return newStorage; - } - - return 0; -} - -void StorageInternalImpl_Destroy( - StorageInternalImpl* This) -{ - StorageBaseImpl_Release((IStorage*)This->ancestorStorage); - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** -** -** Storage32InternalImpl_Commit -** -** The non-root storages cannot be opened in transacted mode thus this function -** does nothing. -*/ -HRESULT WINAPI StorageInternalImpl_Commit( - IStorage* iface, - DWORD grfCommitFlags) /* [in] */ -{ - return S_OK; -} - -/****************************************************************************** -** -** Storage32InternalImpl_Revert -** -** The non-root storages cannot be opened in transacted mode thus this function -** does nothing. -*/ -HRESULT WINAPI StorageInternalImpl_Revert( - IStorage* iface) -{ - return S_OK; -} - -/****************************************************************************** -** IEnumSTATSTGImpl implementation -*/ - -IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct( - StorageImpl* parentStorage, - ULONG firstPropertyNode) -{ - IEnumSTATSTGImpl* newEnumeration; - - newEnumeration = HeapAlloc(GetProcessHeap(), 0, sizeof(IEnumSTATSTGImpl)); - - if (newEnumeration!=0) - { - /* - * Set-up the virtual function table and reference count. - */ - newEnumeration->lpVtbl = &IEnumSTATSTGImpl_Vtbl; - newEnumeration->ref = 0; - - /* - * We want to nail-down the reference to the storage in case the - * enumeration out-lives the storage in the client application. - */ - newEnumeration->parentStorage = parentStorage; - IStorage_AddRef((IStorage*)newEnumeration->parentStorage); - - newEnumeration->firstPropertyNode = firstPropertyNode; - - /* - * Initialize the search stack - */ - newEnumeration->stackSize = 0; - newEnumeration->stackMaxSize = ENUMSTATSGT_SIZE_INCREMENT; - newEnumeration->stackToVisit = - HeapAlloc(GetProcessHeap(), 0, sizeof(ULONG)*ENUMSTATSGT_SIZE_INCREMENT); - - /* - * Make sure the current node of the iterator is the first one. - */ - IEnumSTATSTGImpl_Reset((IEnumSTATSTG*)newEnumeration); - } - - return newEnumeration; -} - -void IEnumSTATSTGImpl_Destroy(IEnumSTATSTGImpl* This) -{ - IStorage_Release((IStorage*)This->parentStorage); - HeapFree(GetProcessHeap(), 0, This->stackToVisit); - HeapFree(GetProcessHeap(), 0, This); -} - -HRESULT WINAPI IEnumSTATSTGImpl_QueryInterface( - IEnumSTATSTG* iface, - REFIID riid, - void** ppvObject) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - /* - * Perform a sanity check on the parameters. - */ - if (ppvObject==0) - return E_INVALIDARG; - - /* - * Initialize the return parameter. - */ - *ppvObject = 0; - - /* - * Compare the riid with the interface IDs implemented by this object. - */ - if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) - { - *ppvObject = (IEnumSTATSTG*)This; - } - else if (memcmp(&IID_IStorage, riid, sizeof(IID_IEnumSTATSTG)) == 0) - { - *ppvObject = (IEnumSTATSTG*)This; - } - - /* - * Check that we obtained an interface. - */ - if ((*ppvObject)==0) - return E_NOINTERFACE; - - /* - * Query Interface always increases the reference count by one when it is - * successful - */ - IEnumSTATSTGImpl_AddRef((IEnumSTATSTG*)This); - - return S_OK; -} - -ULONG WINAPI IEnumSTATSTGImpl_AddRef( - IEnumSTATSTG* iface) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - return InterlockedIncrement(&This->ref); -} - -ULONG WINAPI IEnumSTATSTGImpl_Release( - IEnumSTATSTG* iface) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - ULONG newRef; - - newRef = InterlockedDecrement(&This->ref); - - /* - * If the reference count goes down to 0, perform suicide. - */ - if (newRef==0) - { - IEnumSTATSTGImpl_Destroy(This); - } - - return newRef; -} - -HRESULT WINAPI IEnumSTATSTGImpl_Next( - IEnumSTATSTG* iface, - ULONG celt, - STATSTG* rgelt, - ULONG* pceltFetched) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - StgProperty currentProperty; - STATSTG* currentReturnStruct = rgelt; - ULONG objectFetched = 0; - ULONG currentSearchNode; - - /* - * Perform a sanity check on the parameters. - */ - if ( (rgelt==0) || ( (celt!=1) && (pceltFetched==0) ) ) - return E_INVALIDARG; - - /* - * To avoid the special case, get another pointer to a ULONG value if - * the caller didn't supply one. - */ - if (pceltFetched==0) - pceltFetched = &objectFetched; - - /* - * Start the iteration, we will iterate until we hit the end of the - * linked list or until we hit the number of items to iterate through - */ - *pceltFetched = 0; - - /* - * Start with the node at the top of the stack. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - - while ( ( *pceltFetched < celt) && - ( currentSearchNode!=PROPERTY_NULL) ) - { - /* - * Remove the top node from the stack - */ - IEnumSTATSTGImpl_PopSearchNode(This, TRUE); - - /* - * Read the property from the storage. - */ - StorageImpl_ReadProperty(This->parentStorage, - currentSearchNode, - ¤tProperty); - - /* - * Copy the information to the return buffer. - */ - StorageUtl_CopyPropertyToSTATSTG(currentReturnStruct, - ¤tProperty, - STATFLAG_DEFAULT); - - /* - * Step to the next item in the iteration - */ - (*pceltFetched)++; - currentReturnStruct++; - - /* - * Push the next search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, currentProperty.nextProperty); - - /* - * continue the iteration. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - } - - if (*pceltFetched == celt) - return S_OK; - - return S_FALSE; -} - - -HRESULT WINAPI IEnumSTATSTGImpl_Skip( - IEnumSTATSTG* iface, - ULONG celt) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - StgProperty currentProperty; - ULONG objectFetched = 0; - ULONG currentSearchNode; - - /* - * Start with the node at the top of the stack. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - - while ( (objectFetched < celt) && - (currentSearchNode!=PROPERTY_NULL) ) - { - /* - * Remove the top node from the stack - */ - IEnumSTATSTGImpl_PopSearchNode(This, TRUE); - - /* - * Read the property from the storage. - */ - StorageImpl_ReadProperty(This->parentStorage, - currentSearchNode, - ¤tProperty); - - /* - * Step to the next item in the iteration - */ - objectFetched++; - - /* - * Push the next search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, currentProperty.nextProperty); - - /* - * continue the iteration. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - } - - if (objectFetched == celt) - return S_OK; - - return S_FALSE; -} - -HRESULT WINAPI IEnumSTATSTGImpl_Reset( - IEnumSTATSTG* iface) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - StgProperty rootProperty; - BOOL readSuccessful; - - /* - * Re-initialize the search stack to an empty stack - */ - This->stackSize = 0; - - /* - * Read the root property from the storage. - */ - readSuccessful = StorageImpl_ReadProperty( - This->parentStorage, - This->firstPropertyNode, - &rootProperty); - - if (readSuccessful) - { - assert(rootProperty.sizeOfNameString!=0); - - /* - * Push the search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, rootProperty.dirProperty); - } - - return S_OK; -} - -HRESULT WINAPI IEnumSTATSTGImpl_Clone( - IEnumSTATSTG* iface, - IEnumSTATSTG** ppenum) -{ - IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface; - - IEnumSTATSTGImpl* newClone; - - /* - * Perform a sanity check on the parameters. - */ - if (ppenum==0) - return E_INVALIDARG; - - newClone = IEnumSTATSTGImpl_Construct(This->parentStorage, - This->firstPropertyNode); - - - /* - * The new clone enumeration must point to the same current node as - * the ole one. - */ - newClone->stackSize = This->stackSize ; - newClone->stackMaxSize = This->stackMaxSize ; - newClone->stackToVisit = - HeapAlloc(GetProcessHeap(), 0, sizeof(ULONG) * newClone->stackMaxSize); - - memcpy( - newClone->stackToVisit, - This->stackToVisit, - sizeof(ULONG) * newClone->stackSize); - - *ppenum = (IEnumSTATSTG*)newClone; - - /* - * Don't forget to nail down a reference to the clone before - * returning it. - */ - IEnumSTATSTGImpl_AddRef(*ppenum); - - return S_OK; -} - -INT IEnumSTATSTGImpl_FindParentProperty( - IEnumSTATSTGImpl *This, - ULONG childProperty, - StgProperty *currentProperty, - ULONG *thisNodeId) -{ - ULONG currentSearchNode; - ULONG foundNode; - - /* - * To avoid the special case, get another pointer to a ULONG value if - * the caller didn't supply one. - */ - if (thisNodeId==0) - thisNodeId = &foundNode; - - /* - * Start with the node at the top of the stack. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - - - while (currentSearchNode!=PROPERTY_NULL) - { - /* - * Store the current node in the returned parameters - */ - *thisNodeId = currentSearchNode; - - /* - * Remove the top node from the stack - */ - IEnumSTATSTGImpl_PopSearchNode(This, TRUE); - - /* - * Read the property from the storage. - */ - StorageImpl_ReadProperty( - This->parentStorage, - currentSearchNode, - currentProperty); - - if (currentProperty->previousProperty == childProperty) - return PROPERTY_RELATION_PREVIOUS; - - else if (currentProperty->nextProperty == childProperty) - return PROPERTY_RELATION_NEXT; - - else if (currentProperty->dirProperty == childProperty) - return PROPERTY_RELATION_DIR; - - /* - * Push the next search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, currentProperty->nextProperty); - - /* - * continue the iteration. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - } - - return PROPERTY_NULL; -} - -ULONG IEnumSTATSTGImpl_FindProperty( - IEnumSTATSTGImpl* This, - const OLECHAR* lpszPropName, - StgProperty* currentProperty) -{ - ULONG currentSearchNode; - - /* - * Start with the node at the top of the stack. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - - while (currentSearchNode!=PROPERTY_NULL) - { - /* - * Remove the top node from the stack - */ - IEnumSTATSTGImpl_PopSearchNode(This, TRUE); - - /* - * Read the property from the storage. - */ - StorageImpl_ReadProperty(This->parentStorage, - currentSearchNode, - currentProperty); - - if ( propertyNameCmp( - (const OLECHAR*)currentProperty->name, - (const OLECHAR*)lpszPropName) == 0) - return currentSearchNode; - - /* - * Push the next search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, currentProperty->nextProperty); - - /* - * continue the iteration. - */ - currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE); - } - - return PROPERTY_NULL; -} - -void IEnumSTATSTGImpl_PushSearchNode( - IEnumSTATSTGImpl* This, - ULONG nodeToPush) -{ - StgProperty rootProperty; - BOOL readSuccessful; - - /* - * First, make sure we're not trying to push an unexisting node. - */ - if (nodeToPush==PROPERTY_NULL) - return; - - /* - * First push the node to the stack - */ - if (This->stackSize == This->stackMaxSize) - { - This->stackMaxSize += ENUMSTATSGT_SIZE_INCREMENT; - - This->stackToVisit = HeapReAlloc( - GetProcessHeap(), - 0, - This->stackToVisit, - sizeof(ULONG) * This->stackMaxSize); - } - - This->stackToVisit[This->stackSize] = nodeToPush; - This->stackSize++; - - /* - * Read the root property from the storage. - */ - readSuccessful = StorageImpl_ReadProperty( - This->parentStorage, - nodeToPush, - &rootProperty); - - if (readSuccessful) - { - assert(rootProperty.sizeOfNameString!=0); - - /* - * Push the previous search node in the search stack. - */ - IEnumSTATSTGImpl_PushSearchNode(This, rootProperty.previousProperty); - } -} - -ULONG IEnumSTATSTGImpl_PopSearchNode( - IEnumSTATSTGImpl* This, - BOOL remove) -{ - ULONG topNode; - - if (This->stackSize == 0) - return PROPERTY_NULL; - - topNode = This->stackToVisit[This->stackSize-1]; - - if (remove) - This->stackSize--; - - return topNode; -} - -/****************************************************************************** -** StorageUtl implementation -*/ - -void StorageUtl_ReadWord(void* buffer, ULONG offset, WORD* value) -{ - memcpy(value, (BYTE*)buffer+offset, sizeof(WORD)); -} - -void StorageUtl_WriteWord(void* buffer, ULONG offset, WORD value) -{ - memcpy((BYTE*)buffer+offset, &value, sizeof(WORD)); -} - -void StorageUtl_ReadDWord(void* buffer, ULONG offset, DWORD* value) -{ - memcpy(value, (BYTE*)buffer+offset, sizeof(DWORD)); -} - -void StorageUtl_WriteDWord(void* buffer, ULONG offset, DWORD value) -{ - memcpy((BYTE*)buffer+offset, &value, sizeof(DWORD)); -} - -void StorageUtl_ReadGUID(void* buffer, ULONG offset, GUID* value) -{ - StorageUtl_ReadDWord(buffer, offset, &(value->Data1)); - StorageUtl_ReadWord(buffer, offset+4, &(value->Data2)); - StorageUtl_ReadWord(buffer, offset+6, &(value->Data3)); - - memcpy(value->Data4, (BYTE*)buffer+offset+8, sizeof(value->Data4)); -} - -void StorageUtl_WriteGUID(void* buffer, ULONG offset, GUID* value) -{ - StorageUtl_WriteDWord(buffer, offset, value->Data1); - StorageUtl_WriteWord(buffer, offset+4, value->Data2); - StorageUtl_WriteWord(buffer, offset+6, value->Data3); - - memcpy((BYTE*)buffer+offset+8, value->Data4, sizeof(value->Data4)); -} - -void StorageUtl_CopyPropertyToSTATSTG( - STATSTG* destination, - StgProperty* source, - int statFlags) -{ - /* - * The copy of the string occurs only when the flag is not set - */ - if( ((statFlags & STATFLAG_NONAME) != 0) || - (source->name == NULL) || - (source->name[0] == 0) ) - { - destination->pwcsName = 0; - } - else - { - destination->pwcsName = - CoTaskMemAlloc((lstrlenW(source->name)+1)*sizeof(WCHAR)); - - strcpyW((LPWSTR)destination->pwcsName, source->name); - } - - switch (source->propertyType) - { - case PROPTYPE_STORAGE: - case PROPTYPE_ROOT: - destination->type = STGTY_STORAGE; - break; - case PROPTYPE_STREAM: - destination->type = STGTY_STREAM; - break; - default: - destination->type = STGTY_STREAM; - break; - } - - destination->cbSize = source->size; -/* - currentReturnStruct->mtime = {0}; TODO - currentReturnStruct->ctime = {0}; - currentReturnStruct->atime = {0}; -*/ - destination->grfMode = 0; - destination->grfLocksSupported = 0; - destination->clsid = source->propertyUniqueID; - destination->grfStateBits = 0; - destination->reserved = 0; -} - -/****************************************************************************** -** BlockChainStream implementation -*/ - -BlockChainStream* BlockChainStream_Construct( - StorageImpl* parentStorage, - ULONG* headOfStreamPlaceHolder, - ULONG propertyIndex) -{ - BlockChainStream* newStream; - ULONG blockIndex; - - newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(BlockChainStream)); - - newStream->parentStorage = parentStorage; - newStream->headOfStreamPlaceHolder = headOfStreamPlaceHolder; - newStream->ownerPropertyIndex = propertyIndex; - newStream->lastBlockNoInSequence = 0xFFFFFFFF; - newStream->tailIndex = BLOCK_END_OF_CHAIN; - newStream->numBlocks = 0; - - blockIndex = BlockChainStream_GetHeadOfChain(newStream); - - while (blockIndex != BLOCK_END_OF_CHAIN) - { - newStream->numBlocks++; - newStream->tailIndex = blockIndex; - - if(FAILED(StorageImpl_GetNextBlockInChain( - parentStorage, - blockIndex, - &blockIndex))) - { - HeapFree(GetProcessHeap(), 0, newStream); - return NULL; - } - } - - return newStream; -} - -void BlockChainStream_Destroy(BlockChainStream* This) -{ - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** - * BlockChainStream_GetHeadOfChain - * - * Returns the head of this stream chain. - * Some special chains don't have properties, their heads are kept in - * This->headOfStreamPlaceHolder. - * - */ -ULONG BlockChainStream_GetHeadOfChain(BlockChainStream* This) -{ - StgProperty chainProperty; - BOOL readSuccessful; - - if (This->headOfStreamPlaceHolder != 0) - return *(This->headOfStreamPlaceHolder); - - if (This->ownerPropertyIndex != PROPERTY_NULL) - { - readSuccessful = StorageImpl_ReadProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProperty); - - if (readSuccessful) - { - return chainProperty.startingBlock; - } - } - - return BLOCK_END_OF_CHAIN; -} - -/****************************************************************************** - * BlockChainStream_GetCount - * - * Returns the number of blocks that comprises this chain. - * This is not the size of the stream as the last block may not be full! - * - */ -ULONG BlockChainStream_GetCount(BlockChainStream* This) -{ - ULONG blockIndex; - ULONG count = 0; - - blockIndex = BlockChainStream_GetHeadOfChain(This); - - while (blockIndex != BLOCK_END_OF_CHAIN) - { - count++; - - if(FAILED(StorageImpl_GetNextBlockInChain( - This->parentStorage, - blockIndex, - &blockIndex))) - return 0; - } - - return count; -} - -/****************************************************************************** - * BlockChainStream_ReadAt - * - * Reads a specified number of bytes from this chain at the specified offset. - * bytesRead may be NULL. - * Failure will be returned if the specified number of bytes has not been read. - */ -BOOL BlockChainStream_ReadAt(BlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - void* buffer, - ULONG* bytesRead) -{ - ULONG blockNoInSequence = offset.u.LowPart / This->parentStorage->bigBlockSize; - ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->bigBlockSize; - ULONG bytesToReadInBuffer; - ULONG blockIndex; - BYTE* bufferWalker; - BYTE* bigBlockBuffer; - - /* - * Find the first block in the stream that contains part of the buffer. - */ - if ( (This->lastBlockNoInSequence == 0xFFFFFFFF) || - (This->lastBlockNoInSequenceIndex == BLOCK_END_OF_CHAIN) || - (blockNoInSequence < This->lastBlockNoInSequence) ) - { - blockIndex = BlockChainStream_GetHeadOfChain(This); - This->lastBlockNoInSequence = blockNoInSequence; - } - else - { - ULONG temp = blockNoInSequence; - - blockIndex = This->lastBlockNoInSequenceIndex; - blockNoInSequence -= This->lastBlockNoInSequence; - This->lastBlockNoInSequence = temp; - } - - while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) - { - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex))) - return FALSE; - blockNoInSequence--; - } - - This->lastBlockNoInSequenceIndex = blockIndex; - - /* - * Start reading the buffer. - */ - *bytesRead = 0; - bufferWalker = buffer; - - while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) ) - { - /* - * Calculate how many bytes we can copy from this big block. - */ - bytesToReadInBuffer = - min(This->parentStorage->bigBlockSize - offsetInBlock, size); - - /* - * Copy those bytes to the buffer - */ - bigBlockBuffer = - StorageImpl_GetROBigBlock(This->parentStorage, blockIndex); - - memcpy(bufferWalker, bigBlockBuffer + offsetInBlock, bytesToReadInBuffer); - - StorageImpl_ReleaseBigBlock(This->parentStorage, bigBlockBuffer); - - /* - * Step to the next big block. - */ - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex))) - return FALSE; - - bufferWalker += bytesToReadInBuffer; - size -= bytesToReadInBuffer; - *bytesRead += bytesToReadInBuffer; - offsetInBlock = 0; /* There is no offset on the next block */ - - } - - return (size == 0); -} - -/****************************************************************************** - * BlockChainStream_WriteAt - * - * Writes the specified number of bytes to this chain at the specified offset. - * bytesWritten may be NULL. - * Will fail if not all specified number of bytes have been written. - */ -BOOL BlockChainStream_WriteAt(BlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - const void* buffer, - ULONG* bytesWritten) -{ - ULONG blockNoInSequence = offset.u.LowPart / This->parentStorage->bigBlockSize; - ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->bigBlockSize; - ULONG bytesToWrite; - ULONG blockIndex; - const BYTE* bufferWalker; - BYTE* bigBlockBuffer; - - /* - * Find the first block in the stream that contains part of the buffer. - */ - if ( (This->lastBlockNoInSequence == 0xFFFFFFFF) || - (This->lastBlockNoInSequenceIndex == BLOCK_END_OF_CHAIN) || - (blockNoInSequence < This->lastBlockNoInSequence) ) - { - blockIndex = BlockChainStream_GetHeadOfChain(This); - This->lastBlockNoInSequence = blockNoInSequence; - } - else - { - ULONG temp = blockNoInSequence; - - blockIndex = This->lastBlockNoInSequenceIndex; - blockNoInSequence -= This->lastBlockNoInSequence; - This->lastBlockNoInSequence = temp; - } - - while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) - { - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, - &blockIndex))) - return FALSE; - blockNoInSequence--; - } - - This->lastBlockNoInSequenceIndex = blockIndex; - - /* - * Here, I'm casting away the constness on the buffer variable - * This is OK since we don't intend to modify that buffer. - */ - *bytesWritten = 0; - bufferWalker = (const BYTE*)buffer; - - while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) ) - { - /* - * Calculate how many bytes we can copy from this big block. - */ - bytesToWrite = - min(This->parentStorage->bigBlockSize - offsetInBlock, size); - - /* - * Copy those bytes to the buffer - */ - bigBlockBuffer = StorageImpl_GetBigBlock(This->parentStorage, blockIndex); - - memcpy(bigBlockBuffer + offsetInBlock, bufferWalker, bytesToWrite); - - StorageImpl_ReleaseBigBlock(This->parentStorage, bigBlockBuffer); - - /* - * Step to the next big block. - */ - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, - &blockIndex))) - return FALSE; - bufferWalker += bytesToWrite; - size -= bytesToWrite; - *bytesWritten += bytesToWrite; - offsetInBlock = 0; /* There is no offset on the next block */ - } - - return (size == 0); -} - -/****************************************************************************** - * BlockChainStream_Shrink - * - * Shrinks this chain in the big block depot. - */ -BOOL BlockChainStream_Shrink(BlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULONG blockIndex, extraBlock; - ULONG numBlocks; - ULONG count = 1; - - /* - * Reset the last accessed block cache. - */ - This->lastBlockNoInSequence = 0xFFFFFFFF; - This->lastBlockNoInSequenceIndex = BLOCK_END_OF_CHAIN; - - /* - * Figure out how many blocks are needed to contain the new size - */ - numBlocks = newSize.u.LowPart / This->parentStorage->bigBlockSize; - - if ((newSize.u.LowPart % This->parentStorage->bigBlockSize) != 0) - numBlocks++; - - blockIndex = BlockChainStream_GetHeadOfChain(This); - - /* - * Go to the new end of chain - */ - while (count < numBlocks) - { - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, - &blockIndex))) - return FALSE; - count++; - } - - /* Get the next block before marking the new end */ - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, - &extraBlock))) - return FALSE; - - /* Mark the new end of chain */ - StorageImpl_SetNextBlockInChain( - This->parentStorage, - blockIndex, - BLOCK_END_OF_CHAIN); - - This->tailIndex = blockIndex; - This->numBlocks = numBlocks; - - /* - * Mark the extra blocks as free - */ - while (extraBlock != BLOCK_END_OF_CHAIN) - { - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, extraBlock, - &blockIndex))) - return FALSE; - StorageImpl_FreeBigBlock(This->parentStorage, extraBlock); - extraBlock = blockIndex; - } - - return TRUE; -} - -/****************************************************************************** - * BlockChainStream_Enlarge - * - * Grows this chain in the big block depot. - */ -BOOL BlockChainStream_Enlarge(BlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULONG blockIndex, currentBlock; - ULONG newNumBlocks; - ULONG oldNumBlocks = 0; - - blockIndex = BlockChainStream_GetHeadOfChain(This); - - /* - * Empty chain. Create the head. - */ - if (blockIndex == BLOCK_END_OF_CHAIN) - { - blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage); - StorageImpl_SetNextBlockInChain(This->parentStorage, - blockIndex, - BLOCK_END_OF_CHAIN); - - if (This->headOfStreamPlaceHolder != 0) - { - *(This->headOfStreamPlaceHolder) = blockIndex; - } - else - { - StgProperty chainProp; - assert(This->ownerPropertyIndex != PROPERTY_NULL); - - StorageImpl_ReadProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProp); - - chainProp.startingBlock = blockIndex; - - StorageImpl_WriteProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProp); - } - - This->tailIndex = blockIndex; - This->numBlocks = 1; - } - - /* - * Figure out how many blocks are needed to contain this stream - */ - newNumBlocks = newSize.u.LowPart / This->parentStorage->bigBlockSize; - - if ((newSize.u.LowPart % This->parentStorage->bigBlockSize) != 0) - newNumBlocks++; - - /* - * Go to the current end of chain - */ - if (This->tailIndex == BLOCK_END_OF_CHAIN) - { - currentBlock = blockIndex; - - while (blockIndex != BLOCK_END_OF_CHAIN) - { - This->numBlocks++; - currentBlock = blockIndex; - - if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, currentBlock, - &blockIndex))) - return FALSE; - } - - This->tailIndex = currentBlock; - } - - currentBlock = This->tailIndex; - oldNumBlocks = This->numBlocks; - - /* - * Add new blocks to the chain - */ - if (oldNumBlocks < newNumBlocks) - { - while (oldNumBlocks < newNumBlocks) - { - blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage); - - StorageImpl_SetNextBlockInChain( - This->parentStorage, - currentBlock, - blockIndex); - - StorageImpl_SetNextBlockInChain( - This->parentStorage, - blockIndex, - BLOCK_END_OF_CHAIN); - - currentBlock = blockIndex; - oldNumBlocks++; - } - - This->tailIndex = blockIndex; - This->numBlocks = newNumBlocks; - } - - return TRUE; -} - -/****************************************************************************** - * BlockChainStream_SetSize - * - * Sets the size of this stream. The big block depot will be updated. - * The file will grow if we grow the chain. - * - * TODO: Free the actual blocks in the file when we shrink the chain. - * Currently, the blocks are still in the file. So the file size - * doesn't shrink even if we shrink streams. - */ -BOOL BlockChainStream_SetSize( - BlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULARGE_INTEGER size = BlockChainStream_GetSize(This); - - if (newSize.u.LowPart == size.u.LowPart) - return TRUE; - - if (newSize.u.LowPart < size.u.LowPart) - { - BlockChainStream_Shrink(This, newSize); - } - else - { - ULARGE_INTEGER fileSize = - BIGBLOCKFILE_GetSize(This->parentStorage->bigBlockFile); - - ULONG diff = newSize.u.LowPart - size.u.LowPart; - - /* - * Make sure the file stays a multiple of blocksize - */ - if ((diff % This->parentStorage->bigBlockSize) != 0) - diff += (This->parentStorage->bigBlockSize - - (diff % This->parentStorage->bigBlockSize) ); - - fileSize.u.LowPart += diff; - BIGBLOCKFILE_SetSize(This->parentStorage->bigBlockFile, fileSize); - - BlockChainStream_Enlarge(This, newSize); - } - - return TRUE; -} - -/****************************************************************************** - * BlockChainStream_GetSize - * - * Returns the size of this chain. - * Will return the block count if this chain doesn't have a property. - */ -ULARGE_INTEGER BlockChainStream_GetSize(BlockChainStream* This) -{ - StgProperty chainProperty; - - if(This->headOfStreamPlaceHolder == NULL) - { - /* - * This chain is a data stream read the property and return - * the appropriate size - */ - StorageImpl_ReadProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProperty); - - return chainProperty.size; - } - else - { - /* - * this chain is a chain that does not have a property, figure out the - * size by making the product number of used blocks times the - * size of them - */ - ULARGE_INTEGER result; - result.u.HighPart = 0; - - result.u.LowPart = - BlockChainStream_GetCount(This) * - This->parentStorage->bigBlockSize; - - return result; - } -} - -/****************************************************************************** -** SmallBlockChainStream implementation -*/ - -SmallBlockChainStream* SmallBlockChainStream_Construct( - StorageImpl* parentStorage, - ULONG propertyIndex) -{ - SmallBlockChainStream* newStream; - - newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(SmallBlockChainStream)); - - newStream->parentStorage = parentStorage; - newStream->ownerPropertyIndex = propertyIndex; - - return newStream; -} - -void SmallBlockChainStream_Destroy( - SmallBlockChainStream* This) -{ - HeapFree(GetProcessHeap(), 0, This); -} - -/****************************************************************************** - * SmallBlockChainStream_GetHeadOfChain - * - * Returns the head of this chain of small blocks. - */ -ULONG SmallBlockChainStream_GetHeadOfChain( - SmallBlockChainStream* This) -{ - StgProperty chainProperty; - BOOL readSuccessful; - - if (This->ownerPropertyIndex) - { - readSuccessful = StorageImpl_ReadProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProperty); - - if (readSuccessful) - { - return chainProperty.startingBlock; - } - - } - - return BLOCK_END_OF_CHAIN; -} - -/****************************************************************************** - * SmallBlockChainStream_GetNextBlockInChain - * - * Returns the index of the next small block in this chain. - * - * Return Values: - * - BLOCK_END_OF_CHAIN: end of this chain - * - BLOCK_UNUSED: small block 'blockIndex' is free - */ -HRESULT SmallBlockChainStream_GetNextBlockInChain( - SmallBlockChainStream* This, - ULONG blockIndex, - ULONG* nextBlockInChain) -{ - ULARGE_INTEGER offsetOfBlockInDepot; - DWORD buffer; - ULONG bytesRead; - BOOL success; - - *nextBlockInChain = BLOCK_END_OF_CHAIN; - - offsetOfBlockInDepot.u.HighPart = 0; - offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG); - - /* - * Read those bytes in the buffer from the small block file. - */ - success = BlockChainStream_ReadAt( - This->parentStorage->smallBlockDepotChain, - offsetOfBlockInDepot, - sizeof(DWORD), - &buffer, - &bytesRead); - - if (success) - { - StorageUtl_ReadDWord(&buffer, 0, nextBlockInChain); - return S_OK; - } - - return STG_E_READFAULT; -} - -/****************************************************************************** - * SmallBlockChainStream_SetNextBlockInChain - * - * Writes the index of the next block of the specified block in the small - * block depot. - * To set the end of chain use BLOCK_END_OF_CHAIN as nextBlock. - * To flag a block as free use BLOCK_UNUSED as nextBlock. - */ -void SmallBlockChainStream_SetNextBlockInChain( - SmallBlockChainStream* This, - ULONG blockIndex, - ULONG nextBlock) -{ - ULARGE_INTEGER offsetOfBlockInDepot; - DWORD buffer; - ULONG bytesWritten; - - offsetOfBlockInDepot.u.HighPart = 0; - offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG); - - StorageUtl_WriteDWord(&buffer, 0, nextBlock); - - /* - * Read those bytes in the buffer from the small block file. - */ - BlockChainStream_WriteAt( - This->parentStorage->smallBlockDepotChain, - offsetOfBlockInDepot, - sizeof(DWORD), - &buffer, - &bytesWritten); -} - -/****************************************************************************** - * SmallBlockChainStream_FreeBlock - * - * Flag small block 'blockIndex' as free in the small block depot. - */ -void SmallBlockChainStream_FreeBlock( - SmallBlockChainStream* This, - ULONG blockIndex) -{ - SmallBlockChainStream_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED); -} - -/****************************************************************************** - * SmallBlockChainStream_GetNextFreeBlock - * - * Returns the index of a free small block. The small block depot will be - * enlarged if necessary. The small block chain will also be enlarged if - * necessary. - */ -ULONG SmallBlockChainStream_GetNextFreeBlock( - SmallBlockChainStream* This) -{ - ULARGE_INTEGER offsetOfBlockInDepot; - DWORD buffer; - ULONG bytesRead; - ULONG blockIndex = 0; - ULONG nextBlockIndex = BLOCK_END_OF_CHAIN; - BOOL success = TRUE; - ULONG smallBlocksPerBigBlock; - - offsetOfBlockInDepot.u.HighPart = 0; - - /* - * Scan the small block depot for a free block - */ - while (nextBlockIndex != BLOCK_UNUSED) - { - offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG); - - success = BlockChainStream_ReadAt( - This->parentStorage->smallBlockDepotChain, - offsetOfBlockInDepot, - sizeof(DWORD), - &buffer, - &bytesRead); - - /* - * If we run out of space for the small block depot, enlarge it - */ - if (success) - { - StorageUtl_ReadDWord(&buffer, 0, &nextBlockIndex); - - if (nextBlockIndex != BLOCK_UNUSED) - blockIndex++; - } - else - { - ULONG count = - BlockChainStream_GetCount(This->parentStorage->smallBlockDepotChain); - - ULONG sbdIndex = This->parentStorage->smallBlockDepotStart; - ULONG nextBlock, newsbdIndex; - BYTE* smallBlockDepot; - - nextBlock = sbdIndex; - while (nextBlock != BLOCK_END_OF_CHAIN) - { - sbdIndex = nextBlock; - StorageImpl_GetNextBlockInChain(This->parentStorage, sbdIndex, &nextBlock); - } - - newsbdIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage); - if (sbdIndex != BLOCK_END_OF_CHAIN) - StorageImpl_SetNextBlockInChain( - This->parentStorage, - sbdIndex, - newsbdIndex); - - StorageImpl_SetNextBlockInChain( - This->parentStorage, - newsbdIndex, - BLOCK_END_OF_CHAIN); - - /* - * Initialize all the small blocks to free - */ - smallBlockDepot = - StorageImpl_GetBigBlock(This->parentStorage, newsbdIndex); - - memset(smallBlockDepot, BLOCK_UNUSED, This->parentStorage->bigBlockSize); - StorageImpl_ReleaseBigBlock(This->parentStorage, smallBlockDepot); - - if (count == 0) - { - /* - * We have just created the small block depot. - */ - StgProperty rootProp; - ULONG sbStartIndex; - - /* - * Save it in the header - */ - This->parentStorage->smallBlockDepotStart = newsbdIndex; - StorageImpl_SaveFileHeader(This->parentStorage); - - /* - * And allocate the first big block that will contain small blocks - */ - sbStartIndex = - StorageImpl_GetNextFreeBigBlock(This->parentStorage); - - StorageImpl_SetNextBlockInChain( - This->parentStorage, - sbStartIndex, - BLOCK_END_OF_CHAIN); - - StorageImpl_ReadProperty( - This->parentStorage, - This->parentStorage->rootPropertySetIndex, - &rootProp); - - rootProp.startingBlock = sbStartIndex; - rootProp.size.u.HighPart = 0; - rootProp.size.u.LowPart = This->parentStorage->bigBlockSize; - - StorageImpl_WriteProperty( - This->parentStorage, - This->parentStorage->rootPropertySetIndex, - &rootProp); - } - } - } - - smallBlocksPerBigBlock = - This->parentStorage->bigBlockSize / This->parentStorage->smallBlockSize; - - /* - * Verify if we have to allocate big blocks to contain small blocks - */ - if (blockIndex % smallBlocksPerBigBlock == 0) - { - StgProperty rootProp; - ULONG blocksRequired = (blockIndex / smallBlocksPerBigBlock) + 1; - - StorageImpl_ReadProperty( - This->parentStorage, - This->parentStorage->rootPropertySetIndex, - &rootProp); - - if (rootProp.size.u.LowPart < - (blocksRequired * This->parentStorage->bigBlockSize)) - { - rootProp.size.u.LowPart += This->parentStorage->bigBlockSize; - - BlockChainStream_SetSize( - This->parentStorage->smallBlockRootChain, - rootProp.size); - - StorageImpl_WriteProperty( - This->parentStorage, - This->parentStorage->rootPropertySetIndex, - &rootProp); - } - } - - return blockIndex; -} - -/****************************************************************************** - * SmallBlockChainStream_ReadAt - * - * Reads a specified number of bytes from this chain at the specified offset. - * bytesRead may be NULL. - * Failure will be returned if the specified number of bytes has not been read. - */ -BOOL SmallBlockChainStream_ReadAt( - SmallBlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - void* buffer, - ULONG* bytesRead) -{ - ULARGE_INTEGER offsetInBigBlockFile; - ULONG blockNoInSequence = - offset.u.LowPart / This->parentStorage->smallBlockSize; - - ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize; - ULONG bytesToReadInBuffer; - ULONG blockIndex; - ULONG bytesReadFromBigBlockFile; - BYTE* bufferWalker; - - /* - * This should never happen on a small block file. - */ - assert(offset.u.HighPart==0); - - /* - * Find the first block in the stream that contains part of the buffer. - */ - blockIndex = SmallBlockChainStream_GetHeadOfChain(This); - - while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) - { - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, - &blockIndex))) - return FALSE; - blockNoInSequence--; - } - - /* - * Start reading the buffer. - */ - *bytesRead = 0; - bufferWalker = buffer; - - while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) ) - { - /* - * Calculate how many bytes we can copy from this small block. - */ - bytesToReadInBuffer = - min(This->parentStorage->smallBlockSize - offsetInBlock, size); - - /* - * Calculate the offset of the small block in the small block file. - */ - offsetInBigBlockFile.u.HighPart = 0; - offsetInBigBlockFile.u.LowPart = - blockIndex * This->parentStorage->smallBlockSize; - - offsetInBigBlockFile.u.LowPart += offsetInBlock; - - /* - * Read those bytes in the buffer from the small block file. - */ - BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain, - offsetInBigBlockFile, - bytesToReadInBuffer, - bufferWalker, - &bytesReadFromBigBlockFile); - - assert(bytesReadFromBigBlockFile == bytesToReadInBuffer); - - /* - * Step to the next big block. - */ - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex))) - return FALSE; - bufferWalker += bytesToReadInBuffer; - size -= bytesToReadInBuffer; - *bytesRead += bytesToReadInBuffer; - offsetInBlock = 0; /* There is no offset on the next block */ - } - - return (size == 0); -} - -/****************************************************************************** - * SmallBlockChainStream_WriteAt - * - * Writes the specified number of bytes to this chain at the specified offset. - * bytesWritten may be NULL. - * Will fail if not all specified number of bytes have been written. - */ -BOOL SmallBlockChainStream_WriteAt( - SmallBlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - const void* buffer, - ULONG* bytesWritten) -{ - ULARGE_INTEGER offsetInBigBlockFile; - ULONG blockNoInSequence = - offset.u.LowPart / This->parentStorage->smallBlockSize; - - ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize; - ULONG bytesToWriteInBuffer; - ULONG blockIndex; - ULONG bytesWrittenFromBigBlockFile; - const BYTE* bufferWalker; - - /* - * This should never happen on a small block file. - */ - assert(offset.u.HighPart==0); - - /* - * Find the first block in the stream that contains part of the buffer. - */ - blockIndex = SmallBlockChainStream_GetHeadOfChain(This); - - while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) - { - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex))) - return FALSE; - blockNoInSequence--; - } - - /* - * Start writing the buffer. - * - * Here, I'm casting away the constness on the buffer variable - * This is OK since we don't intend to modify that buffer. - */ - *bytesWritten = 0; - bufferWalker = (const BYTE*)buffer; - while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) ) - { - /* - * Calculate how many bytes we can copy to this small block. - */ - bytesToWriteInBuffer = - min(This->parentStorage->smallBlockSize - offsetInBlock, size); - - /* - * Calculate the offset of the small block in the small block file. - */ - offsetInBigBlockFile.u.HighPart = 0; - offsetInBigBlockFile.u.LowPart = - blockIndex * This->parentStorage->smallBlockSize; - - offsetInBigBlockFile.u.LowPart += offsetInBlock; - - /* - * Write those bytes in the buffer to the small block file. - */ - BlockChainStream_WriteAt(This->parentStorage->smallBlockRootChain, - offsetInBigBlockFile, - bytesToWriteInBuffer, - bufferWalker, - &bytesWrittenFromBigBlockFile); - - assert(bytesWrittenFromBigBlockFile == bytesToWriteInBuffer); - - /* - * Step to the next big block. - */ - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, - &blockIndex))) - return FALSE; - bufferWalker += bytesToWriteInBuffer; - size -= bytesToWriteInBuffer; - *bytesWritten += bytesToWriteInBuffer; - offsetInBlock = 0; /* There is no offset on the next block */ - } - - return (size == 0); -} - -/****************************************************************************** - * SmallBlockChainStream_Shrink - * - * Shrinks this chain in the small block depot. - */ -BOOL SmallBlockChainStream_Shrink( - SmallBlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULONG blockIndex, extraBlock; - ULONG numBlocks; - ULONG count = 0; - - numBlocks = newSize.u.LowPart / This->parentStorage->smallBlockSize; - - if ((newSize.u.LowPart % This->parentStorage->smallBlockSize) != 0) - numBlocks++; - - blockIndex = SmallBlockChainStream_GetHeadOfChain(This); - - /* - * Go to the new end of chain - */ - while (count < numBlocks) - { - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, - &blockIndex))) - return FALSE; - count++; - } - - /* - * If the count is 0, we have a special case, the head of the chain was - * just freed. - */ - if (count == 0) - { - StgProperty chainProp; - - StorageImpl_ReadProperty(This->parentStorage, - This->ownerPropertyIndex, - &chainProp); - - chainProp.startingBlock = BLOCK_END_OF_CHAIN; - - StorageImpl_WriteProperty(This->parentStorage, - This->ownerPropertyIndex, - &chainProp); - - /* - * We start freeing the chain at the head block. - */ - extraBlock = blockIndex; - } - else - { - /* Get the next block before marking the new end */ - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, - &extraBlock))) - return FALSE; - - /* Mark the new end of chain */ - SmallBlockChainStream_SetNextBlockInChain( - This, - blockIndex, - BLOCK_END_OF_CHAIN); - } - - /* - * Mark the extra blocks as free - */ - while (extraBlock != BLOCK_END_OF_CHAIN) - { - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, extraBlock, - &blockIndex))) - return FALSE; - SmallBlockChainStream_FreeBlock(This, extraBlock); - extraBlock = blockIndex; - } - - return TRUE; -} - -/****************************************************************************** - * SmallBlockChainStream_Enlarge - * - * Grows this chain in the small block depot. - */ -BOOL SmallBlockChainStream_Enlarge( - SmallBlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULONG blockIndex, currentBlock; - ULONG newNumBlocks; - ULONG oldNumBlocks = 0; - - blockIndex = SmallBlockChainStream_GetHeadOfChain(This); - - /* - * Empty chain - */ - if (blockIndex == BLOCK_END_OF_CHAIN) - { - - StgProperty chainProp; - - StorageImpl_ReadProperty(This->parentStorage, This->ownerPropertyIndex, - &chainProp); - - chainProp.startingBlock = SmallBlockChainStream_GetNextFreeBlock(This); - - StorageImpl_WriteProperty(This->parentStorage, This->ownerPropertyIndex, - &chainProp); - - blockIndex = chainProp.startingBlock; - SmallBlockChainStream_SetNextBlockInChain( - This, - blockIndex, - BLOCK_END_OF_CHAIN); - } - - currentBlock = blockIndex; - - /* - * Figure out how many blocks are needed to contain this stream - */ - newNumBlocks = newSize.u.LowPart / This->parentStorage->smallBlockSize; - - if ((newSize.u.LowPart % This->parentStorage->smallBlockSize) != 0) - newNumBlocks++; - - /* - * Go to the current end of chain - */ - while (blockIndex != BLOCK_END_OF_CHAIN) - { - oldNumBlocks++; - currentBlock = blockIndex; - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, currentBlock, &blockIndex))) - return FALSE; - } - - /* - * Add new blocks to the chain - */ - while (oldNumBlocks < newNumBlocks) - { - blockIndex = SmallBlockChainStream_GetNextFreeBlock(This); - SmallBlockChainStream_SetNextBlockInChain(This, currentBlock, blockIndex); - - SmallBlockChainStream_SetNextBlockInChain( - This, - blockIndex, - BLOCK_END_OF_CHAIN); - - currentBlock = blockIndex; - oldNumBlocks++; - } - - return TRUE; -} - -/****************************************************************************** - * SmallBlockChainStream_GetCount - * - * Returns the number of blocks that comprises this chain. - * This is not the size of this chain as the last block may not be full! - */ -ULONG SmallBlockChainStream_GetCount(SmallBlockChainStream* This) -{ - ULONG blockIndex; - ULONG count = 0; - - blockIndex = SmallBlockChainStream_GetHeadOfChain(This); - - while (blockIndex != BLOCK_END_OF_CHAIN) - { - count++; - - if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex))) - return 0; - } - - return count; -} - -/****************************************************************************** - * SmallBlockChainStream_SetSize - * - * Sets the size of this stream. - * The file will grow if we grow the chain. - * - * TODO: Free the actual blocks in the file when we shrink the chain. - * Currently, the blocks are still in the file. So the file size - * doesn't shrink even if we shrink streams. - */ -BOOL SmallBlockChainStream_SetSize( - SmallBlockChainStream* This, - ULARGE_INTEGER newSize) -{ - ULARGE_INTEGER size = SmallBlockChainStream_GetSize(This); - - if (newSize.u.LowPart == size.u.LowPart) - return TRUE; - - if (newSize.u.LowPart < size.u.LowPart) - { - SmallBlockChainStream_Shrink(This, newSize); - } - else - { - SmallBlockChainStream_Enlarge(This, newSize); - } - - return TRUE; -} - -/****************************************************************************** - * SmallBlockChainStream_GetSize - * - * Returns the size of this chain. - */ -ULARGE_INTEGER SmallBlockChainStream_GetSize(SmallBlockChainStream* This) -{ - StgProperty chainProperty; - - StorageImpl_ReadProperty( - This->parentStorage, - This->ownerPropertyIndex, - &chainProperty); - - return chainProperty.size; -} - -/****************************************************************************** - * StgCreateDocfile [OLE32.@] - */ -HRESULT WINAPI StgCreateDocfile( - LPCOLESTR pwcsName, - DWORD grfMode, - DWORD reserved, - IStorage **ppstgOpen) -{ - StorageImpl* newStorage = 0; - HANDLE hFile = INVALID_HANDLE_VALUE; - HRESULT hr = S_OK; - DWORD shareMode; - DWORD accessMode; - DWORD creationMode; - DWORD fileAttributes; - WCHAR tempFileName[MAX_PATH]; - - TRACE("(%s, %lx, %ld, %p)\n", - debugstr_w(pwcsName), grfMode, - reserved, ppstgOpen); - - /* - * Validate the parameters - */ - if (ppstgOpen == 0) - return STG_E_INVALIDPOINTER; - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - return STG_E_INVALIDFLAG; - - /* - * Generate a unique name. - */ - if (pwcsName == 0) - { - WCHAR tempPath[MAX_PATH]; - static const WCHAR prefix[] = { 'S', 'T', 'O', 0 }; - - if (!(grfMode & STGM_SHARE_EXCLUSIVE)) - return STG_E_INVALIDFLAG; - if (!(grfMode & (STGM_WRITE|STGM_READWRITE))) - return STG_E_INVALIDFLAG; - - memset(tempPath, 0, sizeof(tempPath)); - memset(tempFileName, 0, sizeof(tempFileName)); - - if ((GetTempPathW(MAX_PATH, tempPath)) == 0 ) - tempPath[0] = '.'; - - if (GetTempFileNameW(tempPath, prefix, 0, tempFileName) != 0) - pwcsName = tempFileName; - else - return STG_E_INSUFFICIENTMEMORY; - - creationMode = TRUNCATE_EXISTING; - } - else - { - creationMode = GetCreationModeFromSTGM(grfMode); - } - - /* - * Interpret the STGM value grfMode - */ - shareMode = GetShareModeFromSTGM(grfMode); - accessMode = GetAccessModeFromSTGM(grfMode); - - if (grfMode & STGM_DELETEONRELEASE) - fileAttributes = FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE; - else - fileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; - - if (grfMode & STGM_TRANSACTED) - FIXME("Transacted mode not implemented.\n"); - - /* - * Initialize the "out" parameter. - */ - *ppstgOpen = 0; - - hFile = CreateFileW(pwcsName, - accessMode, - shareMode, - NULL, - creationMode, - fileAttributes, - 0); - - if (hFile == INVALID_HANDLE_VALUE) - { - return E_FAIL; - } - - /* - * Allocate and initialize the new IStorage32object. - */ - newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl)); - - if (newStorage == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = StorageImpl_Construct( - newStorage, - hFile, - pwcsName, - NULL, - grfMode, - TRUE, - TRUE); - - if (FAILED(hr)) - { - HeapFree(GetProcessHeap(), 0, newStorage); - return hr; - } - - /* - * Get an "out" pointer for the caller. - */ - hr = StorageBaseImpl_QueryInterface( - (IStorage*)newStorage, - (REFIID)&IID_IStorage, - (void**)ppstgOpen); - - return hr; -} - -/****************************************************************************** - * StgCreateStorageEx [OLE32.@] - */ -HRESULT WINAPI StgCreateStorageEx(const WCHAR* pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS* pStgOptions, void* reserved, REFIID riid, void** ppObjectOpen) -{ - TRACE("(%s, %lx, %lx, %lx, %p, %p, %p, %p)\n", debugstr_w(pwcsName), - grfMode, stgfmt, grfAttrs, pStgOptions, reserved, riid, ppObjectOpen); - return STG_E_UNIMPLEMENTEDFUNCTION; -} - -/****************************************************************************** - * StgOpenStorage [OLE32.@] - */ -HRESULT WINAPI StgOpenStorage( - const OLECHAR *pwcsName, - IStorage *pstgPriority, - DWORD grfMode, - SNB snbExclude, - DWORD reserved, - IStorage **ppstgOpen) -{ - StorageImpl* newStorage = 0; - HRESULT hr = S_OK; - HANDLE hFile = 0; - DWORD shareMode; - DWORD accessMode; - WCHAR fullname[MAX_PATH]; - DWORD length; - - TRACE("(%s, %p, %lx, %p, %ld, %p)\n", - debugstr_w(pwcsName), pstgPriority, grfMode, - snbExclude, reserved, ppstgOpen); - - /* - * Perform a sanity check - */ - if (( pwcsName == 0) || (ppstgOpen == 0) ) - { - hr = STG_E_INVALIDPOINTER; - goto end; - } - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - { - hr = STG_E_INVALIDFLAG; - goto end; - } - - /* - * Interpret the STGM value grfMode - */ - shareMode = GetShareModeFromSTGM(grfMode); - accessMode = GetAccessModeFromSTGM(grfMode); - - /* - * Initialize the "out" parameter. - */ - *ppstgOpen = 0; - - hFile = CreateFileW( pwcsName, - accessMode, - shareMode, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, - 0); - - length = GetFileSize(hFile, NULL); - - if (hFile==INVALID_HANDLE_VALUE) - { - DWORD last_error = GetLastError(); - - hr = E_FAIL; - - switch (last_error) - { - case ERROR_FILE_NOT_FOUND: - hr = STG_E_FILENOTFOUND; - break; - - case ERROR_PATH_NOT_FOUND: - hr = STG_E_PATHNOTFOUND; - break; - - case ERROR_ACCESS_DENIED: - case ERROR_WRITE_PROTECT: - hr = STG_E_ACCESSDENIED; - break; - - case ERROR_SHARING_VIOLATION: - hr = STG_E_SHAREVIOLATION; - break; - - default: - hr = E_FAIL; - } - - goto end; - } - - /* - * Allocate and initialize the new IStorage32object. - */ - newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl)); - - if (newStorage == 0) - { - hr = STG_E_INSUFFICIENTMEMORY; - goto end; - } - - /* if the file's length was zero, initialize the storage */ - hr = StorageImpl_Construct( - newStorage, - hFile, - pwcsName, - NULL, - grfMode, - TRUE, - !length ); - - if (FAILED(hr)) - { - HeapFree(GetProcessHeap(), 0, newStorage); - /* - * According to the docs if the file is not a storage, return STG_E_FILEALREADYEXISTS - */ - if(hr == STG_E_INVALIDHEADER) - hr = STG_E_FILEALREADYEXISTS; - goto end; - } - - /* prepare the file name string given in lieu of the root property name */ - GetFullPathNameW(pwcsName, MAX_PATH, fullname, NULL); - memcpy(newStorage->filename, fullname, PROPERTY_NAME_BUFFER_LEN); - newStorage->filename[PROPERTY_NAME_BUFFER_LEN-1] = '\0'; - - /* - * Get an "out" pointer for the caller. - */ - hr = StorageBaseImpl_QueryInterface( - (IStorage*)newStorage, - (REFIID)&IID_IStorage, - (void**)ppstgOpen); - -end: - TRACE("<-- %08lx, IStorage %p\n", hr, ppstgOpen ? *ppstgOpen : NULL); - return hr; -} - -/****************************************************************************** - * StgCreateDocfileOnILockBytes [OLE32.@] - */ -HRESULT WINAPI StgCreateDocfileOnILockBytes( - ILockBytes *plkbyt, - DWORD grfMode, - DWORD reserved, - IStorage** ppstgOpen) -{ - StorageImpl* newStorage = 0; - HRESULT hr = S_OK; - - /* - * Validate the parameters - */ - if ((ppstgOpen == 0) || (plkbyt == 0)) - return STG_E_INVALIDPOINTER; - - /* - * Allocate and initialize the new IStorage object. - */ - newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl)); - - if (newStorage == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = StorageImpl_Construct( - newStorage, - 0, - 0, - plkbyt, - grfMode, - FALSE, - TRUE); - - if (FAILED(hr)) - { - HeapFree(GetProcessHeap(), 0, newStorage); - return hr; - } - - /* - * Get an "out" pointer for the caller. - */ - hr = StorageBaseImpl_QueryInterface( - (IStorage*)newStorage, - (REFIID)&IID_IStorage, - (void**)ppstgOpen); - - return hr; -} - -/****************************************************************************** - * StgOpenStorageOnILockBytes [OLE32.@] - */ -HRESULT WINAPI StgOpenStorageOnILockBytes( - ILockBytes *plkbyt, - IStorage *pstgPriority, - DWORD grfMode, - SNB snbExclude, - DWORD reserved, - IStorage **ppstgOpen) -{ - StorageImpl* newStorage = 0; - HRESULT hr = S_OK; - - /* - * Perform a sanity check - */ - if ((plkbyt == 0) || (ppstgOpen == 0)) - return STG_E_INVALIDPOINTER; - - /* - * Validate the STGM flags - */ - if ( FAILED( validateSTGM(grfMode) )) - return STG_E_INVALIDFLAG; - - /* - * Initialize the "out" parameter. - */ - *ppstgOpen = 0; - - /* - * Allocate and initialize the new IStorage object. - */ - newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl)); - - if (newStorage == 0) - return STG_E_INSUFFICIENTMEMORY; - - hr = StorageImpl_Construct( - newStorage, - 0, - 0, - plkbyt, - grfMode, - FALSE, - FALSE); - - if (FAILED(hr)) - { - HeapFree(GetProcessHeap(), 0, newStorage); - return hr; - } - - /* - * Get an "out" pointer for the caller. - */ - hr = StorageBaseImpl_QueryInterface( - (IStorage*)newStorage, - (REFIID)&IID_IStorage, - (void**)ppstgOpen); - - return hr; -} - -/****************************************************************************** - * StgSetTimes [ole32.@] - * StgSetTimes [OLE32.@] - * - * - */ -HRESULT WINAPI StgSetTimes(OLECHAR const *str, FILETIME const *a, - FILETIME const *b, FILETIME const *c ) -{ - FIXME("(%s, %p, %p, %p),stub!\n", debugstr_w(str), a, b, c); - return S_OK; -} - -/****************************************************************************** - * StgIsStorageILockBytes [OLE32.@] - * - * Determines if the ILockBytes contains a storage object. - */ -HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt) -{ - BYTE sig[8]; - ULARGE_INTEGER offset; - - offset.u.HighPart = 0; - offset.u.LowPart = 0; - - ILockBytes_ReadAt(plkbyt, offset, sig, sizeof(sig), NULL); - - if (memcmp(sig, STORAGE_magic, sizeof(STORAGE_magic)) == 0) - return S_OK; - - return S_FALSE; -} - -/****************************************************************************** - * WriteClassStg [OLE32.@] - * - * This method will store the specified CLSID in the specified storage object - */ -HRESULT WINAPI WriteClassStg(IStorage* pStg, REFCLSID rclsid) -{ - HRESULT hRes; - - assert(pStg != 0); - - hRes = IStorage_SetClass(pStg, rclsid); - - return hRes; -} - -/*********************************************************************** - * ReadClassStg (OLE32.@) - * - * This method reads the CLSID previously written to a storage object with the WriteClassStg. - */ -HRESULT WINAPI ReadClassStg(IStorage *pstg,CLSID *pclsid){ - - STATSTG pstatstg; - HRESULT hRes; - - TRACE("()\n"); - - if(pclsid==NULL) - return E_POINTER; - /* - * read a STATSTG structure (contains the clsid) from the storage - */ - hRes=IStorage_Stat(pstg,&pstatstg,STATFLAG_DEFAULT); - - if(SUCCEEDED(hRes)) - *pclsid=pstatstg.clsid; - - return hRes; -} - -/*********************************************************************** - * OleLoadFromStream (OLE32.@) - * - * This function loads an object from stream - */ -HRESULT WINAPI OleLoadFromStream(IStream *pStm,REFIID iidInterface,void** ppvObj) -{ - CLSID clsid; - HRESULT res; - LPPERSISTSTREAM xstm; - - TRACE("(%p,%s,%p)\n",pStm,debugstr_guid(iidInterface),ppvObj); - - res=ReadClassStm(pStm,&clsid); - if (!SUCCEEDED(res)) - return res; - res=CoCreateInstance(&clsid,NULL,CLSCTX_INPROC_SERVER,iidInterface,ppvObj); - if (!SUCCEEDED(res)) - return res; - res=IUnknown_QueryInterface((IUnknown*)*ppvObj,&IID_IPersistStream,(LPVOID*)&xstm); - if (!SUCCEEDED(res)) { - IUnknown_Release((IUnknown*)*ppvObj); - return res; - } - res=IPersistStream_Load(xstm,pStm); - IPersistStream_Release(xstm); - /* FIXME: all refcounts ok at this point? I think they should be: - * pStm : unchanged - * ppvObj : 1 - * xstm : 0 (released) - */ - return res; -} - -/*********************************************************************** - * OleSaveToStream (OLE32.@) - * - * This function saves an object with the IPersistStream interface on it - * to the specified stream. - */ -HRESULT WINAPI OleSaveToStream(IPersistStream *pPStm,IStream *pStm) -{ - - CLSID clsid; - HRESULT res; - - TRACE("(%p,%p)\n",pPStm,pStm); - - res=IPersistStream_GetClassID(pPStm,&clsid); - - if (SUCCEEDED(res)){ - - res=WriteClassStm(pStm,&clsid); - - if (SUCCEEDED(res)) - - res=IPersistStream_Save(pPStm,pStm,TRUE); - } - - TRACE("Finished Save\n"); - return res; -} - -/**************************************************************************** - * This method validate a STGM parameter that can contain the values below - * - * STGM_DIRECT 0x00000000 - * STGM_TRANSACTED 0x00010000 - * STGM_SIMPLE 0x08000000 - * - * STGM_READ 0x00000000 - * STGM_WRITE 0x00000001 - * STGM_READWRITE 0x00000002 - * - * STGM_SHARE_DENY_NONE 0x00000040 - * STGM_SHARE_DENY_READ 0x00000030 - * STGM_SHARE_DENY_WRITE 0x00000020 - * STGM_SHARE_EXCLUSIVE 0x00000010 - * - * STGM_PRIORITY 0x00040000 - * STGM_DELETEONRELEASE 0x04000000 - * - * STGM_CREATE 0x00001000 - * STGM_CONVERT 0x00020000 - * STGM_FAILIFTHERE 0x00000000 - * - * STGM_NOSCRATCH 0x00100000 - * STGM_NOSNAPSHOT 0x00200000 - */ -static HRESULT validateSTGM(DWORD stgm) -{ - BOOL bSTGM_TRANSACTED = ((stgm & STGM_TRANSACTED) == STGM_TRANSACTED); - BOOL bSTGM_SIMPLE = ((stgm & STGM_SIMPLE) == STGM_SIMPLE); - BOOL bSTGM_DIRECT = ! (bSTGM_TRANSACTED || bSTGM_SIMPLE); - - BOOL bSTGM_WRITE = ((stgm & STGM_WRITE) == STGM_WRITE); - BOOL bSTGM_READWRITE = ((stgm & STGM_READWRITE) == STGM_READWRITE); - BOOL bSTGM_READ = ! (bSTGM_WRITE || bSTGM_READWRITE); - - BOOL bSTGM_SHARE_DENY_NONE = - ((stgm & STGM_SHARE_DENY_NONE) == STGM_SHARE_DENY_NONE); - - BOOL bSTGM_SHARE_DENY_READ = - ((stgm & STGM_SHARE_DENY_READ) == STGM_SHARE_DENY_READ); - - BOOL bSTGM_SHARE_DENY_WRITE = - ((stgm & STGM_SHARE_DENY_WRITE) == STGM_SHARE_DENY_WRITE); - - BOOL bSTGM_SHARE_EXCLUSIVE = - ((stgm & STGM_SHARE_EXCLUSIVE) == STGM_SHARE_EXCLUSIVE); - - BOOL bSTGM_CREATE = ((stgm & STGM_CREATE) == STGM_CREATE); - BOOL bSTGM_CONVERT = ((stgm & STGM_CONVERT) == STGM_CONVERT); - - BOOL bSTGM_NOSCRATCH = ((stgm & STGM_NOSCRATCH) == STGM_NOSCRATCH); - BOOL bSTGM_NOSNAPSHOT = ((stgm & STGM_NOSNAPSHOT) == STGM_NOSNAPSHOT); - - /* - * STGM_DIRECT | STGM_TRANSACTED | STGM_SIMPLE - */ - if ( ! bSTGM_DIRECT ) - if( bSTGM_TRANSACTED && bSTGM_SIMPLE ) - return E_FAIL; - - /* - * STGM_WRITE | STGM_READWRITE | STGM_READ - */ - if ( ! bSTGM_READ ) - if( bSTGM_WRITE && bSTGM_READWRITE ) - return E_FAIL; - - /* - * STGM_SHARE_DENY_NONE | others - * (I assume here that DENY_READ implies DENY_WRITE) - */ - if ( bSTGM_SHARE_DENY_NONE ) - if ( bSTGM_SHARE_DENY_READ || - bSTGM_SHARE_DENY_WRITE || - bSTGM_SHARE_EXCLUSIVE) - return E_FAIL; - - /* - * STGM_CREATE | STGM_CONVERT - * if both are false, STGM_FAILIFTHERE is set to TRUE - */ - if ( bSTGM_CREATE && bSTGM_CONVERT ) - return E_FAIL; - - /* - * STGM_NOSCRATCH requires STGM_TRANSACTED - */ - if ( bSTGM_NOSCRATCH && ! bSTGM_TRANSACTED ) - return E_FAIL; - - /* - * STGM_NOSNAPSHOT requires STGM_TRANSACTED and - * not STGM_SHARE_EXCLUSIVE or STGM_SHARE_DENY_WRITE` - */ - if (bSTGM_NOSNAPSHOT) - { - if ( ! ( bSTGM_TRANSACTED && - !(bSTGM_SHARE_EXCLUSIVE || bSTGM_SHARE_DENY_WRITE)) ) - return E_FAIL; - } - - return S_OK; -} - -/**************************************************************************** - * GetShareModeFromSTGM - * - * This method will return a share mode flag from a STGM value. - * The STGM value is assumed valid. - */ -static DWORD GetShareModeFromSTGM(DWORD stgm) -{ - DWORD dwShareMode = 0; - BOOL bSTGM_SHARE_DENY_NONE = - ((stgm & STGM_SHARE_DENY_NONE) == STGM_SHARE_DENY_NONE); - - BOOL bSTGM_SHARE_DENY_READ = - ((stgm & STGM_SHARE_DENY_READ) == STGM_SHARE_DENY_READ); - - BOOL bSTGM_SHARE_DENY_WRITE = - ((stgm & STGM_SHARE_DENY_WRITE) == STGM_SHARE_DENY_WRITE); - - BOOL bSTGM_SHARE_EXCLUSIVE = - ((stgm & STGM_SHARE_EXCLUSIVE) == STGM_SHARE_EXCLUSIVE); - - if ((bSTGM_SHARE_EXCLUSIVE) || (bSTGM_SHARE_DENY_READ)) - dwShareMode = 0; - - if (bSTGM_SHARE_DENY_NONE) - dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; - - if (bSTGM_SHARE_DENY_WRITE) - dwShareMode = FILE_SHARE_READ; - - return dwShareMode; -} - -/**************************************************************************** - * GetAccessModeFromSTGM - * - * This method will return an access mode flag from a STGM value. - * The STGM value is assumed valid. - */ -static DWORD GetAccessModeFromSTGM(DWORD stgm) -{ - DWORD dwDesiredAccess = GENERIC_READ; - BOOL bSTGM_WRITE = ((stgm & STGM_WRITE) == STGM_WRITE); - BOOL bSTGM_READWRITE = ((stgm & STGM_READWRITE) == STGM_READWRITE); - BOOL bSTGM_READ = ! (bSTGM_WRITE || bSTGM_READWRITE); - - if (bSTGM_READ) - dwDesiredAccess = GENERIC_READ; - - if (bSTGM_WRITE) - dwDesiredAccess |= GENERIC_WRITE; - - if (bSTGM_READWRITE) - dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; - - return dwDesiredAccess; -} - -/**************************************************************************** - * GetCreationModeFromSTGM - * - * This method will return a creation mode flag from a STGM value. - * The STGM value is assumed valid. - */ -static DWORD GetCreationModeFromSTGM(DWORD stgm) -{ - if ( stgm & STGM_CREATE) - return CREATE_ALWAYS; - if (stgm & STGM_CONVERT) { - FIXME("STGM_CONVERT not implemented!\n"); - return CREATE_NEW; - } - /* All other cases */ - if (stgm & ~ (STGM_CREATE|STGM_CONVERT)) - FIXME("unhandled storage mode : 0x%08lx\n",stgm & ~ (STGM_CREATE|STGM_CONVERT)); - return CREATE_NEW; -} - - -/************************************************************************* - * OLECONVERT_LoadOLE10 [Internal] - * - * Loads the OLE10 STREAM to memory - * - * PARAMS - * pOleStream [I] The OLESTREAM - * pData [I] Data Structure for the OLESTREAM Data - * - * RETURNS - * Success: S_OK - * Failure: CONVERT10_E_OLESTREAM_GET for invalid Get - * CONVERT10_E_OLESTREAM_FMT if the OLEID is invalide - * - * NOTES - * This function is used by OleConvertOLESTREAMToIStorage only. - * - * Memory allocated for pData must be freed by the caller - */ -HRESULT OLECONVERT_LoadOLE10(LPOLESTREAM pOleStream, OLECONVERT_OLESTREAM_DATA *pData, BOOL bStrem1) -{ - DWORD dwSize; - HRESULT hRes = S_OK; - int nTryCnt=0; - int max_try = 6; - - pData->pData = NULL; - pData->pstrOleObjFileName = (CHAR *) NULL; - - for( nTryCnt=0;nTryCnt < max_try; nTryCnt++) - { - /* Get the OleID */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwOleID), sizeof(pData->dwOleID)); - if(dwSize != sizeof(pData->dwOleID)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - else if(pData->dwOleID != OLESTREAM_ID) - { - hRes = CONVERT10_E_OLESTREAM_FMT; - } - else - { - hRes = S_OK; - break; - } - } - - if(hRes == S_OK) - { - /* Get the TypeID...more info needed for this field */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwTypeID), sizeof(pData->dwTypeID)); - if(dwSize != sizeof(pData->dwTypeID)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - if(hRes == S_OK) - { - if(pData->dwTypeID != 0) - { - /* Get the length of the OleTypeName */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *) &(pData->dwOleTypeNameLength), sizeof(pData->dwOleTypeNameLength)); - if(dwSize != sizeof(pData->dwOleTypeNameLength)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - - if(hRes == S_OK) - { - if(pData->dwOleTypeNameLength > 0) - { - /* Get the OleTypeName */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)pData->strOleTypeName, pData->dwOleTypeNameLength); - if(dwSize != pData->dwOleTypeNameLength) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - } - if(bStrem1) - { - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwOleObjFileNameLength), sizeof(pData->dwOleObjFileNameLength)); - if(dwSize != sizeof(pData->dwOleObjFileNameLength)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - if(hRes == S_OK) - { - if(pData->dwOleObjFileNameLength < 1) /* there is no file name exist */ - pData->dwOleObjFileNameLength = sizeof(pData->dwOleObjFileNameLength); - pData->pstrOleObjFileName = (CHAR *)HeapAlloc(GetProcessHeap(), 0, pData->dwOleObjFileNameLength); - if(pData->pstrOleObjFileName) - { - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)(pData->pstrOleObjFileName),pData->dwOleObjFileNameLength); - if(dwSize != pData->dwOleObjFileNameLength) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - else - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - else - { - /* Get the Width of the Metafile */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwMetaFileWidth), sizeof(pData->dwMetaFileWidth)); - if(dwSize != sizeof(pData->dwMetaFileWidth)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - if(hRes == S_OK) - { - /* Get the Height of the Metafile */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwMetaFileHeight), sizeof(pData->dwMetaFileHeight)); - if(dwSize != sizeof(pData->dwMetaFileHeight)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - } - if(hRes == S_OK) - { - /* Get the Length of the Data */ - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwDataLength), sizeof(pData->dwDataLength)); - if(dwSize != sizeof(pData->dwDataLength)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - - if(hRes == S_OK) /* I don't know what is this 8 byts information is we have to figure out */ - { - if(!bStrem1) /* if it is a second OLE stream data */ - { - pData->dwDataLength -= 8; - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)(pData->strUnknown), sizeof(pData->strUnknown)); - if(dwSize != sizeof(pData->strUnknown)) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - } - if(hRes == S_OK) - { - if(pData->dwDataLength > 0) - { - pData->pData = (BYTE *)HeapAlloc(GetProcessHeap(),0,pData->dwDataLength); - - /* Get Data (ex. IStorage, Metafile, or BMP) */ - if(pData->pData) - { - dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)pData->pData, pData->dwDataLength); - if(dwSize != pData->dwDataLength) - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - else - { - hRes = CONVERT10_E_OLESTREAM_GET; - } - } - } - } - } - return hRes; -} - -/************************************************************************* - * OLECONVERT_SaveOLE10 [Internal] - * - * Saves the OLE10 STREAM From memory - * - * PARAMS - * pData [I] Data Structure for the OLESTREAM Data - * pOleStream [I] The OLESTREAM to save - * - * RETURNS - * Success: S_OK - * Failure: CONVERT10_E_OLESTREAM_PUT for invalid Put - * - * NOTES - * This function is used by OleConvertIStorageToOLESTREAM only. - * - */ -HRESULT OLECONVERT_SaveOLE10(OLECONVERT_OLESTREAM_DATA *pData, LPOLESTREAM pOleStream) -{ - DWORD dwSize; - HRESULT hRes = S_OK; - - - /* Set the OleID */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwOleID), sizeof(pData->dwOleID)); - if(dwSize != sizeof(pData->dwOleID)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - - if(hRes == S_OK) - { - /* Set the TypeID */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwTypeID), sizeof(pData->dwTypeID)); - if(dwSize != sizeof(pData->dwTypeID)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - - if(pData->dwOleID == OLESTREAM_ID && pData->dwTypeID != 0 && hRes == S_OK) - { - /* Set the Length of the OleTypeName */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwOleTypeNameLength), sizeof(pData->dwOleTypeNameLength)); - if(dwSize != sizeof(pData->dwOleTypeNameLength)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - - if(hRes == S_OK) - { - if(pData->dwOleTypeNameLength > 0) - { - /* Set the OleTypeName */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *) pData->strOleTypeName, pData->dwOleTypeNameLength); - if(dwSize != pData->dwOleTypeNameLength) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - } - - if(hRes == S_OK) - { - /* Set the width of the Metafile */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwMetaFileWidth), sizeof(pData->dwMetaFileWidth)); - if(dwSize != sizeof(pData->dwMetaFileWidth)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - - if(hRes == S_OK) - { - /* Set the height of the Metafile */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwMetaFileHeight), sizeof(pData->dwMetaFileHeight)); - if(dwSize != sizeof(pData->dwMetaFileHeight)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - - if(hRes == S_OK) - { - /* Set the length of the Data */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwDataLength), sizeof(pData->dwDataLength)); - if(dwSize != sizeof(pData->dwDataLength)) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - - if(hRes == S_OK) - { - if(pData->dwDataLength > 0) - { - /* Set the Data (eg. IStorage, Metafile, Bitmap) */ - dwSize = pOleStream->lpstbl->Put(pOleStream, (void *) pData->pData, pData->dwDataLength); - if(dwSize != pData->dwDataLength) - { - hRes = CONVERT10_E_OLESTREAM_PUT; - } - } - } - } - return hRes; -} - -/************************************************************************* - * OLECONVERT_GetOLE20FromOLE10[Internal] - * - * This function copies OLE10 Data (the IStorage in the OLESTREAM) to disk, - * opens it, and copies the content to the dest IStorage for - * OleConvertOLESTREAMToIStorage - * - * - * PARAMS - * pDestStorage [I] The IStorage to copy the data to - * pBuffer [I] Buffer that contains the IStorage from the OLESTREAM - * nBufferLength [I] The size of the buffer - * - * RETURNS - * Nothing - * - * NOTES - * - * - */ -void OLECONVERT_GetOLE20FromOLE10(LPSTORAGE pDestStorage, BYTE *pBuffer, DWORD nBufferLength) -{ - HRESULT hRes; - HANDLE hFile; - IStorage *pTempStorage; - DWORD dwNumOfBytesWritten; - WCHAR wstrTempDir[MAX_PATH], wstrTempFile[MAX_PATH]; - static const WCHAR wstrPrefix[] = {'s', 'i', 's', 0}; - - /* Create a temp File */ - GetTempPathW(MAX_PATH, wstrTempDir); - GetTempFileNameW(wstrTempDir, wstrPrefix, 0, wstrTempFile); - hFile = CreateFileW(wstrTempFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if(hFile != INVALID_HANDLE_VALUE) - { - /* Write IStorage Data to File */ - WriteFile(hFile, pBuffer, nBufferLength, &dwNumOfBytesWritten, NULL); - CloseHandle(hFile); - - /* Open and copy temp storage to the Dest Storage */ - hRes = StgOpenStorage(wstrTempFile, NULL, STGM_READ, NULL, 0, &pTempStorage); - if(hRes == S_OK) - { - hRes = StorageImpl_CopyTo(pTempStorage, 0, NULL, NULL, pDestStorage); - StorageBaseImpl_Release(pTempStorage); - } - DeleteFileW(wstrTempFile); - } -} - - -/************************************************************************* - * OLECONVERT_WriteOLE20ToBuffer [Internal] - * - * Saves the OLE10 STREAM From memory - * - * PARAMS - * pStorage [I] The Src IStorage to copy - * pData [I] The Dest Memory to write to. - * - * RETURNS - * The size in bytes allocated for pData - * - * NOTES - * Memory allocated for pData must be freed by the caller - * - * Used by OleConvertIStorageToOLESTREAM only. - * - */ -DWORD OLECONVERT_WriteOLE20ToBuffer(LPSTORAGE pStorage, BYTE **pData) -{ - HANDLE hFile; - HRESULT hRes; - DWORD nDataLength = 0; - IStorage *pTempStorage; - WCHAR wstrTempDir[MAX_PATH], wstrTempFile[MAX_PATH]; - static const WCHAR wstrPrefix[] = {'s', 'i', 's', 0}; - - *pData = NULL; - - /* Create temp Storage */ - GetTempPathW(MAX_PATH, wstrTempDir); - GetTempFileNameW(wstrTempDir, wstrPrefix, 0, wstrTempFile); - hRes = StgCreateDocfile(wstrTempFile, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pTempStorage); - - if(hRes == S_OK) - { - /* Copy Src Storage to the Temp Storage */ - StorageImpl_CopyTo(pStorage, 0, NULL, NULL, pTempStorage); - StorageBaseImpl_Release(pTempStorage); - - /* Open Temp Storage as a file and copy to memory */ - hFile = CreateFileW(wstrTempFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if(hFile != INVALID_HANDLE_VALUE) - { - nDataLength = GetFileSize(hFile, NULL); - *pData = (BYTE *) HeapAlloc(GetProcessHeap(),0,nDataLength); - ReadFile(hFile, *pData, nDataLength, &nDataLength, 0); - CloseHandle(hFile); - } - DeleteFileW(wstrTempFile); - } - return nDataLength; -} - -/************************************************************************* - * OLECONVERT_CreateOleStream [Internal] - * - * Creates the "\001OLE" stream in the IStorage if necessary. - * - * PARAMS - * pStorage [I] Dest storage to create the stream in - * - * RETURNS - * Nothing - * - * NOTES - * This function is used by OleConvertOLESTREAMToIStorage only. - * - * This stream is still unknown, MS Word seems to have extra data - * but since the data is stored in the OLESTREAM there should be - * no need to recreate the stream. If the stream is manually - * deleted it will create it with this default data. - * - */ -void OLECONVERT_CreateOleStream(LPSTORAGE pStorage) -{ - HRESULT hRes; - IStream *pStream; - static const WCHAR wstrStreamName[] = {1,'O', 'l', 'e', 0}; - BYTE pOleStreamHeader [] = - { - 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - }; - - /* Create stream if not present */ - hRes = IStorage_CreateStream(pStorage, wstrStreamName, - STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream ); - - if(hRes == S_OK) - { - /* Write default Data */ - hRes = IStream_Write(pStream, pOleStreamHeader, sizeof(pOleStreamHeader), NULL); - IStream_Release(pStream); - } -} - -/* write a string to a stream, preceded by its length */ -static HRESULT STREAM_WriteString( IStream *stm, LPCWSTR string ) -{ - HRESULT r; - LPSTR str; - DWORD len = 0; - - if( string ) - len = WideCharToMultiByte( CP_ACP, 0, string, -1, NULL, 0, NULL, NULL); - r = IStream_Write( stm, &len, sizeof(len), NULL); - if( FAILED( r ) ) - return r; - if(len == 0) - return r; - str = CoTaskMemAlloc( len ); - WideCharToMultiByte( CP_ACP, 0, string, -1, str, len, NULL, NULL); - r = IStream_Write( stm, str, len, NULL); - CoTaskMemFree( str ); - return r; -} - -/* read a string preceded by its length from a stream */ -static HRESULT STREAM_ReadString( IStream *stm, LPWSTR *string ) -{ - HRESULT r; - DWORD len, count = 0; - LPSTR str; - LPWSTR wstr; - - r = IStream_Read( stm, &len, sizeof(len), &count ); - if( FAILED( r ) ) - return r; - if( count != sizeof(len) ) - return E_OUTOFMEMORY; - - TRACE("%ld bytes\n",len); - - str = CoTaskMemAlloc( len ); - if( !str ) - return E_OUTOFMEMORY; - count = 0; - r = IStream_Read( stm, str, len, &count ); - if( FAILED( r ) ) - return r; - if( count != len ) - { - CoTaskMemFree( str ); - return E_OUTOFMEMORY; - } - - TRACE("Read string %s\n",debugstr_an(str,len)); - - len = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 ); - wstr = CoTaskMemAlloc( (len + 1)*sizeof (WCHAR) ); - if( wstr ) - MultiByteToWideChar( CP_ACP, 0, str, count, wstr, len ); - CoTaskMemFree( str ); - - *string = wstr; - - return r; -} - - -static HRESULT STORAGE_WriteCompObj( LPSTORAGE pstg, CLSID *clsid, - LPCWSTR lpszUserType, LPCWSTR szClipName, LPCWSTR szProgIDName ) -{ - IStream *pstm; - HRESULT r = S_OK; - static const WCHAR szwStreamName[] = {1, 'C', 'o', 'm', 'p', 'O', 'b', 'j', 0}; - - static const BYTE unknown1[12] = - { 0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF}; - static const BYTE unknown2[16] = - { 0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - TRACE("%p %s %s %s %s\n", pstg, debugstr_guid(clsid), - debugstr_w(lpszUserType), debugstr_w(szClipName), - debugstr_w(szProgIDName)); - - /* Create a CompObj stream if it doesn't exist */ - r = IStorage_CreateStream(pstg, szwStreamName, - STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pstm ); - if( FAILED (r) ) - return r; - - /* Write CompObj Structure to stream */ - r = IStream_Write(pstm, unknown1, sizeof(unknown1), NULL); - - if( SUCCEEDED( r ) ) - r = WriteClassStm( pstm, clsid ); - - if( SUCCEEDED( r ) ) - r = STREAM_WriteString( pstm, lpszUserType ); - if( SUCCEEDED( r ) ) - r = STREAM_WriteString( pstm, szClipName ); - if( SUCCEEDED( r ) ) - r = STREAM_WriteString( pstm, szProgIDName ); - if( SUCCEEDED( r ) ) - r = IStream_Write(pstm, unknown2, sizeof(unknown2), NULL); - - IStream_Release( pstm ); - - return r; -} - -/* enumerate HKEY_CLASSES_ROOT\\CLSID looking for a CLSID whose name matches */ -static HRESULT CLSIDFromUserType(LPCWSTR lpszUserType, CLSID *clsid) -{ - LONG r, i, len; - ULONG count; - WCHAR szKey[0x40]; - HKEY hkey, hkeyclsid; - LPWSTR buffer = NULL; - BOOL found = FALSE; - static const WCHAR szclsid[] = { 'C','L','S','I','D',0 }; - - TRACE("Finding CLSID for %s\n", debugstr_w(lpszUserType)); - - r = RegOpenKeyW( HKEY_CLASSES_ROOT, szclsid, &hkeyclsid ); - if( r ) - return E_INVALIDARG; - - len = lstrlenW( lpszUserType ) + 1; - buffer = CoTaskMemAlloc( len * sizeof (WCHAR) ); - if( !buffer ) - goto end; - - for(i=0; !found; i++ ) - { - r = RegEnumKeyW( hkeyclsid, i, szKey, sizeof(szKey)/sizeof(WCHAR)); - if( r != ERROR_SUCCESS ) - break; - hkey = 0; - r = RegOpenKeyW( hkeyclsid, szKey, &hkey ); - if( r != ERROR_SUCCESS ) - break; - count = len * sizeof (WCHAR); - r = RegQueryValueW( hkey, NULL, buffer, &count ); - found = ( r == ERROR_SUCCESS ) && - ( count == len*sizeof(WCHAR) ) && - !lstrcmpW( buffer, lpszUserType ) ; - RegCloseKey( hkey ); - } - -end: - if( buffer ) - CoTaskMemFree( buffer ); - RegCloseKey( hkeyclsid ); - - if ( !found ) - return E_INVALIDARG; - - TRACE("clsid is %s\n", debugstr_w( szKey ) ); - - r = CLSIDFromString( szKey, clsid ); - - return r; -} - - -/*********************************************************************** - * WriteFmtUserTypeStg (OLE32.@) - */ -HRESULT WINAPI WriteFmtUserTypeStg( - LPSTORAGE pstg, CLIPFORMAT cf, LPOLESTR lpszUserType) -{ - HRESULT r; - WCHAR szwClipName[0x40]; - WCHAR szCLSIDName[OLESTREAM_MAX_STR_LEN]; - CLSID clsid; - LPWSTR wstrProgID; - DWORD n; - LPMALLOC allocator = NULL; - - TRACE("(%p,%x,%s)\n",pstg,cf,debugstr_w(lpszUserType)); - - r = CoGetMalloc(0, &allocator); - if( FAILED( r) ) - return E_OUTOFMEMORY; - - /* get the clipboard format name */ - n = GetClipboardFormatNameW( cf, szwClipName, sizeof(szwClipName) ); - szwClipName[n]=0; - - TRACE("Clipboard name is %s\n", debugstr_w(szwClipName)); - - /* Get the CLSID */ - szCLSIDName[0]=0; - r = CLSIDFromUserType(lpszUserType, &clsid); - if( FAILED( r ) ) - return r; - - TRACE("CLSID is %s\n",debugstr_guid(&clsid)); - - /* get the real program ID */ - r = ProgIDFromCLSID( &clsid, &wstrProgID); - if( FAILED( r ) ) - return r; - - TRACE("progid is %s\n",debugstr_w(wstrProgID)); - - /* if we have a good string, write the stream */ - if( wstrProgID ) - r = STORAGE_WriteCompObj( pstg, &clsid, - lpszUserType, szwClipName, wstrProgID ); - else - r = E_OUTOFMEMORY; - - IMalloc_Free( allocator, wstrProgID); - - return r; -} - - -/****************************************************************************** - * ReadFmtUserTypeStg [OLE32.@] - */ -HRESULT WINAPI ReadFmtUserTypeStg (LPSTORAGE pstg, CLIPFORMAT* pcf, LPOLESTR* lplpszUserType) -{ - HRESULT r; - IStream *stm = 0; - static const WCHAR szCompObj[] = { 1, 'C','o','m','p','O','b','j', 0 }; - unsigned char unknown1[12]; - unsigned char unknown2[16]; - DWORD count; - LPWSTR szProgIDName = NULL, szCLSIDName = NULL, szOleTypeName = NULL; - CLSID clsid; - - TRACE("(%p,%p,%p)\n", pstg, pcf, lplpszUserType); - - r = IStorage_OpenStream( pstg, szCompObj, NULL, - STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm ); - if( FAILED ( r ) ) - { - ERR("Failed to open stream\n"); - return r; - } - - /* read the various parts of the structure */ - r = IStream_Read( stm, unknown1, sizeof(unknown1), &count ); - if( FAILED( r ) || ( count != sizeof(unknown1) ) ) - goto end; - r = ReadClassStm( stm, &clsid ); - if( FAILED( r ) ) - goto end; - - r = STREAM_ReadString( stm, &szCLSIDName ); - if( FAILED( r ) ) - goto end; - - r = STREAM_ReadString( stm, &szOleTypeName ); - if( FAILED( r ) ) - goto end; - - r = STREAM_ReadString( stm, &szProgIDName ); - if( FAILED( r ) ) - goto end; - - r = IStream_Read( stm, unknown2, sizeof(unknown2), &count ); - if( FAILED( r ) || ( count != sizeof(unknown2) ) ) - goto end; - - /* ok, success... now we just need to store what we found */ - if( pcf ) - *pcf = RegisterClipboardFormatW( szOleTypeName ); - CoTaskMemFree( szOleTypeName ); - - if( lplpszUserType ) - *lplpszUserType = szCLSIDName; - CoTaskMemFree( szProgIDName ); - -end: - IStream_Release( stm ); - - return r; -} - - -/************************************************************************* - * OLECONVERT_CreateCompObjStream [Internal] - * - * Creates a "\001CompObj" is the destination IStorage if necessary. - * - * PARAMS - * pStorage [I] The dest IStorage to create the CompObj Stream - * if necessary. - * strOleTypeName [I] The ProgID - * - * RETURNS - * Success: S_OK - * Failure: REGDB_E_CLASSNOTREG if cannot reconstruct the stream - * - * NOTES - * This function is used by OleConvertOLESTREAMToIStorage only. - * - * The stream data is stored in the OLESTREAM and there should be - * no need to recreate the stream. If the stream is manually - * deleted it will attempt to create it by querying the registry. - * - * - */ -HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName) -{ - IStream *pStream; - HRESULT hStorageRes, hRes = S_OK; - OLECONVERT_ISTORAGE_COMPOBJ IStorageCompObj; - static const WCHAR wstrStreamName[] = {1,'C', 'o', 'm', 'p', 'O', 'b', 'j', 0}; - WCHAR bufferW[OLESTREAM_MAX_STR_LEN]; - - BYTE pCompObjUnknown1[] = {0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}; - BYTE pCompObjUnknown2[] = {0xF4, 0x39, 0xB2, 0x71}; - - /* Initialize the CompObj structure */ - memset(&IStorageCompObj, 0, sizeof(IStorageCompObj)); - memcpy(&(IStorageCompObj.byUnknown1), pCompObjUnknown1, sizeof(pCompObjUnknown1)); - memcpy(&(IStorageCompObj.byUnknown2), pCompObjUnknown2, sizeof(pCompObjUnknown2)); - - - /* Create a CompObj stream if it doesn't exist */ - hStorageRes = IStorage_CreateStream(pStorage, wstrStreamName, - STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream ); - if(hStorageRes == S_OK) - { - /* copy the OleTypeName to the compobj struct */ - IStorageCompObj.dwOleTypeNameLength = strlen(strOleTypeName)+1; - strcpy(IStorageCompObj.strOleTypeName, strOleTypeName); - - /* copy the OleTypeName to the compobj struct */ - /* Note: in the test made, these were Identical */ - IStorageCompObj.dwProgIDNameLength = strlen(strOleTypeName)+1; - strcpy(IStorageCompObj.strProgIDName, strOleTypeName); - - /* Get the CLSID */ - MultiByteToWideChar( CP_ACP, 0, IStorageCompObj.strProgIDName, -1, - bufferW, OLESTREAM_MAX_STR_LEN ); - hRes = CLSIDFromProgID(bufferW, &(IStorageCompObj.clsid)); - - if(hRes == S_OK) - { - HKEY hKey; - LONG hErr; - /* Get the CLSID Default Name from the Registry */ - hErr = RegOpenKeyA(HKEY_CLASSES_ROOT, IStorageCompObj.strProgIDName, &hKey); - if(hErr == ERROR_SUCCESS) - { - char strTemp[OLESTREAM_MAX_STR_LEN]; - IStorageCompObj.dwCLSIDNameLength = OLESTREAM_MAX_STR_LEN; - hErr = RegQueryValueA(hKey, NULL, strTemp, &(IStorageCompObj.dwCLSIDNameLength)); - if(hErr == ERROR_SUCCESS) - { - strcpy(IStorageCompObj.strCLSIDName, strTemp); - } - RegCloseKey(hKey); - } - } - - /* Write CompObj Structure to stream */ - hRes = IStream_Write(pStream, IStorageCompObj.byUnknown1, sizeof(IStorageCompObj.byUnknown1), NULL); - - WriteClassStm(pStream,&(IStorageCompObj.clsid)); - - hRes = IStream_Write(pStream, &(IStorageCompObj.dwCLSIDNameLength), sizeof(IStorageCompObj.dwCLSIDNameLength), NULL); - if(IStorageCompObj.dwCLSIDNameLength > 0) - { - hRes = IStream_Write(pStream, IStorageCompObj.strCLSIDName, IStorageCompObj.dwCLSIDNameLength, NULL); - } - hRes = IStream_Write(pStream, &(IStorageCompObj.dwOleTypeNameLength) , sizeof(IStorageCompObj.dwOleTypeNameLength), NULL); - if(IStorageCompObj.dwOleTypeNameLength > 0) - { - hRes = IStream_Write(pStream, IStorageCompObj.strOleTypeName , IStorageCompObj.dwOleTypeNameLength, NULL); - } - hRes = IStream_Write(pStream, &(IStorageCompObj.dwProgIDNameLength) , sizeof(IStorageCompObj.dwProgIDNameLength), NULL); - if(IStorageCompObj.dwProgIDNameLength > 0) - { - hRes = IStream_Write(pStream, IStorageCompObj.strProgIDName , IStorageCompObj.dwProgIDNameLength, NULL); - } - hRes = IStream_Write(pStream, IStorageCompObj.byUnknown2 , sizeof(IStorageCompObj.byUnknown2), NULL); - IStream_Release(pStream); - } - return hRes; -} - - -/************************************************************************* - * OLECONVERT_CreateOlePresStream[Internal] - * - * Creates the "\002OlePres000" Stream with the Metafile data - * - * PARAMS - * pStorage [I] The dest IStorage to create \002OLEPres000 stream in. - * dwExtentX [I] Width of the Metafile - * dwExtentY [I] Height of the Metafile - * pData [I] Metafile data - * dwDataLength [I] Size of the Metafile data - * - * RETURNS - * Success: S_OK - * Failure: CONVERT10_E_OLESTREAM_PUT for invalid Put - * - * NOTES - * This function is used by OleConvertOLESTREAMToIStorage only. - * - */ -void OLECONVERT_CreateOlePresStream(LPSTORAGE pStorage, DWORD dwExtentX, DWORD dwExtentY , BYTE *pData, DWORD dwDataLength) -{ - HRESULT hRes; - IStream *pStream; - static const WCHAR wstrStreamName[] = {2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0}; - BYTE pOlePresStreamHeader [] = - { - 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - }; - - BYTE pOlePresStreamHeaderEmpty [] = - { - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - }; - - /* Create the OlePres000 Stream */ - hRes = IStorage_CreateStream(pStorage, wstrStreamName, - STGM_CREATE | STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream ); - - if(hRes == S_OK) - { - DWORD nHeaderSize; - OLECONVERT_ISTORAGE_OLEPRES OlePres; - - memset(&OlePres, 0, sizeof(OlePres)); - /* Do we have any metafile data to save */ - if(dwDataLength > 0) - { - memcpy(OlePres.byUnknown1, pOlePresStreamHeader, sizeof(pOlePresStreamHeader)); - nHeaderSize = sizeof(pOlePresStreamHeader); - } - else - { - memcpy(OlePres.byUnknown1, pOlePresStreamHeaderEmpty, sizeof(pOlePresStreamHeaderEmpty)); - nHeaderSize = sizeof(pOlePresStreamHeaderEmpty); - } - /* Set width and height of the metafile */ - OlePres.dwExtentX = dwExtentX; - OlePres.dwExtentY = -dwExtentY; - - /* Set Data and Length */ - if(dwDataLength > sizeof(METAFILEPICT16)) - { - OlePres.dwSize = dwDataLength - sizeof(METAFILEPICT16); - OlePres.pData = &(pData[8]); - } - /* Save OlePres000 Data to Stream */ - hRes = IStream_Write(pStream, OlePres.byUnknown1, nHeaderSize, NULL); - hRes = IStream_Write(pStream, &(OlePres.dwExtentX), sizeof(OlePres.dwExtentX), NULL); - hRes = IStream_Write(pStream, &(OlePres.dwExtentY), sizeof(OlePres.dwExtentY), NULL); - hRes = IStream_Write(pStream, &(OlePres.dwSize), sizeof(OlePres.dwSize), NULL); - if(OlePres.dwSize > 0) - { - hRes = IStream_Write(pStream, OlePres.pData, OlePres.dwSize, NULL); - } - IStream_Release(pStream); - } -} - -/************************************************************************* - * OLECONVERT_CreateOle10NativeStream [Internal] - * - * Creates the "\001Ole10Native" Stream (should contain a BMP) - * - * PARAMS - * pStorage [I] Dest storage to create the stream in - * pData [I] Ole10 Native Data (ex. bmp) - * dwDataLength [I] Size of the Ole10 Native Data - * - * RETURNS - * Nothing - * - * NOTES - * This function is used by OleConvertOLESTREAMToIStorage only. - * - * Might need to verify the data and return appropriate error message - * - */ -void OLECONVERT_CreateOle10NativeStream(LPSTORAGE pStorage, BYTE *pData, DWORD dwDataLength) -{ - HRESULT hRes; - IStream *pStream; - static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0}; - - /* Create the Ole10Native Stream */ - hRes = IStorage_CreateStream(pStorage, wstrStreamName, - STGM_CREATE | STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream ); - - if(hRes == S_OK) - { - /* Write info to stream */ - hRes = IStream_Write(pStream, &dwDataLength, sizeof(dwDataLength), NULL); - hRes = IStream_Write(pStream, pData, dwDataLength, NULL); - IStream_Release(pStream); - } - -} - -/************************************************************************* - * OLECONVERT_GetOLE10ProgID [Internal] - * - * Finds the ProgID (or OleTypeID) from the IStorage - * - * PARAMS - * pStorage [I] The Src IStorage to get the ProgID - * strProgID [I] the ProgID string to get - * dwSize [I] the size of the string - * - * RETURNS - * Success: S_OK - * Failure: REGDB_E_CLASSNOTREG if cannot reconstruct the stream - * - * NOTES - * This function is used by OleConvertIStorageToOLESTREAM only. - * - * - */ -HRESULT OLECONVERT_GetOLE10ProgID(LPSTORAGE pStorage, char *strProgID, DWORD *dwSize) -{ - HRESULT hRes; - IStream *pStream; - LARGE_INTEGER iSeekPos; - OLECONVERT_ISTORAGE_COMPOBJ CompObj; - static const WCHAR wstrStreamName[] = {1,'C', 'o', 'm', 'p', 'O', 'b', 'j', 0}; - - /* Open the CompObj Stream */ - hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL, - STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream ); - if(hRes == S_OK) - { - - /*Get the OleType from the CompObj Stream */ - iSeekPos.u.LowPart = sizeof(CompObj.byUnknown1) + sizeof(CompObj.clsid); - iSeekPos.u.HighPart = 0; - - IStream_Seek(pStream, iSeekPos, STREAM_SEEK_SET, NULL); - IStream_Read(pStream, &CompObj.dwCLSIDNameLength, sizeof(CompObj.dwCLSIDNameLength), NULL); - iSeekPos.u.LowPart = CompObj.dwCLSIDNameLength; - IStream_Seek(pStream, iSeekPos, STREAM_SEEK_CUR , NULL); - IStream_Read(pStream, &CompObj.dwOleTypeNameLength, sizeof(CompObj.dwOleTypeNameLength), NULL); - iSeekPos.u.LowPart = CompObj.dwOleTypeNameLength; - IStream_Seek(pStream, iSeekPos, STREAM_SEEK_CUR , NULL); - - IStream_Read(pStream, dwSize, sizeof(*dwSize), NULL); - if(*dwSize > 0) - { - IStream_Read(pStream, strProgID, *dwSize, NULL); - } - IStream_Release(pStream); - } - else - { - STATSTG stat; - LPOLESTR wstrProgID; - - /* Get the OleType from the registry */ - REFCLSID clsid = &(stat.clsid); - IStorage_Stat(pStorage, &stat, STATFLAG_NONAME); - hRes = ProgIDFromCLSID(clsid, &wstrProgID); - if(hRes == S_OK) - { - *dwSize = WideCharToMultiByte(CP_ACP, 0, wstrProgID, -1, strProgID, *dwSize, NULL, FALSE); - } - - } - return hRes; -} - -/************************************************************************* - * OLECONVERT_GetOle10PresData [Internal] - * - * Converts IStorage "/001Ole10Native" stream to a OLE10 Stream - * - * PARAMS - * pStorage [I] Src IStroage - * pOleStream [I] Dest OleStream Mem Struct - * - * RETURNS - * Nothing - * - * NOTES - * This function is used by OleConvertIStorageToOLESTREAM only. - * - * Memory allocated for pData must be freed by the caller - * - * - */ -void OLECONVERT_GetOle10PresData(LPSTORAGE pStorage, OLECONVERT_OLESTREAM_DATA *pOleStreamData) -{ - - HRESULT hRes; - IStream *pStream; - static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0}; - - /* Initialize Default data for OLESTREAM */ - pOleStreamData[0].dwOleID = OLESTREAM_ID; - pOleStreamData[0].dwTypeID = 2; - pOleStreamData[1].dwOleID = OLESTREAM_ID; - pOleStreamData[1].dwTypeID = 0; - pOleStreamData[0].dwMetaFileWidth = 0; - pOleStreamData[0].dwMetaFileHeight = 0; - pOleStreamData[0].pData = NULL; - pOleStreamData[1].pData = NULL; - - /* Open Ole10Native Stream */ - hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL, - STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream ); - if(hRes == S_OK) - { - - /* Read Size and Data */ - IStream_Read(pStream, &(pOleStreamData->dwDataLength), sizeof(pOleStreamData->dwDataLength), NULL); - if(pOleStreamData->dwDataLength > 0) - { - pOleStreamData->pData = (LPSTR) HeapAlloc(GetProcessHeap(),0,pOleStreamData->dwDataLength); - IStream_Read(pStream, pOleStreamData->pData, pOleStreamData->dwDataLength, NULL); - } - IStream_Release(pStream); - } - -} - - -/************************************************************************* - * OLECONVERT_GetOle20PresData[Internal] - * - * Converts IStorage "/002OlePres000" stream to a OLE10 Stream - * - * PARAMS - * pStorage [I] Src IStroage - * pOleStreamData [I] Dest OleStream Mem Struct - * - * RETURNS - * Nothing - * - * NOTES - * This function is used by OleConvertIStorageToOLESTREAM only. - * - * Memory allocated for pData must be freed by the caller - */ -void OLECONVERT_GetOle20PresData(LPSTORAGE pStorage, OLECONVERT_OLESTREAM_DATA *pOleStreamData) -{ - HRESULT hRes; - IStream *pStream; - OLECONVERT_ISTORAGE_OLEPRES olePress; - static const WCHAR wstrStreamName[] = {2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0}; - - /* Initialize Default data for OLESTREAM */ - pOleStreamData[0].dwOleID = OLESTREAM_ID; - pOleStreamData[0].dwTypeID = 2; - pOleStreamData[0].dwMetaFileWidth = 0; - pOleStreamData[0].dwMetaFileHeight = 0; - pOleStreamData[0].dwDataLength = OLECONVERT_WriteOLE20ToBuffer(pStorage, &(pOleStreamData[0].pData)); - pOleStreamData[1].dwOleID = OLESTREAM_ID; - pOleStreamData[1].dwTypeID = 0; - pOleStreamData[1].dwOleTypeNameLength = 0; - pOleStreamData[1].strOleTypeName[0] = 0; - pOleStreamData[1].dwMetaFileWidth = 0; - pOleStreamData[1].dwMetaFileHeight = 0; - pOleStreamData[1].pData = NULL; - pOleStreamData[1].dwDataLength = 0; - - - /* Open OlePress000 stream */ - hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL, - STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream ); - if(hRes == S_OK) - { - LARGE_INTEGER iSeekPos; - METAFILEPICT16 MetaFilePict; - static const char strMetafilePictName[] = "METAFILEPICT"; - - /* Set the TypeID for a Metafile */ - pOleStreamData[1].dwTypeID = 5; - - /* Set the OleTypeName to Metafile */ - pOleStreamData[1].dwOleTypeNameLength = strlen(strMetafilePictName) +1; - strcpy(pOleStreamData[1].strOleTypeName, strMetafilePictName); - - iSeekPos.u.HighPart = 0; - iSeekPos.u.LowPart = sizeof(olePress.byUnknown1); - - /* Get Presentation Data */ - IStream_Seek(pStream, iSeekPos, STREAM_SEEK_SET, NULL); - IStream_Read(pStream, &(olePress.dwExtentX), sizeof(olePress.dwExtentX), NULL); - IStream_Read(pStream, &(olePress.dwExtentY), sizeof(olePress.dwExtentY), NULL); - IStream_Read(pStream, &(olePress.dwSize), sizeof(olePress.dwSize), NULL); - - /*Set width and Height */ - pOleStreamData[1].dwMetaFileWidth = olePress.dwExtentX; - pOleStreamData[1].dwMetaFileHeight = -olePress.dwExtentY; - if(olePress.dwSize > 0) - { - /* Set Length */ - pOleStreamData[1].dwDataLength = olePress.dwSize + sizeof(METAFILEPICT16); - - /* Set MetaFilePict struct */ - MetaFilePict.mm = 8; - MetaFilePict.xExt = olePress.dwExtentX; - MetaFilePict.yExt = olePress.dwExtentY; - MetaFilePict.hMF = 0; - - /* Get Metafile Data */ - pOleStreamData[1].pData = (BYTE *) HeapAlloc(GetProcessHeap(),0,pOleStreamData[1].dwDataLength); - memcpy(pOleStreamData[1].pData, &MetaFilePict, sizeof(MetaFilePict)); - IStream_Read(pStream, &(pOleStreamData[1].pData[sizeof(MetaFilePict)]), pOleStreamData[1].dwDataLength-sizeof(METAFILEPICT16), NULL); - } - IStream_Release(pStream); - } -} - -/************************************************************************* - * OleConvertOLESTREAMToIStorage [OLE32.@] - * - * Read info on MSDN - * - * TODO - * DVTARGETDEVICE paramenter is not handled - * Still unsure of some mem fields for OLE 10 Stream - * Still some unknowns for the IStorage: "\002OlePres000", "\001CompObj", - * and "\001OLE" streams - * - */ -HRESULT WINAPI OleConvertOLESTREAMToIStorage ( - LPOLESTREAM pOleStream, - LPSTORAGE pstg, - const DVTARGETDEVICE* ptd) -{ - int i; - HRESULT hRes=S_OK; - OLECONVERT_OLESTREAM_DATA pOleStreamData[2]; - - memset(pOleStreamData, 0, sizeof(pOleStreamData)); - - if(ptd != NULL) - { - FIXME("DVTARGETDEVICE is not NULL, unhandled parameter\n"); - } - - if(pstg == NULL || pOleStream == NULL) - { - hRes = E_INVALIDARG; - } - - if(hRes == S_OK) - { - /* Load the OLESTREAM to Memory */ - hRes = OLECONVERT_LoadOLE10(pOleStream, &pOleStreamData[0], TRUE); - } - - if(hRes == S_OK) - { - /* Load the OLESTREAM to Memory (part 2)*/ - hRes = OLECONVERT_LoadOLE10(pOleStream, &pOleStreamData[1], FALSE); - } - - if(hRes == S_OK) - { - - if(pOleStreamData[0].dwDataLength > sizeof(STORAGE_magic)) - { - /* Do we have the IStorage Data in the OLESTREAM */ - if(memcmp(pOleStreamData[0].pData, STORAGE_magic, sizeof(STORAGE_magic)) ==0) - { - OLECONVERT_GetOLE20FromOLE10(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength); - OLECONVERT_CreateOlePresStream(pstg, pOleStreamData[1].dwMetaFileWidth, pOleStreamData[1].dwMetaFileHeight, pOleStreamData[1].pData, pOleStreamData[1].dwDataLength); - } - else - { - /* It must be an original OLE 1.0 source */ - OLECONVERT_CreateOle10NativeStream(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength); - } - } - else - { - /* It must be an original OLE 1.0 source */ - OLECONVERT_CreateOle10NativeStream(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength); - } - - /* Create CompObj Stream if necessary */ - hRes = OLECONVERT_CreateCompObjStream(pstg, pOleStreamData[0].strOleTypeName); - if(hRes == S_OK) - { - /*Create the Ole Stream if necessary */ - OLECONVERT_CreateOleStream(pstg); - } - } - - - /* Free allocated memory */ - for(i=0; i < 2; i++) - { - if(pOleStreamData[i].pData != NULL) - { - HeapFree(GetProcessHeap(),0,pOleStreamData[i].pData); - } - if(pOleStreamData[i].pstrOleObjFileName != NULL) - { - HeapFree(GetProcessHeap(),0,pOleStreamData[i].pstrOleObjFileName); - pOleStreamData[i].pstrOleObjFileName = NULL; - } - } - return hRes; -} - -/************************************************************************* - * OleConvertIStorageToOLESTREAM [OLE32.@] - * - * Read info on MSDN - * - * Read info on MSDN - * - * TODO - * Still unsure of some mem fields for OLE 10 Stream - * Still some unknowns for the IStorage: "\002OlePres000", "\001CompObj", - * and "\001OLE" streams. - * - */ -HRESULT WINAPI OleConvertIStorageToOLESTREAM ( - LPSTORAGE pstg, - LPOLESTREAM pOleStream) -{ - int i; - HRESULT hRes = S_OK; - IStream *pStream; - OLECONVERT_OLESTREAM_DATA pOleStreamData[2]; - static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0}; - - - memset(pOleStreamData, 0, sizeof(pOleStreamData)); - - if(pstg == NULL || pOleStream == NULL) - { - hRes = E_INVALIDARG; - } - if(hRes == S_OK) - { - /* Get the ProgID */ - pOleStreamData[0].dwOleTypeNameLength = OLESTREAM_MAX_STR_LEN; - hRes = OLECONVERT_GetOLE10ProgID(pstg, pOleStreamData[0].strOleTypeName, &(pOleStreamData[0].dwOleTypeNameLength)); - } - if(hRes == S_OK) - { - /* Was it originally Ole10 */ - hRes = IStorage_OpenStream(pstg, wstrStreamName, 0, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream); - if(hRes == S_OK) - { - IStream_Release(pStream); - /* Get Presentation Data for Ole10Native */ - OLECONVERT_GetOle10PresData(pstg, pOleStreamData); - } - else - { - /* Get Presentation Data (OLE20) */ - OLECONVERT_GetOle20PresData(pstg, pOleStreamData); - } - - /* Save OLESTREAM */ - hRes = OLECONVERT_SaveOLE10(&(pOleStreamData[0]), pOleStream); - if(hRes == S_OK) - { - hRes = OLECONVERT_SaveOLE10(&(pOleStreamData[1]), pOleStream); - } - - } - - /* Free allocated memory */ - for(i=0; i < 2; i++) - { - if(pOleStreamData[i].pData != NULL) - { - HeapFree(GetProcessHeap(),0,pOleStreamData[i].pData); - } - } - - return hRes; -} - -/*********************************************************************** - * GetConvertStg (OLE32.@) - */ -HRESULT WINAPI GetConvertStg(IStorage *stg) { - FIXME("unimplemented stub!\n"); - return E_FAIL; -} - -/****************************************************************************** - * StgIsStorageFile [OLE32.@] - */ -HRESULT WINAPI -StgIsStorageFile(LPCOLESTR fn) -{ - HANDLE hf; - BYTE magic[8]; - DWORD bytes_read; - - TRACE("(\'%s\')\n", debugstr_w(fn)); - hf = CreateFileW(fn, GENERIC_READ, - FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - - if (hf == INVALID_HANDLE_VALUE) - return STG_E_FILENOTFOUND; - - if (!ReadFile(hf, magic, 8, &bytes_read, NULL)) - { - WARN(" unable to read file\n"); - CloseHandle(hf); - return S_FALSE; - } - - CloseHandle(hf); - - if (bytes_read != 8) { - WARN(" too short\n"); - return S_FALSE; - } - - if (!memcmp(magic,STORAGE_magic,8)) { - WARN(" -> YES\n"); - return S_OK; - } - - WARN(" -> Invalid header.\n"); - return S_FALSE; -} diff --git a/reactos/lib/ole32/storage32.h b/reactos/lib/ole32/storage32.h deleted file mode 100644 index 05ceaed9727..00000000000 --- a/reactos/lib/ole32/storage32.h +++ /dev/null @@ -1,892 +0,0 @@ -/* - * Compound Storage (32 bit version) - * - * Implemented using the documentation of the LAOLA project at - * - * (Thanks to Martin Schwartz ) - * - * This include file contains definitions of types and function - * prototypes that are used in the many files implementing the - * storage functionality - * - * Copyright 1998,1999 Francis Beaudet - * Copyright 1998,1999 Thuy Nguyen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef __STORAGE32_H__ -#define __STORAGE32_H__ - -#include - -#include "windef.h" -#include "winbase.h" -#include "winnt.h" -#include "objbase.h" - -/* - * Definitions for the file format offsets. - */ -static const ULONG OFFSET_BIGBLOCKSIZEBITS = 0x0000001e; -static const ULONG OFFSET_SMALLBLOCKSIZEBITS = 0x00000020; -static const ULONG OFFSET_BBDEPOTCOUNT = 0x0000002C; -static const ULONG OFFSET_ROOTSTARTBLOCK = 0x00000030; -static const ULONG OFFSET_SBDEPOTSTART = 0x0000003C; -static const ULONG OFFSET_SBDEPOTCOUNT = 0x00000040; -static const ULONG OFFSET_EXTBBDEPOTSTART = 0x00000044; -static const ULONG OFFSET_EXTBBDEPOTCOUNT = 0x00000048; -static const ULONG OFFSET_BBDEPOTSTART = 0x0000004C; -static const ULONG OFFSET_PS_NAME = 0x00000000; -static const ULONG OFFSET_PS_NAMELENGTH = 0x00000040; -static const ULONG OFFSET_PS_PROPERTYTYPE = 0x00000042; -static const ULONG OFFSET_PS_PREVIOUSPROP = 0x00000044; -static const ULONG OFFSET_PS_NEXTPROP = 0x00000048; -static const ULONG OFFSET_PS_DIRPROP = 0x0000004C; -static const ULONG OFFSET_PS_GUID = 0x00000050; -static const ULONG OFFSET_PS_TSS1 = 0x00000064; -static const ULONG OFFSET_PS_TSD1 = 0x00000068; -static const ULONG OFFSET_PS_TSS2 = 0x0000006C; -static const ULONG OFFSET_PS_TSD2 = 0x00000070; -static const ULONG OFFSET_PS_STARTBLOCK = 0x00000074; -static const ULONG OFFSET_PS_SIZE = 0x00000078; -static const WORD DEF_BIG_BLOCK_SIZE_BITS = 0x0009; -static const WORD DEF_SMALL_BLOCK_SIZE_BITS = 0x0006; -static const WORD DEF_BIG_BLOCK_SIZE = 0x0200; -static const WORD DEF_SMALL_BLOCK_SIZE = 0x0040; -static const ULONG BLOCK_EXTBBDEPOT = 0xFFFFFFFC; -static const ULONG BLOCK_SPECIAL = 0xFFFFFFFD; -static const ULONG BLOCK_END_OF_CHAIN = 0xFFFFFFFE; -static const ULONG BLOCK_UNUSED = 0xFFFFFFFF; -static const ULONG PROPERTY_NULL = 0xFFFFFFFF; - -#define PROPERTY_NAME_MAX_LEN 0x20 -#define PROPERTY_NAME_BUFFER_LEN 0x40 - -#define PROPSET_BLOCK_SIZE 0x00000080 - -/* - * Property type of relation - */ -#define PROPERTY_RELATION_PREVIOUS 0 -#define PROPERTY_RELATION_NEXT 1 -#define PROPERTY_RELATION_DIR 2 - -/* - * Property type constants - */ -#define PROPTYPE_STORAGE 0x01 -#define PROPTYPE_STREAM 0x02 -#define PROPTYPE_ROOT 0x05 - -/* - * These defines assume a hardcoded blocksize. The code will assert - * if the blocksize is different. Some changes will have to be done if it - * becomes the case. - */ -#define BIG_BLOCK_SIZE 0x200 -#define COUNT_BBDEPOTINHEADER 109 -#define LIMIT_TO_USE_SMALL_BLOCK 0x1000 -#define NUM_BLOCKS_PER_DEPOT_BLOCK 128 - -/* - * These are signatures to detect the type of Document file. - */ -static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1}; -static const BYTE STORAGE_oldmagic[8] ={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d}; - -/* - * Forward declarations of all the structures used by the storage - * module. - */ -typedef struct StorageBaseImpl StorageBaseImpl; -typedef struct StorageImpl StorageImpl; -typedef struct StorageInternalImpl StorageInternalImpl; -typedef struct BlockChainStream BlockChainStream; -typedef struct SmallBlockChainStream SmallBlockChainStream; -typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl; -typedef struct StgProperty StgProperty; -typedef struct StgStreamImpl StgStreamImpl; - -/* - * This utility structure is used to read/write the information in a storage - * property. - */ -struct StgProperty -{ - WCHAR name[PROPERTY_NAME_MAX_LEN]; - WORD sizeOfNameString; - BYTE propertyType; - ULONG previousProperty; - ULONG nextProperty; - ULONG dirProperty; - GUID propertyUniqueID; - ULONG timeStampS1; - ULONG timeStampD1; - ULONG timeStampS2; - ULONG timeStampD2; - ULONG startingBlock; - ULARGE_INTEGER size; -}; - -/************************************************************************* - * Big Block File support - * - * The big block file is an abstraction of a flat file separated in - * same sized blocks. The implementation for the methods described in - * this section appear in stg_bigblockfile.c - */ - -/* - * Declaration of the data structures - */ -typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE; -typedef struct MappedPage MappedPage,*LPMAPPEDPAGE; - -struct BigBlockFile -{ - BOOL fileBased; - ULARGE_INTEGER filesize; - ULONG blocksize; - HANDLE hfile; - HANDLE hfilemap; - DWORD flProtect; - MappedPage *maplist; - MappedPage *victimhead, *victimtail; - ULONG num_victim_pages; - ILockBytes *pLkbyt; - HGLOBAL hbytearray; - LPVOID pbytearray; -}; - -/* - * Declaration of the functions used to manipulate the BigBlockFile - * data structure. - */ -BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile, - ILockBytes* pLkByt, - DWORD openFlags, - ULONG blocksize, - BOOL fileBased); -void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This); -void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index); -void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index); -void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock); -void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize); -ULARGE_INTEGER BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This); - -/************************************************************************* - * Ole Convert support - */ - -void OLECONVERT_CreateOleStream(LPSTORAGE pStorage); -HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName); - -/**************************************************************************** - * Storage32BaseImpl definitions. - * - * This structure defines the base information contained in all implementations - * of IStorage32 contained in this file storage implementation. - * - * In OOP terms, this is the base class for all the IStorage32 implementations - * contained in this file. - */ -struct StorageBaseImpl -{ - IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct - * since we want to cast this in a Storage32 pointer */ - - /* - * Reference count of this object - */ - ULONG ref; - - /* - * Ancestor storage (top level) - */ - StorageImpl* ancestorStorage; - - /* - * Index of the property for the root of - * this storage - */ - ULONG rootPropertySetIndex; - - /* - * virtual Destructor method. - */ - void (*v_destructor)(StorageBaseImpl*); -}; - - -/* - * Prototypes for the methods of the Storage32BaseImpl class. - */ -HRESULT WINAPI StorageBaseImpl_QueryInterface( - IStorage* iface, - REFIID riid, - void** ppvObject); - -ULONG WINAPI StorageBaseImpl_AddRef( - IStorage* iface); - -ULONG WINAPI StorageBaseImpl_Release( - IStorage* iface); - -HRESULT WINAPI StorageBaseImpl_OpenStream( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - void* reserved1, /* [unique][in] */ - DWORD grfMode, /* [in] */ - DWORD reserved2, /* [in] */ - IStream** ppstm); /* [out] */ - -HRESULT WINAPI StorageBaseImpl_OpenStorage( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][unique][in] */ - IStorage* pstgPriority, /* [unique][in] */ - DWORD grfMode, /* [in] */ - SNB snbExclude, /* [unique][in] */ - DWORD reserved, /* [in] */ - IStorage** ppstg); /* [out] */ - -HRESULT WINAPI StorageBaseImpl_EnumElements( - IStorage* iface, - DWORD reserved1, /* [in] */ - void* reserved2, /* [size_is][unique][in] */ - DWORD reserved3, /* [in] */ - IEnumSTATSTG** ppenum); /* [out] */ - -HRESULT WINAPI StorageBaseImpl_Stat( - IStorage* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -HRESULT WINAPI StorageBaseImpl_RenameElement( - IStorage* iface, - const OLECHAR* pwcsOldName, /* [string][in] */ - const OLECHAR* pwcsNewName); /* [string][in] */ - -HRESULT WINAPI StorageBaseImpl_CreateStream( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - DWORD grfMode, /* [in] */ - DWORD reserved1, /* [in] */ - DWORD reserved2, /* [in] */ - IStream** ppstm); /* [out] */ - -HRESULT WINAPI StorageBaseImpl_SetClass( - IStorage* iface, - REFCLSID clsid); /* [in] */ - -/**************************************************************************** - * Storage32Impl definitions. - * - * This implementation of the IStorage32 interface represents a root - * storage. Basically, a document file. - */ -struct StorageImpl -{ - IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct - * since we want to cast this in a Storage32 pointer */ - - /* - * Declare the member of the Storage32BaseImpl class to allow - * casting as a Storage32BaseImpl - */ - ULONG ref; - struct StorageImpl* ancestorStorage; - ULONG rootPropertySetIndex; - void (*v_destructor)(struct StorageImpl*); - - /* - * The following data members are specific to the Storage32Impl - * class - */ - HANDLE hFile; /* Physical support for the Docfile */ - LPOLESTR pwcsName; /* Full path of the document file */ - - /* FIXME: should this be in Storage32BaseImpl ? */ - WCHAR filename[PROPERTY_NAME_BUFFER_LEN]; - - /* - * File header - */ - WORD bigBlockSizeBits; - WORD smallBlockSizeBits; - ULONG bigBlockSize; - ULONG smallBlockSize; - ULONG bigBlockDepotCount; - ULONG rootStartBlock; - ULONG smallBlockDepotStart; - ULONG extBigBlockDepotStart; - ULONG extBigBlockDepotCount; - ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER]; - - ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK]; - ULONG indexBlockDepotCached; - ULONG prevFreeBlock; - - /* - * Abstraction of the big block chains for the chains of the header. - */ - BlockChainStream* rootBlockChain; - BlockChainStream* smallBlockDepotChain; - BlockChainStream* smallBlockRootChain; - - /* - * Pointer to the big block file abstraction - */ - BigBlockFile* bigBlockFile; -}; - -/* - * Method declaration for the Storage32Impl class - */ - -HRESULT WINAPI StorageImpl_CreateStorage( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - DWORD grfMode, /* [in] */ - DWORD dwStgFmt, /* [in] */ - DWORD reserved2, /* [in] */ - IStorage** ppstg); /* [out] */ - -HRESULT WINAPI StorageImpl_CopyTo( - IStorage* iface, - DWORD ciidExclude, /* [in] */ - const IID* rgiidExclude, /* [size_is][unique][in] */ - SNB snbExclude, /* [unique][in] */ - IStorage* pstgDest); /* [unique][in] */ - -HRESULT WINAPI StorageImpl_MoveElementTo( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - IStorage* pstgDest, /* [unique][in] */ - const OLECHAR* pwcsNewName, /* [string][in] */ - DWORD grfFlags); /* [in] */ - -HRESULT WINAPI StorageImpl_Commit( - IStorage* iface, - DWORD grfCommitFlags); /* [in] */ - -HRESULT WINAPI StorageImpl_Revert( - IStorage* iface); - -HRESULT WINAPI StorageImpl_DestroyElement( - IStorage* iface, - const OLECHAR* pwcsName); /* [string][in] */ - -HRESULT WINAPI StorageImpl_SetElementTimes( - IStorage* iface, - const OLECHAR* pwcsName, /* [string][in] */ - const FILETIME* pctime, /* [in] */ - const FILETIME* patime, /* [in] */ - const FILETIME* pmtime); /* [in] */ - -HRESULT WINAPI StorageImpl_SetStateBits( - IStorage* iface, - DWORD grfStateBits, /* [in] */ - DWORD grfMask); /* [in] */ - -HRESULT WINAPI StorageImpl_Stat(IStorage* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -void StorageImpl_Destroy( - StorageImpl* This); - -HRESULT StorageImpl_Construct( - StorageImpl* This, - HANDLE hFile, - LPCOLESTR pwcsName, - ILockBytes* pLkbyt, - DWORD openFlags, - BOOL fileBased, - BOOL fileCreate); - -BOOL StorageImpl_ReadBigBlock( - StorageImpl* This, - ULONG blockIndex, - void* buffer); - -BOOL StorageImpl_WriteBigBlock( - StorageImpl* This, - ULONG blockIndex, - void* buffer); - -void* StorageImpl_GetROBigBlock( - StorageImpl* This, - ULONG blockIndex); - -void* StorageImpl_GetBigBlock( - StorageImpl* This, - ULONG blockIndex); - -void StorageImpl_ReleaseBigBlock( - StorageImpl* This, - void* pBigBlock); - -ULONG StorageImpl_GetNextFreeBigBlock( - StorageImpl* This); - -void StorageImpl_FreeBigBlock( - StorageImpl* This, - ULONG blockIndex); - -HRESULT StorageImpl_GetNextBlockInChain( - StorageImpl* This, - ULONG blockIndex, - ULONG* nextBlockIndex); - -void StorageImpl_SetNextBlockInChain( - StorageImpl* This, - ULONG blockIndex, - ULONG nextBlock); - -HRESULT StorageImpl_LoadFileHeader( - StorageImpl* This); - -void StorageImpl_SaveFileHeader( - StorageImpl* This); - -BOOL StorageImpl_ReadProperty( - StorageImpl* This, - ULONG index, - StgProperty* buffer); - -BOOL StorageImpl_WriteProperty( - StorageImpl* This, - ULONG index, - StgProperty* buffer); - -BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks( - StorageImpl* This, - SmallBlockChainStream** ppsbChain); - -ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, - ULONG blockIndex); - -void Storage32Impl_AddBlockDepot(StorageImpl* This, - ULONG blockIndex); - -ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This); - -ULONG Storage32Impl_GetExtDepotBlock(StorageImpl* This, - ULONG depotIndex); - -void Storage32Impl_SetExtDepotBlock(StorageImpl* This, - ULONG depotIndex, - ULONG blockIndex); -/**************************************************************************** - * Storage32InternalImpl definitions. - * - * Definition of the implementation structure for the IStorage32 interface. - * This one implements the IStorage32 interface for storage that are - * inside another storage. - */ -struct StorageInternalImpl -{ - IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct - * since we want to cast this in a Storage32 pointer */ - - /* - * Declare the member of the Storage32BaseImpl class to allow - * casting as a Storage32BaseImpl - */ - ULONG ref; - struct StorageImpl* ancestorStorage; - ULONG rootPropertySetIndex; - void (*v_destructor)(struct StorageInternalImpl*); - - /* - * There is no specific data for this class. - */ -}; - -/* - * Method definitions for the Storage32InternalImpl class. - */ -StorageInternalImpl* StorageInternalImpl_Construct( - StorageImpl* ancestorStorage, - ULONG rootTropertyIndex); - -void StorageInternalImpl_Destroy( - StorageInternalImpl* This); - -HRESULT WINAPI StorageInternalImpl_Commit( - IStorage* iface, - DWORD grfCommitFlags); /* [in] */ - -HRESULT WINAPI StorageInternalImpl_Revert( - IStorage* iface); - - -/**************************************************************************** - * IEnumSTATSTGImpl definitions. - * - * Definition of the implementation structure for the IEnumSTATSTGImpl interface. - * This class allows iterating through the content of a storage and to find - * specific items inside it. - */ -struct IEnumSTATSTGImpl -{ - IEnumSTATSTGVtbl *lpVtbl; /* Needs to be the first item in the struct - * since we want to cast this in a IEnumSTATSTG pointer */ - - ULONG ref; /* Reference count */ - StorageImpl* parentStorage; /* Reference to the parent storage */ - ULONG firstPropertyNode; /* Index of the root of the storage to enumerate */ - - /* - * The current implementation of the IEnumSTATSTGImpl class uses a stack - * to walk the property sets to get the content of a storage. This stack - * is implemented by the following 3 data members - */ - ULONG stackSize; - ULONG stackMaxSize; - ULONG* stackToVisit; - -#define ENUMSTATSGT_SIZE_INCREMENT 10 -}; - -/* - * Method definitions for the IEnumSTATSTGImpl class. - */ -HRESULT WINAPI IEnumSTATSTGImpl_QueryInterface( - IEnumSTATSTG* iface, - REFIID riid, - void** ppvObject); - -ULONG WINAPI IEnumSTATSTGImpl_AddRef( - IEnumSTATSTG* iface); - -ULONG WINAPI IEnumSTATSTGImpl_Release( - IEnumSTATSTG* iface); - -HRESULT WINAPI IEnumSTATSTGImpl_Next( - IEnumSTATSTG* iface, - ULONG celt, - STATSTG* rgelt, - ULONG* pceltFetched); - -HRESULT WINAPI IEnumSTATSTGImpl_Skip( - IEnumSTATSTG* iface, - ULONG celt); - -HRESULT WINAPI IEnumSTATSTGImpl_Reset( - IEnumSTATSTG* iface); - -HRESULT WINAPI IEnumSTATSTGImpl_Clone( - IEnumSTATSTG* iface, - IEnumSTATSTG** ppenum); - -IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct( - StorageImpl* This, - ULONG firstPropertyNode); - -void IEnumSTATSTGImpl_Destroy( - IEnumSTATSTGImpl* This); - -void IEnumSTATSTGImpl_PushSearchNode( - IEnumSTATSTGImpl* This, - ULONG nodeToPush); - -ULONG IEnumSTATSTGImpl_PopSearchNode( - IEnumSTATSTGImpl* This, - BOOL remove); - -ULONG IEnumSTATSTGImpl_FindProperty( - IEnumSTATSTGImpl* This, - const OLECHAR* lpszPropName, - StgProperty* buffer); - -INT IEnumSTATSTGImpl_FindParentProperty( - IEnumSTATSTGImpl *This, - ULONG childProperty, - StgProperty *currentProperty, - ULONG *propertyId); - - -/**************************************************************************** - * StgStreamImpl definitions. - * - * This class imlements the IStream32 inteface and represents a stream - * located inside a storage object. - */ -struct StgStreamImpl -{ - IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct - * since we want to cast this in a IStream pointer */ - - /* - * Reference count - */ - ULONG ref; - - /* - * Storage that is the parent(owner) of the stream - */ - StorageBaseImpl* parentStorage; - - /* - * Access mode of this stream. - */ - DWORD grfMode; - - /* - * Index of the property that owns (points to) this stream. - */ - ULONG ownerProperty; - - /* - * Helper variable that contains the size of the stream - */ - ULARGE_INTEGER streamSize; - - /* - * This is the current position of the cursor in the stream - */ - ULARGE_INTEGER currentPosition; - - /* - * The information in the stream is represented by a chain of small blocks - * or a chain of large blocks. Depending on the case, one of the two - * following variabled points to that information. - */ - BlockChainStream* bigBlockChain; - SmallBlockChainStream* smallBlockChain; -}; - -/* - * Method definition for the StgStreamImpl class. - */ -StgStreamImpl* StgStreamImpl_Construct( - StorageBaseImpl* parentStorage, - DWORD grfMode, - ULONG ownerProperty); - -void StgStreamImpl_Destroy( - StgStreamImpl* This); - -void StgStreamImpl_OpenBlockChain( - StgStreamImpl* This); - -HRESULT WINAPI StgStreamImpl_QueryInterface( - IStream* iface, - REFIID riid, /* [in] */ - void** ppvObject); /* [iid_is][out] */ - -ULONG WINAPI StgStreamImpl_AddRef( - IStream* iface); - -ULONG WINAPI StgStreamImpl_Release( - IStream* iface); - -HRESULT WINAPI StgStreamImpl_Read( - IStream* iface, - void* pv, /* [length_is][size_is][out] */ - ULONG cb, /* [in] */ - ULONG* pcbRead); /* [out] */ - -HRESULT WINAPI StgStreamImpl_Write( - IStream* iface, - const void* pv, /* [size_is][in] */ - ULONG cb, /* [in] */ - ULONG* pcbWritten); /* [out] */ - -HRESULT WINAPI StgStreamImpl_Seek( - IStream* iface, - LARGE_INTEGER dlibMove, /* [in] */ - DWORD dwOrigin, /* [in] */ - ULARGE_INTEGER* plibNewPosition); /* [out] */ - -HRESULT WINAPI StgStreamImpl_SetSize( - IStream* iface, - ULARGE_INTEGER libNewSize); /* [in] */ - -HRESULT WINAPI StgStreamImpl_CopyTo( - IStream* iface, - IStream* pstm, /* [unique][in] */ - ULARGE_INTEGER cb, /* [in] */ - ULARGE_INTEGER* pcbRead, /* [out] */ - ULARGE_INTEGER* pcbWritten); /* [out] */ - -HRESULT WINAPI StgStreamImpl_Commit( - IStream* iface, - DWORD grfCommitFlags); /* [in] */ - -HRESULT WINAPI StgStreamImpl_Revert( - IStream* iface); - -HRESULT WINAPI StgStreamImpl_LockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI StgStreamImpl_UnlockRegion( - IStream* iface, - ULARGE_INTEGER libOffset, /* [in] */ - ULARGE_INTEGER cb, /* [in] */ - DWORD dwLockType); /* [in] */ - -HRESULT WINAPI StgStreamImpl_Stat( - IStream* iface, - STATSTG* pstatstg, /* [out] */ - DWORD grfStatFlag); /* [in] */ - -HRESULT WINAPI StgStreamImpl_Clone( - IStream* iface, - IStream** ppstm); /* [out] */ - - -/******************************************************************************** - * The StorageUtl_ functions are miscelaneous utility functions. Most of which are - * abstractions used to read values from file buffers without having to worry - * about bit order - */ -void StorageUtl_ReadWord(void* buffer, ULONG offset, WORD* value); -void StorageUtl_WriteWord(void* buffer, ULONG offset, WORD value); -void StorageUtl_ReadDWord(void* buffer, ULONG offset, DWORD* value); -void StorageUtl_WriteDWord(void* buffer, ULONG offset, DWORD value); -void StorageUtl_ReadGUID(void* buffer, ULONG offset, GUID* value); -void StorageUtl_WriteGUID(void* buffer, ULONG offset, GUID* value); -void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination, - StgProperty* source, - int statFlags); - -/**************************************************************************** - * BlockChainStream definitions. - * - * The BlockChainStream class is a utility class that is used to create an - * abstraction of the big block chains in the storage file. - */ -struct BlockChainStream -{ - StorageImpl* parentStorage; - ULONG* headOfStreamPlaceHolder; - ULONG ownerPropertyIndex; - ULONG lastBlockNoInSequence; - ULONG lastBlockNoInSequenceIndex; - ULONG tailIndex; - ULONG numBlocks; -}; - -/* - * Methods for the BlockChainStream class. - */ -BlockChainStream* BlockChainStream_Construct( - StorageImpl* parentStorage, - ULONG* headOfStreamPlaceHolder, - ULONG propertyIndex); - -void BlockChainStream_Destroy( - BlockChainStream* This); - -ULONG BlockChainStream_GetHeadOfChain( - BlockChainStream* This); - -BOOL BlockChainStream_ReadAt( - BlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - void* buffer, - ULONG* bytesRead); - -BOOL BlockChainStream_WriteAt( - BlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - const void* buffer, - ULONG* bytesWritten); - -BOOL BlockChainStream_SetSize( - BlockChainStream* This, - ULARGE_INTEGER newSize); - -ULARGE_INTEGER BlockChainStream_GetSize( - BlockChainStream* This); - -ULONG BlockChainStream_GetCount( - BlockChainStream* This); - -/**************************************************************************** - * SmallBlockChainStream definitions. - * - * The SmallBlockChainStream class is a utility class that is used to create an - * abstraction of the small block chains in the storage file. - */ -struct SmallBlockChainStream -{ - StorageImpl* parentStorage; - ULONG ownerPropertyIndex; -}; - -/* - * Methods of the SmallBlockChainStream class. - */ -SmallBlockChainStream* SmallBlockChainStream_Construct( - StorageImpl* parentStorage, - ULONG propertyIndex); - -void SmallBlockChainStream_Destroy( - SmallBlockChainStream* This); - -ULONG SmallBlockChainStream_GetHeadOfChain( - SmallBlockChainStream* This); - -HRESULT SmallBlockChainStream_GetNextBlockInChain( - SmallBlockChainStream* This, - ULONG blockIndex, - ULONG* nextBlockIndex); - -void SmallBlockChainStream_SetNextBlockInChain( - SmallBlockChainStream* This, - ULONG blockIndex, - ULONG nextBlock); - -void SmallBlockChainStream_FreeBlock( - SmallBlockChainStream* This, - ULONG blockIndex); - -ULONG SmallBlockChainStream_GetNextFreeBlock( - SmallBlockChainStream* This); - -BOOL SmallBlockChainStream_ReadAt( - SmallBlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - void* buffer, - ULONG* bytesRead); - -BOOL SmallBlockChainStream_WriteAt( - SmallBlockChainStream* This, - ULARGE_INTEGER offset, - ULONG size, - const void* buffer, - ULONG* bytesWritten); - -BOOL SmallBlockChainStream_SetSize( - SmallBlockChainStream* This, - ULARGE_INTEGER newSize); - -ULARGE_INTEGER SmallBlockChainStream_GetSize( - SmallBlockChainStream* This); - -ULONG SmallBlockChainStream_GetCount( - SmallBlockChainStream* This); - - -#endif /* __STORAGE32_H__ */ diff --git a/reactos/lib/ole32/tests/Makefile b/reactos/lib/ole32/tests/Makefile deleted file mode 100644 index 675c78c43a3..00000000000 --- a/reactos/lib/ole32/tests/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# $Id: Makefile,v 1.1 2004/11/07 22:19:07 sedwards Exp $ - -PATH_TO_TOP = ../../.. - -TARGET_NORC = yes - -TARGET_TYPE = program - -TARGET_APPTYPE = console - -# require os code to explicitly request A/W version of structs/functions -TARGET_CFLAGS += -D_DISABLE_TIDENTS -D__USE_W32API -D_WIN32_IE=0x0600 \ - -D_WIN32_WINNT=0x0501 -D__REACTOS__ - -TARGET_NAME = ole32_test - -TARGET_SDKLIBS = oleaut32.a ole32.a ntdll.a - -TARGET_OBJECTS = \ - testlist.o \ - propvariant.o \ - storage32.o - -include $(PATH_TO_TOP)/rules.mak - -include $(TOOLS_PATH)/helper.mk - -# EOF \ No newline at end of file diff --git a/reactos/lib/ole32/tests/propvariant.c b/reactos/lib/ole32/tests/propvariant.c deleted file mode 100644 index 9cb71adf8f9..00000000000 --- a/reactos/lib/ole32/tests/propvariant.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * PropVariant Tests - * - * Copyright 2004 Robert Shearman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "windows.h" - -HRESULT WINAPI PropVariantCopy(PROPVARIANT*,const PROPVARIANT*); -HRESULT WINAPI PropVariantClear(PROPVARIANT*); - -#include "wine/test.h" - -#ifdef NONAMELESSUNION -# define U(x) (x).u -#else -# define U(x) (x) -#endif - -struct valid_mapping -{ - BOOL simple; - BOOL with_array; - BOOL with_vector; - BOOL byref; -} valid_types[] = -{ - { TRUE , FALSE, FALSE, FALSE }, /* VT_EMPTY */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_NULL */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_I2 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_I4 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_R4 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_R8 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_CY */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_DATE */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_BSTR */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_DISPATCH */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_ERROR */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_BOOL */ - { FALSE, FALSE, TRUE , FALSE }, /* VT_VARIANT */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_UNKNOWN */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_DECIMAL */ - { FALSE, FALSE, FALSE, FALSE }, /* 15 */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_I1 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_UI1 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_UI2 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_UI4 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_I8 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_UI8 */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_INT */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_UINT */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_VOID */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_HRESULT */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_PTR */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_SAFEARRAY */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_CARRAY */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_USERDEFINED */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_LPSTR */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_LPWSTR */ - { FALSE, FALSE, FALSE, FALSE }, /* 32 */ - { FALSE, FALSE, FALSE, FALSE }, /* 33 */ - { FALSE, FALSE, FALSE, FALSE }, /* 34 */ - { FALSE, FALSE, FALSE, FALSE }, /* 35 */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_RECORD */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_INT_PTR */ - { FALSE, FALSE, FALSE, FALSE }, /* VT_UINT_PTR */ - { FALSE, FALSE, FALSE, FALSE }, /* 39 */ - { FALSE, FALSE, FALSE, FALSE }, /* 40 */ - { FALSE, FALSE, FALSE, FALSE }, /* 41 */ - { FALSE, FALSE, FALSE, FALSE }, /* 42 */ - { FALSE, FALSE, FALSE, FALSE }, /* 43 */ - { FALSE, FALSE, FALSE, FALSE }, /* 44 */ - { FALSE, FALSE, FALSE, FALSE }, /* 45 */ - { FALSE, FALSE, FALSE, FALSE }, /* 46 */ - { FALSE, FALSE, FALSE, FALSE }, /* 47 */ - { FALSE, FALSE, FALSE, FALSE }, /* 48 */ - { FALSE, FALSE, FALSE, FALSE }, /* 49 */ - { FALSE, FALSE, FALSE, FALSE }, /* 50 */ - { FALSE, FALSE, FALSE, FALSE }, /* 51 */ - { FALSE, FALSE, FALSE, FALSE }, /* 52 */ - { FALSE, FALSE, FALSE, FALSE }, /* 53 */ - { FALSE, FALSE, FALSE, FALSE }, /* 54 */ - { FALSE, FALSE, FALSE, FALSE }, /* 55 */ - { FALSE, FALSE, FALSE, FALSE }, /* 56 */ - { FALSE, FALSE, FALSE, FALSE }, /* 57 */ - { FALSE, FALSE, FALSE, FALSE }, /* 58 */ - { FALSE, FALSE, FALSE, FALSE }, /* 59 */ - { FALSE, FALSE, FALSE, FALSE }, /* 60 */ - { FALSE, FALSE, FALSE, FALSE }, /* 61 */ - { FALSE, FALSE, FALSE, FALSE }, /* 62 */ - { FALSE, FALSE, FALSE, FALSE }, /* 63 */ - { TRUE , FALSE, TRUE , FALSE }, /* VT_FILETIME */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_BLOB */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_STREAM */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_STORAGE */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_STREAMED_OBJECT */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_STORED_OBJECT */ - { TRUE , FALSE, FALSE, FALSE }, /* VT_BLOB_OBJECT */ - { TRUE , FALSE, TRUE , FALSE } /* VT_CF */ -}; - -static const char* wine_vtypes[VT_CLSID+1] = -{ - "VT_EMPTY","VT_NULL","VT_I2","VT_I4","VT_R4","VT_R8","VT_CY","VT_DATE", - "VT_BSTR","VT_DISPATCH","VT_ERROR","VT_BOOL","VT_VARIANT","VT_UNKNOWN", - "VT_DECIMAL","15","VT_I1","VT_UI1","VT_UI2","VT_UI4","VT_I8","VT_UI8", - "VT_INT","VT_UINT","VT_VOID","VT_HRESULT","VT_PTR","VT_SAFEARRAY", - "VT_CARRAY","VT_USERDEFINED","VT_LPSTR","VT_LPWSTR","32","33","34","35", - "VT_RECORD","VT_INT_PTR","VT_UINT_PTR","39","40","41","42","43","44","45", - "46","47","48","49","50","51","52","53","54","55","56","57","58","59","60", - "61","62","63","VT_FILETIME","VT_BLOB","VT_STREAM","VT_STORAGE", - "VT_STREAMED_OBJECT","VT_STORED_OBJECT","VT_BLOB_OBJECT","VT_CF","VT_CLSID" -}; - -static void test_validtypes() -{ - PROPVARIANT propvar; - HRESULT hr; - unsigned int i; - - memset(&propvar, 0, sizeof(propvar)); - - for (i = 0; i < sizeof(valid_types)/sizeof(valid_types[0]); i++) - { - propvar.vt = i; - hr = PropVariantClear(&propvar); - ok(valid_types[i].simple == !(hr == STG_E_INVALIDPARAMETER), - "PropVariantClear(%s) should have returned 0x%08lx, but returned 0x%08lx\n", - wine_vtypes[i], - valid_types[i].simple ? S_OK : STG_E_INVALIDPARAMETER, hr); - - propvar.vt = i | VT_ARRAY; - hr = PropVariantClear(&propvar); - ok(valid_types[i].with_array == !(hr == STG_E_INVALIDPARAMETER), - "PropVariantClear(%s|VT_ARRAY) should have returned 0x%08lx, but returned 0x%08lx\n", - wine_vtypes[i], - valid_types[i].with_array ? S_OK : STG_E_INVALIDPARAMETER, hr); - - propvar.vt = i | VT_VECTOR; - hr = PropVariantClear(&propvar); - ok(valid_types[i].with_vector == !(hr == STG_E_INVALIDPARAMETER), - "PropVariantClear(%s|VT_VECTOR) should have returned 0x%08lx, but returned 0x%08lx\n", - wine_vtypes[i], - valid_types[i].with_vector ? S_OK : STG_E_INVALIDPARAMETER, hr); - - propvar.vt = i | VT_BYREF; - hr = PropVariantClear(&propvar); - ok(valid_types[i].byref == !(hr == STG_E_INVALIDPARAMETER), - "PropVariantClear(%s|VT_BYREF) should have returned 0x%08lx, but returned 0x%08lx\n", - wine_vtypes[i], - valid_types[i].byref ? S_OK : STG_E_INVALIDPARAMETER, hr); - } -} - -static void test_copy() -{ - static const char szTestString[] = "Test String"; - static const WCHAR wszTestString[] = {'T','e','s','t',' ','S','t','r','i','n','g',0}; - PROPVARIANT propvarSrc; - PROPVARIANT propvarDst; - HRESULT hr; - - propvarSrc.vt = VT_BSTR; - U(propvarSrc).bstrVal = SysAllocString(wszTestString); - - hr = PropVariantCopy(&propvarDst, &propvarSrc); - ok(hr == S_OK, "PropVariantCopy(...VT_BSTR...) failed\n"); - ok(!lstrcmpW(U(propvarSrc).bstrVal, U(propvarDst).bstrVal), "BSTR not copied properly\n"); - hr = PropVariantClear(&propvarSrc); - ok(hr == S_OK, "PropVariantClear(...VT_BSTR...) failed\n"); - hr = PropVariantClear(&propvarDst); - ok(hr == S_OK, "PropVariantClear(...VT_BSTR...) failed\n"); - - propvarSrc.vt = VT_LPWSTR; - U(propvarSrc).pwszVal = (LPWSTR)wszTestString; - hr = PropVariantCopy(&propvarDst, &propvarSrc); - ok(hr == S_OK, "PropVariantCopy(...VT_LPWSTR...) failed\n"); - ok(!lstrcmpW(U(propvarSrc).pwszVal, U(propvarDst).pwszVal), "Wide string not copied properly\n"); - hr = PropVariantClear(&propvarDst); - ok(hr == S_OK, "PropVariantClear(...VT_LPWSTR...) failed\n"); - memset(&propvarSrc, 0, sizeof(propvarSrc)); - - propvarSrc.vt = VT_LPSTR; - U(propvarSrc).pszVal = (LPSTR)szTestString; - hr = PropVariantCopy(&propvarDst, &propvarSrc); - ok(hr == S_OK, "PropVariantCopy(...VT_LPSTR...) failed\n"); - ok(!strcmp(U(propvarSrc).pszVal, U(propvarDst).pszVal), "String not copied properly\n"); - hr = PropVariantClear(&propvarDst); - ok(hr == S_OK, "PropVariantClear(...VT_LPSTR...) failed\n"); - memset(&propvarSrc, 0, sizeof(propvarSrc)); -} - -START_TEST(propvariant) -{ - test_validtypes(); - test_copy(); -} diff --git a/reactos/lib/ole32/tests/storage32.c b/reactos/lib/ole32/tests/storage32.c deleted file mode 100644 index 24cb512852e..00000000000 --- a/reactos/lib/ole32/tests/storage32.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Unit tests for OLE storage - * - * Copyright (c) 2004 Mike McCormack - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#define COBJMACROS - -#include "wine/test.h" -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "ole2.h" -#include "objidl.h" -#include "initguid.h" - -DEFINE_GUID( test_stg_cls, 0x88888888, 0x0425, 0x0000, 0,0,0,0,0,0,0,0); - -void test_hglobal_storage_stat(void) -{ - ILockBytes *ilb = NULL; - IStorage *stg = NULL; - HRESULT r; - STATSTG stat; - DWORD mode, refcount; - - r = CreateILockBytesOnHGlobal( NULL, TRUE, &ilb ); - ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n"); - - mode = STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE;/*0x1012*/ - r = StgCreateDocfileOnILockBytes( ilb, mode, 0, &stg ); - ok( r == S_OK, "CreateILockBytesOnHGlobal failed\n"); - - r = WriteClassStg( stg, &test_stg_cls ); - ok( r == S_OK, "WriteClassStg failed\n"); - - memset( &stat, 0, sizeof stat ); - r = IStorage_Stat( stg, &stat, 0 ); - - ok( stat.pwcsName == NULL, "storage name not null\n"); - ok( stat.type == 1, "type is wrong\n"); -#ifndef __REACTOS__ - todo_wine { - ok( stat.grfMode == 0x12, "grf mode is incorrect\n"); - } -#endif - ok( !memcmp(&stat.clsid, &test_stg_cls, sizeof test_stg_cls), "CLSID is wrong\n"); - - refcount = IStorage_Release( stg ); - ok( refcount == 0, "IStorage refcount is wrong\n"); - refcount = ILockBytes_Release( ilb ); - ok( refcount == 0, "ILockBytes refcount is wrong\n"); -} - -START_TEST(storage32) -{ - test_hglobal_storage_stat(); -} diff --git a/reactos/lib/ole32/tests/testlist.c b/reactos/lib/ole32/tests/testlist.c deleted file mode 100644 index 8d3b343b864..00000000000 --- a/reactos/lib/ole32/tests/testlist.c +++ /dev/null @@ -1,27 +0,0 @@ -/* Automatically generated file; DO NOT EDIT!! */ - -/* stdarg.h is needed for Winelib */ -#include -#include -#include -#include "windef.h" -#include "winbase.h" - -extern void func_propvariant(void); -extern void func_storage32(void); - -struct test -{ - const char *name; - void (*func)(void); -}; - -static const struct test winetest_testlist[] = -{ - { "propvariant", func_propvariant }, - { "storage32", func_storage32 }, - { 0, 0 } -}; - -#define WINETEST_WANT_MAIN -#include "wine/test.h" diff --git a/reactos/lib/ole32/version.rc b/reactos/lib/ole32/version.rc deleted file mode 100644 index e498134858e..00000000000 --- a/reactos/lib/ole32/version.rc +++ /dev/null @@ -1,24 +0,0 @@ -/* - * version information for ole32.dll - * - * Copyright (C) 2003 John K. Hohm - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#define WINE_OLESELFREGISTER -#define WINE_FILENAME_STR "ole32.dll" - -#include diff --git a/reactos/lib/ole32/winehq2ros.patch b/reactos/lib/ole32/winehq2ros.patch deleted file mode 100644 index c993a2d5cea..00000000000 --- a/reactos/lib/ole32/winehq2ros.patch +++ /dev/null @@ -1,67 +0,0 @@ -Index: ifs.h -=================================================================== -RCS file: /home/wine/wine/dlls/ole32/ifs.h,v -retrieving revision 1.13 -diff -u -r1.13 ifs.h ---- ifs.h 5 Oct 2004 04:16:21 -0000 1.13 -+++ ifs.h 6 Dec 2004 10:15:06 -0000 -@@ -33,8 +33,7 @@ - * IMalloc16 interface - */ - --typedef struct IMalloc16 IMalloc16, *LPMALLOC16; -- -+#undef INTERFACE - #define INTERFACE IMalloc16 - DECLARE_INTERFACE_(IMalloc16,IUnknown) - { -@@ -52,14 +51,14 @@ - }; - #undef INTERFACE - -+typedef struct IMalloc16 *LPMALLOC16; -+ - /**********************************************************************/ - - extern LPMALLOC16 IMalloc16_Constructor(); - - /**********************************************************************/ - --typedef struct ILockBytes16 *LPLOCKBYTES16, ILockBytes16; -- - #define INTERFACE ILockBytes16 - DECLARE_INTERFACE_(ILockBytes16,IUnknown) - { -@@ -95,8 +94,6 @@ - DWORD reserved; - } STATSTG16; - --typedef struct IStream16 IStream16, *LPSTREAM16; -- - #define INTERFACE IStream16 - DECLARE_INTERFACE_(IStream16,ISequentialStream) - { -@@ -123,8 +120,6 @@ - /**********************************************************************/ - - typedef OLECHAR16 **SNB16; -- --typedef struct IStorage16 IStorage16, *LPSTORAGE16; - - #define INTERFACE IStorage16 - DECLARE_INTERFACE_(IStorage16,IUnknown) -Index: oleproxy.c -=================================================================== -RCS file: /home/wine/wine/dlls/ole32/oleproxy.c,v -retrieving revision 1.23 -diff -u -r1.23 oleproxy.c ---- oleproxy.c 7 Oct 2004 03:06:49 -0000 1.23 -+++ oleproxy.c 6 Dec 2004 10:15:06 -0000 -@@ -38,6 +38,7 @@ - - #include - #include -+#include - #include - #include -